This document explains the solution to the Tutori4l challenge presented in the Challenge.sol
contract.
The Tutori4l challenge involves interacting with a complex smart contract system that includes a PoolManager, a custom Hook, and the main Challenge contract. The goal is to drain the challenge contract of its ETH balance.
- Interact with the PoolManager contract to manipulate liquidity.
- Exploit the
arbitrary
function in the Challenge contract. - Fetch non-public immutable addresses from the challenge contract.
The solution involves several key steps:
-
Fetching non-public immutable addresses:
- Retrieve the bytecode of the challenge contract.
- Analyze the bytecode using tools like evm.codes to find the addresses being used.
-
Exploiting the
arbitrary
function:- Use the
arbitrary
function to call the PoolManager'sunlock
function. - Within the unlock callback, perform the following actions:
a. Mint
1 ether
curreny 0 to the exploit contract. b. Use thearbitrary
function again to callsettleFor
on the PoolManager which passes 1 ether to PoolManager c. Take the minted liquidity and burn it.
- Use the
-
Withdrawing the drained ETH to the player's address.
The key steps in the Solution.s.sol
script are:
-
Create an
Exploit
contract that handles the complex interactions. -
In the
unlockCallback
function of theExploit
contract:- Mint liquidity
- Call
arbitrary
on the challenge to executesettleFor
, which passed1 ether
to poolManager - Take and burn the minted liquidity
-
Use the
runIt
function to initiate the exploit:exploit.runIt(challenge, manager);
-
Withdraw the drained ETH:
exploit.withdraw(playerAddress);
A crucial part of this challenge was retrieving non-public immutable addresses from the challenge contract. This was accomplished by:
-
Fetching the bytecode of the challenge contract:
bytes memory contractCode = getContractCode(challengeAddress);
-
Analyzing the bytecode using tools like evm.codes to identify the addresses being used in the contract.
This step was essential for interacting correctly with the challenge contract and its associated components.