Lucky Faucet

Personal Rating: Medium

This challenge is about another Ethereum smart contract.

Private key     :  0x98232553931a8017da5506efcb6e19783fcb4eb567f5669a63f799212242a462
Address         :  0x1051eb53BCBcceB0bf037791592720051C9A3a5E
Target contract :  0xA2CF6183f3482bd338E4912338b3bdcfCBf868aC
Setup contract  :  0x94D9eFd7E2C92648aF0787218A6948119b8C1d90
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.7.6;

import {LuckyFaucet} from "./LuckyFaucet.sol";

contract Setup {
    LuckyFaucet public immutable TARGET;

    uint256 constant INITIAL_BALANCE = 500 ether;

    constructor() payable {
        TARGET = new LuckyFaucet{value: INITIAL_BALANCE}();
    }

    function isSolved() public view returns (bool) {
        return address(TARGET).balance <= INITIAL_BALANCE - 10 ether;
    }
}

We can see that the initial account balance is 500 ether and the win condition that is checked by the isSolved() function requires the balance to be 490 or lower. This means that we have to send a negative amount to the wallet. Lets look at the contract:

Okay this looks a bit daunting at first, but we will figure this out.

With cast block -r http://<IP>:<PORT> we can get some more infos:

Our target is to set a negative value for amountToSend (-10 or less) to satisfy the win condition in Setup.sol

To realize this, we have this equation:

-10 = uint64(int256(blockhash(block.number - 1)) % (upperBound - lowerBound + 1) + lowerBound);

Through the setBounds function we control int64 _newLowerBound and int64 _newUpperBound

First we have to find out what int256(blockhash(block.number - 1)) is. Through the cast block command above we could determine the block number to be 1.

So we have int256(blockhash(1 - 1)) which should be 0

This gives us:

-10 = uint64(0 % (upperBound - lowerBound + 1) + lowerBound);

This should just be lowerbound. Maybe we can just set the lowerBound to a negative number and the upperBound to anything.

-> This did not work as the resulting value is unsigned and thus cannot be negative.

cast send --private-key 0x98232553931a8017da5506efcb6e19783fcb4eb567f5669a63f799212242a462 0xA2CF6183f3482bd338E4912338b3bdcfCBf868aC -r "http://94.237.54.161:50890" "setBounds(int64, int64)" 0 0

What worked in the end was to just call the sendRandomETH() very often to reduce the account balance. This is the script I used for it:

Last updated