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

Check for liquidation in value() #76

Open
code423n4 opened this issue Nov 22, 2021 · 0 comments
Open

Check for liquidation in value() #76

code423n4 opened this issue Nov 22, 2021 · 0 comments
Labels
bug Something isn't working G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

gpersoon

Vulnerability details

Impact

The function value() of OverlayV1OVLCollateral.sol doesn't explicitly check for liquidated positions.
However because oiShares and debt are set to 0 during liquidation the resulting value will still be 0.

It seems more logical to check for liquidation in the beginning of the function and immediately return 0.
This saves gas for the situation where the function value() is called from another smart contract.

Proof of Concept

https://github.com/code-423n4/2021-11-overlay/blob/914bed22f190ebe7088194453bab08c424c3f70c/contracts/collateral/OverlayV1OVLCollateral.sol#L424-L448

function value (  uint _positionId ) public view returns ( uint256 value_) {
        Position.Info storage pos = positions[_positionId];
        IOverlayV1Market _market = IOverlayV1Market(pos.market);
        (   uint _oi,  uint _oiShares,   uint _priceFrame ) = _market.positionInfo( pos.isLong, pos.pricePoint );
        value_ = pos.value(  _oi, _oiShares,  _priceFrame );
}

Tools Used

Recommended Mitigation Steps

Add something like the following to function value():

        if (pos.oiShares == 0) return 0; // liquidated
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 22, 2021
code423n4 added a commit that referenced this issue Nov 22, 2021
@mikeyrf mikeyrf added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

2 participants