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

tradeFee and liquidationPenalty can be set to any value > 0 #84

Closed
code423n4 opened this issue Feb 23, 2022 · 3 comments
Closed

tradeFee and liquidationPenalty can be set to any value > 0 #84

code423n4 opened this issue Feb 23, 2022 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-02-hubble/blob/ed1d885d5dbc2eae24e43c3ecbf291a0f5a52765/contracts/ClearingHouse.sol#L344

Vulnerability details

Impact

If tradeFee or liquidationPenalty is set above PRECISION(1e6), it will charge more than entire trade amount as fee which will lead to negative margin of the user.
If tradeFee+liquidationPenalty is set above maintenanceMargin, the user will have negative margin after liquidation.
If tradeFee is set above maintenanceMargin, it is possible for the user to have negative margin after closing position.

Proof of Concept

https://github.com/code-423n4/2022-02-hubble/blob/ed1d885d5dbc2eae24e43c3ecbf291a0f5a52765/contracts/ClearingHouse.sol#L344

    function setParams(
        int _maintenanceMargin,
        int _minAllowableMargin,
        uint _tradeFee,
        uint _liquidationPenality
    ) external onlyGovernance {
        tradeFee = _tradeFee;
        liquidationPenalty = _liquidationPenality;
        maintenanceMargin = _maintenanceMargin;
        minAllowableMargin = _minAllowableMargin;
    }

Recommended Mitigation Steps

To make sure the protocol remains functional, hard rules should be set to avoid the above situation in setParams. To reduce centralization risk, it is also advised a max fee being hardcoded to the contract (e.g. 10%).

@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 Feb 23, 2022
code423n4 added a commit that referenced this issue Feb 23, 2022
@atvanguard
Copy link
Collaborator

Duplicate of #40

@atvanguard atvanguard marked this as a duplicate of #40 Feb 24, 2022
@atvanguard atvanguard added the duplicate This issue or pull request already exists label Feb 24, 2022
@moose-code
Copy link
Collaborator

Would say slight difference to 40. This is more useful and not just governance can rug users. Given these magic 1e6 number used in calcs, it is very advisable to have hard upper limits set to avoid a botched call by admin

@moose-code moose-code added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Mar 10, 2022
@JeeberC4
Copy link

Grouping with warden's QA report #89

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

4 participants