Skip to content
Business logic Audit finding Intermediate

Pool.sol & Synth.sol : Failing Max Value Allowance

The _approve function in Pool.sol and Synth.sol ignores an allowance of type(uint256).max, leaving the previous allowance unchanged instead of setting it to the maximum. This means integrations that hardcode the maximum value to grant unlimited allowance end up with zero allowance, and approveAndCall sets no allowance at all.

hickuphh3 Follow

Originally disclosed on Code4rena

Submitted by hickuphh3, also found by shw, jonah1005, 0xRajeev and cmichel

In the _approve function, if the allowance passed in is type(uint256).max, nothing happens (ie. allowance will still remain at previous value). Contract integrations (DEXes for example) tend to hardcode this value to set maximum allowance initially, but this will result in zero allowance given instead.

This also makes the comment // No need to re-approve if already max misleading, because the max allowance attainable is type(uint256).max - 1, and re-approval does happen in this case.

This affects the approveAndCall implementation since it uses type(uint256).max as the allowance amount, but the resulting allowance set is zero.

Recommend keeping it simple and removing the condition.

function _approve(address owner, address spender, uint256 amount) internal virtual {
    require(owner != address(0), "!owner");
    require(spender != address(0), "!spender");
    _allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
}

SamusElderg (Spartan) confirmed:

We acknowledge the issue in the max approval for approveAndCall, which we don’t use. Furthermore, the issue is only a problem if a user directly approves a maximum possible amount which would mean they are assuming trust in the contract.

We will also change _approve in the pool and synth contracts. Risk, as outlined above, is low.

ghoul-sol (judge) commented:

This is high risk as explained in #152

The original report as published on Code4rena, by hickuphh3. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 _approve function contains a conditional check that returns early or does nothing when the amount equals type(uint256).max, instead of always updating the allowance mapping.

Impact

Integrations that rely on setting a maximum allowance will instead have zero allowance, breaking expected token spending; the project acknowledged the issue but considered the risk low because they do not use approveAndCall and users would need to trust the contract to set a maximum approval.

What the attacker needed

Contract uses _approve with max value; user or integration sets max allowance

The fix

The _approve function should be simplified to always set the allowance to the given amount, removing the special case for type(uint256).max.

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, you set an allowance. Some contracts try to set the maximum possible number to mean 'unlimited', but this code skips that value, so the allowance stays at whatever it was before, often zero. As a result, the approved contract cannot spend your tokens even though you tried to give it unlimited permission.

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.

More by hickuphh3

View all

43 more disclosed reports, best first.

More from Spartan Protocol Contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.