2023 | Medium | DeFi Security
Invest Pool
Objective of CTF¶
Your objective is to have a greater token balance than your initial balance.
QuillCTF Challenges - Invest Pool
Vulnerability Description¶
- We need to set
initialized
to true first, in order to usedeposit()
andwithdrawAll()
- The password can be obtained from Solidity Metadata (got hint from Discord)
- I used playground.sourcify.dev and got the password from https://ipfs.io/ipfs/QmU3YCRfRZ1bxDNnxB4LVNCUWLs26wVaqPoQSQ6RH2u86V (The metadata hash is base58 encoded) :D
tokenToShares()
andsharesToToken()
are calculated using the current token balance of the pool, and we can transfer tokens to the pool without callingdeposit()
. Therefore, we can manipulate the ratio of share to token
Attack Steps¶
initialize()
with the password from the metadata- The hacker deposits 1 token, then transfers 1e18 tokens to the pool directly. The current ratio of share to the token is 1: 1e18 + 1
- The user deposits 1000e18 tokens. Because of rounding down, the user can only receive 999 shares. Now the pool has 1000 shares and 1001e18 + 1 token. The current ratio of share to the token is about 1: 1001e15
- The hacker withdraws
Proof of Concept¶
最后更新:
2023年5月11日 22:54:00
Contributors: