Error in allowance logic
The allowance check in the ZcToken contract was inverted, so a non-owner could never withdraw or redeem tokens on behalf of the owner. An attacker could not exploit this to steal funds, but the intended delegation feature was completely broken.
Submitted by 0xDjango, also found by 0x1f8b, 8olidity, arcoun, Bahurum, caventa, csanuragjain, hansfriese, joestakey, jonatascm, Lambda, oyc_109, and ronnyx2017
Impact
There is an error in the allowance functionality to allow a non-owner to withdraw or redeem ZcTokens for the owner. Taking ZcToken.redeem() as an example, behold the following if/else block:
if (holder == msg.sender) {
return redeemer.authRedeem(protocol, underlying, maturity, msg.sender, receiver, principalAmount);
}
else {
uint256 allowed = allowance[holder][msg.sender];
if (allowed >= principalAmount) { revert Approvals(allowed, principalAmount); }
allowance[holder][msg.sender] -= principalAmount;
return redeemer.authRedeem(protocol, underlying, maturity, holder, receiver, principalAmount);
If the msg.sender is the holder, no check for allowance is needed. If the sender is not the holder, then their allowance is checked.
The error lies in the if statement if (allowed >= principalAmount) { revert Approvals(allowed, principalAmount); }. This states that if the sender has equal to or more allowance than the principalAmount, revert.
Therefore, if the sender has the proper allowance or more allowance than necessary, the transaction will revert. If the sender has less allowance than necessary, the transaction will still revert because of the allowance[holder][msg.sender] -= principalAmount; clause.
In conclusion, there is no way to withdraw() or redeem() on behalf of another user.
Recommended Mitigation Steps
The fix is to simply change >= to <.
Approval workflow doesnt leave funds at risk but is a nice to have, that plus scope and this might end up Low risk but I think Medium is appropriate as well.
This is a good issue and I agree with the severity. I decided against making this High severity due to the fact that funds are not necessarily at risk; it’s just intended allowance functionality will not behave as expected.
robrobbins (Swivel) resolved and commented:
See #180.
Making this the main issue for the allowance flipped sign.
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 comparison operator in the allowance check was reversed, so the contract reverted when the allowance was sufficient and also reverted when it was insufficient.
Impact
The allowance functionality was unusable, meaning no one could withdraw or redeem on behalf of another user; funds were not at risk.
What the attacker needed
A ZcToken holder who has approved a spender
The fix
The comparison should be changed from greater-than-or-equal to less-than so the contract reverts only when the allowance is 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.
A smart contract token lets one person approve another to spend tokens on their behalf, using an 'allowance'. Here the check that should confirm the spender has enough allowance was written backwards, so every attempt to spend on someone else's behalf failed. No money was lost, but the feature simply did not work.
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.