Staking.sol#stake() DoS by staking 1 wei for the recipient when warmUpPeriod > 0
The stake function allows anyone to specify an arbitrary recipient, and when the warm-up period is greater than zero, a tiny deposit resets the recipient's warm-up expiry. An attacker could repeatedly push back the expiry for any user, preventing them from claiming their staked tokens.
Submitted by WatchPug, also found by BowTiedWardens, cccz, minhquanym, parashar, pashov, shung, and zzzitron
if (warmUpPeriod == 0) {
IYieldy(YIELDY_TOKEN).mint(_recipient, _amount);
} else {
// create a claim and mint tokens so a user can claim them once warm up has passed
warmUpInfo[_recipient] = Claim({
amount: info.amount + _amount,
credits: info.credits +
IYieldy(YIELDY_TOKEN).creditsForTokenBalance(_amount),
expiry: epoch.number + warmUpPeriod
});
IYieldy(YIELDY_TOKEN).mint(address(this), _amount);
}
Staking.sol#stake() is a public function and you can specify an arbitrary address as the _recipient.
When warmUpPeriod > 0, with as little as 1 wei of YIELDY_TOKEN, the _recipient’s warmUpInfo will be push back til epoch.number + warmUpPeriod.
Recommended Mitigation Steps
Consider changing to not allow deposit to another address when warmUpPeriod > 0.
Should be high right? Funds are locked. See https://github.com/code-423n4/2022-06-yieldy-findings/issues/245#issuecomment-1167616593
moose-code (judge) increased severity to High and commented:
Agree this should be high. The cost of the attack is negligible and could cause basic perpetual grievance on all users with one simple script.
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 stake function does not restrict deposits to other addresses when a warm-up period is active, allowing an attacker to overwrite the recipient's warm-up expiry with a minimal deposit.
Impact
An attacker could cause a denial of service for all users by repeatedly resetting their warm-up expiry with negligible cost, locking their funds indefinitely.
What the attacker needed
WarmUpPeriod > 0; attacker has 1 wei of YIELDY_TOKEN
The fix
The contract should be changed to disallow deposits to another address when the warm-up period is greater than zero.
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.
A staking contract lets people deposit tokens and later claim them after a waiting period. The deposit function lets you choose who receives the stake, and if a waiting period is active, even a tiny deposit resets that person's waiting timer. An attacker can keep resetting the timer for any user, so that user can never claim their tokens.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.