Skip to content
Smart contracts Audit finding Intermediate

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.

jayjonah8 Follow

Originally disclosed on Code4rena

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

Recommended Mitigation Steps

Reentrancy guard modifiers should be placed on the deposit(), withdraw() and all other important protocol functions to prevent devastating attacks.

ryuheimat (Sandclock) confirmed

The original report as published on Code4rena, by jayjonah8. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by jayjonah8

View all

18 more disclosed reports, best first.

More from Sandclock contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.