The Vault.sol contract within the stake.link platform contains a critical reentrancy vulnerability in its _depositLiquidity and _withdrawLiquidity functions. These functions perform external calls to strategy contracts without implementing reentrancy protection or following the checks-effects-interactions pattern. This flaw can be exploited by malicious or compromised strategy contracts to manipulate crucial state variables, potentially leading to unauthorized token minting, manipulation of staking balances, or draining of funds.
_depositLiquidity FunctionExplanation:
The _depositLiquidity function iterates through the strategies array and calls the deposit function on each strategy contract.
These external calls are made before updating any critical state variables, such as totalStaked.
There is no reentrancy guard in place, allowing a malicious strategy to re-enter the Vault contract during these external calls.
_withdrawLiquidity FunctionExplanation:
Similar to _depositLiquidity, the _withdrawLiquidity function makes external calls to strategy contracts.
These calls occur before updating state variables like totalStaked.
The absence of reentrancy protection allows for potential reentrant attacks during withdrawals.
Explanation:
A MaliciousStrategy contract is created that implements the IStrategy interface.
In its deposit and withdraw functions, it calls back into the Vault contract's deposit and withdraw functions, enabling reentrancy.
Explanation:
The MaliciousStrategy is deployed with references to the Vault contract and the attacker's address.
The malicious strategy is added to the Vault's strategies, making the Vault interact with it during deposits and withdrawals.
Explanation:
The attacker initiates a deposit, triggering the Vault to call strategy.deposit().
The MaliciousStrategy's deposit function re-enters the Vault's deposit function before totalStaked is updated.
This allows the attacker to manipulate totalStaked and mint extra stLINK tokens.
Explanation:
After the attack, totalStaked is checked to verify if it has been improperly increased.
An inflated totalStaked indicates successful exploitation of the reentrancy vulnerability.
Financial Loss: Attackers can manipulate totalStaked, mint additional stLINK tokens, or withdraw more funds than permitted, leading to significant financial losses.
Token Integrity: Unauthorized minting or burning of tokens undermines the token's integrity and trust within the ecosystem.
Fund Drainage: Exploiting this vulnerability can result in draining funds from the contract, affecting all stakeholders.
Manual review
Implement ReentrancyGuard:
Import and Inherit:
Apply nonReentrant Modifier:
Follow Checks-Effects-Interactions Pattern:
Rearrange State Updates:
Update state variables before making external calls.
Example for deposit function:
Restrict Strategy Contracts:
Access Controls:
Ensure only trusted and audited strategy contracts can be added.
Modify the addStrategy function to include stringent checks.
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.