Skip to content
DoS Audit finding Intermediate

uint128 changeAmount might overflow

The report claims that a uint128 variable in the swap function could overflow if the amount swapped is extremely large, causing the transaction to revert. The attacker could not exploit this for gain, but it could make the protocol unusable for certain large swaps.

__141345__ Follow

Originally disclosed on Code4rena

Submitted by 141345

https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/facets/Swapper.sol#L189 https://github.com/AngleProtocol/angle-transmuter/blob/9707ee4ed3d221e02dcfcd2ebaa4b4d38d280936/contracts/transmuter/facets/Swapper.sol#L210

This issue is an edge case, that uint128 changeAmount could overflow, making the protocol fail for certain amount of swap.

Proof of Concept

Let’s break down the changeAmount:

  1. amountOut/amountIn
  2. BASE_27
  3. normalizer
File: transmuter/contracts/transmuter/facets/Swapper.sol
176:     function _swap() {

189:                 uint128 changeAmount = (amountOut.mulDiv(BASE_27, ts.normalizer, Math.Rounding.Up)).toUint128();

210:                 uint128 changeAmount = ((amountIn * BASE_27) / ts.normalizer).toUint128();
  1. normalizer

could take value ranging from 1e18 to 1e36, we take the worst case, 1e18.

File: transmuter/contracts/transmuter/facets/Redeemer.sol
193:         if (newNormalizerValue <= BASE_18 || newNormalizerValue >= BASE_36) {

208:             newNormalizerValue = BASE_27;
209:         }
  1. BASE_27 is constant 1e27.
  2. amountOut/amountIn is AgToken with 18 decimals.

Combine the above 1, 2, 3, we have the “total decimal”: 1e18 * 1e27 / 1e18 = 1e27.

The max value of uint128 is 3.4e38. To overflow, the amountOut/amountIn need to be around 3.4e38 / 1e27 = 3.4e11.

For nowadays currencies around the world, we can look at Iranian Rial (IRR). 3.4e11 IRR is around 8M USD. 8M USD is a big amount for now. However considering the following, this concern maybe not nonsense:

  • USD itself is depreciating, from 1970s to now, the gold price(historical chart) has changed from 35 USD/oz to 2000 USD/oz, almost 60 times.
  • Some countries have high inflation rate (Iran, Vietnam, Sierra, Leonean, Lao, etc. That’s how the many zeros in these currencies come).
  • Taking a longer time span of 10-20 years, the depreciation could be influential.

If after 20 years, 3.4e11 of some currency with high inflation depreciates more than 100 times . In that case, the amount is around 80k USD, a reasonable amount to use (especially for institutions).

Although the possibility is low for current use cases, in the future, things could change. To make the stablecoin protocol universal for all countries in the world, the edge case might be some concern.

Recommended Mitigation Steps

  • Use uint256 for changeAmount, then the likelihood would be negligible small, making the system more robust to special situations. uint256 wont add too much cost, but can avoid much more potential issue.
  • Use narrower range for normalizer. 1e9 for both up and down direction might be too big, and not necessary.

Picodes (Angle) disagreed with severity and commented:

Although the possibility of overflow is real, I don’t think the scenario is convincing and this likely to happen. Worst case the code is already using safeCast.

hansfriese (Judge) commented:

@Picodes - Will keep it as medium because it’s likely to happen and _swap() will revert during the safeCast.

Angle chose not to mitigate:

We consider that there is no risk here as swaps will be reverting, and that the chances that this happen are infinitesimals.


The original report as published on Code4rena, by __141345__. 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 use of a uint128 variable for an intermediate calculation that can exceed its maximum value when the swap amount is very large.

Impact

The swap function would revert, preventing large swaps from being processed; the report notes the likelihood is low and the protocol team considers the risk negligible.

What the attacker needed

Swap amount around 3.4e11 tokens; normalizer at minimum value (1e18)

The fix

The report recommends using uint256 for the variable or narrowing the allowed range of the normalizer.

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 uint128 is a type of number in a smart contract that can only hold values up to about 3.4e38. If a calculation produces a larger number, it overflows and the transaction fails. The report says that if someone tries to swap a very large amount of tokens, the calculation might exceed this limit and the swap would fail.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by __141345__

View all

18 more disclosed reports, best first.

More from Angle Protocol - Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.