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

Upstream Certora Specs #256

Merged
merged 152 commits into from
Aug 20, 2024
Merged

Upstream Certora Specs #256

merged 152 commits into from
Aug 20, 2024

Conversation

andrew-certora
Copy link
Collaborator

This is an upstream of all the Certora specs for the Vault aside from the ones generated by contest participants.

@andrew-certora andrew-certora marked this pull request as ready for review June 28, 2024 15:00
@andrew-certora andrew-certora requested review from hoytech and shoham-certora and removed request for hoytech June 28, 2024 15:01
src/EVault/modules/Liquidation.sol Outdated Show resolved Hide resolved
certora/specs/benchmarking/Benchmarking.spec Outdated Show resolved Hide resolved
Copy link
Collaborator

@nd-certora nd-certora left a comment

Choose a reason for hiding this comment

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

first pass, left some comments and will continue

certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
@andrew-certora
Copy link
Collaborator Author

I have an implementation of @nd-certora 's improvements here: https://github.com/Certora/euler-vault/tree/andrew%40HolyGrailImprovements . There are timeouts that I am attempting to address before putting those changes here.

@andrew-certora
Copy link
Collaborator Author

Thanks @nd-certora for suggesting these improvements! I think the spec is better now. Here are a new (mostly*) complete set of passing runs after these improvements:

Borrowing (all, splitting not needed anymore apparently):
https://vaas-stg.certora.com/output/65266/42f0d1daee0d4d67bbba50c7ef6b6552/?anonymousKey=ed4a0f6419ec4f68f9e03b2a120e73efcd1ef27c

BalanceForwarder:
https://vaas-stg.certora.com/output/65266/21aa5ff6ad3f49a48b4f00301282e460/?anonymousKey=808bc3ed43f9552037f6d30c604bc4fb3708f321

Governance:
https://vaas-stg.certora.com/output/65266/8b84dad883d143fd95b5becda89f297d/?anonymousKey=192877ffea6c9c61f5779d74d316591abbcc0447

Initialize:
https://vaas-stg.certora.com/output/65266/75232ebc9f174cd2a070ad1bf8f75acf/?anonymousKey=7a0069d9d9fc87a12606ac9e3c202b4fb65ef700

Liquidation (all except liquidate):
https://vaas-stg.certora.com/output/65266/d241b000591c4426b825a401d3db6ca2/?anonymousKey=bc58163eaa5ad63aa44f7792bb8571731104feed

Liquidation.liquidate:
(split into 4 cases, less general with EToken addresses)
Account of HS check is vault contract itself: https://vaas-stg.certora.com/output/65266/335793b332e4450eaf43b675c913bc68/?anonymousKey=81d49968e147ad18fc254adc7146200747be615d
Account of HS check is not violator:
https://vaas-stg.certora.com/output/65266/bd31ddbe06c54293a112528ee5a68dda/?anonymousKey=55aef02bbcea7eb0754dc05cdb6688044db9f0c7
Account of HS check is is liquidator and debt socialization always enabled:
https://vaas-stg.certora.com/output/65266/bb0bcbd4d4e04338b2672711acbe4fa2/?anonymousKey=b2133a942588545f6539611f295751f8fcbcbedd
Account of HS check is liquidator and debt socialization always disabled (vacuity check timeout):
https://vaas-stg.certora.com/output/65266/6f316a40d9ba4839aa7918a288d4a393/?anonymousKey=af25c9702c275d308e2e8cc1d9a0d239fc2351ef

Token:
https://vaas-stg.certora.com/output/65266/50af43ed34b34e2cab39d39e41b1d7d3/?anonymousKey=e260fca0de244d18b85e27fa9ee13564084f1d50

Vault most:
https://vaas-stg.certora.com/output/65266/907605ead586473f99d4715e8ebdb4f4/?anonymousKey=e3b0ccbaa13dfbd8b39cecd0676cefdd8ae23924

Vault.redeem:
https://vaas-stg.certora.com/output/65266/1ad29288e6cc435d96163bc59fe2de15/?anonymousKey=837473fba09d216ec7875e54b4f4b07adda4b988

Vault.withdraw:
https://vaas-stg.certora.com/output/65266/ecbdb69cd9b949c293474dae4f1885fa/?anonymousKey=b6093401ee6d677a438113a99fea738e8d35edb2

Caveat* the Liquidation.liquidate case "Account of HS check is liquidator and debt socialization always disabled" has a vacuity check timeout. This should be a less intersting case than the one where socialization is enabled and because of all the other cases passing the vacuity check, I doubt there is an issue with vacuity. I will try just rerunning and also rerunning without the vacuity check and add the result. (I am optimistic enough that this will work to merge the changes into the PR).

@andrew-certora
Copy link
Collaborator Author

Copy link
Collaborator

@shoham-certora shoham-certora left a comment

Choose a reason for hiding this comment

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

Sorry it took so long, I was sidetracked. Here is the first part of my review.

certora/specs/BalanceForwarder.spec Outdated Show resolved Hide resolved
certora/specs/Cache.spec Outdated Show resolved Hide resolved
certora/conf/Cache.conf Outdated Show resolved Hide resolved
certora/conf/Cache.conf Outdated Show resolved Hide resolved
certora/specs/Cache.spec Outdated Show resolved Hide resolved
certora/specs/GhostPow.spec Show resolved Hide resolved
certora/specs/Liquidation.spec Show resolved Hide resolved
certora/specs/Liquidation.spec Outdated Show resolved Hide resolved
Copy link
Collaborator

@shoham-certora shoham-certora left a comment

Choose a reason for hiding this comment

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

Here is the second half of my review.

certora/specs/LoadVaultSummary.spec Outdated Show resolved Hide resolved
certora/conf/EVault/modules/RiskManager.conf Show resolved Hide resolved
certora/specs/RiskManager.spec Outdated Show resolved Hide resolved
certora/conf/ERC4626Split/VaultERC4626.conf Show resolved Hide resolved
certora/conf/ERC4626Split/VaultERC4626.conf Show resolved Hide resolved
certora/specs/VaultERC4626.spec Outdated Show resolved Hide resolved
certora/specs/VaultERC4626.spec Show resolved Hide resolved
certora/specs/VaultERC4626.spec Outdated Show resolved Hide resolved
certora/specs/VaultERC4626.spec Show resolved Hide resolved
Copy link
Collaborator

@shoham-certora shoham-certora left a comment

Choose a reason for hiding this comment

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

Looks good to me. Waiting on @nd-certora 's approval.

andrew-certora added a commit that referenced this pull request Jul 25, 2024
We need to change two private functions to internal so we can harness them
and verify properties of these functions.
See related PR that builds on this change: #256
certora/conf/VaultERC4626.conf Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/harness/AbstractBaseHarness.sol Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Show resolved Hide resolved
certora/specs/Cache.spec Outdated Show resolved Hide resolved
certora/harness/modules/GovernanceHarness.sol Outdated Show resolved Hide resolved
certora/harness/TokenHarness.sol Outdated Show resolved Hide resolved
certora/harness/TokenHarness.sol Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Show resolved Hide resolved
certora/specs/LiquidateHealthStatus.spec Outdated Show resolved Hide resolved
certora/specs/LiquidateHealthStatus.spec Show resolved Hide resolved
certora/specs/VaultERC4626.spec Outdated Show resolved Hide resolved
certora/specs/VaultERC4626.spec Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@andrew-certora andrew-certora left a comment

Choose a reason for hiding this comment

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

@kasperpawlowski Made some fixes according to your suggestions and looked into your points. I'm just waiting on a few runs (some with rather long runtimes) to finish so we can confirm everything.

certora/harness/TokenHarness.sol Outdated Show resolved Hide resolved
certora/harness/TokenHarness.sol Outdated Show resolved Hide resolved
certora/harness/modules/GovernanceHarness.sol Outdated Show resolved Hide resolved
certora/specs/HealthStatusInvariant.spec Outdated Show resolved Hide resolved
certora/specs/Liquidation.spec Outdated Show resolved Hide resolved
certora/specs/VaultERC4626.spec Outdated Show resolved Hide resolved
certora/specs/RiskManager.spec Show resolved Hide resolved
certora/specs/VaultERC4626.spec Outdated Show resolved Hide resolved
certora/harness/AbstractBaseHarness.sol Show resolved Hide resolved

bool healthyBefore = checkLiquidityReturning(e, account, collaterals);
f(e, args);
// The only way to call a vault funciton is through EVC's call, batch,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @kasperpawlowski. Thanks so much for pointing this out and for your thorough review. You are absolutely right, and this helped us identify a mistake in the spec. It should need and include an assumption that checks are deferred here, but there was another issue with the spec. This was subtle and we have been investigating it. Fortunately, we think we have it fixed now, and are rerunning the fixed rules to confirm that our fix is correct.

It turns out that due to a mistake in our summaries, with this setup we could spuriously prove EVC.areChecksDeferred() returns true in all cases: https://vaas-stg.certora.com/output/65266/0f25180bc5304f6c9c1f3a1f3e53a195/?anonymousKey=6b7327f914bb55c04494f19c57f409a2045bc1c2. The reason for this is that with the env variables in our CVLCheckAccountStatusInternal summary as they were written when you reviewed this we actually caused checkAccountStatus@withRevert to always revert:

function CVLCheckAccountStatusInternalBool(env e, address account) returns bool {
    address[] collaterals = evc.getCollaterals(e, account);
    checkAccountStatus@withrevert(e, account, collaterals); // the problem is with this env variable more details below.
    return !lastReverted;
}

// This summary is applied to EthereumVaultConnector.checkAccountStatusInternal
function CVLCheckAccountStatusInternal(env e, address account) returns (bool, bytes) {
    return (CVLCheckAccountStatusInternalBool(e, account), 
        checkAccountMagicValueMemory(e));
}

The issue with this is that here we are passing the env e that was used during the the vault’s call to EVC’s checkAccountStatus.Because env variables have the msg.sender in them, this forces the msg.sender to be the the same for both: 1) the call from the contract under verification (a vault module) to EVC.requireAccountStatusCheck (which is reached as part of Base.init’s call to EVCRequireStatusChecks) and 2) the call back from EVC into the vault (the call from EVC.requireAccountStatusCheckInternal into Riskmanager.checkAccountStatus). As a result, msg.sender will be the contract under verification during RiskManager.checkAccountStatus rather than evc and when we reach this revert check as a part of the checkAccountStatus call it will always revert

    function checkAccountStatus(address account, address[] calldata collaterals)
        public
        virtual
        reentrantOK
        onlyEVCChecks /// this is the important part
        returns (bytes4 magicValue)
    {
    }

    modifier onlyEVCChecks() {
        if (msg.sender != address(evc) || !evc.areChecksInProgress()) { 
            revert E_CheckUnauthorized(); // we were always reverting here during just the EVC checkAccount/Vault summaries
        }

        _;
    }

There is a similar problem with both the summary for checkAccountStatusInternal and checkVaultStatusInternal.

We confirmed this was the issue by declaring fresh environment variables for these summaries and continuing to omit the requirement that evc.areChecksDeferred().In this case there is a counterexample as you would expect: https://vaas-stg.certora.com/output/65266/7663d91b72c04214898586e968adee89/?anonymousKey=a9b11593bd253324353519853241b692b2f82a24 Note also that in this failing case, evc.areChecksDeferred is returning false indicating this is the reason for the counterexample.

Here is the code that declares a fresh environment variable in the summary. Our candidate fix is to make this change and also add the assumption that evc.areChecksDeferred:

function CVLCheckAccountStatusInternal(address account) returns (bool, bytes) {
    // We need a new env for the first function.
    // Since the vault calls the EVC, otherwise msg.sender
    // would become the vault unless we declare a fresh environment.
    env eEVC;
    return (CVLCheckAccountStatusInternalBool(eEVC, account), 
        checkAccountMagicValueMemory());
}

We are currently rerunning all the holy grail runs to make sure that it still passes with this fix. I do want to assure you though that despite this problem and investigation, I did not suspect there was a critical issue with the main intent of the rule – during the development of the rule it failed unless we called evc.checkStatusAll to make the EVC’s call to this function (as a part of restoring the execution context) at the end of call/batch. This is a good sign because it means the rule would catch any issues related to not enqueueing the right deferred account checks. The issue was just that we subtly forced the deferred status checks flag to always be true.

That said, we take the quality of our specifications and verification results very seriously and:
We are rerunning all the holy grail runs to confirm it still passes after this fix
We will thoroughly re-review all of our specifications here
We will write the additional rules you requested and potentially a few others related to assumptions made about the EVC.

Thanks again for your own very detailed and thorough review of the specifications.

@andrew-certora
Copy link
Collaborator Author

@kasperpawlowski Here is the set of runs after the latest fix to the holy grail rule. It all still passes after this fix. We need to split it into more runs than we used to (more modules need to be run with each method separately), which is why there are more links.

(risk manager is included in BalanceForwarder)

BalanceForwarder:
https://vaas-stg.certora.com/output/65266/968885322f9649ba9d6e152e48dec816/?anonymousKey=1f31ce5686893adb7b93093c61e7a0db1dd310b4
Borrowing:
https://vaas-stg.certora.com/output/65266/3d9b9b8c987444c3b661b1220e1b7898/?anonymousKey=7d51ad38e55dbf271fddac2daca00dc0f34847b8

Governance
https://vaas-stg.certora.com/output/65266/b858525e3cb042a7b01614d0346fd81b/?anonymousKey=6179f8b8b1ac2aa2470ee37da3eec22c4577f01d
https://vaas-stg.certora.com/output/65266/11e2f45935da448cbc89383bf36b918f/?anonymousKey=012f2647cdd904975697bc4a30c32c2f09243aa5
https://vaas-stg.certora.com/output/65266/02b4baa67bf04987bdcf65725d4981f5/?anonymousKey=531b906dc7518f9664ad0574c88f050f8f0cb8bd
https://vaas-stg.certora.com/output/65266/5bf070b63efc4acc9fe9ee9c0d9602b4/?anonymousKey=f13c607185b6851882b64937afaea0c9f7ff1efc
https://vaas-stg.certora.com/output/65266/9591739d56ab4c78b99730f9df6a4fa4/?anonymousKey=b5e0fd14fbde04727fd57535eef5a7b65ad8b5a4
https://vaas-stg.certora.com/output/65266/13b08be5db7f4f5984c1c79b59829968/?anonymousKey=c0eef49343cdbace25324f8858f0a18664e343ed
https://vaas-stg.certora.com/output/65266/d8924d422a144eef8a83096acfc63744/?anonymousKey=428699a5882ca9cc95e59e899f7bf7e475aece2d
https://vaas-stg.certora.com/output/65266/cd7cbbc21d234b8294a3e94851487a68/?anonymousKey=bdc5fa7dd08a965cd20ce269a6e1a87004ff6d7c
https://vaas-stg.certora.com/output/65266/59b9ec4c6177424d96825b389075ad42/?anonymousKey=398cf8c01a66a9d1194c81c8602dc79558f99279
https://vaas-stg.certora.com/output/65266/06598b06aef44a22afc08126ba2f84cd/?anonymousKey=039263fe44ef53a936d43e686010d2c5de954764

Initialize
https://vaas-stg.certora.com/output/65266/d65e47402e474b7a9349a33e2682d35e/?anonymousKey=c45714df90e9a085bca73d9ebddbd08b00d66051
Liquidation (all but liquidate)
https://vaas-stg.certora.com/output/65266/02b54dd021af4698b1709ab7a9bed520/?anonymousKey=b968def29a462ac03e2647984bbcbf0664265ae1

Liquidation.liquidate
https://vaas-stg.certora.com/output/65266/46882b4559da48169f9ac49e3020b33b/?anonymousKey=4f816f1523b501c8095d37923b8ead83dc54e0d1
https://vaas-stg.certora.com/output/65266/9debd90a3ecb4e0abf6c3c7df408b11e/?anonymousKey=9ab562607377237cdbecae2603fb03b04245ebe3
https://vaas-stg.certora.com/output/65266/8ce6be90e5ed4eeca476be3c06965f61/?anonymousKey=e7dbfa1b0215ba950a24c08432f887a6d191295e

Vault
https://vaas-stg.certora.com/output/65266/91ab4292727c465e8fcbf8bc4b96a894/?anonymousKey=d93d01c2c6a1e1ba764154a3665ad693d0e0c4cb
https://vaas-stg.certora.com/output/65266/43519c20e70e4a80ba4d5f650f46b4f6/?anonymousKey=1506ea2fd3ed98c50e1b075e7a418164447f0e41
https://vaas-stg.certora.com/output/65266/853035da7c8c497ca73ea62ea2930edd/?anonymousKey=b00138b07180a8edb6e2943354397ed1408a66be
https://vaas-stg.certora.com/output/65266/3c541734f5db44de884def4f4af3a737/?anonymousKey=8e5ed8a8df492799aacdce39178ac2e894f2a652
https://vaas-stg.certora.com/output/65266/8e2c2085ff80419faa60097420ba5dd8/?anonymousKey=ba00f2500a2165819d4c8e13d04b0f47bdeb8ce3

Token
https://vaas-stg.certora.com/output/65266/f58f9f6c29f5403eae755fd7c0efe1a6/?anonymousKey=73db086609e9c5bb1d59c0c56ebac9cfc5ef068c
https://vaas-stg.certora.com/output/65266/bb3b80a8fa20453090847a7ef2c2b04d/?anonymousKey=a1a5416830fb47240ec39be2b0334af3fc39a162
https://vaas-stg.certora.com/output/65266/3a35901031a047659e8e70b2ab627c44/?anonymousKey=e3a58a15964e9187bf55fc52a987cf338e3813b9
https://vaas-stg.certora.com/output/65266/5d7d09d6c2d545d6bd4adcfdec807164/?anonymousKey=7afccf35e6a73603a307aae64fa74f46d233d15e

@andrew-certora andrew-certora merged commit 272c8bb into master Aug 20, 2024
5 checks passed
@andrew-certora andrew-certora deleted the certora branch August 20, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants