The deposit function violates the Checks-Effects-Interactions (CEI) security pattern. While this specific instance is not exploitable due to the code's structure, it represents a deviation from best practices and could lead to vulnerabilities during future code maintenance.
Normal Behavior: A user calls deposit, the contract calculates shares, pulls the user's tokens, and mints the shares to the user.
The Problem: The deposit function executes two external safeTransferFrom calls (Interactions) before it updates the vault's internal state by calling _mint (Effect). This is a clear violation of the CEI pattern and at first glance appears to open a reentrancy attack vector.
Likelihood: Low
An exploit is not possible.
Reason 1: The critical value, participantShares, is calculated and stored in a local variable before the external calls.
Reason 2: A re-entrant call while possible, cannot modify the original function's local variables. The original call will resume and mint the correct, pre-calculated number of shares, preventing state corruption.
Impact: Low
Impact 1: A successful reentrancy attack could manipulate the share calculation, allowing the attacker to mint an excessive number of shares
Impact 2: Breaking of the vault's accounting and could lead to a direct loss of funds for other users.
The following demonstrates that re-entrancy is possible but has no negative effect. It uses a single test contract that also acts as the malicious ERC20 token. The test triggers a re-entrant deposit call but asserts that the final state totalSupply and balanceOf(vault) is correct, proving the state was not corrupted.
The function should be refactored to strictly follow the Checks-Effects-Interactions pattern. This makes the code safer, easier to read, and aligns with security best practices, even though no exploit exists here.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.