Unsecure transferFrom
The transferFrom function checks only the allowance, not the actual credit balance, so a user could transfer more than their credit balance and cause an underflow in the subtraction. This could allow the attacker to create credits out of thin air or break the contract's accounting.
Submitted by 0x1f8b, also found by 0xNineDec and StErMi
The security of the Yieldy contract is delegated to the compiler used.
Proof of Concept
The allowance of an account does not have to reflect the real balance of an account, however in the transferFrom method, it is the value that is checked in order to verify that the user has enough balance to make the transfer.
function transferFrom(
address _from,
address _to,
uint256 _value
) public override returns (bool) {
require(_allowances[_from][msg.sender] >= _value, "Allowance too low");
However, the real balance of the Yieldy contract is based on the calculation made by the creditsForTokenBalance method, so an underflow could be made in the subtraction of the balance of the from account.
uint256 creditAmount = creditsForTokenBalance(_value);
creditBalances[_from] = creditBalances[_from] - creditAmount;
creditBalances[_to] = creditBalances[_to] + creditAmount;
emit Transfer(_from, _to, _value);
This means that the security of the contract is delegated to the checks added by the compiler depending on the pragma used, it must be taken into account that these checks may appear and disappear in future versions of the compiler, so they must be checked at the level of smart contracts.
Affected source code:
Recommended Mitigation Steps
- Check that the from account has a
creditAmountbalance.
toshiSat (Yieldy) confirmed and commented:
Looking into this, the balance isn’t calculated through the
creditsForTokenBalancemethod, it’s calculated through thebalanceOfmethod, which in this case the functionality is correct. We aren’t transferring credits, we are transferring the value and adding to the credits. Allowance is for value amounts, not credits, also balance can only go up against credits, so if the balance is valid then credits are inherently valid too. I’m unsure of what to label this as, because we do need to check to see if the user has the correct balance. I feel like this issue is partially correct.
https://github.com/shapeshift/foxy/pull/130/files for the fix.
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
Impact
An attacker could cause an underflow in the credit balance, potentially creating credits out of thin air or disrupting the contract's accounting, though the project maintainer disputed the severity and noted that balance checks may still prevent it.
What the attacker needed
A user with some allowance; ability to call transferFrom
The fix
The fix was to add a check that the from account has sufficient credit balance before subtracting.
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 function that moves tokens checks one number (the allowance) but not another (the actual credit balance). If the credit balance is too low, subtracting from it can wrap around to a huge number, letting someone create credits from nothing. The fix is to also check that the sender has enough credits before subtracting.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.