code-423n4 / 2022-01-sandclock-findings

0 stars 0 forks source link

Claimer can reenter contract on deposit withdrawal #85

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

kenzo

Vulnerability details

Upon withdrawal of deposit, the claimer will be called with onDepositBurned. This happens after the claimer shares have been updated, but before the underlying has been sent away from the contract. Therefore the claimer can reenter the contract, at an intermediary state where the invariants are not held.

Impact

Claimer can claim more yield than he deserves.

Proof of Concept

The withdraw function iterates on all deposits, and then sends underlying only at the end. For each deposit (while iterating), Sandclock first updates the shares state, and then calls onDepositBurned. So the claimer can reenter the vault after the shares have been updated but before underlying was sent.

POC for exploit:

Recommended Mitigation Steps

Usual reentrancy protection: conform with checks-effects-interaction pattern, or add reentrancy lock.

r2moon commented 2 years ago

duplicated with https://github.com/code-423n4/2022-01-sandclock-findings/issues/3