cooldown is set to 0 when the user sends all tokens to himself
The token contract resets a user's cooldown to zero when they transfer their entire balance to themselves, which unintentionally extends the lock period. An attacker could exploit this to freeze a victim's funds for an additional period, though the funds are not permanently locked.
Submitted by cccz, also found by hyh and Czar102
In the _beforeTokenTransfer function, cooldowns will be set to 0 when the user transfers all tokens to himself. Consider the following scenario: Day 0: The user stakes 100 tokens and calls the cooldown function. Day 10: the user wanted to unstake the tokens, but accidentally transferred all the tokens to himself, which caused the cooldown to be set to 0 and the user could not unstake.
Proof of Concept
HolyPaladinToken.sol#L891-L905
Recommended Mitigation Steps
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override {
if(from != address(0)) { //check must be skipped on minting
// Only allow the balance that is unlocked to be transfered
require(amount <= _availableBalanceOf(from), "hPAL: Available balance too low");
}
// Update user rewards before any change on their balance (staked and locked)
_updateUserRewards(from);
uint256 fromCooldown = cooldowns[from]; //If from is address 0x00...0, cooldown is always 0
if(from != to) {
// Update user rewards before any change on their balance (staked and locked)
_updateUserRewards(to);
// => we don't want a self-transfer to double count new claimable rewards
// + no need to update the cooldown on a self-transfer
uint256 previousToBalance = balanceOf(to);
cooldowns[to] = _getNewReceiverCooldown(fromCooldown, amount, to, previousToBalance);
// If from transfer all of its balance, reset the cooldown to 0
uint256 previousFromBalance = balanceOf(from);
if(previousFromBalance == amount && fromCooldown != 0) {
cooldowns[from] = 0;
}
}
}
Kogaroshi (Paladin) confirmed, resolved, and commented:
Issue fixed in the PR: PaladinFinance/Paladin-Tokenomics#2. Applying the recommended mitigation. An extra test for that scenario was added to the hPAL tests.
Based on additional information this doesn’t permanently lock user funds, but it does unintentionally extend the duration of the lock.
See issue #88:
This effectively means that user funds be frozen for an additional period, which is the difference between his former cooldown and current timestamp. There is no reason for that and it will go against user’s expectations.Therefore, I agree this should be a medium severity issue.
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
The _beforeTokenTransfer function does not skip the cooldown reset logic when the sender and receiver are the same address, so a self-transfer of the full balance triggers the reset.
Impact
The user's funds are not permanently locked but the lock duration is unintentionally extended, going against user expectations.
What the attacker needed
User has staked tokens and called cooldown; user transfers all tokens to self
The fix
The issue was fixed by applying the recommended mitigation, which skips the cooldown reset when the transfer is a self-transfer.
How it was found
- The user stakes 100 tokens and calls the cooldown function.
- After 10 days, the user transfers all tokens to himself.
- The cooldown is set to 0, preventing unstaking.
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.
This is a smart contract bug where a user's lock-up timer (cooldown) is accidentally reset to zero if they send all their tokens to their own address. Instead of unlocking, the timer restarts, so the user has to wait longer to access their funds. It's like resetting a countdown by mistake.
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.