Skip to content

Commit

Permalink
chore: make certora rules passa gain
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-r4bbit committed Sep 4, 2024
1 parent 6df329d commit e21b333
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
7 changes: 5 additions & 2 deletions certora/confs/StakeManager.conf
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"files":
"files":
["contracts/StakeManager.sol",
"certora/helpers/StakeRewardEstimateA.sol",
"certora/helpers/ERC20A.sol"
],
"link" : [
"StakeManager:stakedToken=ERC20A"
"StakeManager:stakedToken=ERC20A",
"StakeManager:stakeRewardEstimate=StakeRewardEstimateA"
],
"msg": "Verifying StakeManager.sol",
"rule_sanity": "basic",
"verify": "StakeManager:certora/specs/StakeManager.spec",
"optimistic_loop": true,
"loop_iter": "3",
"packages": [
"forge-std=lib/forge-std/src",
"@openzeppelin=lib/openzeppelin-contracts"
]
}
Expand Down
9 changes: 6 additions & 3 deletions certora/confs/StakeManagerProcess.conf
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"files":
"files":
["contracts/StakeManager.sol",
"certora/helpers/ERC20A.sol"
"certora/helpers/ERC20A.sol",
"certora/helpers/StakeRewardEstimateA.sol"
],
"link" : [
"StakeManager:stakedToken=ERC20A"
"StakeManager:stakedToken=ERC20A",
"StakeManager:stakeRewardEstimate=StakeRewardEstimateA"
],
"msg": "Verifying StakeManager ProcessAccount",
"rule_sanity": "basic",
"verify": "StakeManager:certora/specs/StakeManagerProcessAccount.spec",
"optimistic_loop": true,
"loop_iter": "3",
"packages": [
"forge-std=lib/forge-std/src",
"@openzeppelin=lib/openzeppelin-contracts"
]
}
Expand Down
8 changes: 8 additions & 0 deletions certora/helpers/StakeRewardEstimateA.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import { StakeRewardEstimate } from "./../../contracts/StakeManager.sol";

contract StakeRewardEstimateA is StakeRewardEstimate {}

Check warning on line 7 in certora/helpers/StakeRewardEstimateA.sol

View workflow job for this annotation

GitHub Actions / lint

Code contains empty blocks

15 changes: 8 additions & 7 deletions certora/specs/StakeManager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ methods {
function previousManager() external returns (address) envfree;
function _.migrateFrom(address, bool, StakeManager.Account) external => NONDET;
function _.increaseTotalMP(uint256) external => NONDET;
function _.migrationInitialize(uint256,uint256,uint256,uint256) external => NONDET;
function accounts(address) external returns(address, uint256, uint256, uint256, uint256, uint256, uint256) envfree;
function _.migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256) external => NONDET;
function accounts(address) external returns(address, uint256, uint256, uint256, uint256, uint256, uint256, uint256) envfree;
function Math.mulDiv(uint256 a, uint256 b, uint256 c) internal returns uint256 => mulDivSummary(a,b,c);
function _._ external => DISPATCH [] default NONDET;
}

function mulDivSummary(uint256 a, uint256 b, uint256 c) returns uint256 {
Expand All @@ -18,28 +19,28 @@ function mulDivSummary(uint256 a, uint256 b, uint256 c) returns uint256 {

function getAccountBalance(address addr) returns uint256 {
uint256 balance;
_, balance, _, _, _, _, _ = accounts(addr);
_, balance, _, _, _, _, _, _ = accounts(addr);

return balance;
}

function getAccountBonusMultiplierPoints(address addr) returns uint256 {
uint256 bonusMP;
_, _, bonusMP, _, _, _, _ = accounts(addr);
_, _, bonusMP, _, _, _, _, _ = accounts(addr);

return bonusMP;
}

function getAccountCurrentMultiplierPoints(address addr) returns uint256 {
uint256 totalMP;
_, _, _, totalMP, _, _, _ = accounts(addr);
_, _, _, totalMP, _, _, _, _ = accounts(addr);

return totalMP;
}

function getAccountLockUntil(address addr) returns uint256 {
uint256 lockUntil;
_, _, _, _, _, lockUntil, _ = accounts(addr);
_, _, _, _, _, lockUntil, _, _ = accounts(addr);

return lockUntil;
}
Expand All @@ -59,7 +60,7 @@ function simplification(env e) {
}

definition requiresPreviousManager(method f) returns bool = (
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256).selector ||
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256).selector ||
f.selector == sig:migrateFrom(address,bool,StakeManager.Account).selector ||
f.selector == sig:increaseTotalMP(uint256).selector
);
Expand Down
11 changes: 7 additions & 4 deletions certora/specs/StakeManagerProcessAccount.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ 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 totalSupplyMP() external returns (uint256) envfree;
function totalMPPerEpoch() external returns (uint256) envfree;
function accounts(address) external returns(address, uint256, 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;
function _.migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256) external => NONDET;
function pendingMPToBeMinted() external returns (uint256) envfree;
}

// keeps track of the last epoch an account was processed
Expand All @@ -19,7 +22,7 @@ function markAccountProccessed(address account, uint256 _limitEpoch) {

function getAccountLockUntil(address addr) returns uint256 {
uint256 lockUntil;
_, _, _, _, _, lockUntil, _ = accounts(addr);
_, _, _, _, _, lockUntil, _, _ = accounts(addr);

return lockUntil;
}
Expand All @@ -29,7 +32,7 @@ hook Sstore accounts[KEY address addr].balance uint256 newValue (uint256 oldValu
}

definition requiresPreviousManager(method f) returns bool = (
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256).selector ||
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256).selector ||
f.selector == sig:migrateFrom(address,bool,StakeManager.Account).selector ||
f.selector == sig:increaseTotalMP(uint256).selector
);
Expand Down

0 comments on commit e21b333

Please sign in to comment.