Skip to content
Access control Audit finding Intermediate

addLiquidity Does Not Reset Approval If Not All Tokens Were Added To Liquidity Pool

The addLiquidity function leaves residual token approvals to the Uniswap router when not all approved tokens are used, and these leftover allowances accumulate over time. This could leave large outstanding approvals that may cause problems with certain tokens and prevents gas refunds.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

addLiquidity is called when users reinvest their tokens through bonding events. The RewardReinvestor first transfers Malt and rewards tokens before adding liquidity to the token pool. addLiquidity provides protections against slippage by a margin of 5%, and any dust token amounts are transferred back to the caller. In this instance, the caller is the RewardReinvestor contract which further distributes the dust token amounts to the protocol’s treasury. However, the token approval for this outcome is not handled properly. Dust approval amounts can accrue over time, leading to large Uniswap approval amounts by the UniswapHandler contract.

Proof of Concept

https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/DexHandlers/UniswapHandler.sol#L212-L214 https://github.com/code-423n4/2021-11-malt/blob/main/src/contracts/DexHandlers/UniswapHandler.sol#L216-L218

Recommended Mitigation Steps

Consider resetting the approval amount if either maltUsed < maltBalance or rewardUsed < rewardBalance in addLiquidity.

0xScotch (sponsor) confirmed

Alex the Entreprenerd (judge) commented:

The UniV2Router will first calculate the amounts and then pull them from the msg.sender

This means that approvals may not be fully utilized, leaving traces of approvals here and there. This can cause issues with certain tokens (USDT comes to mind), and will also not trigger gas refunds.

The original report as published on Code4rena, by leastwood. 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 code approves a maximum token amount for the Uniswap router but does not reset the approval when the actual amount used is less than the balance.

Impact

Leftover approvals could accumulate into large outstanding allowances, which may cause issues with certain tokens such as USDT and will not trigger gas refunds.

What the attacker needed

Protocol uses UniswapHandler for liquidity; repeated addLiquidity calls with partial usage

The fix

The approval amount should be reset whenever the amount of Malt or reward tokens actually used is less than the balance available.

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 a contract lets another contract spend its tokens, it gives an 'allowance' - a permission to take up to a certain amount. Here the code set a large allowance but only part of it was used, and the unused permission was never cancelled. Over many transactions these leftover permissions pile up, which is risky because anyone who can abuse that permission could move more tokens than intended.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by leastwood

View all

70 more disclosed reports, best first.

More from Malt Protocol - Versus contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.