This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
lending: Add overflow check in liquidation proptest #1199
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This issue was discovered during CI:
https://github.com/solana-labs/solana-program-library/runs/1833196857
The approach is to do the same calc as
_liquidate_obligation
and makesure that the
MockConverter
doesn't overflowDecimal
. This seemedlike a simpler approach than doing a local proptest constraint.
The actual failure is on line 150 in
_liquidate_obligation
:obligation.max_liquidation_amount()
is always the amount we try to convert, and in this case:conversion rate = 681
collateral = u64::MAX (roughly)
max liquidation amount = collateral / 2
collateral exchange rate = 0.01
receive amount = conversion_rate * (collateral / 2) * collateral_exchange_rate
receive_amount = 681 * u64::MAX / 2 * 0.01 > u64::MAX
On top of that, this PR includes the proptest regression to run the failing case
on every
cargo test
.