-
Notifications
You must be signed in to change notification settings - Fork 4
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
chore(StakeManagerProcessAccount.spec): add specs for processAccount #57
Merged
Merged
Changes from all commits
Commits
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 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": | ||
["contracts/StakeManager.sol", | ||
"certora/helpers/ERC20A.sol" | ||
], | ||
"link" : [ | ||
"StakeManager:stakedToken=ERC20A" | ||
], | ||
"msg": "Verifying StakeManager ProcessAccount", | ||
"rule_sanity": "basic", | ||
"verify": "StakeManager:certora/specs/StakeManagerProcessAccount.spec", | ||
"optimistic_loop": true, | ||
"loop_iter": "3", | ||
"packages": [ | ||
"@openzeppelin=lib/openzeppelin-contracts" | ||
] | ||
} | ||
|
||
|
This file contains 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,86 @@ | ||
using ERC20A as staked; | ||
methods { | ||
function staked.balanceOf(address) external returns (uint256) envfree; | ||
function totalSupplyBalance() external returns (uint256) envfree; | ||
function accounts(address) external returns(address, uint256, uint256, uint256, uint256, uint256, uint256) envfree; | ||
|
||
function _processAccount(StakeManager.Account storage account, uint256 _limitEpoch) internal with(env e) => markAccountProccessed(e.msg.sender, _limitEpoch); | ||
function _.migrationInitialize(uint256,uint256,uint256,uint256) external => NONDET; | ||
} | ||
|
||
// keeps track of the last epoch an account was processed | ||
ghost mapping (address => mathint) accountProcessed; | ||
// balance changed in an epoch that was processed | ||
ghost mapping (address => mathint) balanceChangedInEpoch; | ||
|
||
function markAccountProccessed(address account, uint256 _limitEpoch) { | ||
accountProcessed[account] = to_mathint(_limitEpoch); | ||
} | ||
|
||
function getAccountLockUntil(address addr) returns uint256 { | ||
uint256 lockUntil; | ||
_, _, _, _, _, lockUntil, _ = accounts(addr); | ||
|
||
return lockUntil; | ||
} | ||
|
||
hook Sstore accounts[KEY address addr].balance uint256 newValue (uint256 oldValue) STORAGE { | ||
balanceChangedInEpoch[addr] = accountProcessed[addr]; | ||
} | ||
|
||
definition requiresPreviousManager(method f) returns bool = ( | ||
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256).selector || | ||
f.selector == sig:migrateFrom(address,bool,StakeManager.Account).selector || | ||
f.selector == sig:increaseMPFromMigration(uint256).selector | ||
); | ||
|
||
definition requiresNextManager(method f) returns bool = ( | ||
f.selector == sig:migrateTo(bool).selector || | ||
f.selector == sig:transferNonPending().selector | ||
); | ||
|
||
/* | ||
If a balance of an account has changed, the account should have been processed up to the `currentEpoch`. | ||
This is filtering out most of migration related functions, as those will be vacuous. | ||
|
||
Verified on two mutations: | ||
https://prover.certora.com/output/40726/68668bbb7b6e49828da8521c3425a20b/?anonymousKey=015fce76d5d66ef40de8342b75fda4cff1dfdd57 | ||
https://prover.certora.com/output/40726/055d52bc67154e3fbea330fd7d68d36d/?anonymousKey=73030555b4cefe429d4eed6718b9a7e5be3a22c8 | ||
*/ | ||
rule checkAccountProcessedBeforeStoring(method f) filtered { | ||
f -> !requiresPreviousManager(f) && !requiresNextManager(f) | ||
} { | ||
address account; | ||
|
||
mathint lastChanged = balanceChangedInEpoch[account]; | ||
env e; | ||
calldataarg args; | ||
|
||
require currentContract.migration == 0; | ||
|
||
// If the account's `lockUntil` == 0, then the account will be initialized | ||
// with the current epoch and no processing is required. | ||
require getAccountLockUntil(account) > 0; | ||
|
||
f(e,args); | ||
|
||
assert balanceChangedInEpoch[account] != lastChanged => | ||
balanceChangedInEpoch[account] == to_mathint(currentContract.currentEpoch); | ||
|
||
} | ||
|
||
/* | ||
Below is a rule that finds all methods that change an account's balance. | ||
This is just for debugging purposes and not meant to be a production rule. | ||
Hence it is commented out. | ||
*/ | ||
/* | ||
rule whoChangeERC20Balance( method f ) filtered { f -> f.contract != staked } | ||
{ | ||
address user; | ||
uint256 before = staked.balanceOf(user); | ||
calldataarg args; | ||
env e; | ||
f(e,args); | ||
assert before == staked.balanceOf(user); | ||
} */ |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, this was a tricky one to find.
Was debugging a counter example, without realizing that the
accountProcessed
ghost was never touched.