2024-01-24 08:39:04 +00:00
|
|
|
using ERC20A as staked;
|
|
|
|
methods {
|
|
|
|
function staked.balanceOf(address) external returns (uint256) envfree;
|
2024-03-01 09:35:19 +00:00
|
|
|
function totalSupplyBalance() external returns (uint256) envfree;
|
|
|
|
function totalSupplyMP() external returns (uint256) envfree;
|
2024-06-19 09:26:03 +00:00
|
|
|
function previousManager() external returns (address) envfree;
|
2024-01-24 15:07:23 +00:00
|
|
|
function _.migrateFrom(address, bool, StakeManager.Account) external => NONDET;
|
2024-06-19 09:26:03 +00:00
|
|
|
function _.increaseTotalMP(uint256) external => NONDET;
|
2024-01-24 15:07:23 +00:00
|
|
|
function _.migrationInitialize(uint256,uint256,uint256,uint256) external => NONDET;
|
2024-03-01 09:35:19 +00:00
|
|
|
function accounts(address) external returns(address, uint256, uint256, uint256, uint256, uint256, uint256) envfree;
|
2024-03-11 11:38:54 +00:00
|
|
|
function Math.mulDiv(uint256 a, uint256 b, uint256 c) internal returns uint256 => mulDivSummary(a,b,c);
|
2024-01-24 15:07:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 11:38:54 +00:00
|
|
|
function mulDivSummary(uint256 a, uint256 b, uint256 c) returns uint256 {
|
|
|
|
require c != 0;
|
|
|
|
return require_uint256(a*b/c);
|
2024-01-24 15:07:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAccountBalance(address addr) returns uint256 {
|
|
|
|
uint256 balance;
|
2024-03-01 09:35:19 +00:00
|
|
|
_, balance, _, _, _, _, _ = accounts(addr);
|
2024-01-24 15:07:23 +00:00
|
|
|
|
|
|
|
return balance;
|
2024-01-24 08:39:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 11:38:54 +00:00
|
|
|
function getAccountInitialMultiplierPoints(address addr) returns uint256 {
|
|
|
|
uint256 initialMP;
|
|
|
|
_, _, initialMP, _, _, _, _ = accounts(addr);
|
|
|
|
|
|
|
|
return initialMP;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAccountCurrentMultiplierPoints(address addr) returns uint256 {
|
|
|
|
uint256 currentMP;
|
|
|
|
_, _, _, currentMP, _, _, _ = accounts(addr);
|
|
|
|
|
|
|
|
return currentMP;
|
|
|
|
}
|
|
|
|
|
2024-03-12 15:08:28 +00:00
|
|
|
function getAccountLockUntil(address addr) returns uint256 {
|
|
|
|
uint256 lockUntil;
|
|
|
|
_, _, _, _, _, lockUntil, _ = accounts(addr);
|
|
|
|
|
|
|
|
return lockUntil;
|
|
|
|
}
|
|
|
|
|
2024-01-24 08:39:04 +00:00
|
|
|
function isMigrationfunction(method f) returns bool {
|
2024-01-24 15:07:23 +00:00
|
|
|
return
|
2024-03-04 15:19:45 +00:00
|
|
|
f.selector == sig:migrateTo(bool).selector ||
|
|
|
|
f.selector == sig:transferNonPending().selector;
|
2024-01-24 08:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* assume that migration is zero, causing the verification to take into account only
|
|
|
|
cases where it is zero. specifically no externall call to the migration contract */
|
2024-03-04 15:21:41 +00:00
|
|
|
function simplification(env e) {
|
2024-01-24 08:39:04 +00:00
|
|
|
require currentContract.migration == 0;
|
2024-06-19 09:26:03 +00:00
|
|
|
require currentContract.previousManager() == 0;
|
2024-03-04 15:21:41 +00:00
|
|
|
require e.msg.sender != 0;
|
2024-01-24 08:39:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-05 08:52:40 +00:00
|
|
|
definition requiresPreviousManager(method f) returns bool = (
|
|
|
|
f.selector == sig:migrationInitialize(uint256,uint256,uint256,uint256).selector ||
|
|
|
|
f.selector == sig:migrateFrom(address,bool,StakeManager.Account).selector ||
|
2024-06-19 09:26:03 +00:00
|
|
|
f.selector == sig:increaseTotalMP(uint256).selector
|
2024-03-05 08:52:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
definition requiresNextManager(method f) returns bool = (
|
|
|
|
f.selector == sig:migrateTo(bool).selector ||
|
|
|
|
f.selector == sig:transferNonPending().selector
|
|
|
|
);
|
|
|
|
|
2024-01-24 15:07:23 +00:00
|
|
|
ghost mathint sumOfEpochRewards
|
|
|
|
{
|
|
|
|
init_state axiom sumOfEpochRewards == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ghost mathint sumOfMultipliers /* sigma account[u].multiplier forall u */
|
|
|
|
{
|
|
|
|
init_state axiom sumOfMultipliers == 0;
|
|
|
|
}
|
|
|
|
|
2024-01-24 11:16:01 +00:00
|
|
|
ghost mathint sumOfBalances /* sigma account[u].balance forall u */ {
|
|
|
|
init_state axiom sumOfBalances == 0;
|
|
|
|
}
|
|
|
|
|
2024-03-18 11:08:50 +00:00
|
|
|
hook Sstore epochs[KEY uint256 epochId].epochReward uint256 newValue (uint256 oldValue) {
|
2024-01-24 15:07:23 +00:00
|
|
|
sumOfEpochRewards = sumOfEpochRewards - oldValue + newValue;
|
|
|
|
}
|
|
|
|
|
2024-03-18 11:08:50 +00:00
|
|
|
hook Sstore accounts[KEY address addr].balance uint256 newValue (uint256 oldValue) {
|
2024-01-24 15:07:23 +00:00
|
|
|
sumOfBalances = sumOfBalances - oldValue + newValue;
|
|
|
|
}
|
|
|
|
|
2024-03-18 11:08:50 +00:00
|
|
|
hook Sstore accounts[KEY address addr].currentMP uint256 newValue (uint256 oldValue) {
|
2024-01-24 15:07:23 +00:00
|
|
|
sumOfMultipliers = sumOfMultipliers - oldValue + newValue;
|
|
|
|
}
|
|
|
|
|
2024-03-04 15:21:41 +00:00
|
|
|
invariant sumOfBalancesIsTotalSupplyBalance()
|
2024-03-05 08:52:40 +00:00
|
|
|
sumOfBalances == to_mathint(totalSupplyBalance())
|
|
|
|
filtered {
|
|
|
|
m -> !requiresPreviousManager(m) && !requiresNextManager(m)
|
|
|
|
}
|
2024-01-24 15:07:23 +00:00
|
|
|
|
|
|
|
invariant sumOfMultipliersIsMultiplierSupply()
|
2024-03-05 08:52:40 +00:00
|
|
|
sumOfMultipliers == to_mathint(totalSupplyMP())
|
|
|
|
filtered {
|
|
|
|
m -> !requiresPreviousManager(m) && !requiresNextManager(m)
|
|
|
|
}
|
2024-01-24 15:07:23 +00:00
|
|
|
|
|
|
|
invariant sumOfEpochRewardsIsPendingRewards()
|
|
|
|
sumOfEpochRewards == to_mathint(currentContract.pendingReward)
|
|
|
|
{ preserved {
|
|
|
|
requireInvariant highEpochsAreNull(currentContract.currentEpoch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
invariant highEpochsAreNull(uint256 epochNumber)
|
2024-03-04 15:21:41 +00:00
|
|
|
epochNumber >= currentContract.currentEpoch => currentContract.epochs[epochNumber].epochReward == 0
|
2024-03-05 08:52:40 +00:00
|
|
|
filtered {
|
|
|
|
m -> !requiresPreviousManager(m) && !requiresNextManager(m)
|
2024-03-04 15:21:41 +00:00
|
|
|
}
|
2024-01-24 15:07:23 +00:00
|
|
|
|
2024-03-11 14:34:15 +00:00
|
|
|
invariant InitialMPIsNeverSmallerThanBalance(address addr)
|
|
|
|
to_mathint(getAccountInitialMultiplierPoints(addr)) >= to_mathint(getAccountBalance(addr))
|
|
|
|
filtered {
|
|
|
|
f -> f.selector != sig:migrateFrom(address,bool,StakeManager.Account).selector
|
|
|
|
}
|
|
|
|
|
|
|
|
invariant CurrentMPIsNeverSmallerThanInitialMP(address addr)
|
|
|
|
to_mathint(getAccountCurrentMultiplierPoints(addr)) >= to_mathint(getAccountInitialMultiplierPoints(addr))
|
|
|
|
filtered {
|
|
|
|
f -> f.selector != sig:migrateFrom(address,bool,StakeManager.Account).selector
|
|
|
|
}
|
|
|
|
|
2024-03-11 11:38:54 +00:00
|
|
|
invariant MPcantBeGreaterThanMaxMP(address addr)
|
|
|
|
to_mathint(getAccountCurrentMultiplierPoints(addr)) <= (getAccountBalance(addr) * 8) + getAccountInitialMultiplierPoints(addr)
|
|
|
|
filtered {
|
|
|
|
f -> f.selector != sig:migrateFrom(address,bool,StakeManager.Account).selector
|
|
|
|
}
|
|
|
|
{ preserved {
|
2024-03-11 14:34:15 +00:00
|
|
|
requireInvariant InitialMPIsNeverSmallerThanBalance(addr);
|
|
|
|
requireInvariant CurrentMPIsNeverSmallerThanInitialMP(addr);
|
2024-03-11 11:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-24 08:39:04 +00:00
|
|
|
rule reachability(method f)
|
|
|
|
{
|
|
|
|
calldataarg args;
|
|
|
|
env e;
|
|
|
|
f(e,args);
|
|
|
|
satisfy true;
|
|
|
|
}
|
|
|
|
|
2024-03-12 15:08:28 +00:00
|
|
|
rule stakingMintsMultiplierPoints1To1Ratio {
|
|
|
|
|
|
|
|
env e;
|
|
|
|
uint256 amount;
|
|
|
|
uint256 lockupTime;
|
|
|
|
uint256 multiplierPointsBefore;
|
|
|
|
uint256 multiplierPointsAfter;
|
|
|
|
|
|
|
|
requireInvariant InitialMPIsNeverSmallerThanBalance(e.msg.sender);
|
|
|
|
requireInvariant CurrentMPIsNeverSmallerThanInitialMP(e.msg.sender);
|
|
|
|
|
|
|
|
require getAccountLockUntil(e.msg.sender) <= e.block.timestamp;
|
|
|
|
|
|
|
|
multiplierPointsBefore = getAccountInitialMultiplierPoints(e.msg.sender);
|
|
|
|
stake(e, amount, lockupTime);
|
|
|
|
multiplierPointsAfter = getAccountInitialMultiplierPoints(e.msg.sender);
|
|
|
|
|
|
|
|
assert lockupTime == 0 => to_mathint(multiplierPointsAfter) == multiplierPointsBefore + amount;
|
|
|
|
assert to_mathint(multiplierPointsAfter) >= multiplierPointsBefore + amount;
|
|
|
|
}
|
|
|
|
|
2024-03-12 13:13:52 +00:00
|
|
|
rule stakingGreaterLockupTimeMeansGreaterMPs {
|
|
|
|
|
|
|
|
env e;
|
|
|
|
uint256 amount;
|
|
|
|
uint256 lockupTime1;
|
|
|
|
uint256 lockupTime2;
|
|
|
|
uint256 multiplierPointsAfter1;
|
|
|
|
uint256 multiplierPointsAfter2;
|
|
|
|
|
|
|
|
storage initalStorage = lastStorage;
|
|
|
|
|
|
|
|
stake(e, amount, lockupTime1);
|
|
|
|
multiplierPointsAfter1 = getAccountInitialMultiplierPoints(e.msg.sender);
|
|
|
|
|
|
|
|
stake(e, amount, lockupTime2) at initalStorage;
|
|
|
|
multiplierPointsAfter2 = getAccountInitialMultiplierPoints(e.msg.sender);
|
|
|
|
|
|
|
|
assert lockupTime1 >= lockupTime2 => to_mathint(multiplierPointsAfter1) >= to_mathint(multiplierPointsAfter2);
|
|
|
|
satisfy to_mathint(multiplierPointsAfter1) > to_mathint(multiplierPointsAfter2);
|
|
|
|
}
|
|
|
|
|
2024-01-24 08:39:04 +00:00
|
|
|
/**
|
|
|
|
@title when there is no migration - some functions must revert.
|
|
|
|
Other function should have non reverting cases
|
|
|
|
**/
|
|
|
|
rule revertsWhenNoMigration(method f) {
|
|
|
|
calldataarg args;
|
|
|
|
env e;
|
|
|
|
require currentContract.migration == 0;
|
|
|
|
f@withrevert(e,args);
|
|
|
|
bool reverted = lastReverted;
|
|
|
|
if (!isMigrationfunction(f))
|
|
|
|
satisfy !reverted;
|
|
|
|
assert isMigrationfunction(f) => reverted;
|
|
|
|
}
|
2023-12-11 14:10:41 +00:00
|
|
|
|
2024-03-01 09:40:13 +00:00
|
|
|
// This rule is commented out as it's just a helper rule to easily see which
|
|
|
|
// functions change the balance of the `StakeManager` contract.
|
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
// }
|
2024-01-24 15:07:23 +00:00
|
|
|
|
2024-03-04 15:23:47 +00:00
|
|
|
rule epochOnlyIncreases(method f) {
|
2024-01-24 15:07:23 +00:00
|
|
|
env e;
|
|
|
|
calldataarg args;
|
|
|
|
|
|
|
|
uint256 epochBefore = currentContract.currentEpoch;
|
|
|
|
|
|
|
|
f(e, args);
|
|
|
|
|
|
|
|
assert currentContract.currentEpoch >= epochBefore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//TODO codehash / isVault
|
|
|
|
/*
|
|
|
|
ghost mapping(address => bytes32) codehash;
|
|
|
|
|
|
|
|
hook EXTCODEHASH(address a) bytes32 hash {
|
|
|
|
require hash == codehash[a];
|
|
|
|
}
|
|
|
|
|
|
|
|
rule checksCodeHash(method f) filtered {
|
|
|
|
f -> requiresVault(f)
|
|
|
|
} {
|
|
|
|
env e;
|
|
|
|
|
|
|
|
bool isWhitelisted = isVault(codehash[e.msg.sender]);
|
|
|
|
f(e);
|
|
|
|
|
|
|
|
assert isWhitelisted;
|
|
|
|
}
|
|
|
|
*/
|