Skip to content

Commit

Permalink
refactor(TrustedCodehashAccess): add storage gap for upgrade safety
Browse files Browse the repository at this point in the history
Closes #131
  • Loading branch information
0x-r4bbit committed Feb 28, 2025
1 parent ed3577f commit 20c3ef2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions .gas-report
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 95475 | 95475 | 95475 | 95475 | 1 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| lock | 14216 | 52151 | 52082 | 93689 | 260 |
| lock | 14216 | 52150 | 52082 | 93689 | 260 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| migrateToVault | 13563 | 72244 | 15769 | 187401 | 3 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
Expand All @@ -186,7 +186,7 @@
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardStartTime | 429 | 1429 | 1429 | 2429 | 2 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardsBalanceOf | 2324 | 3513 | 3909 | 6324 | 268 |
| rewardsBalanceOf | 2324 | 3507 | 3909 | 6324 | 268 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| setReward | 2484 | 105517 | 107034 | 107034 | 264 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
Expand All @@ -206,17 +206,17 @@
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| totalRewardsAccrued | 384 | 384 | 384 | 384 | 3 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| totalRewardsSupply | 993 | 1612 | 1774 | 6733 | 290 |
| totalRewardsSupply | 993 | 1609 | 1774 | 6733 | 290 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| totalShares | 637 | 637 | 637 | 637 | 6 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| totalStaked | 385 | 385 | 385 | 385 | 1115 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| unstake | 56017 | 81037 | 80911 | 88301 | 269 |
| unstake | 56017 | 81007 | 80911 | 88301 | 269 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| updateGlobalState | 15809 | 27668 | 29200 | 29503 | 276 |
| updateGlobalState | 15809 | 27671 | 29200 | 29503 | 276 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| updateVaultMP | 25103 | 34553 | 36516 | 36819 | 276 |
| updateVaultMP | 25103 | 34573 | 36516 | 36819 | 276 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
| upgradeToAndCall | 3225 | 7892 | 8437 | 10925 | 5 |
|------------------------------------------------------+-----------------+--------+--------+--------+---------|
Expand All @@ -242,7 +242,7 @@
|----------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 12167 | 126461 | 69872 | 353935 | 4 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| lock | 12097 | 67387 | 67531 | 109137 | 261 |
| lock | 12097 | 67386 | 67531 | 109137 | 261 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| migrateToVault | 29034 | 98943 | 31240 | 236555 | 3 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
Expand All @@ -256,7 +256,7 @@
|----------------------------------------+-----------------+--------+--------+--------+---------|
| trustStakeManager | 7577 | 7577 | 7577 | 7577 | 1 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| unstake | 12054 | 111569 | 112021 | 119411 | 270 |
| unstake | 12054 | 111539 | 112021 | 119411 | 270 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| withdraw | 20705 | 20705 | 20705 | 20705 | 1 |
╰----------------------------------------+-----------------+--------+--------+--------+---------╯
Expand Down
12 changes: 6 additions & 6 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 450444)
EmergencyExitTest:test_EmergencyExitWithLock() (gas: 448187)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 435625)
EmergencyExitTest:test_OnlyOwnerCanEnableEmergencyMode() (gas: 39462)
FuzzTests:testFuzz_AccrueMP(uint256,uint256,uint16) (runs: 1006, μ: 521106, ~: 515988)
FuzzTests:testFuzz_EmergencyExit(uint256,uint256) (runs: 1006, μ: 510643, ~: 501981)
FuzzTests:testFuzz_Rewards(uint256,uint256,uint256,uint16,uint16) (runs: 1003, μ: 604659, ~: 605935)
FuzzTests:testFuzz_Stake(uint256,uint256) (runs: 1006, μ: 404095, ~: 395433)
FuzzTests:testFuzz_Unstake(uint256,uint256,uint16,uint256) (runs: 1001, μ: 530264, ~: 529949)
FuzzTests:testFuzz_AccrueMP(uint256,uint256,uint16) (runs: 1000, μ: 521208, ~: 515988)
FuzzTests:testFuzz_EmergencyExit(uint256,uint256) (runs: 1000, μ: 510918, ~: 502017)
FuzzTests:testFuzz_Rewards(uint256,uint256,uint256,uint16,uint16) (runs: 1000, μ: 604660, ~: 605935)
FuzzTests:testFuzz_Stake(uint256,uint256) (runs: 1000, μ: 404370, ~: 395469)
FuzzTests:testFuzz_Unstake(uint256,uint256,uint16,uint256) (runs: 1000, μ: 530262, ~: 529949)
IntegrationTest:testStakeFoo() (gas: 1403381)
KarmaMintAllowanceTest:testAddKarmaDistributorOnlyOwner() (gas: 348463)
KarmaMintAllowanceTest:testBalanceOf() (gas: 428643)
Expand Down Expand Up @@ -48,7 +48,7 @@ KarmaTest:testTransfersNotAllowed() (gas: 20662)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 7249868)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 350352)
LeaveTest:test_TrustNewStakeManager() (gas: 7302750)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1009, μ: 406917, ~: 406944)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1000, μ: 406917, ~: 406944)
LockTest:test_LockFailsWithNoStake() (gas: 114574)
LockTest:test_LockFailsWithZero() (gas: 367631)
LockTest:test_LockWithoutPriorLock() (gas: 465087)
Expand Down
2 changes: 2 additions & 0 deletions src/TrustedCodehashAccess.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ITrustedCodehashAccess } from "./interfaces/ITrustedCodehashAccess.sol"
abstract contract TrustedCodehashAccess is ITrustedCodehashAccess, OwnableUpgradeable {
/// @notice Whidelisted codehashes.
mapping(bytes32 codehash => bool permission) private trustedCodehashes;
/// @notice Gap for upgrade safety.
uint256[10] private __gap;

/**
* @notice Restricts access based on the codehash of the caller.
Expand Down

0 comments on commit 20c3ef2

Please sign in to comment.