-
Notifications
You must be signed in to change notification settings - Fork 56
Certora: verify ERC4626 round-trip properties #465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
88eb69a
certora: verify ERC4626 round-trip properties
claude ac936c6
certora: fix inherited internal method summary receivers in ERC4626 spec
claude 1dab280
certora: inline ERC4626 round-trip rules to one-liners
claude cae88ee
certora: format ERC4626 rules as blocks, drop per-rule comments
claude 263baeb
certora: generalize ERC4626 round-trips to arbitrary decimals offset
claude cd47e89
Apply suggestion from @MathisGD
MathisGD e9bb085
certora: prove Math.mulDiv matches basic floor/ceil (discharge summary)
claude 2fe19d0
certora: prove mulDiv via tight two-sided bounds (more SMT-tractable)
claude 7ea4f55
certora: revert MulDivCorrectness lemma (OZ 512-bit mulDiv unmodelable)
claude 2906920
Apply suggestion from @MathisGD
MathisGD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "files": [ | ||
| "certora/helpers/MetaMorphoHarness.sol" | ||
| ], | ||
| "solc": "solc-0.8.21", | ||
| "verify": "MetaMorphoHarness:certora/specs/ERC4626.spec", | ||
| "loop_iter": "2", | ||
| "optimistic_loop": true, | ||
| "prover_args": [ | ||
| "-depth 0", | ||
| "-timeout 300", | ||
| "-smt_nonLinearArithmetic true", | ||
| "-backendStrategy singlerace", | ||
| "-solvers [z3:def{randomSeed=1},z3:def{randomSeed=2},z3:def{randomSeed=3},z3:def{randomSeed=4},z3:def{randomSeed=5},z3:def{randomSeed=6},z3:def{randomSeed=7},z3:def{randomSeed=8},z3:def{randomSeed=9},z3:def{randomSeed=10}]" | ||
| ], | ||
| "rule_sanity": "basic", | ||
| "server": "production", | ||
| "msg": "MetaMorpho ERC4626" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
|
|
||
| methods { | ||
| function convertToShares(uint256) external returns(uint256) envfree; | ||
| function convertToAssets(uint256) external returns(uint256) envfree; | ||
| function previewDeposit(uint256) external returns(uint256) envfree; | ||
| function previewMint(uint256) external returns(uint256) envfree; | ||
| function previewWithdraw(uint256) external returns(uint256) envfree; | ||
| function previewRedeem(uint256) external returns(uint256) envfree; | ||
|
|
||
| function MetaMorpho._accruedFeeShares() internal returns (uint256, uint256) => summaryAccruedFeeShares(); | ||
| function ERC4626._decimalsOffset() internal returns (uint8) => summaryDecimalsOffset(); | ||
|
claude[bot] marked this conversation as resolved.
|
||
| function Math.mulDiv(uint256 x, uint256 y, uint256 denominator, Math.Rounding rounding) internal returns (uint256) => cvlMulDiv(x, y, denominator, rounding); | ||
| } | ||
|
|
||
| ghost uint256 gTotalAssets; | ||
| ghost uint256 gFeeShares; | ||
| persistent ghost uint8 gDecimalsOffset; | ||
|
|
||
| function summaryAccruedFeeShares() returns (uint256, uint256) { | ||
| return (gFeeShares, gTotalAssets); | ||
| } | ||
|
|
||
| function summaryDecimalsOffset() returns uint8 { | ||
| require to_mathint(gDecimalsOffset) <= 18; | ||
| return gDecimalsOffset; | ||
| } | ||
|
|
||
| // necessary because metamorpho uses unmodelable 512 bits math. | ||
| function cvlMulDiv(uint256 x, uint256 y, uint256 denominator, Math.Rounding rounding) returns uint256 { | ||
|
MathisGD marked this conversation as resolved.
|
||
| if (rounding == Math.Rounding.Ceil || rounding == Math.Rounding.Expand) { | ||
| return require_uint256((x * y + (denominator - 1)) / denominator); | ||
| } else { | ||
| return require_uint256((x * y) / denominator); | ||
| } | ||
| } | ||
|
MathisGD marked this conversation as resolved.
MathisGD marked this conversation as resolved.
|
||
|
|
||
| rule convertRoundTripAssets(uint256 assets) { | ||
| assert convertToAssets(convertToShares(assets)) <= assets; | ||
| } | ||
|
|
||
| rule convertRoundTripShares(uint256 shares) { | ||
| assert convertToShares(convertToAssets(shares)) <= shares; | ||
| } | ||
|
|
||
| rule roundTripDepositRedeem(uint256 assets) { | ||
| assert previewRedeem(previewDeposit(assets)) <= assets; | ||
| } | ||
|
|
||
| rule roundTripDepositWithdraw(uint256 assets) { | ||
| assert previewWithdraw(assets) >= previewDeposit(assets); | ||
| } | ||
|
|
||
| rule roundTripRedeemDeposit(uint256 shares) { | ||
| assert previewDeposit(previewRedeem(shares)) <= shares; | ||
| } | ||
|
|
||
| rule roundTripRedeemMint(uint256 shares) { | ||
| assert previewMint(shares) >= previewRedeem(shares); | ||
| } | ||
|
|
||
| rule roundTripMintWithdraw(uint256 shares) { | ||
| assert previewWithdraw(previewMint(shares)) >= shares; | ||
| } | ||
|
|
||
| rule roundTripMintRedeem(uint256 shares) { | ||
| assert previewRedeem(shares) <= previewMint(shares); | ||
| } | ||
|
|
||
| rule roundTripWithdrawMint(uint256 assets) { | ||
| assert previewMint(previewWithdraw(assets)) >= assets; | ||
| } | ||
|
|
||
| rule roundTripWithdrawDeposit(uint256 assets) { | ||
| assert previewDeposit(assets) <= previewWithdraw(assets); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.