Tidal Finance Logic Error Bug Fix Review
A logic error in Tidal Finance's staking contract allowed a malicious user to claim more rewards than they were entitled to. The attacker could deposit after a payout was finished and then call doPayout to increase their reward amount without a corresponding reward debt.
immunefi.com
Published on immunefi.com
Whitehat Csanuragjain submitted a critical vulnerability in Tidal Finance to Immunefi on July 31, 2021. The vulnerability was a logic error that permitted a malicious user to claim more rewards from staking than they were entitled to.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the reward debt variable was not updated after a payout was finished, so it remained zero and the contract could not tell that rewards had already been allocated.
Impact
The attacker could claim more rewards than they were entitled to, but the exact amount is unclear because it depends on accumulated rewards and pool share; the exploit cannot be run repeatedly.
What the attacker needed
A staking contract on Polygon; a payout for an asset index is finished; attacker deposits after payout is finished
The fix
The fix duplicated the reward debt update line and moved it into the if statement that checks if the payout is finished, so the reward debt is updated after payout and does not remain zero.
How it was found
- The admin initiates a payout for Asset Index 0.
- The four payout functions are called in order and the payout is marked as finished.
- A malicious user enters the pool and deposits an arbitrary amount.
- After some time, the malicious user calls doPayout with Asset Index 0 and their wallet address.
- The user's rewardAmount increases but rewardDebt remains 0, so they receive more rewards than entitled.
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 write-up has not been written yet. The Original tab links to the source.
This is a bug in a smart contract that handles staking rewards. Normally, the contract tracks how much reward a user has already been given so it doesn't pay them twice. Here, a mistake meant that tracking number stayed at zero, so the contract thought the user was owed more than they really were.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.