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

invariant_reserves failure when take / bucketTake #1050

Merged
merged 10 commits into from
Jan 3, 2024

Conversation

grandizzy
Copy link
Contributor

@grandizzy grandizzy commented Dec 21, 2023

Description

reserves invariant failure

Add logic in invariant test harness to allow reserves to increase up to ~1e-18th of the current inflator.

Purpose

Because debt is stores in t0 terms and reserves include current debt, due to roundoff error the reserves will fluctuate up to 1 WAD times the current inflator value. This change allows for this expected error in reserves changes, enabling deeper invariant test runs. In particular, it fixes regression sequences test_regression_failure_reserves_bucketTake_18precision and test_regression_failure_reserves_regularTake_18precision.

Impact

Core contracts are untouched by this change, so no impact on size or gas.

Tasks

  • Changes to protocol contracts are covered by unit tests executed by CI.
  • Protocol contract size limits have not been exceeded.
  • Gas consumption for impacted transactions have been compared with the target branch, and nontrivial changes cited in the Impact section above.
  • Scope labels have been assigned as appropriate.
  • Invariant tests have been manually executed as appropriate for the nature of the change.

@grandizzy grandizzy changed the title Add test_regression_failure_reserves_bucketTake_18precision invariant_reserves failure when take / bucketTake Dec 21, 2023
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.

Could be missing something but is this accurate? -> https://github.com/ajna-finance/contracts/blob/6da58b4cdd2f75decac124502da0c55f6c70e9d2/tests/INVARIANTS.md?plain=1#L67

also see -> https://github.com/ajna-finance/contracts/blob/dcae802c991caab094af74fe7a47776117d3b882/tests/forge/invariants/base/ReserveInvariants.t.sol#L20-L21

I think the reservesErrorMargin value has a maximum of 1e13 value not 1e15. Suggest invariants.md is updated to match the code accordingly.

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.

Fine with this. Note I was not able to reproduce the failure at 600 depth. Also, merge conflict needs resolution.

@ith-harvey ith-harvey removed the request for review from mattcushman January 2, 2024 20:02
@ith-harvey
Copy link
Contributor

Fine with this. Note I was not able to reproduce the failure at 600 depth. Also, merge conflict needs resolution.

Fixed. -> dcae802

@ith-harvey
Copy link
Contributor

Could be missing something but is this accurate? ->

https://github.com/ajna-finance/contracts/blob/6da58b4cdd2f75decac124502da0c55f6c70e9d2/tests/INVARIANTS.md?plain=1#L67

also see ->

https://github.com/ajna-finance/contracts/blob/dcae802c991caab094af74fe7a47776117d3b882/tests/forge/invariants/base/ReserveInvariants.t.sol#L20-L21

I think the reservesErrorMargin value has a maximum of 1e13 value not 1e15. Suggest invariants.md is updated to match the code accordingly.

Changed 1e15 -> 1e13 to reflect code -> e8abacf

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

Copy link
Collaborator

@MikeHathaway MikeHathaway left a comment

Choose a reason for hiding this comment

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

LGTM

@ith-harvey ith-harvey merged commit 99c89e7 into develop Jan 3, 2024
3 checks passed
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.

5 participants