Skip to content
Business logic Audit finding Intermediate

Submiting an offchain delayed offer will revert due to incorrect decimal calculations

The liquidationType2 function in a smart contract incorrectly scales the sizeDelta parameter when submitting an offchain delayed order to Synthetix, resulting in a value with 50 decimal places instead of the required 18. This causes the call to revert, preventing users from being liquidated through this method.

0x37 Follow with Audinarey, Aymen0909 and 7 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-autonomint-judging/issues/942

Found by

0x37, Audinarey, Aymen0909, John44, LordAlive, ParthMandale, PeterSR, futureHack, nuthan2x, valuevalk

Summary

liquidationType2 takes 50% of a liquidated user's collateral and transfers it to Synthethix. To do that it first must convert the collateral into WETH and after that the WETH to sETH. After that the sETH is converted into sUSD and used to submit an offchain delayed order in Synthetix for short position with 1X leverage. The issue is that the sizeDelta parameter of the call to submitOffchainDelayedOrder is scaled incorrectly, causing the call to revert.

Root Cause

In liquidationType2 when a call is made to submitOffchainDelayedOrder the following value is passed for the sizeDelta/first parameter:

https://github.com/sherlock-audit/2024-11-autonomint/blob/0d324e04d4c0ca306e1ae4d4c65f0cb9d681751b/Blockchain/Blockchian/contracts/Core_logic/borrowLiquidation.sol#L362-L365

Solidity
        synthetixPerpsV2.submitOffchainDelayedOrder(
            -int((uint(margin * 1 ether * 1e16) / currentEthPrice)),
            currentEthPrice * 1e16
        );

As we an see the first parameter will have the following decimal precision: -margin: 18 decimals -1 ether: 18 decimals -1e16: 16 decimals -currentEthPrice: 2 decimals

Therefore, 18 + 18 + 16 - 2 = 50 decimal places. This is problematic as the decimals are too high and will cause the call to Synthetix to revert. The sizeDelta must instead be: 'sizeDelta: A wei value of the size in units of the asset being traded' per the Synthetix documentations, therefore, it should have 18 decimal places instead.

https://docs.synthetix.io/v3/for-perp-integrators/perps-v3#:~:text=sizeDelta,asset%20being%20traded

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. User gets liquidated through liquidationType2.
  2. The call fails because the amount passed as the sizeDelta of submitOffchainDelayedOrder is significantly higher than it should be.

Impact

Users will fail to be liquidated through liquidationType2.

PoC

No response

Mitigation

Make sure to use the appropriate decimal scaling when calling submitOffchainDelayedOrder.

The original report as published on Sherlock, by 0x37. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 sizeDelta calculation used incorrect decimal scaling, multiplying by 1 ether and 1e16 while dividing by a price with only 2 decimals, resulting in 50 decimal places instead of the required 18.

Impact

Users will fail to be liquidated through liquidationType2.

What the attacker needed

A user is liquidated via liquidationType2

The fix

The code should use the appropriate decimal scaling when calling submitOffchainDelayedOrder, ensuring sizeDelta has 18 decimal places.

How it was found

  1. A user is liquidated through liquidationType2.
  2. The call to submitOffchainDelayedOrder fails because the sizeDelta value is incorrectly scaled.

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.

In a blockchain contract, numbers are stored with a fixed number of decimal places. When calling another contract, the number must be scaled correctly. Here, the code multiplied by too many factors, making the number have 50 decimal places instead of 18, so the external call failed and the liquidation could not complete.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0x37

View all

79 more disclosed reports, best first.

More from Autonomint Colored Dollar V1

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.