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
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().
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
- Alter the datatype of
multipliertoint256to account for both positive and negative values. - 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);
- Revise the
_parseResultfunction to either multiply or divide the_quoteResultdepending on themultipliervalue.
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
The warden has demonstrated how
CamelotRelayer.solandUniV3Relayer.solcannot be deployed for tokens with more than 18 decimals, which limits the functionality of the protocol unnecessarily. As such, medium severity is appropriate.
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.