refactor(StakeVault): Remove obsolete trust stake manager logic

This commit is contained in:
Ricardo Guilherme Schmidt
2025-08-02 04:28:55 -03:00
parent a2ba7d2045
commit 787a04e9fb
5 changed files with 145 additions and 267 deletions

View File

@@ -10,7 +10,7 @@
|-------------------------------------------------------------------------------------------+-----------------+-------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|-------------------------------------------------------------------------------------------+-----------------+-------+--------+--------+---------|
| fallback | 5145 | 65039 | 33119 | 193478 | 3522 |
| fallback | 5145 | 65021 | 33119 | 193478 | 3520 |
╰-------------------------------------------------------------------------------------------+-----------------+-------+--------+--------+---------╯
╭-----------------------------------------------------+-----------------+---------+---------+---------+---------╮
@@ -24,7 +24,7 @@
|-----------------------------------------------------+-----------------+---------+---------+---------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|-----------------------------------------------------+-----------------+---------+---------+---------+---------|
| run | 4666141 | 4666141 | 4666141 | 4666141 | 182 |
| run | 4666141 | 4666141 | 4666141 | 4666141 | 180 |
╰-----------------------------------------------------+-----------------+---------+---------+---------+---------╯
╭-----------------------------------------------------------+-----------------+---------+---------+---------+---------╮
@@ -60,13 +60,13 @@
+=============================================================================================================================+
| Deployment Cost | Deployment Size | | | | |
|-------------------------------------------------------------------+-----------------+---------+---------+---------+---------|
| 8493016 | 40508 | | | | |
| 8406945 | 40092 | | | | |
|-------------------------------------------------------------------+-----------------+---------+---------+---------+---------|
| | | | | | |
|-------------------------------------------------------------------+-----------------+---------+---------+---------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|-------------------------------------------------------------------+-----------------+---------+---------+---------+---------|
| run | 7425695 | 7425695 | 7425695 | 7425695 | 90 |
| run | 7342367 | 7342367 | 7342367 | 7342367 | 88 |
╰-------------------------------------------------------------------+-----------------+---------+---------+---------+---------╯
╭---------------------------------------------------------+-----------------+------+--------+------+---------╮
@@ -80,7 +80,7 @@
|---------------------------------------------------------+-----------------+------+--------+------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|---------------------------------------------------------+-----------------+------+--------+------+---------|
| activeNetworkConfig | 455 | 2040 | 455 | 4455 | 482 |
| activeNetworkConfig | 455 | 2043 | 455 | 4455 | 476 |
╰---------------------------------------------------------+-----------------+------+--------+------+---------╯
╭---------------------------------------------------------------------+-----------------+---------+---------+---------+---------╮
@@ -94,7 +94,7 @@
|---------------------------------------------------------------------+-----------------+---------+---------+---------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|---------------------------------------------------------------------+-----------------+---------+---------+---------+---------|
| runWithAdminAndProxy | 3407494 | 3407494 | 3407494 | 3407494 | 4 |
| runWithAdminAndProxy | 3407494 | 3407494 | 3407494 | 3407494 | 3 |
╰---------------------------------------------------------------------+-----------------+---------+---------+---------+---------╯
╭------------------------------+-----------------+--------+--------+--------+---------╮
@@ -118,7 +118,7 @@
|------------------------------+-----------------+--------+--------+--------+---------|
| accountSlashAmount | 2611 | 2611 | 2611 | 2611 | 2 |
|------------------------------+-----------------+--------+--------+--------+---------|
| addRewardDistributor | 29975 | 63592 | 70903 | 70903 | 296 |
| addRewardDistributor | 29975 | 63542 | 70903 | 70903 | 294 |
|------------------------------+-----------------+--------+--------+--------+---------|
| allowance | 573 | 573 | 573 | 573 | 8 |
|------------------------------+-----------------+--------+--------+--------+---------|
@@ -134,7 +134,7 @@
|------------------------------+-----------------+--------+--------+--------+---------|
| hasRole | 2754 | 2754 | 2754 | 2754 | 4 |
|------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 116796 | 116796 | 116796 | 116796 | 182 |
| initialize | 116796 | 116796 | 116796 | 116796 | 180 |
|------------------------------+-----------------+--------+--------+--------+---------|
| mint | 4869 | 50370 | 51342 | 51342 | 551 |
|------------------------------+-----------------+--------+--------+--------+---------|
@@ -232,17 +232,17 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| getAccountVaults | 5230 | 5230 | 5230 | 5230 | 4 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| getVault | 13653 | 13653 | 13653 | 13653 | 4180 |
| getVault | 13653 | 13653 | 13653 | 13653 | 4181 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 92752 | 92752 | 92752 | 92752 | 90 |
| initialize | 92752 | 92752 | 92752 | 92752 | 88 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| lastRewardTime | 2407 | 2407 | 2407 | 2407 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 66348 | 66348 | 66348 | 66348 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| lock | 7040 | 43282 | 46713 | 87673 | 1034 |
| lock | 7040 | 43192 | 46735 | 86561 | 1034 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| migrateToVault | 9294 | 53513 | 17021 | 170715 | 4 |
| migrateToVault | 9294 | 52631 | 16883 | 167465 | 4 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| mpAccruedOf | 2629 | 2629 | 2629 | 2629 | 20 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
@@ -250,9 +250,9 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| mpBalanceOfAccount | 30210 | 31283 | 31283 | 32356 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| proxiableUUID | 342 | 342 | 342 | 342 | 4 |
| proxiableUUID | 342 | 342 | 342 | 342 | 3 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| registerVault | 2583 | 74539 | 75107 | 75107 | 369 |
| registerVault | 2583 | 74434 | 75014 | 75014 | 361 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardEndTime | 2429 | 2429 | 2429 | 2429 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
@@ -264,19 +264,19 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| setReward | 2508 | 105565 | 107076 | 107076 | 265 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| setRewardsSupplier | 26875 | 26875 | 26875 | 26875 | 90 |
| setRewardsSupplier | 26875 | 26875 | 26875 | 26875 | 88 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| setTrustedCodehash | 24238 | 24238 | 24238 | 24238 | 90 |
| setTrustedCodehash | 24238 | 24238 | 24238 | 24238 | 88 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| stake | 2639 | 132245 | 60725 | 228623 | 2669 |
| stake | 2639 | 131939 | 60747 | 227511 | 2667 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMP | 6805 | 8257 | 8257 | 9710 | 6 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMPAccrued | 2385 | 2385 | 2385 | 2385 | 4160 |
| totalMPAccrued | 2385 | 2385 | 2385 | 2385 | 4161 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMPStaked | 2429 | 2429 | 2429 | 2429 | 4163 |
| totalMPStaked | 2429 | 2429 | 2429 | 2429 | 4164 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMaxMP | 2407 | 2407 | 2407 | 2407 | 4160 |
| totalMaxMP | 2407 | 2407 | 2407 | 2407 | 4161 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalRewardsAccrued | 2407 | 2407 | 2407 | 2407 | 3 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
@@ -284,17 +284,17 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalShares | 4597 | 4597 | 4597 | 4597 | 6 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalStaked | 2408 | 2408 | 2408 | 2408 | 4166 |
| totalStaked | 2408 | 2408 | 2408 | 2408 | 4167 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| unstake | 9886 | 41179 | 39781 | 79550 | 271 |
| unstake | 9908 | 40701 | 39803 | 79572 | 271 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| updateAccount | 347677 | 347677 | 347677 | 347677 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| updateGlobalState | 15820 | 25876 | 29230 | 29230 | 8 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| updateVault | 31948 | 34490 | 31948 | 110579 | 1022 |
| updateVault | 31948 | 34474 | 31948 | 110579 | 1023 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| upgradeTo | 10279 | 10772 | 10279 | 12745 | 5 |
| upgradeTo | 10279 | 10895 | 10279 | 12745 | 4 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| upgradeToAndCall | 3228 | 3228 | 3228 | 3228 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
@@ -306,47 +306,45 @@
+===============================================================================================+
| Deployment Cost | Deployment Size | | | | |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| 1683255 | 7965 | | | | |
| 1597234 | 7549 | | | | |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| | | | | | |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| STAKING_TOKEN | 252 | 252 | 252 | 252 | 1 |
| STAKING_TOKEN | 240 | 240 | 240 | 240 | 1 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| emergencyExit | 15073 | 31537 | 31535 | 48635 | 263 |
| emergencyExit | 15023 | 31463 | 31461 | 48561 | 263 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 95576 | 97600 | 97688 | 97688 | 385 |
| initialize | 70234 | 70234 | 70234 | 70234 | 374 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 10111 | 88896 | 46478 | 356508 | 7 |
| leave | 43417 | 143791 | 89206 | 353335 | 4 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| lock | 10039 | 58728 | 62251 | 103208 | 1036 |
| lock | 19468 | 55620 | 59163 | 98986 | 1034 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| lockUntil | 2363 | 2363 | 2363 | 2363 | 7760 |
| lockUntil | 2385 | 2385 | 2385 | 2385 | 7757 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| migrateToVault | 24910 | 77530 | 32637 | 219937 | 4 |
| migrateToVault | 21788 | 73521 | 29377 | 213541 | 4 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| owner | 448 | 479 | 448 | 2448 | 377 |
| owner | 379 | 411 | 379 | 2379 | 369 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| register | 922 | 74999 | 78761 | 78761 | 385 |
| register | 3398 | 79818 | 83144 | 83144 | 374 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| stake | 2617 | 166407 | 76290 | 284275 | 2677 |
| stake | 2593 | 163058 | 73202 | 280041 | 2673 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| stakeManager | 393 | 393 | 393 | 393 | 368 |
| stakeManager | 369 | 369 | 369 | 369 | 360 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| trustStakeManager | 7650 | 7650 | 7650 | 7650 | 4 |
| unstake(uint256) | 22335 | 54106 | 52230 | 107578 | 272 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| unstake(uint256) | 12108 | 57732 | 55296 | 110656 | 273 |
| unstake(uint256,address) | 2652 | 2652 | 2652 | 2652 | 1 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| unstake(uint256,address) | 2700 | 2700 | 2700 | 2700 | 1 |
| updateLockUntil | 3298 | 19649 | 20398 | 20398 | 524 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| updateLockUntil | 4432 | 20779 | 21532 | 21532 | 518 |
| withdraw(address,uint256) | 13539 | 24440 | 24440 | 35341 | 2 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| withdraw(address,uint256) | 13623 | 24518 | 24518 | 35413 | 2 |
| withdraw(address,uint256,address) | 2752 | 19118 | 19118 | 35484 | 2 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| withdraw(address,uint256,address) | 2812 | 19196 | 19196 | 35580 | 2 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| withdrawFromVault | 20391 | 20391 | 20391 | 20391 | 1 |
| withdrawFromVault | 20331 | 20331 | 20331 | 20331 | 1 |
╰----------------------------------------+-----------------+--------+--------+--------+---------╯
╭----------------------------------------------------+-----------------+-------+--------+--------+---------╮
@@ -360,9 +358,7 @@
|----------------------------------------------------+-----------------+-------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|----------------------------------------------------+-----------------+-------+--------+--------+---------|
| fallback | 5208 | 12837 | 7353 | 374054 | 23153 |
|----------------------------------------------------+-----------------+-------+--------+--------+---------|
| implementation | 346 | 2133 | 2346 | 2346 | 4874 |
| fallback | 5208 | 12834 | 7353 | 374054 | 23157 |
╰----------------------------------------------------+-----------------+-------+--------+--------+---------╯
╭--------------------------------------------+-----------------+--------+--------+--------+---------╮
@@ -376,7 +372,7 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| createVault | 168262 | 244525 | 248213 | 248213 | 384 |
| createVault | 145396 | 221995 | 225142 | 225142 | 373 |
|--------------------------------------------+-----------------+--------+--------+--------+---------|
| vaultImplementation | 2345 | 2345 | 2345 | 2345 | 1 |
╰--------------------------------------------+-----------------+--------+--------+--------+---------╯
@@ -498,8 +494,6 @@
|-----------------------------------------------------------+-----------------+-----+--------+-----+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|-----------------------------------------------------------+-----------------+-----+--------+-----+---------|
| implementation | 234 | 234 | 234 | 234 | 26 |
|-----------------------------------------------------------+-----------------+-----+--------+-----+---------|
| stakedBalanceOf | 376 | 376 | 376 | 376 | 1 |
╰-----------------------------------------------------------+-----------------+-----+--------+-----+---------╯
@@ -508,17 +502,17 @@
+==================================================================================================+
| Deployment Cost | Deployment Size | | | | |
|---------------------------------------------+-----------------+-------+--------+-------+---------|
| 770657 | 3987 | | | | |
| 770717 | 3987 | | | | |
|---------------------------------------------+-----------------+-------+--------+-------+---------|
| | | | | | |
|---------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|---------------------------------------------+-----------------+-------+--------+-------+---------|
| approve | 29075 | 31607 | 29183 | 46259 | 2687 |
| approve | 26359 | 31544 | 29183 | 46259 | 2676 |
|---------------------------------------------+-----------------+-------+--------+-------+---------|
| balanceOf | 2561 | 2561 | 2561 | 2561 | 4964 |
| balanceOf | 2561 | 2561 | 2561 | 2561 | 4965 |
|---------------------------------------------+-----------------+-------+--------+-------+---------|
| mint | 33964 | 37353 | 34072 | 68248 | 2699 |
| mint | 33964 | 37263 | 34072 | 68248 | 2688 |
╰---------------------------------------------+-----------------+-------+--------+-------+---------╯
╭-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╮

View File

@@ -9,23 +9,23 @@ AddRewardDistributorTest:testTotalSupply() (gas: 359391)
AddRewardDistributorTest:testTransfersNotAllowed() (gas: 61947)
AddRewardDistributorTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 68406)
EmergencyExitTest:test_CannotEnableEmergencyModeTwice() (gas: 93554)
EmergencyExitTest:test_CannotLeaveBeforeEmergencyMode() (gas: 336067)
EmergencyExitTest:test_EmergencyExitBasic() (gas: 524580)
EmergencyExitTest:test_EmergencyExitMultipleUsers() (gas: 937615)
EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 479110)
EmergencyExitTest:test_EmergencyExitWithLock() (gas: 452444)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 484810)
EmergencyExitTest:test_CannotLeaveBeforeEmergencyMode() (gas: 332917)
EmergencyExitTest:test_EmergencyExitBasic() (gas: 521406)
EmergencyExitTest:test_EmergencyExitMultipleUsers() (gas: 931267)
EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 475936)
EmergencyExitTest:test_EmergencyExitWithLock() (gas: 448136)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 481636)
EmergencyExitTest:test_OnlyOwnerCanEnableEmergencyMode() (gas: 39176)
FuzzTests:testFuzz_AccrueMP(uint128,uint64,uint64) (runs: 1024, μ: 584053, ~: 549046)
FuzzTests:testFuzz_AccrueMP_Relock(uint128,uint64,uint64,uint64) (runs: 1024, μ: 809067, ~: 777235)
FuzzTests:testFuzz_EmergencyExit(uint256,uint256) (runs: 1007, μ: 588195, ~: 578267)
FuzzTests:testFuzz_Lock(uint256,uint64) (runs: 1025, μ: 961448, ~: 961235)
FuzzTests:testFuzz_Relock(uint256,uint64,uint64) (runs: 1025, μ: 601095, ~: 574234)
FuzzTests:testFuzz_Rewards(uint256,uint256,uint256,uint16,uint16) (runs: 1001, μ: 650436, ~: 653254)
FuzzTests:testFuzz_Stake(uint256,uint64) (runs: 1025, μ: 378939, ~: 346089)
FuzzTests:testFuzz_Unstake(uint128,uint64,uint16,uint128) (runs: 1024, μ: 803140, ~: 780598)
FuzzTests:testFuzz_UpdateVault(uint128,uint64,uint64) (runs: 1024, μ: 584076, ~: 549069)
IntegrationTest:testStakeFoo() (gas: 2348931)
FuzzTests:testFuzz_AccrueMP(uint128,uint64,uint64) (runs: 1024, μ: 580650, ~: 546005)
FuzzTests:testFuzz_AccrueMP_Relock(uint128,uint64,uint64,uint64) (runs: 1024, μ: 801595, ~: 771127)
FuzzTests:testFuzz_EmergencyExit(uint256,uint256) (runs: 1007, μ: 584678, ~: 575129)
FuzzTests:testFuzz_Lock(uint256,uint64) (runs: 1025, μ: 955205, ~: 955091)
FuzzTests:testFuzz_Relock(uint256,uint64,uint64) (runs: 1025, μ: 591734, ~: 568102)
FuzzTests:testFuzz_Rewards(uint256,uint256,uint256,uint16,uint16) (runs: 1001, μ: 646223, ~: 649020)
FuzzTests:testFuzz_Stake(uint256,uint64) (runs: 1025, μ: 373876, ~: 343023)
FuzzTests:testFuzz_Unstake(uint128,uint64,uint16,uint128) (runs: 1024, μ: 795765, ~: 774510)
FuzzTests:testFuzz_UpdateVault(uint128,uint64,uint64) (runs: 1024, μ: 580673, ~: 546028)
IntegrationTest:testStakeFoo() (gas: 2333475)
KarmaNFTTest:testApproveNotAllowed() (gas: 10507)
KarmaNFTTest:testGetApproved() (gas: 10531)
KarmaNFTTest:testIsApprovedForAll() (gas: 10705)
@@ -63,25 +63,23 @@ KarmaTiersTest:test_Revert_When_TiersNotStartingAtZero() (gas: 37667)
KarmaTiersTest:test_Revert_When_UpdateTiersCalledByNonOwner() (gas: 36642)
KarmaTiersTest:test_Success_When_LastTierIsUnlimited() (gas: 242295)
KarmaTiersTest:test_Success_When_TiersAreContiguous() (gas: 336294)
LeaveTest:test_LeaveShouldKeepFundsLockedInStakeVault() (gas: 9938411)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 10011059)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 333238)
LeaveTest:test_TrustNewStakeManager() (gas: 9944491)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1025, μ: 384561, ~: 384588)
LockTest:test_LockFailsWithNoStake() (gas: 89700)
LockTest:test_LockFailsWithZero() (gas: 343310)
LockTest:test_LockMultipleTimesExceedMaxLock() (gas: 746921)
LockTest:test_LockWithPriorLock() (gas: 681021)
LockTest:test_LockWithoutPriorLock() (gas: 521888)
LockTest:test_RevertWhenVaultToLockIsEmpty() (gas: 89700)
MaliciousUpgradeTest:test_UpgradeStackOverflowStakeManager() (gas: 2056691)
LeaveTest:test_LeaveShouldKeepFundsLockedInStakeVault() (gas: 9932270)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 10006034)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1025, μ: 378373, ~: 378400)
LockTest:test_LockFailsWithNoStake() (gas: 86612)
LockTest:test_LockFailsWithZero() (gas: 337100)
LockTest:test_LockMultipleTimesExceedMaxLock() (gas: 736511)
LockTest:test_LockWithPriorLock() (gas: 669477)
LockTest:test_LockWithoutPriorLock() (gas: 514566)
LockTest:test_RevertWhenVaultToLockIsEmpty() (gas: 86612)
MaliciousUpgradeTest:test_UpgradeStackOverflowStakeManager() (gas: 2050418)
MathTest:test_CalcAbsoluteMaxTotalMP() (gas: 5240)
MathTest:test_CalcAccrueMP() (gas: 8599)
MathTest:test_CalcBonusMP() (gas: 30744)
MathTest:test_CalcInitialMP() (gas: 5836)
MathTest:test_CalcMaxAccruedMP() (gas: 4886)
MathTest:test_CalcMaxTotalMP() (gas: 31506)
MultipleVaultsStakeTest:test_StakeMultipleVaults() (gas: 918979)
MultipleVaultsStakeTest:test_StakeMultipleVaults() (gas: 909679)
NFTMetadataGeneratorSVGTest:testGenerateMetadata() (gas: 92580)
NFTMetadataGeneratorSVGTest:testSetImageStrings() (gas: 77581)
NFTMetadataGeneratorSVGTest:testSetImageStringsRevert() (gas: 35891)
@@ -152,72 +150,69 @@ SlashTest:test_RevertWhen_KarmaBalanceIsInvalid() (gas: 71550)
SlashTest:test_RevertWhen_SenderIsNotDefaultAdminOrSlasher() (gas: 43232)
SlashTest:test_Slash() (gas: 428385)
SlashTest:test_SlashRemainingBalanceIfBalanceIsLow() (gas: 251800)
StakeManager_RewardsTest:testRewardsBalanceOf() (gas: 2712133)
StakeManager_RewardsTest:testRewardsBalanceOf() (gas: 2705933)
StakeManager_RewardsTest:testSetRewards() (gas: 278149)
StakeManager_RewardsTest:testSetRewards_RevertsBadAmount() (gas: 63800)
StakeManager_RewardsTest:testSetRewards_RevertsBadDuration() (gas: 103558)
StakeManager_RewardsTest:testSetRewards_RevertsNotAuthorized() (gas: 39367)
StakeManager_RewardsTest:testTotalRewardsSupply() (gas: 1280822)
StakeTest:test_StakeMultipleAccounts() (gas: 666808)
StakeTest:test_StakeMultipleAccountsAndRewards() (gas: 721800)
StakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 1324461)
StakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 615074)
StakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 645732)
StakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1780357)
StakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 691504)
StakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1191100)
StakeTest:test_StakeOneAccount() (gas: 390362)
StakeTest:test_StakeOneAccountAndRewards() (gas: 445417)
StakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 825302)
StakeTest:test_StakeOneAccountReachingMPLimit() (gas: 714792)
StakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 381583)
StakeTest:test_StakeOneAccountWithMinLockUp() (gas: 382223)
StakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 382268)
StakeVaultCoverageTest:testOwner() (gas: 15391)
StakeVaultCoverageTest:test_LeaveRevertsWhenManagerTrusted() (gas: 44836)
StakeVaultCoverageTest:test_LeaveTransfersAllFundsAfterUntrustingManager() (gas: 189561)
StakeVaultCoverageTest:test_LockRevertsIfManagerNotTrusted() (gas: 76902)
StakeVaultCoverageTest:test_StakeRevertsIfManagerNotTrusted() (gas: 77108)
StakeVaultCoverageTest:test_StakeRevertsIfNotOwner() (gas: 37239)
StakeVaultCoverageTest:test_StakeTransfersTokensToVault() (gas: 93148)
StakeVaultCoverageTest:test_UnstakeRevertsWithInvalidDestination() (gas: 113163)
StakeVaultCoverageTest:test_UnstakeTransfersTokensBackToOwner() (gas: 144361)
StakeVaultCoverageTest:test_WithdrawOtherTokenTransfersToDestination() (gas: 142411)
StakeVaultCoverageTest:test_WithdrawRevertsIfInsufficientAvailableBalance() (gas: 126421)
StakeVaultCoverageTest:test_WithdrawRevertsIfInvalidDestination() (gas: 111219)
StakeVaultCoverageTest:test_WithdrawTransfersGenericTokenToOwner() (gas: 139759)
StakeVaultMigrationTest:testMigrateToVault() (gas: 1157152)
StakeVaultMigrationTest:test_RevertWhenDestinationVaultIsNotRegistered() (gas: 166681)
StakeVaultMigrationTest:test_RevertWhenMigrationVaultNotEmpty() (gas: 631911)
StakeVaultMigrationTest:test_RevertWhenNotOwnerOfMigrationVault() (gas: 70563)
StakeVaultTest:testOwner() (gas: 15331)
StakingTokenTest:testOwner() (gas: 15331)
StakingTokenTest:testStakeToken() (gas: 13156)
TrustedCodehashAccessTest:test_RevertWhenProxyCloneCodehashNotTrusted() (gas: 2021691)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 461737)
UnstakeTest:test_StakeMultipleAccounts() (gas: 666787)
UnstakeTest:test_StakeMultipleAccountsAndRewards() (gas: 721844)
UnstakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 1324527)
UnstakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 615140)
UnstakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 645731)
UnstakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1780413)
UnstakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 691459)
UnstakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1191111)
UnstakeTest:test_StakeOneAccount() (gas: 390384)
UnstakeTest:test_StakeOneAccountAndRewards() (gas: 445416)
UnstakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 825301)
UnstakeTest:test_StakeOneAccountReachingMPLimit() (gas: 714772)
UnstakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 381605)
UnstakeTest:test_StakeOneAccountWithMinLockUp() (gas: 382223)
UnstakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 382268)
UnstakeTest:test_UnstakeBonusMPAndAccuredMP() (gas: 754339)
UnstakeTest:test_UnstakeMultipleAccounts() (gas: 1037350)
UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 1322871)
UnstakeTest:test_UnstakeOneAccount() (gas: 759178)
UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 719489)
UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 673681)
UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 722241)
UpdateVaultTest:test_UpdateAccount() (gas: 2587427)
StakeManager_RewardsTest:testTotalRewardsSupply() (gas: 1277722)
StakeTest:test_StakeMultipleAccounts() (gas: 660608)
StakeTest:test_StakeMultipleAccountsAndRewards() (gas: 715600)
StakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 1318261)
StakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 607740)
StakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 637264)
StakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1746485)
StakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 679948)
StakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1169110)
StakeTest:test_StakeOneAccount() (gas: 387262)
StakeTest:test_StakeOneAccountAndRewards() (gas: 442317)
StakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 822202)
StakeTest:test_StakeOneAccountReachingMPLimit() (gas: 711692)
StakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 377349)
StakeTest:test_StakeOneAccountWithMinLockUp() (gas: 377989)
StakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 378034)
StakeVaultCoverageTest:testOwner() (gas: 15367)
StakeVaultCoverageTest:test_LeaveTransfersAllFunds() (gas: 151083)
StakeVaultCoverageTest:test_StakeRevertsIfNotOwner() (gas: 37215)
StakeVaultCoverageTest:test_StakeTransfersTokensToVault() (gas: 90116)
StakeVaultCoverageTest:test_UnstakeRevertsWithInvalidDestination() (gas: 110127)
StakeVaultCoverageTest:test_UnstakeTransfersTokensBackToOwner() (gas: 138319)
StakeVaultCoverageTest:test_WithdrawOtherTokenTransfersToDestination() (gas: 142293)
StakeVaultCoverageTest:test_WithdrawRevertsIfInsufficientAvailableBalance() (gas: 123327)
StakeVaultCoverageTest:test_WithdrawRevertsIfInvalidDestination() (gas: 111137)
StakeVaultCoverageTest:test_WithdrawTransfersGenericTokenToOwner() (gas: 139665)
StakeVaultMigrationTest:testMigrateToVault() (gas: 1124585)
StakeVaultMigrationTest:test_RevertWhenDestinationVaultIsNotRegistered() (gas: 163559)
StakeVaultMigrationTest:test_RevertWhenMigrationVaultNotEmpty() (gas: 602480)
StakeVaultMigrationTest:test_RevertWhenNotOwnerOfMigrationVault() (gas: 67303)
StakeVaultTest:testOwner() (gas: 15262)
StakingTokenTest:testOwner() (gas: 15262)
StakingTokenTest:testStakeToken() (gas: 13144)
TrustedCodehashAccessTest:test_RevertWhenProxyCloneCodehashNotTrusted() (gas: 1904991)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 452589)
UnstakeTest:test_StakeMultipleAccounts() (gas: 660587)
UnstakeTest:test_StakeMultipleAccountsAndRewards() (gas: 715644)
UnstakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 1318327)
UnstakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 607806)
UnstakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 637263)
UnstakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1746541)
UnstakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 679903)
UnstakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1169121)
UnstakeTest:test_StakeOneAccount() (gas: 387284)
UnstakeTest:test_StakeOneAccountAndRewards() (gas: 442316)
UnstakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 822201)
UnstakeTest:test_StakeOneAccountReachingMPLimit() (gas: 711672)
UnstakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 377371)
UnstakeTest:test_StakeOneAccountWithMinLockUp() (gas: 377989)
UnstakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 378034)
UnstakeTest:test_UnstakeBonusMPAndAccuredMP() (gas: 747027)
UnstakeTest:test_UnstakeMultipleAccounts() (gas: 1024994)
UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 1308669)
UnstakeTest:test_UnstakeOneAccount() (gas: 751152)
UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 713311)
UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 667503)
UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 714929)
UpdateVaultTest:test_UpdateAccount() (gas: 2505814)
UpgradeTest:test_RevertWhenNotOwner() (gas: 3696209)
UpgradeTest:test_UpgradeStakeManager() (gas: 9855347)
UpgradeTest:test_UpgradeStakeManager() (gas: 9852247)
VaultRegistrationTest:test_VaultRegistration() (gas: 90138)

View File

@@ -31,8 +31,6 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
error StakeVault__NotAllowedToExit();
/// @notice Emitted when not allowed to leave the system
error StakeVault__NotAllowedToLeave();
/// @notice Emitted when the configured stake manager is not trusted
error StakeVault__StakeManagerImplementationNotTrusted();
/// @notice Emitted when migration failed
error StakeVault__MigrationFailed();
/// @notice Emitted when the caller is not the owner of the vault
@@ -48,8 +46,6 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
IERC20 public immutable STAKING_TOKEN;
/// @notice Stake manager proxy contract
IStakeManagerProxy public stakeManager;
/// @notice Address of the trusted stake manager implementation
address public stakeManagerImplementationAddress;
/// @notice Timestamp until the funds are locked
uint256 public lockUntil;
@@ -60,13 +56,6 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
_;
}
modifier onlyTrustedStakeManager() {
if (!_stakeManagerImplementationTrusted()) {
revert StakeVault__StakeManagerImplementationNotTrusted();
}
_;
}
/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/
@@ -96,16 +85,6 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
function initialize(address _owner, address _stakeManager) public initializer {
_transferOwnership(_owner);
stakeManager = IStakeManagerProxy(_stakeManager);
stakeManagerImplementationAddress = stakeManager.implementation();
}
/**
* @notice Allows the owner to trust a new stake manager implementation.
* @dev This function is only callable by the owner.
* @param stakeManagerAddress The address of the new stake manager implementation.
*/
function trustStakeManager(address stakeManagerAddress) external onlyOwner {
stakeManagerImplementationAddress = stakeManagerAddress;
}
/**
@@ -124,7 +103,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @param _amount The amount of tokens to stake.
* @param _seconds The time period to stake for.
*/
function stake(uint256 _amount, uint256 _seconds) external onlyOwner onlyTrustedStakeManager {
function stake(uint256 _amount, uint256 _seconds) external onlyOwner {
_stake(_amount, _seconds, msg.sender);
}
@@ -138,7 +117,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @param _seconds The time period to stake for.
* @param _from The address from which tokens will be transferred.
*/
function stake(uint256 _amount, uint256 _seconds, address _from) external onlyOwner onlyTrustedStakeManager {
function stake(uint256 _amount, uint256 _seconds, address _from) external onlyOwner {
_stake(_amount, _seconds, _from);
}
@@ -148,7 +127,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @dev Can only be called if the stake manager is trusted.
* @param _seconds The time period to lock the staked amount for.
*/
function lock(uint256 _seconds) external onlyOwner onlyTrustedStakeManager {
function lock(uint256 _seconds) external onlyOwner {
stakeManager.lock(_seconds);
}
@@ -159,7 +138,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @dev Reverts if the staking token transfer fails.
* @param _amount The amount of tokens to unstake.
*/
function unstake(uint256 _amount) external onlyOwner onlyTrustedStakeManager {
function unstake(uint256 _amount) external onlyOwner {
_unstake(_amount, msg.sender);
}
@@ -172,15 +151,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @param _amount The amount of tokens to unstake.
* @param _destination The address to receive the unstaked tokens.
*/
function unstake(
uint256 _amount,
address _destination
)
external
onlyOwner
validDestination(_destination)
onlyTrustedStakeManager
{
function unstake(uint256 _amount, address _destination) external onlyOwner validDestination(_destination) {
_unstake(_amount, _destination);
}
@@ -191,20 +162,9 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @param _destination The address to receive the funds.
*/
function leave(address _destination) external onlyOwner validDestination(_destination) {
if (_stakeManagerImplementationTrusted()) {
// If the stakeManager is trusted, the vault cannot leave the system
// and has to properly unstake instead (which might not be possible if
// funds are locked).
revert StakeVault__NotAllowedToLeave();
}
// If the stakeManager is not trusted, we know there was an upgrade.
// In this case, vaults are free to leave the system and move their funds back
// to the owner.
//
// We have to `try/catch` here in case the upgrade was malicious and `leave()`
// We have to `try/catch` here in case the upgrade was bad and `leave()`
// either doesn't exist on the new stake manager or reverts for some reason.
// If it was a benign upgrade, it will cause the stake manager to properly update
// If it was a good upgrade, it will cause the stake manager to properly update
// its internal accounting before we move the funds out.
try stakeManager.leave() {
if (lockUntil <= block.timestamp) {
@@ -224,7 +184,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @dev Reverts when the stake manager reverts or the funds can't be transferred.
* @param migrateTo The address of the new vault.
*/
function migrateToVault(address migrateTo) external onlyOwner onlyTrustedStakeManager {
function migrateToVault(address migrateTo) external onlyOwner {
stakeManager.migrateToVault(migrateTo);
bool success = STAKING_TOKEN.transfer(migrateTo, STAKING_TOKEN.balanceOf(address(this)));
if (!success) {
@@ -299,7 +259,7 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
* @dev This function is only callable by the trusted stake manager.
* @param _lockUntil The new lock until timestamp.
*/
function updateLockUntil(uint256 _lockUntil) external onlyTrustedStakeManager {
function updateLockUntil(uint256 _lockUntil) external {
if (msg.sender != address(stakeManager)) {
revert StakeVault__NotAuthorized();
}
@@ -374,16 +334,6 @@ contract StakeVault is IStakeVault, Initializable, OwnableUpgradeable {
}
}
/**
* @notice Checks if the current stake manager implementation is trusted.
* @dev Trusted implementation address is set during initialization.
* @dev Trusted implementation address can be changed by owner.
* @return True if the current stake manager implementation is trusted, otherwise false.
*/
function _stakeManagerImplementationTrusted() internal view virtual returns (bool) {
return stakeManagerImplementationAddress == stakeManager.implementation();
}
/*//////////////////////////////////////////////////////////////////////////
VIEW FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

View File

@@ -2277,12 +2277,6 @@ contract LeaveTest is StakeManagerTest {
super.setUp();
}
function test_RevertWhenStakeManagerIsTrusted() public {
_stake(alice, 10e18, 0);
vm.expectRevert(StakeVault.StakeVault__NotAllowedToLeave.selector);
_leave(alice);
}
function test_LeaveShouldProperlyUpdateAccounting() public {
uint256 aliceInitialBalance = stakingToken.balanceOf(alice);
@@ -2359,37 +2353,6 @@ contract LeaveTest is StakeManagerTest {
assertEq(stakingToken.balanceOf(alice), aliceInitialBalance, "Alice has withdrawn her funds");
}
function test_TrustNewStakeManager() public {
// first, upgrade to new stake manager, marking it as not trusted
_upgradeStakeManager();
// ensure vault functions revert if stake manager is not trusted
vm.expectRevert(StakeVault.StakeVault__StakeManagerImplementationNotTrusted.selector);
_stake(alice, 100e18, 0);
// ensure vault functions revert if stake manager is not trusted
StakeVault vault = StakeVault(vaults[alice]);
vm.prank(alice);
vm.expectRevert(StakeVault.StakeVault__StakeManagerImplementationNotTrusted.selector);
vault.lock(365 days);
// ensure vault functions revert if stake manager is not trusted
vm.expectRevert(StakeVault.StakeVault__StakeManagerImplementationNotTrusted.selector);
_unstake(alice, 100e18);
// now, trust the new stake manager
address newStakeManagerImpl = IStakeManagerProxy(address(streamer)).implementation();
vm.prank(alice);
vault.trustStakeManager(newStakeManagerImpl);
// stake manager is now trusted, so functions are enabeled again
_stake(alice, 100e18, 0);
// however, a trusted manager cannot be left
vm.expectRevert(StakeVault.StakeVault__NotAllowedToLeave.selector);
_leave(alice);
}
}
contract MaliciousUpgradeTest is StakeManagerTest {

View File

@@ -70,22 +70,6 @@ contract StakeVaultCoverageTest is StakeVaultTest {
stakeVault.stake(1e18, 90 days);
}
function test_StakeRevertsIfManagerNotTrusted() public {
vm.prank(alice);
stakeVault.trustStakeManager(address(0xDEAD));
vm.prank(alice);
vm.expectRevert(StakeVault.StakeVault__StakeManagerImplementationNotTrusted.selector);
stakeVault.stake(1e18, 3600);
}
function test_LockRevertsIfManagerNotTrusted() public {
vm.prank(alice);
stakeVault.trustStakeManager(address(0xBEEF));
vm.prank(alice);
vm.expectRevert(StakeVault.StakeVault__StakeManagerImplementationNotTrusted.selector);
stakeVault.lock(3600);
}
function test_UnstakeTransfersTokensBackToOwner() public {
uint256 startBalance = stakingToken.balanceOf(alice);
vm.prank(alice);
@@ -107,18 +91,10 @@ contract StakeVaultCoverageTest is StakeVaultTest {
TESTES PARA leave()
////////////////////////////////////////////////////////////*/
function test_LeaveRevertsWhenManagerTrusted() public {
vm.prank(alice);
vm.expectRevert(StakeVault.StakeVault__NotAllowedToLeave.selector);
stakeVault.leave(alice);
}
function test_LeaveTransfersAllFundsAfterUntrustingManager() public {
function test_LeaveTransfersAllFunds() public {
vm.prank(alice);
stakeVault.stake(2e18, 0);
vm.prank(alice);
stakeVault.trustStakeManager(address(1));
vm.prank(alice);
stakeVault.leave(bob);
assertEq(stakingToken.balanceOf(bob), 2e18);
}