Skip to content

Fix Ethernaut's Delegation exploitΒ #24

@leovct

Description

@leovct
$ forge test -vvv --match-contract Delegation                                                                                                                                                      
[⠊] Compiling...
No files changed, compilation skipped

Ran 1 test for test/Ethernaut/DelegationExploit.t.sol:DelegationExploit
[FAIL. Reason: assertion failed] testExploit() (gas: 37866)
Logs:
  Target contract deployed
  Current owner: 0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946
  New owner: 0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946
  Error: a == b not satisfied [address]
        Left: 0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946
       Right: 0x5Bf3eeB5560eEACC941C553320999006D27dD42b

Traces:
  [37866] DelegationExploit::testExploit()
    β”œβ”€ [2303] Delegation::owner() [staticcall]
    β”‚   └─ ← [Return] deployer: [0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946]
    β”œβ”€ [0] console::log("Current owner: %s", deployer: [0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946]) [staticcall]
    β”‚   └─ ← [Stop] 
    β”œβ”€ [0] VM::startPrank(exploiter: [0x5Bf3eeB5560eEACC941C553320999006D27dD42b])
    β”‚   └─ ← [Return] 
    β”œβ”€ [4983] Delegation::pwn()
    β”‚   β”œβ”€ [0] exploiter::pwn() [delegatecall]
    β”‚   β”‚   └─ ← [Stop] 
    β”‚   └─ ← [Stop] 
    β”œβ”€ [0] VM::stopPrank()
    β”‚   └─ ← [Return] 
    β”œβ”€ [303] Delegation::owner() [staticcall]
    β”‚   └─ ← [Return] deployer: [0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946]
    β”œβ”€ [0] console::log("New owner: %s", deployer: [0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946]) [staticcall]
    β”‚   └─ ← [Stop] 
    β”œβ”€ emit log(val: "Error: a == b not satisfied [address]")
    β”œβ”€ emit log_named_address(key: "      Left", val: deployer: [0xaE0bDc4eEAC5E950B67C6819B118761CaAF61946])
    β”œβ”€ emit log_named_address(key: "     Right", val: exploiter: [0x5Bf3eeB5560eEACC941C553320999006D27dD42b])
    β”œβ”€ [0] VM::store(VM: [0x7109709ECfa91a80626fF3989D68f67F5b1DD12D], 0x6661696c65640000000000000000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000000000000000000000000001)
    β”‚   └─ ← [Return] 
    └─ ← [Stop] 

Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 582.42Β΅s (94.83Β΅s CPU time)

Ran 1 test suite in 167.48ms (582.42Β΅s CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in test/Ethernaut/DelegationExploit.t.sol:DelegationExploit
[FAIL. Reason: assertion failed] testExploit() (gas: 37866)

Encountered a total of 1 failing tests, 0 tests succeeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions