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

Sherlock-111: Wrong Inflator used in calculating HTP to determine accrualIndex #916

Merged
merged 8 commits into from
Jun 30, 2023

Conversation

grandizzy
Copy link
Contributor

@grandizzy grandizzy commented Jun 28, 2023

Description of change

High level

Contract size (same as pre change)

Pre Change

N/A

Post Change

N/A

Gas usage (same as pre change)

Pre Change

N/A

Post Change

N/A

Copy link
Contributor

@mattcushman mattcushman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -874,8 +874,8 @@ contract ERC721PoolCollateralTest is ERC721HelperContract {
kickMomp: 0.000000099836282890 * 1e18,
totalBondEscrowed: 5.907892673985352325 * 1e18,
auctionPrice: 0.000004621809202112 * 1e18,
debtInAuction: 439.681348088864224563 * 1e18,
thresholdPrice: 385.774399985858744479 * 1e18,
debtInAuction: 467.777790958346588935 * 1e18,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this surprised me at first, but makes sense as less deposit was available in higher priced buckets to swap for collateral

@grandizzy grandizzy changed the title Sherlock 111: Wrong Inflator used in calculating HTP to determine accrualIndex Sherlock-111: Wrong Inflator used in calculating HTP to determine accrualIndex Jun 29, 2023
);
}
(, uint256 maxThresholdPrice,) = _pool.loansInfo();
maxThresholdPrice = Maths.wdiv(maxThresholdPrice, inflator);
Copy link
Contributor Author

@grandizzy grandizzy Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I don't think we need to wdiv and then wmul again to obtain HTP, _pool.loansInfo() already does this

    function loansInfo() external view override returns (address, uint256, uint256) {
        return (
            Loans.getMax(loans).borrower,
            Maths.wmul(Loans.getMax(loans).thresholdPrice, inflatorState.inflator),
            Loans.noOfLoans(loans)
        );
    }

, so I suggest getting rid of (uint256 inflator, ) = _pool.inflatorInfo(); and simplify this to

        // get TP of worst loan and poolDebt
        (, uint256 htp,)         = _pool.loansInfo();
        (, uint256 poolDebt, , ) = _pool.debtInfo();

        uint256 accrualIndex;

        if (htp > MAX_PRICE)      accrualIndex = 1;                          // if HTP is over the highest price bucket then no buckets earn interest
        else if (htp < MIN_PRICE) accrualIndex = MAX_FENWICK_INDEX;          // if HTP is under the lowest price bucket then all buckets earn interest
        else                      accrualIndex = _poolInfo.priceToIndex(htp);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 64e811a

Copy link
Contributor

@prateek105 prateek105 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@EdNoepel EdNoepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern about unused param/variable.

src/libraries/external/PoolCommons.sol Show resolved Hide resolved
Copy link
Contributor

@EdNoepel EdNoepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@ith-harvey ith-harvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grandizzy grandizzy merged commit 0332f34 into develop Jun 30, 2023
3 checks passed
@grandizzy grandizzy deleted the sherlock-111 branch June 30, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants