Skip to content
Audit finding Intermediate

Decimal Limitation in CamelotRelayer and UniV3Relayer Contract Deployment

The CamelotRelayer and UniV3Relayer contracts compute a multiplier as 18 minus the quote token's decimals, which underflows when the token has more than 18 decimals. This prevents deployment of the relayer for such tokens, limiting the protocol's compatibility.

0xmystery Follow with phoenixV110, hals and 12 others

Originally disclosed on Code4rena

Submitted by 0xmystery, also found by phoenixV110, hals, ni8mare, Tendency, tnquanghuy0512, spark, 0x6d6164616e, niki, twcctop, lsaudit, 0xsurena, ZanyBonzy, cryptothemex, and 0xWaitress

https://github.com/open-dollar/od-contracts/blob/v1.5.5-audit/src/contracts/oracles/CamelotRelayer.sol#L58

https://github.com/open-dollar/od-contracts/blob/v1.5.5-audit/src/contracts/oracles/CamelotRelayer.sol#L103-L105

https://github.com/open-dollar/od-contracts/blob/v1.5.5-audit/src/contracts/oracles/UniV3Relayer.sol#L64

https://github.com/open-dollar/od-contracts/blob/v1.5.5-audit/src/contracts/oracles/UniV3Relayer.sol#L110-L112

The current design of the CamelotRelayer and UniV3Relayer contracts limits its compatibility to only those _quoteTokens that have a decimal count of 18 or fewer. If an attempt is made to deploy the contract with a token having more than 18 decimals as the _quoteToken, the contract deployment will fail due to an underflow issue during the multiplier calculation. This poses no financial risk but restricts the contract’s adaptability in the wider DeFi ecosystem, preventing its use with tokens that have more than 18 decimals.

Proof of Concept

The restriction emerges from the constructor, where the multiplier is deduced as 18 - IERC20Metadata(_quoteToken).decimals().

https://github.com/open-dollar/od-contracts/blob/v1.5.5-audit/src/contracts/oracles/CamelotRelayer.sol#L58

https://github.com/open-dollar/od-contracts/blob/v1.5.5-audit/src/contracts/oracles/UniV3Relayer.sol#L64

    multiplier = 18 - IERC20Metadata(_quoteToken).decimals();

For tokens like YAMv2, which possess 24 decimals, the computation would attempt 18 - 24, which results in an underflow, making the contract deployment unsuccessful.

Recommended Mitigation Steps

  1. Alter the datatype of multiplier to int256 to account for both positive and negative values.
  2. Adjust the multiplier’s computation in the constructor to handle situations where token decimals might be greater or less than 18.
    int8 decimalsDifference = 18 - int8(IERC20Metadata(_quoteToken).decimals());
    multiplier = int256(decimalsDifference);
  1. Revise the _parseResult function to either multiply or divide the _quoteResult depending on the multiplier value.
    function _parseResult(uint256 _quoteResult) internal view returns (uint256 _result) {
        if (multiplier > 0) {
            return _quoteResult * (10 ** uint256(multiplier));
        } else if (multiplier < 0) {
            return _quoteResult / (10 ** uint256(-multiplier));
        } else {
            return _quoteResult;
        }
    }

Note: It will require additional code refactoring to make baseAmount and its value assignment as int256 as well.

pi0neerpat (OpenDollar) confirmed

MiloTruck (Judge) commented:

The warden has demonstrated how CamelotRelayer.sol and UniV3Relayer.sol cannot be deployed for tokens with more than 18 decimals, which limits the functionality of the protocol unnecessarily. As such, medium severity is appropriate.


The original report as published on Code4rena, by 0xmystery. 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

The multiplier is calculated as an unsigned integer subtraction of the token's decimals from 18, which underflows when decimals exceed 18.

Impact

The relayer contracts cannot be deployed for quote tokens with more than 18 decimals, restricting the protocol's use with such tokens; there is no financial risk.

What the attacker needed

Quote token has more than 18 decimals

The fix

The multiplier should be stored as a signed integer and the parsing logic should multiply or divide depending on its sign, so tokens with more than 18 decimals are supported.

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.

Some tokens can have more than 18 decimal places. The contract subtracts the token's decimals from 18, and if the token has more than 18, the result goes below zero, which the code cannot handle. This makes the contract fail to deploy for those tokens.

More by 0xmystery

View all

3 more disclosed reports, best first.

More from Open Dollar

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.