Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solution to Hats Challenge #2 by Santiago Quinteros (@santypk4)

This is a fork from the original hardhat project from the challenge

To run the exploit

npm run test

Explanation

By abusing self-destruct opcode an attacker can break the sync between the "totalSupply" and "totalShares" variables, responsible for transferring exceeding ether to the vault owner when call*ing the Redeem and Withdraw functions.

Combined with a reentrancy vulnerability in the aforementioned functions, an attacker could call withdraw several times until the smart contract balance becomes 0.

Possible solutions:

  1. Add a reentrancy guard to the withdraw and redeem functions
  2. Find a way to keep in sync the contract balance with the erc20 shares state variable

Original description below


Hats Challenge #2

Capture the Flag

The contract Vault.sol is an ERC4626-like vault customized to be used with ETH. It allows anyone to deposit ETH in the vault and get shares corresponding to the amount deposited. The shares are an ERC20 which can be freely used by users, functioning effectively just like Wrapped ETH. The shares can also be redeemed at any time for the corresponding underlying amount of ETH.

The Hats Challenge

The Vault.sol is deployed with the contract owning 1 ETH of the shares.

Your mission is to capture the flag by emptying the vault, then calling captureTheFlag with an address you control to prove that you have succeeded in completing the challenge, so that vault.flagHolder returns your address.

How to submit

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages