Skip to content
Audit finding Intermediate

_handleDeposit and _handleWithdraw do not account for tokens with decimals higher than 18

yjrwkk Follow with chaduke, rbserver and 14 others

Originally disclosed on Code4rena

Submitted by yjrwkk, also found by chaduke, rbserver, 0xdeadbeef0x, Tointer, Englave, Avci, Deivitto, 0xDecorativePineapple, ak1, Critical, unforgiven, Dinesh11G, izhelyazkov, rvierdiiev, 0x4non, and pwnforce

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L650

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L675

Impact

In Trading.sol a deposit or withdrawal of tokens with decimals higher than 18 will always revert.

This is the case e.g. for NEAR which is divisible into 10e24 yocto

Proof of Concept

Change 00.Mocks.js#L33 to:

args: ["USDC", "USDC", 24, deployer, ethers.utils.parseUnits("1000", 24)]

Then in 07.Trading.js:

Opening and closing a position with tigUSD output
Opening and closing a position with <18 decimal token output

are going to fail with:

Error: VM Exception while processing transaction: reverted with panic code 0x11 (Arithmetic operation underflowed or overflowed outside of an unchecked block)

Tools Used

VS Code

Recommended Mitigation Steps

Update calculations in the contract to account for tokens with decimals higher than 18.

TriHaz (Tigris Trade) acknowledged and commented:

We are aware of that. We are not planning on adding any token that has more than 18 dec.

Alex the Entreprenerd (judge) commented:

The Warden has shown how, due to an underflow, the system in-scope can revert when using tokens with more than 18 decimals.

Because of how scope was defined, I believe the finding to be valid, I believe a nofix is acceptable as long as the sponsor keeps in mind this risk.

Because of the risk shown, I agree with Medium Severity.


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

What is known

A medium-severity security bug in Tigris Trade contest. Code4rena made it public on 17 February 2023. Found in the 2022-12-tigris audit contest (finding M-19), also found by 16 other wardens.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

More from Tigris Trade contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.