token transfers in LiquidityReserve and Staking contract don’t support deflationary ERC20 tokens, and user funds can be lost if stacking token was deflationary
The contracts stake and addLiquidity functions transfer tokens from the user and assume the full amount is received, but if the token is deflationary (charges a fee on transfer), the contract receives less than the requested amount while still minting or crediting the full amount to the user. This can cause other stakers to lose funds because the user receives more than they contributed.
Originally disclosed on Code4rena
Submitted by unforgiven, also found by hake, robee, and TrungOre
Impact
If the token is deflationary then contract will receive less token that requested amount but contract don’t check for the real transferred amount. because this is happening in receiving stacking_token in addLiquidity() of LiquidityReserve and stake() of Staking then those logics for minting YIELDY_TOKEN or LP token is wrong. (contract receive less than amount but mint or transfer amount to user). This can cause other users which staked to lose funds.
Proof of Concept
This is the related code where transfer happens (stake() and addLiquidity()):
function stake(uint256 _amount, address _recipient) public {
// if override staking, then don't allow stake
require(!isStakingPaused, "Staking is paused");
// amount must be non zero
require(_amount > 0, "Must have valid amount");
uint256 yieldyTotalSupply = IYieldy(YIELDY_TOKEN).totalSupply();
// Don't rebase unless tokens are already staked or could get locked out of staking
if (yieldyTotalSupply > 0) {
rebase();
}
IERC20Upgradeable(STAKING_TOKEN).safeTransferFrom(
msg.sender,
address(this),
_amount
);
Claim storage info = warmUpInfo[_recipient];
// if claim is available then auto claim tokens
if (_isClaimAvailable(_recipient)) {
claim(_recipient);
}
_depositToTokemak(_amount);
// skip adding to warmup contract if period is 0
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);
}
function addLiquidity(uint256 _amount) external {
require(isReserveEnabled, "Not enabled yet");
uint256 stakingTokenBalance = IERC20Upgradeable(stakingToken).balanceOf(
address(this)
);
uint256 rewardTokenBalance = IERC20Upgradeable(rewardToken).balanceOf(
address(this)
);
uint256 lrFoxSupply = totalSupply();
uint256 coolDownAmount = IStaking(stakingContract)
.coolDownInfo(address(this))
.amount;
uint256 totalLockedValue = stakingTokenBalance +
rewardTokenBalance +
coolDownAmount;
uint256 amountToMint = (_amount * lrFoxSupply) / totalLockedValue;
IERC20Upgradeable(stakingToken).safeTransferFrom(
msg.sender,
address(this),
_amount
);
_mint(msg.sender, amountToMint);
}
As you can see contract transfers amount of STAKE_TOKEN and assumes it is going to receive that amount and then mint the same amount of YIELDY_TOKEN or LP token. So user receive more funds which belongs to other users. protocol logics are not suitable for deflationary tokens and funds would be lost.
Tools Used
VIM
Recommended Mitigation Steps
Check the real amount of tokens that the contract receives.
toshiSat (Yieldy) acknowledged and commented:
We will not be supporting deflationary tokens in Yieldy. We will document this.
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 contracts do not check the actual balance increase after a safeTransferFrom, so they mint or credit the requested amount even when fewer tokens are received due to a transfer fee.
Impact
If the staking token is deflationary, users can receive more YIELDY or LP tokens than they should, potentially causing other stakers to lose funds.
What the attacker needed
The staking token is deflationary
The fix
The contracts should check the actual amount of tokens received after the transfer and use that amount for minting or crediting, or explicitly document that deflationary tokens are not supported.
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.
Some tokens take a small fee when they are transferred, so the receiver gets less than the sender sent. The contracts here assume they receive the full amount and give the user credit for the full amount, which means the user gets more than they actually put in. This can take funds away from other users who have staked their tokens.
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.