Tigris Trade contest - 0Kage's results

A multi-chain decentralized leveraged exchange featuring instant settlement and guaranteed price execution on 30+ pairs.

General Information

Platform: Code4rena

Start Date: 09/12/2022

Pot Size: $90,500 USDC

Total HM: 35

Participants: 84

Period: 7 days

Judge: GalloDaSballo

Total Solo HM: 12

Id: 192

League: ETH

Tigris Trade

Findings Distribution

Researcher Performance

Rank: 19/84

Findings: 2

Award: $939.60

🌟 Selected for report: 1

🚀 Solo Findings: 0

Findings Information

🌟 Selected for report: minhtrng

Also found by: 0Kage, Aymen0909, HollaDieWaldfee, Jeiwan, KingNFT, bin2chen, hansfriese, rvierdiiev

Labels

bug
3 (High Risk)
satisfactory
duplicate-659

Awards

201.2303 USDC - $201.23

External Links

Lines of code

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L275 https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L651

Vulnerability details

Impact

'addToPosition' function adds additional margin to an existing trade. Margin value sent to '_handleDeposit' function sends margin adjusted for 'fees' instead of sending full margin. This results in a lesser margin withdrawn from traders account - since this directly impacts the margin amount deposited in stable vault, I have assigned 'HiGH' risk to this finding

In Line 275, margin value sent to '_handleDeposit' is '_add Margin -_fee' instead of '_addMargin'.

In Line 651, note that the 'margin' amount is transfered from trader to this contract. Since we sent a 'margin adjusted for fees', a lesser margin will be deducted from trader account.

This messes with the fees calculations as tgUSD is minted to govNFT holders with no collateral backing the tokens. On a cumulative basis, when traders add Margin, this shortfall keeps growing

Proof of Concept

Bob is a trader with an existing position on ETH/USDT pair. Bob adds an additional 100k USDT as margin. At a 0.1% mint fee, Bob will have a fees of 100$. Current contract is only sending 99,900 USDT margin amount to '_handleDeposit' which subsequently withdraws this amount from trader account.

100$ that was supposed to be rewarded to Gov NFT holders never made it to the protocol. Essentially the tgUSD minted to referrer/ bots is unbacked because of this shortfall

Tools Used

Strangely in Line 180 , when a new market order is created, logic is correctly handled. '_tradeinfo.margin' is sent to '_handleDeposit' instead of '_marginAfterfees'. However exact same logic in 'addPosition' is not followed.

I recommend to pass '_addMargin' instead of '_addMargin -_fee' to the 'handleDeposit' function in line 275 for correct accounting

#0 - c4-judge

2022-12-20T16:16:26Z

GalloDaSballo marked the issue as duplicate of #659

#1 - c4-judge

2023-01-22T17:43:19Z

GalloDaSballo marked the issue as satisfactory

Findings Information

🌟 Selected for report: 0Kage

Also found by: chaduke

Labels

bug
2 (Med Risk)
downgraded by judge
primary issue
satisfactory
selected for report
sponsor confirmed
M-11

Awards

738.3681 USDC - $738.37

External Links

Lines of code

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L178 https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L734

Vulnerability details

Impact

Formula for fee paid in Line 734 is incorrect leading to incorrect margin calculations. Since this directly impacts the trader margin and associated fee calculations, I've marked as HIGH risk

On initiating a market order, Margin is adjusted for the fees that is charged by protocol. This adjustment is in Line 178 of Trading. Fees computed by _handleOpenFees is deducted from Initial margin posted by user.

formula misses to account the 2*referralFee component while calculaing _feePaid

Proof of Concept

Note that _feePaid as per formula in Line 734 is the sum of _daoFeesPaid', and sum of burnerFee&botFee. _daoFeesPaidis calculated from_fees.daoFeeswhich itself is calculated by subtracting2*referralFeeandbotFee`.

So when we add back burnerFee and botFee to _feePaid, we are missing to add back the 2*referralFee which was earlier excluded when calculating _daoFeesPaid. While botFee is added back correctly, same adjustment is not being done viz-a-viz referral fee.

This results in under calculating the _feePaid and impacts the rewards paid to the protocol NFT holders.

Tools Used

Suggest replacing the formula in line 734 with below (adding back _fees.referralFees*2)

_feePaid = _positionSize * (_fees.burnFees + _fees.botFees + _fees.referralFees*2 ) / DIVISION_CONSTANT // divide by 100% + _daoFeesPaid;

#0 - c4-judge

2022-12-22T02:04:49Z

GalloDaSballo marked the issue as duplicate of #476

#1 - c4-judge

2023-01-16T08:53:04Z

GalloDaSballo changed the severity to 2 (Med Risk)

#2 - c4-judge

2023-01-22T17:48:43Z

GalloDaSballo marked the issue as satisfactory

#3 - c4-judge

2023-01-30T15:12:13Z

GalloDaSballo marked the issue as not a duplicate

#4 - c4-judge

2023-01-30T15:12:20Z

GalloDaSballo marked the issue as primary issue

#5 - c4-judge

2023-01-30T15:13:38Z

GalloDaSballo marked the issue as selected for report

#6 - GalloDaSballo

2023-01-30T15:14:07Z

The warden has shown a mistake in how fees are calculated, the impact will cause a loss of yield to the protocol, however no convincing argument was made as to how this can cause a loss to depositors or users (loss of principal), for this reason, I believe Medium Severity to be the most appropriate

#8 - c4-sponsor

2023-02-13T21:52:58Z

GainsGoblin marked the issue as sponsor confirmed

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter