Need help with Ethernaut level 27: Good Samaritan

I tried a bunch of things to bubble up the NotEnoughBalance() error from INotifyable(dest_).notify(amount_) function to the catch block in GoodSamaritan contract, but none of them seem to work.

My best guess is this attacker contract:

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;

interface IGS {
    function requestDonation() external returns (bool);
}

contract Notifyable {
    address public gs = 0x4EFa9A4f7617D7331cDE4D04ee9990DCEE71d3Bd; // GoodSamaritan contract instance

    // error NotEnoughBalance();

    function attackGS() external {
        IGS(gs).requestDonation();
    }

    function notify(uint256 _amount) external {
        revert("NotEnoughBalance()");
    }
}

On calling attackGS(), the txn successfully completes (after doing an internal revert as expected) but Wallet contract is not drained.
Also, on uncommenting error NotEnoughBalance(); and replacing revert("NotEnoughBalance()") with revert NotEnoughBalance(), the txn actually reverts and the catch block in GoodSamaritan contract is not able to catch it.

Would appreciate any help on this one.
Thanks.

Hi @smitrajput. You are on the right path. A hint for you (without revealing the solution):

In this flow you are describing, not only one but two reverts are happening (the second one is the one the catch block is unable to catch).

Hope this helps!

2 Likes

Nice catch, thanks a lot!

1 Like