Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

being referred discount is calculated wrongly #322

Closed
code423n4 opened this issue Dec 16, 2022 · 2 comments
Closed

being referred discount is calculated wrongly #322

code423n4 opened this issue Dec 16, 2022 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-542 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L708-L718
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L786-L792
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L954-L967

Vulnerability details

Impact

If user is referred, referral fees will be sent to the referral and a discount will be deducted on the trading fees of user. However, the amount for the discount is the same as the referral fees in the calculation, causing user to pay lesser fees than they should if they are referred.

Proof of Concept

In handleOpenFees, you can see that if referrer is present, it will mint referralFees for the referrer. The next step is to deduct the referral fees and discount from user fees that they will pay, instead of deducting discount which is 10% of trade fees separately, referralFees is being used instead as the amount for the discount for referred user.

According to https://docs.tigris.trade/protocol/trading-and-fees and https://docs.tigris.trade/protocol/referrals, The discount should be 10% of 0.1% trading fees for commodities and crypto, which is significantly lesser than 0.05% that referrer will get according to the docs. User will pay lesser fees, dao will get lesser fees and therefore GovNFT holders will lose out on fees.

        if (_referrer != address(0)) {
            unchecked {
                IStable(_tigAsset).mintFor(
                    _referrer,
                    _positionSize
                    * _fees.referralFees // get referral fee%
                    / DIVISION_CONSTANT // divide by 100%
                );
            }
            _fees.daoFees = _fees.daoFees - _fees.referralFees*2;
        }

Tools Used

Manual Review

Recommended Mitigation Steps

Few places need to be rewritten to calculate the discount standalone instead of using referral fees as the discount

https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L708-L718
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L788-L792
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L954-L967

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 16, 2022
code423n4 added a commit that referenced this issue Dec 16, 2022
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #542

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-542 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants