BANK [MISC]

Description:

Can you steal the bank’s money?

File:

pragma solidity ^0.7.0;

contract Bank {
    uint48 flag_cost = 50;
    uint48 amount_you_have = 0;
    uint48 loaned = 0;
    function deposit(uint48 amount) public payable {
        require(msg.sender==YOUR_WALLET_ADDRESS,"Please use the wallet provided to you"); // This is for security purposes
    require(amount==msg.value,"Please send exact amount");
        amount_you_have += amount;
    }
    function withdraw(uint48 amount) public payable {
        require(msg.sender==YOUR_WALLET_ADDRESS,"Please use the wallet provided to you"); // This is for security purposes
        require((amount) < amount_you_have, "You cannot withdraw what you do not have!");
        amount_you_have -= amount;
        msg.sender.call{value:amount}("");
    }

    function getMoney() public payable {
        // Used for deployment, can be safely ignored
    }
    function loan(uint48 amount) public payable {
        require(msg.sender==YOUR_WALLET_ADDRESS,"Please use the wallet provided to you"); // This is for security purposes
        loaned += amount;
        msg.sender.call{value:amount}("");
    }

    function isChallSolved() public view returns (bool solved) {
        if ((amount_you_have >= flag_cost) && (loaned == 0)) {
            return true;
        }
        else {
            return false;
        }
    }


}

Solution:

  • The goal of this challenge is to make the function isChallSolved() return true. Once achieved, the challenge will be completed. The function will check whether the balance of amount_you_have is greater than flag_cost and if the loan is zero.

    In this instance, they have provided the following details:

  • First, I checked the balance of the provided wallet and contract. If the wallet has sufficient funds to deposit 50 wei into the contract, the challenge will be solved upon deposit. Here is the script to check the balance:

  • After running the above code, I obtained my balance as follows:

  • We can see that the ETH balance of the wallet is much greater than 50 wei, which is also sufficient to cover the gas fee for calling the deposit() function. Once we call the deposit() function, the challenge will be solved.

  • Here is the script for calling the deposit() function:

Flag:

Last updated