A critical reentrancy vulnerability has been identified in the PriorityPool.sol contract of the stake.link platform. This vulnerability arises due to the absence of reentrancy guards in key functions that perform state updates followed by external calls. An attacker can exploit this flaw to manipulate the contract's state and potentially drain funds, leading to significant financial losses and compromising the platform's integrity.
PriorityPool.solThe PriorityPool.sol contract lacks proper reentrancy protection in its deposit(), _deposit(), withdraw(), and _withdraw() functions. These functions update state variables and subsequently perform external calls without any safeguards against reentrant calls.
A malicious contract can exploit this vulnerability by re-entering the deposit() function during an external token transfer. Here's how the exploit unfolds:
Explanation:
The ReentrantToken contract overrides the transfer function.
When transferring tokens to the PriorityPool, it sets attackInitiated to true and calls back into the deposit() function.
This reentrant call occurs before the initial deposit() execution completes, allowing the attacker to manipulate state variables multiple times within a single transaction.
By re-entering the deposit() function during the token transfer, the attacker can repeatedly adjust critical state variables such as totalQueued and accountQueuedTokens.
Explanation:
The ReentrantAttack contract initiates the attack by calling the vulnerable deposit() function.
During the safeTransfer in the PriorityPool, the overridden transfer function in ReentrantToken is invoked.
This triggers the onTokenTransfer callback, which re-enters the deposit() function, allowing the attacker to manipulate the contract's state repeatedly within the same transaction.
Through this exploit, the attacker can:
Increase totalQueued: Manipulate the total queued tokens, allowing for unauthorized withdrawals.
Alter accountQueuedTokens: Adjust individual account queues to withdraw more tokens than legitimately entitled.
Drain Funds: Extract more tokens than deposited, leading to significant financial losses for the platform and its users.
Financial Loss: Unauthorized withdrawal of tokens can lead to substantial financial damage, eroding user trust and platform credibility.
State Corruption: Inconsistent state variables disrupt the contract's functionality, potentially causing denial of service or other unintended behaviors.
Reputation Damage: Successful exploitation can tarnish the platform's reputation, making it a target for further attacks and reducing user participation.
Manual Review
To mitigate the identified reentrancy vulnerability in PriorityPool.sol, implement the following measures:
Utilize OpenZeppelin's ReentrancyGuard to prevent reentrant calls in vulnerable functions.
Explanation:
The nonReentrant modifier ensures that a function cannot be called while it is still executing, effectively preventing reentrant calls.
Ensure that all state changes occur before making any external calls to minimize the risk of reentrancy.
Explanation:
Checks: Validate inputs and conditions.
Effects: Update state variables.
Interactions: Perform external calls, such as token transfers, after state updates.
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.