deposit() function is open to reentrancy attacks
The deposit() function in Vault.sol calls external NFT minting functions that trigger a callback to the sender, allowing reentrancy before execution completes. An attacker could mint multiple NFTs for themselves and manipulate state variables like newShares or enter other functions such as withdraw.
Submitted by jayjonah8, also found by bugwriter001, camden, cccz, cmichel, danb, defsec, Fitraldys, harleythedog, hickuphh3, jayjonah8, kenzo, leastwood, onewayfunction, pedroais, and WatchPug
In Vault.sol the deposit() function is left wide open to reentrancy attacks. The function eventually calls \_createDeposit() => \_createClaim() which calls depositors.mint() which will then mint an NFT. When the NFT is minted the sender will receive a callback which can then be used to call the deposit() function again before execution is finished. An attacker can do this minting multiple NFT’s for themselves. claimers.mint() is also called in the same function which can also be used to call back into the deposit function before execution is complete. Since there are several state updates before and after NFT’s are minted this can be used to further manipulate the protocol like with newShares which is called before minting. This is not counting what an attacker can do with cross function reentrancy entering into several other protocol functions (like withdraw) before code execution is complete further manipulating the system.
Proof of Concept
- https://github.com/code-423n4/2022-01-sandclock/blob/main/sandclock/contracts/Vault.sol#L160
- https://github.com/code-423n4/2022-01-sandclock/blob/main/sandclock/contracts/Vault.sol#L470
- https://github.com/code-423n4/2022-01-sandclock/blob/main/sandclock/contracts/Vault.sol#L476
Recommended Mitigation Steps
Reentrancy guard modifiers should be placed on the deposit(), withdraw() and all other important protocol functions to prevent devastating attacks.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the deposit() function performs external calls to NFT minting functions before all state updates are complete, and lacks a reentrancy guard.
Impact
An attacker could mint multiple NFTs for themselves and manipulate protocol state, potentially entering other functions like withdraw before execution completes.
What the attacker needed
Ability to call deposit(); contract mints NFT to sender
The fix
Reentrancy guard modifiers should be placed on deposit(), withdraw() and all other important protocol functions.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Reentrancy is when a contract calls another contract, and that other contract calls back into the first one before the first call has finished. Here, the deposit function mints an NFT, which hands control to the sender, who can call deposit again and again to get extra NFTs or mess with the contract's internal numbers.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.