Skip to content
Smart contracts Audit finding Intermediate

sponsor() function in open to reentrancy attacks

The sponsor() function in Vault.sol lacks a reentrancy guard and calls depositors.mint() before updating state, allowing an attacker to reenter and call mint() multiple times while the totalSponsored amount is only updated once.

jayjonah8 Follow

Originally disclosed on Code4rena

Submitted by jayjonah8, also found by camden

In Vault.sol the sponsor() function does not have a reentrancy guard allowing an attacker to reenter the function because the depositors.mint() function has as callback to the msg.sender. Since there are state updates after the call to depositors.mint() function this is especially dangerous. An attacker can make it so the totalSponsored amount is only updated once after calling mint() several times since the update takes place after the callback. The same will be true for the Sponsored event that is emitted.

Proof of Concept

https://github.com/code-423n4/2022-01-sandclock/blob/main/sandclock/contracts/Vault.sol#L244

Recommended Mitigation Steps

A reentrancy guard modifier should be added to the sponsor() function in Vault.sol

naps62 (Sandclock) confirmed and resolved:

Fixed in https://github.com/sandclock-org/solidity-contracts/pull/75

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

The sponsor() function performs an external call to depositors.mint() before updating state variables, and lacks a reentrancy guard.

Impact

An attacker could call mint() several times while the totalSponsored amount and the Sponsored event are only updated once, potentially minting more tokens than intended.

What the attacker needed

Attacker can call sponsor(); depositors.mint() calls back to attacker

The fix

A reentrancy guard modifier should be added to the sponsor() function, and the report states it was fixed.

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.

A reentrancy attack happens when a contract calls another contract before it finishes updating its own records. The other contract can call back into the first one and repeat an action, like minting tokens, before the first contract updates its totals. Here, the sponsor function mints tokens and only later updates the total sponsored amount, so an attacker could mint many times but have the total recorded only once.

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.