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.
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
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.