Users at UNSTAKE_PERIOD can assist other users in unstaking tokens.
A user whose cooldown has almost expired can receive freshly staked tokens from another user and then unstake them immediately, because the weighted-average cooldown calculation lets the receiver's old cooldown dominate. This lets the receiver help another user bypass the intended unstake waiting period.
Submitted by cccz, also found by JC and gzeon
Consider the following scenario: Day 0: User A stakes 200 tokens and calls the cooldown function. At this time, user A’s cooldown is Day 0. Day 15: User B stakes 100 tokens, but then wants to unstake tokens. So user A said that he could assist user B in unstaking tokens, and this could be done by deploying a smart contract. In the smart contract deployed by user A, user B first needs to transfer 100 tokens to user A. In the _getNewReceiverCooldown function, _senderCooldown is Day 15 and receiverCooldown is Day 0, so the latest cooldown of user A is (100 * Day 15 + 200 * Day 0)/(100+200) = Day 5.
function _getNewReceiverCooldown(
uint256 senderCooldown,
uint256 amount,
address receiver,
uint256 receiverBalance
) internal view returns(uint256) {
uint256 receiverCooldown = cooldowns[receiver];
// If receiver has no cooldown, no need to set a new one
if(receiverCooldown == 0) return 0;
uint256 minValidCooldown = block.timestamp - (COOLDOWN_PERIOD + UNSTAKE_PERIOD);
// If last receiver cooldown is expired, set it back to 0
if(receiverCooldown < minValidCooldown) return 0;
// In case the given senderCooldown is 0 (sender has no cooldown, or minting)
uint256 _senderCooldown = senderCooldown < minValidCooldown ? block.timestamp : senderCooldown;
// If the sender cooldown is better, we keep the receiver cooldown
if(_senderCooldown < receiverCooldown) return receiverCooldown;
// Default new cooldown, weighted average based on the amount and the previous balance
return ((amount * _senderCooldown) + (receiverBalance * receiverCooldown)) / (amount + receiverBalance);
}
Since User A is still at UNSTAKE_PERIOD after receiving the tokens, User A unstakes 100 tokens and sends it to User B.
After calculation, we found that when user A has a balance of X and is at the edge of UNSTAKE_PERIOD, user A can assist in unstaking the X/2 amount of tokens just staked.
Proof of Concept
Recommended Mitigation Steps
After calculation, we found that the number of tokens that users at the edge of UNSTAKEPERIOD can assist in unstaking conforms to the following equation UNSTAKEPERIOD/COOLDOWNPERIOD = UNSTAKEAMOUNT/USERBALANCE, when COOLDOWNPERIOD remains unchanged, the smaller the UNSTAKEPERIOD, the less tokens the user can assist in unstaking, so UNSTAKEPERIOD can be adjusted to alleviate this situation.
Kogaroshi (Paladin) confirmed, resolved, and commented:
Reduced the Unstake Period to 2 days to reduce the possibility of such scenario. PaladinFinance/Paladin-Tokenomics#4
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the weighted-average cooldown formula gives too much weight to the receiver's nearly expired cooldown, so incoming tokens inherit a short cooldown instead of the sender's long one.
What the attacker needed
Attacker near end of unstake period; victim has freshly staked tokens; attacker deploys a helper contract
The fix
The unstake period was reduced to two days to make the scenario less likely.
How it was found
- User A stakes tokens and starts the cooldown on day 0.
- On day 15 user B stakes tokens and wants to unstake them.
- User A deploys a contract and user B transfers tokens to user A through it.
- The cooldown calculation blends B's day 15 cooldown with A's day 0 cooldown, giving A a short cooldown.
- User A unstakes the tokens and sends them back to user B.
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 report has not been written yet. The Original tab links to the source.
When you stake tokens, the system makes you wait before you can take them out again. This report shows that someone who has almost finished waiting can take in someone else's freshly staked tokens and then withdraw them straight away, effectively skipping the wait for that other person.
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.