Skip to content

Commit 40c5be4

Browse files
committed
refactor(certora): introduce shared.spec to reuse helper functions
We have a couple of helper functions redefined in multiple spec files. This commit introduces a `shared.spec` that provides such functions. The file is then imported in other spec files, so we can make use of the functions there. Closes #87
1 parent 3e5361f commit 40c5be4

File tree

5 files changed

+52
-79
lines changed

5 files changed

+52
-79
lines changed

certora/specs/StakeManager.spec

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import "./shared.spec";
2+
13
using ERC20A as staked;
4+
25
methods {
36
function staked.balanceOf(address) external returns (uint256) envfree;
47
function totalSupplyBalance() external returns (uint256) envfree;
@@ -17,34 +20,6 @@ function mulDivSummary(uint256 a, uint256 b, uint256 c) returns uint256 {
1720
return require_uint256(a*b/c);
1821
}
1922

20-
function getAccountBalance(address addr) returns uint256 {
21-
uint256 balance;
22-
_, balance, _, _, _, _, _, _ = accounts(addr);
23-
24-
return balance;
25-
}
26-
27-
function getAccountBonusMultiplierPoints(address addr) returns uint256 {
28-
uint256 bonusMP;
29-
_, _, bonusMP, _, _, _, _, _ = accounts(addr);
30-
31-
return bonusMP;
32-
}
33-
34-
function getAccountCurrentMultiplierPoints(address addr) returns uint256 {
35-
uint256 totalMP;
36-
_, _, _, totalMP, _, _, _, _ = accounts(addr);
37-
38-
return totalMP;
39-
}
40-
41-
function getAccountLockUntil(address addr) returns uint256 {
42-
uint256 lockUntil;
43-
_, _, _, _, _, lockUntil, _, _ = accounts(addr);
44-
45-
return lockUntil;
46-
}
47-
4823
function isMigrationfunction(method f) returns bool {
4924
return
5025
f.selector == sig:migrateTo(bool).selector ||
@@ -59,17 +34,6 @@ function simplification(env e) {
5934
require e.msg.sender != 0;
6035
}
6136

62-
definition requiresPreviousManager(method f) returns bool = (
63-
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256).selector ||
64-
f.selector == sig:migrateFrom(address,bool,StakeManager.Account).selector ||
65-
f.selector == sig:increaseTotalMP(uint256).selector
66-
);
67-
68-
definition requiresNextManager(method f) returns bool = (
69-
f.selector == sig:migrateTo(bool).selector ||
70-
f.selector == sig:transferNonPending().selector
71-
);
72-
7337
ghost mathint sumOfEpochRewards
7438
{
7539
init_state axiom sumOfEpochRewards == 0;

certora/specs/StakeManagerProcessAccount.spec

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import "./shared.spec";
2+
13
using ERC20A as staked;
4+
25
methods {
36
function staked.balanceOf(address) external returns (uint256) envfree;
47
function totalSupplyBalance() external returns (uint256) envfree;
@@ -20,28 +23,10 @@ function markAccountProccessed(address account, uint256 _limitEpoch) {
2023
accountProcessed[account] = to_mathint(_limitEpoch);
2124
}
2225

23-
function getAccountLockUntil(address addr) returns uint256 {
24-
uint256 lockUntil;
25-
_, _, _, _, _, lockUntil, _, _ = accounts(addr);
26-
27-
return lockUntil;
28-
}
29-
3026
hook Sstore accounts[KEY address addr].balance uint256 newValue (uint256 oldValue) {
3127
balanceChangedInEpoch[addr] = accountProcessed[addr];
3228
}
3329

34-
definition requiresPreviousManager(method f) returns bool = (
35-
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256).selector ||
36-
f.selector == sig:migrateFrom(address,bool,StakeManager.Account).selector ||
37-
f.selector == sig:increaseTotalMP(uint256).selector
38-
);
39-
40-
definition requiresNextManager(method f) returns bool = (
41-
f.selector == sig:migrateTo(bool).selector ||
42-
f.selector == sig:transferNonPending().selector
43-
);
44-
4530
/*
4631
If a balance of an account has changed, the account should have been processed up to the `currentEpoch`.
4732
This is filtering out most of migration related functions, as those will be vacuous.

certora/specs/StakeManagerStartMigration.spec

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "./shared.spec";
2+
13
using ERC20A as staked;
24
using StakeManagerNew as newStakeManager;
35

@@ -12,21 +14,6 @@ methods {
1214
function StakeManagerNew.totalSupplyBalance() external returns (uint256) envfree;
1315
}
1416

15-
16-
function getAccountMultiplierPoints(address addr) returns uint256 {
17-
uint256 multiplierPoints;
18-
_, _, _, multiplierPoints, _, _, _, _ = accounts(addr);
19-
20-
return multiplierPoints;
21-
}
22-
23-
function getAccountBalance(address addr) returns uint256 {
24-
uint256 balance;
25-
_, balance, _, _, _, _, _, _ = accounts(addr);
26-
27-
return balance;
28-
}
29-
3017
definition blockedWhenMigrating(method f) returns bool = (
3118
f.selector == sig:stake(uint256, uint256).selector ||
3219
f.selector == sig:unstake(uint256).selector ||

certora/specs/StakeVault.spec

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import "./shared.spec";
2+
13
using ERC20A as staked;
24
using StakeManager as stakeManager;
35

@@ -17,13 +19,6 @@ function mulDivSummary(uint256 a, uint256 b, uint256 c) returns uint256 {
1719
return require_uint256(a*b/c);
1820
}
1921

20-
function getAccountBalance(address addr) returns uint256 {
21-
uint256 balance;
22-
_, balance, _, _, _, _, _, _ = stakeManager.accounts(addr);
23-
24-
return balance;
25-
}
26-
2722
definition isMigrationFunction(method f) returns bool = (
2823
f.selector == sig:stakeManager.migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256).selector ||
2924
f.selector == sig:stakeManager.migrateFrom(address,bool,StakeManager.Account).selector ||

certora/specs/shared.spec

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using StakeManager as _stakeManager;
2+
3+
definition requiresPreviousManager(method f) returns bool = (
4+
f.selector == sig:_stakeManager.migrationInitialize(uint256,uint256,uint256,uint256,uint256,uint256,uint256).selector ||
5+
f.selector == sig:_stakeManager.migrateFrom(address,bool,StakeManager.Account).selector ||
6+
f.selector == sig:_stakeManager.increaseTotalMP(uint256).selector
7+
);
8+
9+
definition requiresNextManager(method f) returns bool = (
10+
f.selector == sig:_stakeManager.migrateTo(bool).selector ||
11+
f.selector == sig:_stakeManager.transferNonPending().selector
12+
);
13+
14+
function getAccountBalance(address addr) returns uint256 {
15+
uint256 balance;
16+
_, balance, _, _, _, _, _, _ = _stakeManager.accounts(addr);
17+
18+
return balance;
19+
}
20+
21+
function getAccountBonusMultiplierPoints(address addr) returns uint256 {
22+
uint256 bonusMP;
23+
_, _, bonusMP, _, _, _, _, _ = _stakeManager.accounts(addr);
24+
25+
return bonusMP;
26+
}
27+
28+
function getAccountCurrentMultiplierPoints(address addr) returns uint256 {
29+
uint256 totalMP;
30+
_, _, _, totalMP, _, _, _, _ = _stakeManager.accounts(addr);
31+
32+
return totalMP;
33+
}
34+
35+
function getAccountLockUntil(address addr) returns uint256 {
36+
uint256 lockUntil;
37+
_, _, _, _, _, lockUntil, _, _ = _stakeManager.accounts(addr);
38+
39+
return lockUntil;
40+
}
41+
42+

0 commit comments

Comments
 (0)