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

Upgraded Q -> 2 from #37 [1703589922038] #64

Closed
c4-judge opened this issue Dec 26, 2023 · 2 comments
Closed

Upgraded Q -> 2 from #37 [1703589922038] #64

c4-judge opened this issue Dec 26, 2023 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value duplicate-44 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@c4-judge
Copy link
Contributor

Judge has assessed an item in Issue #37 as 2 risk. The relevant finding follows:

[L-02] openPosition() maybe underflow
in openPosition() -> Base.swap()

function openPosition(
    DataStruct.OpenPositionParams calldata params
) public override nonReentrant returns (uint96 lienId, uint256 collateralTo) {

...
(cache.amountSpent, cache.amountReceived) = Base.swap(
cache.tokenFrom,
cache.tokenTo,
params.amountSwap,
@> collateralTo - cache.amountToBorrowed - params.marginTo, // amount needed to meet requirement
DEX_AGGREGATOR,
params.data
);
The formula collateralTo - cache.amountToBorrowed - params.marginTo may underflow.

This is especially true if the user wants to increase token0PremiumPortion, thereby transferring to marginTo.

For example: (price outOfRange) collateralTo = 100 amountToBorrowed = 100 marginTo = 10 (want to set token0PremiumPortion >10%)

collateralTo - amountToBorrowed - marginTo will underflow.

Suggestions:

    (cache.amountSpent, cache.amountReceived) = Base.swap(
        cache.tokenFrom,
        cache.tokenTo,
        params.amountSwap,
  •       collateralTo - cache.amountToBorrowed - params.marginTo, // amount needed to meet requirement
    
  •      (cache.amountToBorrowed + params.marginTo) > collateralTo ? 0 : (collateralTo - cache.amountToBorrowed - params.marginTo),
          DEX_AGGREGATOR,
          params.data
      );
    
@c4-judge c4-judge added the 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value label Dec 26, 2023
@c4-judge
Copy link
Contributor Author

0xleastwood marked the issue as duplicate of #44

@c4-judge
Copy link
Contributor Author

0xleastwood marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Dec 26, 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 duplicate-44 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

1 participant