Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0aa19d2
WIP mp estimate
3esmit Jul 2, 2024
e6df0a6
wip mp estimate
3esmit Jul 2, 2024
4a699ef
WIP
0x-r4bbit Jul 3, 2024
4cca1db
WIP estimated MP
3esmit Jul 17, 2024
97e50b2
WIP: custom revert when restaking
0x-r4bbit Jul 17, 2024
95f06b4
WIP: make code compile again
0x-r4bbit Jul 17, 2024
86c411a
WIP: make tests compile again
0x-r4bbit Jul 17, 2024
ec98278
WIP: continue implementing mp estimation
0x-r4bbit Jul 18, 2024
be137c7
WIP: fixing one-off error for MP estimation
0x-r4bbit Jul 19, 2024
60d80bf
WIP: more mp estimation debugging
0x-r4bbit Jul 19, 2024
de3790e
WIP
0x-r4bbit Jul 30, 2024
c1f2838
fix: mp estimation to exact correct values
3esmit Aug 1, 2024
2453e18
fix: remove from estimation mps that would not be minted in currentEp…
3esmit Aug 5, 2024
99ee39d
chore: remove console.logs and old comments
3esmit Aug 7, 2024
ca0fb9a
chore: remove old comments
3esmit Aug 7, 2024
2f07513
chore: update .gas-report
3esmit Aug 7, 2024
e213629
WIP: improve gas, fix halfway epoch stake estimation, reject too low …
3esmit Aug 7, 2024
522e4ae
fix: shift mps not minted in stake epoch to final epoch of account MP…
3esmit Aug 9, 2024
6744ce1
WIP: add estimatied MPs to migration system
3esmit Aug 15, 2024
7bf91d4
fix: adorno and workaroud test
3esmit Aug 27, 2024
d2345d2
fix: line lenght size
3esmit Aug 27, 2024
12f16e3
fix: line lenght (other way)
3esmit Aug 27, 2024
5af8d35
fix: update foundry.toml line_lenght to 110 to fix conflict with pret…
3esmit Aug 27, 2024
99370f1
fix: ran foundryup, reverted to 120 max chars and ran forge fmt
3esmit Aug 28, 2024
9e1192d
fix: revert line_lenght to 110
3esmit Aug 28, 2024
5d204fe
refactor: remove restake ability from the same vault
3esmit Aug 31, 2024
3fee281
WIP: vault manager
3esmit Sep 1, 2024
fd8e2c4
refactor: update balanceOf function to include maximum MP minting
3esmit Sep 11, 2024
6a102c9
refactor: Update VaultManager contract to include maximum MP minting …
3esmit Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 0 additions & 98 deletions .gas-report
Original file line number Diff line number Diff line change
@@ -1,98 +0,0 @@
| contracts/StakeManager.sol:StakeManager contract | | | | | |
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 2058079 | 10495 | | | | |
| Function Name | min | avg | median | max | # calls |
| EPOCH_SIZE | 285 | 285 | 285 | 285 | 9 |
| MAX_LOCKUP_PERIOD | 405 | 405 | 405 | 405 | 2 |
| MIN_LOCKUP_PERIOD | 264 | 264 | 264 | 264 | 3 |
| accounts | 1406 | 1406 | 1406 | 1406 | 22 |
| currentEpoch | 341 | 1571 | 2341 | 2341 | 13 |
| epochEnd | 627 | 627 | 627 | 627 | 56 |
| executeAccount | 1311 | 54054 | 58730 | 104630 | 63 |
| executeEpoch | 87833 | 95166 | 87833 | 109833 | 3 |
| isVault | 517 | 2117 | 2517 | 2517 | 15 |
| lock | 2614 | 2614 | 2614 | 2614 | 1 |
| migrateTo | 1041 | 1713 | 1041 | 2721 | 5 |
| oldManager | 240 | 240 | 240 | 240 | 8 |
| owner | 2341 | 2341 | 2341 | 2341 | 8 |
| pendingReward | 386 | 1243 | 386 | 2386 | 21 |
| setVault | 22606 | 22606 | 22606 | 22606 | 12 |
| stake | 2638 | 136864 | 188409 | 189128 | 17 |
| stakedToken | 260 | 260 | 260 | 260 | 26 |
| totalSupply | 561 | 561 | 561 | 561 | 17 |
| totalSupplyBalance | 362 | 1592 | 2362 | 2362 | 13 |
| totalSupplyMP | 384 | 1614 | 2384 | 2384 | 13 |
| unstake | 1730 | 20008 | 8086 | 127550 | 9 |


| contracts/StakeVault.sol:StakeVault contract | | | | | |
|----------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 635445 | 3370 | | | | |
| Function Name | min | avg | median | max | # calls |
| acceptMigration | 1726 | 1726 | 1726 | 1726 | 2 |
| leave | 1712 | 1712 | 1712 | 1712 | 1 |
| owner | 362 | 362 | 362 | 362 | 14 |
| stake | 3433 | 165544 | 219184 | 219903 | 17 |
| stakedToken | 212 | 212 | 212 | 212 | 2 |
| unstake | 2588 | 28122 | 14407 | 131871 | 8 |


| contracts/VaultFactory.sol:VaultFactory contract | | | | | |
|--------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1043406 | 5305 | | | | |
| Function Name | min | avg | median | max | # calls |
| createVault | 670954 | 674204 | 675454 | 675454 | 18 |
| setStakeManager | 2518 | 5317 | 4644 | 8790 | 3 |
| stakeManager | 368 | 1868 | 2368 | 2368 | 4 |


| lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol:ERC20 contract | | | | | |
|---------------------------------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 649818 | 3562 | | | | |
| Function Name | min | avg | median | max | # calls |
| approve | 24603 | 24603 | 24603 | 24603 | 15 |
| balanceOf | 561 | 819 | 561 | 2561 | 139 |
| transfer | 3034 | 8340 | 3034 | 22934 | 15 |
| transferFrom | 27530 | 27530 | 27530 | 27530 | 16 |


| script/Deploy.s.sol:Deploy contract | | | | | |
|-------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 5142589 | 26992 | | | | |
| Function Name | min | avg | median | max | # calls |
| run | 4837698 | 4837698 | 4837698 | 4837698 | 32 |


| script/DeploymentConfig.s.sol:DeploymentConfig contract | | | | | |
|---------------------------------------------------------|-----------------|-----|--------|-----|---------|
| Deployment Cost | Deployment Size | | | | |
| 1634091 | 8548 | | | | |
| Function Name | min | avg | median | max | # calls |
| activeNetworkConfig | 455 | 455 | 455 | 455 | 64 |


| test/mocks/BrokenERC20.s.sol:BrokenERC20 contract | | | | | |
|---------------------------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 475642 | 2660 | | | | |
| Function Name | min | avg | median | max | # calls |
| approve | 24603 | 24603 | 24603 | 24603 | 1 |
| balanceOf | 561 | 1227 | 561 | 2561 | 3 |
| transferFrom | 511 | 511 | 511 | 511 | 1 |


| test/script/DeployBroken.s.sol:DeployBroken contract | | | | | |
|------------------------------------------------------|-----------------|---------|---------|---------|---------|
| Deployment Cost | Deployment Size | | | | |
| 3915327 | 20790 | | | | |
| Function Name | min | avg | median | max | # calls |
| run | 3677521 | 3677521 | 3677521 | 3677521 | 1 |




70 changes: 46 additions & 24 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
CreateVaultTest:testDeployment() (gas: 9774)
CreateVaultTest:test_createVault() (gas: 692923)
ExecuteAccountTest:testDeployment() (gas: 26335)
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3633587)
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1051631)
LeaveTest:testDeployment() (gas: 26335)
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1052239)
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 10794)
LockTest:testDeployment() (gas: 26335)
LockTest:test_RevertWhen_InvalidLockupPeriod() (gas: 865463)
CreateVaultTest:test_createVault() (gas: 692936)
ExecuteAccountTest:testDeployment() (gas: 28720)
ExecuteAccountTest:test_ExecuteAccountMintMP() (gas: 3856669)
ExecuteAccountTest:test_MintMPLimit() (gas: 187)
ExecuteAccountTest:test_PayRewards() (gas: 165)
ExecuteAccountTest:test_RevertWhen_InvalidLimitEpoch() (gas: 1154891)
ExecuteAccountTest:test_ShouldNotMintMoreThanCap() (gas: 77570109)
ExecuteAccountTest:test_UpdateEpoch() (gas: 164)
ExecuteEpochTest:testDeployment() (gas: 28720)
ExecuteEpochTest:testNewDeployment() (gas: 30815)
ExecuteEpochTest:test_ExecuteEpochShouldIncreaseEpoch() (gas: 94832)
ExecuteEpochTest:test_ExecuteEpochShouldIncreasePendingReward() (gas: 253059)
ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochBeforeEnd() (gas: 17994)
ExecuteEpochTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 105720)
LeaveTest:testDeployment() (gas: 28720)
LeaveTest:test_RevertWhen_NoPendingMigration() (gas: 1154740)
LeaveTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
LockTest:testDeployment() (gas: 28720)
LockTest:test_NewLockupPeriod() (gas: 1143590)
LockTest:test_RevertWhen_InvalidNewLockupPeriod() (gas: 1135184)
LockTest:test_RevertWhen_InvalidUpdateLockupPeriod() (gas: 1231816)
LockTest:test_RevertWhen_SenderIsNotVault() (gas: 10630)
MigrateTest:testDeployment() (gas: 26335)
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1049846)
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 10794)
LockTest:test_ShouldIncreaseBonusMP() (gas: 1123712)
LockTest:test_UpdateLockupPeriod() (gas: 1281226)
MigrateTest:testDeployment() (gas: 28720)
MigrateTest:test_RevertWhen_NoPendingMigration() (gas: 1152379)
MigrateTest:test_RevertWhen_SenderIsNotVault() (gas: 10750)
MigrationInitializeTest:testDeployment() (gas: 28720)
MigrationInitializeTest:test_RevertWhen_MigrationPending() (gas: 5718968)
MigrationStakeManagerTest:testDeployment() (gas: 28720)
MigrationStakeManagerTest:testNewDeployment() (gas: 30859)
MigrationStakeManagerTest:test_ExecuteEpochShouldNotIncreaseEpochInMigration() (gas: 105708)
SetStakeManagerTest:testDeployment() (gas: 9774)
SetStakeManagerTest:test_RevertWhen_InvalidStakeManagerAddress() (gas: 20481)
SetStakeManagerTest:test_SetStakeManager() (gas: 19869)
StakeManagerTest:testDeployment() (gas: 26107)
StakeTest:testDeployment() (gas: 26335)
StakeTest:test_RevertWhen_InvalidLockupPeriod() (gas: 883366)
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10650)
StakeManagerTest:testDeployment() (gas: 28492)
StakeTest:testDeployment() (gas: 28720)
StakeTest:test_RevertWhen_InvalidLockupPeriod() (gas: 892157)
StakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10680)
StakeTest:test_RevertWhen_StakeTokenTransferFails() (gas: 175040)
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 948728)
StakeTest:test_StakeWithoutLockUpTimeMintsMultiplierPoints() (gas: 1029276)
StakedTokenTest:testStakeToken() (gas: 7616)
UnstakeTest:testDeployment() (gas: 26357)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1051813)
UnstakeTest:testDeployment() (gas: 28742)
UnstakeTest:test_RevertWhen_AmountMoreThanBalance() (gas: 1129289)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 1158740)
UnstakeTest:test_RevertWhen_SenderIsNotVault() (gas: 10653)
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 3573382)
UnstakeTest:test_UnstakeShouldReturnFunds() (gas: 946825)
UserFlowsTest:testDeployment() (gas: 26335)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1046480)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1825625)
UnstakeTest:test_UnstakeShouldBurnMultiplierPoints() (gas: 5498441)
UnstakeTest:test_UnstakeShouldReturnFund_NoLockUp() (gas: 1026676)
UnstakeTest:test_UnstakeShouldReturnFund_WithLockUp() (gas: 1115802)
UserFlowsTest:testDeployment() (gas: 28720)
UserFlowsTest:test_PendingMPToBeMintedCannotBeGreaterThanTotalSupplyMP(uint8) (runs: 1001, μ: 67957148, ~: 28286436)
UserFlowsTest:test_StakeWithLockUpTimeLocksStake() (gas: 1116690)
UserFlowsTest:test_StakedSupplyShouldIncreaseAndDecreaseAgain() (gas: 1951132)
VaultFactoryTest:testDeployment() (gas: 9774)
3 changes: 2 additions & 1 deletion certora/confs/StakeManager.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"files":
"files":
["contracts/StakeManager.sol",
"certora/helpers/ERC20A.sol"
],
Expand All @@ -12,6 +12,7 @@
"optimistic_loop": true,
"loop_iter": "3",
"packages": [
"forge-std=lib/forge-std/src",
"@openzeppelin=lib/openzeppelin-contracts"
]
}
Expand Down
10 changes: 5 additions & 5 deletions certora/specs/StakeManager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ methods {
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 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);
}

Expand All @@ -18,28 +18,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 Down
25 changes: 23 additions & 2 deletions certora/specs/StakeManagerProcessAccount.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ 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 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 pendingMPToBeMinted() external returns (uint256) envfree;
}

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

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

return lockUntil;
}
Expand Down Expand Up @@ -69,6 +70,26 @@ rule checkAccountProcessedBeforeStoring(method f) filtered {

}

rule pendingMPToMintShouldNotBeBiggerTotalSupplyMP(method f) filtered {
f -> !requiresPreviousManager(f) && !requiresNextManager(f)
} {

calldataarg args;
env e;
address account;
address account2;
mathint amount;

uint256 pendingMPBefore = currentContract.pendingMPToBeMinted();
currentContract.stake(e, amount, 0);
uint256 pendingMPAfter = currentContract.pendingMPToBeMinted();

require e.block.timestamp > currentContract.currentEpoch()
currentContract.executeAccount(account1)
assert pendingMPAfter > pendingMPBefore;
}


/*
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.
Expand Down
Loading