It’s possible to perform DOS and fund lose in Stacking by transferring tokens directly to contract
The Staking contract's rebase function calls Yieldy.rebase with a profit derived from the contract's token balance, and if the ratio of rebasing credits to updated total supply becomes zero the call reverts. An attacker could send tokens directly to the Staking contract to make that ratio zero, causing most Staking functions to revert, or make it very low so rounding errors lose user funds.
Originally disclosed on Code4rena
Submitted by unforgiven
Impact
Function rebase() in contract Staking calls Yieldy.rebase(profit, ) and Yieldy.rebase(profit, ) would revert if rebasingCredits / updatedTotalSupply was equal to 0. it’s possible to transfer some STAKING_TOKEN directly to Stacking contract before or after deployment of Staking and make rebasingCredits / updatedTotalSupply equal to 0, and then most of the functionalities of Staking would not work because they call rebase() which will revert. it’s possible to perform this DOS for any token by transferring some tokens STAKING_TOKEN to contract address and then staking 1 wei in contract. or for tokens with low precisions and low price it’s even possible to perform when totalSupply() of Yieldy is low.
Also attacker can only make rebasingCredits / updatedTotalSupply too low and so rounding error would be significant when rebasingCredits / updatedTotalSupply gets too low and users funds would be lost because of rounding error.
Proof of Concept
This is rebase() code in Yieldy:
function rebase(uint256 _profit, uint256 _epoch)
external
onlyRole(REBASE_ROLE)
{
uint256 currentTotalSupply = _totalSupply;
require(_totalSupply > 0, "Can't rebase if not circulating");
if (_profit == 0) {
emit LogSupply(_epoch, block.timestamp, currentTotalSupply);
emit LogRebase(_epoch, 0, getIndex());
} else {
uint256 updatedTotalSupply = currentTotalSupply + _profit;
if (updatedTotalSupply > MAX_SUPPLY) {
updatedTotalSupply = MAX_SUPPLY;
}
rebasingCreditsPerToken = rebasingCredits / updatedTotalSupply;
require(rebasingCreditsPerToken > 0, "Invalid change in supply");
_totalSupply = updatedTotalSupply;
_storeRebase(updatedTotalSupply, _profit, _epoch);
}
}
As you can see if rebasingCredits / updatedTotalSupply == 0 then the code will revert. updatedTotalSupply is equal to _totalSupply + _profit and rebasingCredits is wad in the first. Yieldy.rebase(profit,) is called by Staking.rebase():
function rebase() public {
// we know about the issues surrounding block.timestamp, using it here will not cause any problems
if (epoch.endTime <= block.timestamp) {
IYieldy(YIELDY_TOKEN).rebase(epoch.distribute, epoch.number);
epoch.endTime = epoch.endTime + epoch.duration;
epoch.timestamp = block.timestamp;
epoch.number++;
uint256 balance = contractBalance();
uint256 staked = IYieldy(YIELDY_TOKEN).totalSupply();
if (balance <= staked) {
epoch.distribute = 0;
} else {
epoch.distribute = balance - staked;
}
}
}
As you can see the value of _profit is set to epoch.distribute which is contractBalance() - IYieldy(YIELDY_TOKEN).totalSupply() and contractBalance() is sum of STAKING_TOKEN and TOKE balance of Staking contract. so if attacker transfers X amount of STAKCING_TOKEN directly to Staking contract then the value of _profit which is going to send to Yieldy.rebase(profit,) would be higher than X. to exploit this attacker call stake(1 wei) after Staking deployment and then transfer STAKING_TOKEN directly to contract. then the value of rebasingCredits in Yieldy would be 2 wad and the value of _profit sent to Yieldy.rebase(profit,) would be bigger than 2 wad and rebasingCredits / updatedTotalSupply would be 0 and from now on all calls to Staking.rebase() would revert and that means functions Stake() and instantUnstakeReserve() and instantUnstakeCurve() wouldnt work anymore.
It’s possible to perform this attack for low precision tokens with low price STAKING_TOKEN too. the only thing attacker needs to do is that in early stage of Staking deployment sends more than rebasingCredits of STAKING_TOKEN token directly to Staking contract address. then in rebase() contract send that amount as profit to Yieldy.rebase() and that call would revert which will cause most of the logics of Staking to revert and not work.
and when rebasingCredits / updatedTotalSupply is low, the rounding error would be high enough that the compounding yield won’t show itself. attacker can make rebasingCredits / updatedTotalSupply too low but not 0 and from then user’s funds would be lost because of rounding error (wrong number of Yieldy token would be mint for user).
Tools Used
VIM
Recommended Mitigation Steps
The default initial value of rebasingCredits should be very high that attacker couldn’t perform this attack.
toshiSat (Yieldy) acknowledged and commented:
rebasingCreditsis in credits andupdatedTotalSupplyis in token amounts. So if even a small amount is staked, the attacker will have to send a large amount to go through with this attack vector for no financial gain.This seems like a low priority issue mainly because user funds won’t get lost as if this were to occur then most likely no one has staked and the worst case scenario we will redeploy the contract. Also, we will be staking on every yieldy as we deploy.
I think we would like to eventually solve this, but for now this seems like it won’t fall in our list of fixes for this iteration.
JasoonS (judge) decreased severity to Medium:
Downgrading to medium.
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 rebase profit is calculated from the contract's raw token balance rather than tracked deposits, so unsolicited transfers inflate the profit and drive the credits-to-supply ratio to zero.
Impact
Most Staking functions that call rebase would revert, and a low but non-zero ratio could cause rounding errors that lose user funds; the project acknowledged the issue but considered it low priority and said they would redeploy if it occurred.
What the attacker needed
Ability to transfer STAKING_TOKEN to the contract; Staking contract deployed; rebase epoch has ended
The fix
The default initial value of rebasingCredits should be set very high so the attacker cannot drive the ratio to zero.
How it was found
- Stake a tiny amount (1 wei) in the Staking contract after deployment.
- Transfer STAKING_TOKEN directly to the Staking contract address.
- Wait for the rebase epoch to end so Staking.rebase() runs.
- Observe that Yieldy.rebase reverts because the credits-to-supply ratio is zero, breaking Staking functions.
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 earn rewards. It regularly recalculates rewards by calling another contract, and that call fails if a certain ratio becomes zero. Because anyone can send tokens straight to the staking contract, an attacker can push that ratio to zero and break the staking features for everyone.
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.