Allowance checks not correctly implemented
The token approval logic checks the whitelist allowance first and reverts if it is insufficient, even when the specific token allowance would be enough. This causes transfers to fail despite having sufficient allowance.
Submitted by cmichel
The nTokenAction implements two token approvals, the nTokenWhitelist which is always used first, and the nTokenAllowance which is checked second. If the nTokenWhitelist does not have enough allowance for the transfer, the transaction fails, even in the case where nTokenAllowance still has enough allowance.
Transfers that have sufficient allowance fail in certain cases.
Recommend that, instead of reverting if the nTokenWhitelist allowance is not enough, default to the nTokenAllowance case.
Something like this:
uint256 requiredAllowance = amount;
uint256 allowance = nTokenWhitelist[from][spender];
// use whitelist allowance first
if (allowance > 0) {
uint256 min = amount < allowance ? amount : allowance;
requiredAllowance -= min;
allowance = allowance.sub(min);
nTokenWhitelist[from][spender] = allowance;
}
// use currency-specific allowance now
if(requiredAllowance > 0)
// This is the specific allowance for the nToken.
allowance = nTokenAllowance[from][spender][currencyId];
require(allowance >= requiredAllowance, "Insufficient allowance");
allowance = allowance.sub(requiredAllowance);
nTokenAllowance[from][spender][currencyId] = allowance;
}
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
Transfers that have sufficient allowance could fail in certain cases.
What the attacker needed
None
The fix
The recommendation is to use the whitelist allowance first and then fall back to the specific token allowance, only reverting if the combined allowances are insufficient.
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.
When you approve someone to spend your tokens, the system checks two separate allowances: a general whitelist and a specific token allowance. The bug is that it stops at the first check if that fails, without trying the second, so a valid transfer can be blocked.
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.