chore(karma-rln): improving tests

This commit is contained in:
Ricardo Guilherme Schmidt
2025-06-02 11:30:50 -03:00
parent 42aa589847
commit c4d211e9bb
6 changed files with 536 additions and 399 deletions

View File

@@ -4,13 +4,13 @@
+==================================================================================================================================================+ +==================================================================================================================================================+
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
|-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| 0 | 1374 | | | | | | 275353 | 1374 | | | | |
|-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| | | | | | | | | | | | | |
|-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| fallback | 666 | 112892 | 97112 | 193429 | 693 | | fallback | 5145 | 102784 | 97112 | 193429 | 783 |
╰-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╯ ╰-------------------------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╯
╭-----------------------------------------------------+-----------------+---------+---------+---------+---------╮ ╭-----------------------------------------------------+-----------------+---------+---------+---------+---------╮
@@ -55,19 +55,19 @@
| run | 7425695 | 7425695 | 7425695 | 7425695 | 95 | | run | 7425695 | 7425695 | 7425695 | 7425695 | 95 |
╰-------------------------------------------------------------------+-----------------+---------+---------+---------+---------╯ ╰-------------------------------------------------------------------+-----------------+---------+---------+---------+---------╯
╭---------------------------------------------------------+-----------------+-----+--------+-----+---------╮ ╭---------------------------------------------------------+-----------------+------+--------+------+---------╮
| script/DeploymentConfig.s.sol:DeploymentConfig Contract | | | | | | | script/DeploymentConfig.s.sol:DeploymentConfig Contract | | | | | |
+==========================================================================================================+ +============================================================================================================+
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
|---------------------------------------------------------+-----------------+-----+--------+-----+---------| |---------------------------------------------------------+-----------------+------+--------+------+---------|
| 0 | 9022 | | | | | | 0 | 9022 | | | | |
|---------------------------------------------------------+-----------------+-----+--------+-----+---------| |---------------------------------------------------------+-----------------+------+--------+------+---------|
| | | | | | | | | | | | | |
|---------------------------------------------------------+-----------------+-----+--------+-----+---------| |---------------------------------------------------------+-----------------+------+--------+------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|---------------------------------------------------------+-----------------+-----+--------+-----+---------| |---------------------------------------------------------+-----------------+------+--------+------+---------|
| activeNetworkConfig | 455 | 455 | 455 | 455 | 414 | | activeNetworkConfig | 455 | 1971 | 455 | 4455 | 414 |
╰---------------------------------------------------------+-----------------+-----+--------+-----+---------╯ ╰---------------------------------------------------------+-----------------+------+--------+------+---------╯
╭---------------------------------------------------------------------+-----------------+---------+---------+---------+---------╮ ╭---------------------------------------------------------------------+-----------------+---------+---------+---------+---------╮
| script/UpgradeStakeManager.s.sol:UpgradeStakeManagerScript Contract | | | | | | | script/UpgradeStakeManager.s.sol:UpgradeStakeManagerScript Contract | | | | | |
@@ -104,13 +104,13 @@
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| approve | 441 | 441 | 441 | 441 | 6 | | approve | 441 | 441 | 441 | 441 | 6 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| balanceOf | 10085 | 13751 | 10085 | 21085 | 18 | | balanceOf | 21085 | 21085 | 21085 | 21085 | 18 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| getRewardDistributors | 1119 | 3523 | 5607 | 5607 | 17 | | getRewardDistributors | 5119 | 7759 | 9607 | 9607 | 17 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| grantRole | 29440 | 29440 | 29440 | 29440 | 5 | | grantRole | 29440 | 29440 | 29440 | 29440 | 5 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| hasRole | 685 | 2185 | 2685 | 2685 | 4 | | hasRole | 2685 | 2685 | 2685 | 2685 | 4 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 94595 | 94595 | 94595 | 94595 | 152 | | initialize | 94595 | 94595 | 94595 | 94595 | 152 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
@@ -120,7 +120,7 @@
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| setReward | 4832 | 147872 | 166705 | 166705 | 307 | | setReward | 4832 | 147872 | 166705 | 166705 | 307 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| totalSupply | 3567 | 7567 | 9567 | 9567 | 18 | | totalSupply | 22567 | 22567 | 22567 | 22567 | 18 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
| transfer | 439 | 439 | 439 | 439 | 6 | | transfer | 439 | 439 | 439 | 439 | 6 |
|------------------------------+-----------------+--------+--------+--------+---------| |------------------------------+-----------------+--------+--------+--------+---------|
@@ -144,7 +144,7 @@
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
| isApprovedForAll | 510 | 510 | 510 | 510 | 1 | | isApprovedForAll | 510 | 510 | 510 | 510 | 1 |
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
| metadataGenerator | 325 | 325 | 325 | 325 | 1 | | metadataGenerator | 2325 | 2325 | 2325 | 2325 | 1 |
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
| safeTransferFrom(address,address,uint256) | 485 | 485 | 485 | 485 | 1 | | safeTransferFrom(address,address,uint256) | 485 | 485 | 485 | 485 | 1 |
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
@@ -154,7 +154,7 @@
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
| setMetadataGenerator | 24036 | 27334 | 28983 | 28983 | 3 | | setMetadataGenerator | 24036 | 27334 | 28983 | 28983 | 3 |
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
| tokenURI | 69222 | 69222 | 69222 | 69222 | 1 | | tokenURI | 75722 | 75722 | 75722 | 75722 | 1 |
|-------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------+-----------------+-------+--------+-------+---------|
| transferFrom | 530 | 530 | 530 | 530 | 1 | | transferFrom | 530 | 530 | 530 | 530 | 1 |
╰-------------------------------------------------+-----------------+-------+--------+-------+---------╯ ╰-------------------------------------------------+-----------------+-------+--------+-------+---------╯
@@ -180,41 +180,41 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| enableEmergencyMode | 2543 | 25291 | 25457 | 25457 | 264 | | enableEmergencyMode | 2543 | 25291 | 25457 | 25457 | 264 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| getAccountTotalMaxMP | 3191 | 3191 | 3191 | 3191 | 1 | | getAccountTotalMaxMP | 21191 | 21191 | 21191 | 21191 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| getAccountTotalStakedBalance | 15170 | 15170 | 15170 | 15170 | 1 | | getAccountTotalStakedBalance | 21170 | 21170 | 21170 | 21170 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| getAccountVaults | 5230 | 5230 | 5230 | 5230 | 4 | | getAccountVaults | 5230 | 5230 | 5230 | 5230 | 4 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| getVault | 1653 | 5709 | 1653 | 13653 | 4180 | | getVault | 13653 | 13653 | 13653 | 13653 | 4181 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 92752 | 92752 | 92752 | 92752 | 95 | | initialize | 92752 | 92752 | 92752 | 92752 | 95 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| lastRewardTime | 407 | 1407 | 1407 | 2407 | 2 | | lastRewardTime | 2407 | 2407 | 2407 | 2407 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 66348 | 66348 | 66348 | 66348 | 2 | | leave | 66348 | 66348 | 66348 | 66348 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| lock | 7040 | 43426 | 46713 | 87964 | 1034 | | lock | 7040 | 43473 | 46713 | 87673 | 1034 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| migrateToVault | 9294 | 53513 | 17021 | 170715 | 4 | | migrateToVault | 9294 | 53513 | 17021 | 170715 | 4 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| mpAccruedOf | 629 | 629 | 629 | 629 | 20 | | mpAccruedOf | 2629 | 2629 | 2629 | 2629 | 20 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| mpBalanceOf | 917 | 2361 | 2316 | 7063 | 12 | | mpBalanceOf | 4917 | 8695 | 10316 | 10316 | 12 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| mpBalanceOfAccount | 6210 | 8283 | 8283 | 10356 | 2 | | mpBalanceOfAccount | 30210 | 31283 | 31283 | 32356 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| proxiableUUID | 342 | 342 | 342 | 342 | 4 | | proxiableUUID | 342 | 342 | 342 | 342 | 4 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| registerVault | 2583 | 74547 | 75107 | 75107 | 374 | | registerVault | 2583 | 74547 | 75107 | 75107 | 374 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardEndTime | 429 | 1429 | 1429 | 2429 | 2 | | rewardEndTime | 2429 | 2429 | 2429 | 2429 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardStartTime | 364 | 1364 | 1364 | 2364 | 2 | | rewardStartTime | 2364 | 2364 | 2364 | 2364 | 2 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardsBalanceOf | 2295 | 3511 | 3908 | 6295 | 268 | | rewardsBalanceOf | 20295 | 24409 | 25908 | 26129 | 268 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| rewardsBalanceOfAccount | 10220 | 10220 | 10220 | 10220 | 1 | | rewardsBalanceOfAccount | 62220 | 62220 | 62220 | 62220 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| setReward | 2508 | 105565 | 107076 | 107076 | 265 | | setReward | 2508 | 105565 | 107076 | 107076 | 265 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
@@ -222,39 +222,39 @@
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| setTrustedCodehash | 24238 | 24238 | 24238 | 24238 | 95 | | setTrustedCodehash | 24238 | 24238 | 24238 | 24238 | 95 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| stake | 2639 | 131085 | 60725 | 228623 | 2670 | | stake | 2639 | 132481 | 60725 | 228623 | 2670 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| stakedBalanceOf | 2622 | 2622 | 2622 | 2622 | 1 | | stakedBalanceOf | 2622 | 2622 | 2622 | 2622 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMP | 805 | 1257 | 1257 | 1710 | 6 | | totalMP | 6805 | 8257 | 8257 | 9710 | 6 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMPAccrued | 385 | 1064 | 385 | 2385 | 4160 | | totalMPAccrued | 2385 | 2385 | 2385 | 2385 | 4161 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMPStaked | 429 | 1107 | 429 | 2429 | 4163 | | totalMPStaked | 2429 | 2429 | 2429 | 2429 | 4164 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalMaxMP | 407 | 1086 | 407 | 2407 | 4160 | | totalMaxMP | 2407 | 2407 | 2407 | 2407 | 4161 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalRewardsAccrued | 407 | 407 | 407 | 407 | 3 | | totalRewardsAccrued | 2407 | 2407 | 2407 | 2407 | 3 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalRewardsSupply | 998 | 1629 | 1792 | 6737 | 290 | | totalRewardsSupply | 6737 | 11058 | 11792 | 11903 | 290 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalShares | 597 | 597 | 597 | 597 | 6 | | totalShares | 4597 | 4597 | 4597 | 4597 | 6 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| totalStaked | 408 | 1086 | 408 | 2408 | 4167 | | totalStaked | 2408 | 2408 | 2408 | 2408 | 4168 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| unstake | 9886 | 41548 | 39781 | 79550 | 271 | | unstake | 9886 | 41170 | 39781 | 79550 | 271 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| updateAccount | 347677 | 347677 | 347677 | 347677 | 1 | | updateAccount | 347677 | 347677 | 347677 | 347677 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| updateGlobalState | 15820 | 25876 | 29230 | 29230 | 8 | | updateGlobalState | 15820 | 25876 | 29230 | 29230 | 8 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| updateVault | 31948 | 34368 | 31948 | 110579 | 1022 | | updateVault | 31948 | 34668 | 31948 | 110579 | 1023 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| upgradeTo | 10279 | 10772 | 10279 | 12745 | 5 | | upgradeTo | 10279 | 10772 | 10279 | 12745 | 5 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| upgradeToAndCall | 3228 | 3228 | 3228 | 3228 | 1 | | upgradeToAndCall | 3228 | 3228 | 3228 | 3228 | 1 |
|--------------------------------------------+-----------------+--------+--------+--------+---------| |--------------------------------------------+-----------------+--------+--------+--------+---------|
| vaultShares | 893 | 1059 | 893 | 2893 | 12 | | vaultShares | 4893 | 4893 | 4893 | 4893 | 12 |
╰--------------------------------------------+-----------------+--------+--------+--------+---------╯ ╰--------------------------------------------+-----------------+--------+--------+--------+---------╯
╭----------------------------------------+-----------------+--------+--------+--------+---------╮ ╭----------------------------------------+-----------------+--------+--------+--------+---------╮
@@ -274,11 +274,11 @@
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 97688 | 97688 | 97688 | 97688 | 374 | | initialize | 97688 | 97688 | 97688 | 97688 | 374 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 12223 | 113138 | 84120 | 356510 | 5 | | leave | 12223 | 113137 | 84120 | 356508 | 5 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| lock | 12151 | 58918 | 62251 | 103499 | 1035 | | lock | 12151 | 58965 | 62251 | 103208 | 1035 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| lockUntil | 363 | 1744 | 2363 | 2363 | 7766 | | lockUntil | 2363 | 2363 | 2363 | 2363 | 7766 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| migrateToVault | 24910 | 77530 | 32637 | 219937 | 4 | | migrateToVault | 24910 | 77530 | 32637 | 219937 | 4 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
@@ -286,36 +286,36 @@
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| register | 12742 | 78218 | 78761 | 78761 | 374 | | register | 12742 | 78218 | 78761 | 78761 | 374 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| stake | 12131 | 165292 | 76290 | 284275 | 2671 | | stake | 12131 | 167018 | 76290 | 284275 | 2671 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| stakeManager | 393 | 393 | 393 | 393 | 373 | | stakeManager | 393 | 393 | 393 | 393 | 373 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| trustStakeManager | 7650 | 7650 | 7650 | 7650 | 1 | | trustStakeManager | 7650 | 7650 | 7650 | 7650 | 1 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| unstake | 12108 | 58273 | 55296 | 110656 | 272 | | unstake | 12108 | 57840 | 55296 | 110656 | 272 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| updateLockUntil | 4432 | 20761 | 21532 | 21532 | 506 | | updateLockUntil | 4432 | 20702 | 21532 | 21532 | 532 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| withdraw | 20817 | 20817 | 20817 | 20817 | 1 | | withdraw | 20817 | 20817 | 20817 | 20817 | 1 |
|----------------------------------------+-----------------+--------+--------+--------+---------| |----------------------------------------+-----------------+--------+--------+--------+---------|
| withdrawFromVault | 20391 | 20391 | 20391 | 20391 | 1 | | withdrawFromVault | 20391 | 20391 | 20391 | 20391 | 1 |
╰----------------------------------------+-----------------+--------+--------+--------+---------╯ ╰----------------------------------------+-----------------+--------+--------+--------+---------╯
╭----------------------------------------------------+-----------------+------+--------+--------+---------╮ ╭----------------------------------------------------+-----------------+-------+--------+--------+---------╮
| src/TransparentProxy.sol:TransparentProxy Contract | | | | | | | src/TransparentProxy.sol:TransparentProxy Contract | | | | | |
+=========================================================================================================+ +==========================================================================================================+
| Deployment Cost | Deployment Size | | | | | | Deployment Cost | Deployment Size | | | | |
|----------------------------------------------------+-----------------+------+--------+--------+---------| |----------------------------------------------------+-----------------+-------+--------+--------+---------|
| 0 | 1520 | | | | | | 0 | 1520 | | | | |
|----------------------------------------------------+-----------------+------+--------+--------+---------| |----------------------------------------------------+-----------------+-------+--------+--------+---------|
| | | | | | | | | | | | | |
|----------------------------------------------------+-----------------+------+--------+--------+---------| |----------------------------------------------------+-----------------+-------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|----------------------------------------------------+-----------------+------+--------+--------+---------| |----------------------------------------------------+-----------------+-------+--------+--------+---------|
| fallback | 708 | 6172 | 2125 | 374054 | 23155 | | fallback | 5208 | 12845 | 7353 | 374054 | 23161 |
|----------------------------------------------------+-----------------+------+--------+--------+---------| |----------------------------------------------------+-----------------+-------+--------+--------+---------|
| implementation | 346 | 2137 | 2346 | 2346 | 4868 | | implementation | 346 | 2128 | 2346 | 2346 | 4894 |
╰----------------------------------------------------+-----------------+------+--------+--------+---------╯ ╰----------------------------------------------------+-----------------+-------+--------+--------+---------╯
╭--------------------------------------------+-----------------+--------+--------+--------+---------╮ ╭--------------------------------------------+-----------------+--------+--------+--------+---------╮
| src/VaultFactory.sol:VaultFactory Contract | | | | | | | src/VaultFactory.sol:VaultFactory Contract | | | | | |
@@ -346,9 +346,9 @@
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| generate | 54775 | 54775 | 54775 | 54775 | 1 | | generate | 54775 | 54775 | 54775 | 54775 | 1 |
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| imagePrefix | 1183 | 2183 | 2183 | 3183 | 2 | | imagePrefix | 3183 | 3183 | 3183 | 3183 | 2 |
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| imageSuffix | 1227 | 2227 | 2227 | 3227 | 2 | | imageSuffix | 3227 | 3227 | 3227 | 3227 | 2 |
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| setImageStrings | 25295 | 30634 | 30634 | 35974 | 2 | | setImageStrings | 25295 | 30634 | 30634 | 35974 | 2 |
╰------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯ ╰------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯
@@ -368,11 +368,65 @@
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| setURLStrings | 25463 | 30802 | 30802 | 36142 | 2 | | setURLStrings | 25463 | 30802 | 30802 | 36142 | 2 |
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| urlPrefix | 1184 | 1184 | 1184 | 1184 | 1 | | urlPrefix | 3184 | 3184 | 3184 | 3184 | 1 |
|------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| urlSuffix | 1228 | 1228 | 1228 | 1228 | 1 | | urlSuffix | 3228 | 3228 | 3228 | 3228 | 1 |
╰------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯ ╰------------------------------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯
╭----------------------------------------+-----------------+--------+--------+--------+---------╮
| src/rln/KarmaRLN.sol:KarmaRLN Contract | | | | | |
+===============================================================================================+
| Deployment Cost | Deployment Size | | | | |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| 2008065 | 9253 | | | | |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| | | | | | |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| DEFAULT_ADMIN_ROLE | 262 | 262 | 262 | 262 | 10 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| REGISTER_ROLE | 262 | 262 | 262 | 262 | 10 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| SET_SIZE | 2339 | 2339 | 2339 | 2339 | 1 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| SLASHER_ROLE | 262 | 262 | 262 | 262 | 10 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| exit | 7158 | 16284 | 18757 | 22939 | 3 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| hasRole | 2707 | 2707 | 2707 | 2707 | 30 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| identityCommitmentIndex | 2340 | 2340 | 2340 | 2340 | 5 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| initialize | 145136 | 145136 | 145136 | 145136 | 11 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| members | 4669 | 4669 | 4669 | 4669 | 6 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| register | 6974 | 45250 | 52888 | 55688 | 11 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| slash | 7186 | 16419 | 18800 | 23272 | 3 |
|----------------------------------------+-----------------+--------+--------+--------+---------|
| verifier | 2359 | 2359 | 2359 | 2359 | 1 |
╰----------------------------------------+-----------------+--------+--------+--------+---------╯
╭-------------------------------------------+-----------------+-------+--------+-------+---------╮
| test/KarmaRLN.t.sol:MockVerifier Contract | | | | | |
+================================================================================================+
| Deployment Cost | Deployment Size | | | | |
|-------------------------------------------+-----------------+-------+--------+-------+---------|
| 204321 | 642 | | | | |
|-------------------------------------------+-----------------+-------+--------+-------+---------|
| | | | | | |
|-------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name | Min | Avg | Median | Max | # Calls |
|-------------------------------------------+-----------------+-------+--------+-------+---------|
| changeResult | 21649 | 21649 | 21649 | 21649 | 2 |
|-------------------------------------------+-----------------+-------+--------+-------+---------|
| result | 2298 | 2298 | 2298 | 2298 | 3 |
|-------------------------------------------+-----------------+-------+--------+-------+---------|
| verifyProof | 4790 | 4790 | 4790 | 4790 | 4 |
╰-------------------------------------------+-----------------+-------+--------+-------+---------╯
╭-------------------------------------------------------------------+-----------------+-------+--------+-------+---------╮ ╭-------------------------------------------------------------------+-----------------+-------+--------+-------+---------╮
| test/mocks/KarmaDistributorMock.sol:KarmaDistributorMock Contract | | | | | | | test/mocks/KarmaDistributorMock.sol:KarmaDistributorMock Contract | | | | | |
+========================================================================================================================+ +========================================================================================================================+
@@ -384,13 +438,13 @@
|-------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|-------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| rewardsBalanceOfAccount | 549 | 1882 | 2549 | 2549 | 36 | | rewardsBalanceOfAccount | 2549 | 2549 | 2549 | 2549 | 36 |
|-------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| setTotalKarmaShares | 43589 | 43589 | 43589 | 43589 | 36 | | setTotalKarmaShares | 43589 | 43589 | 43589 | 43589 | 36 |
|-------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| setUserKarmaShare | 44194 | 44194 | 44194 | 44194 | 12 | | setUserKarmaShare | 44194 | 44194 | 44194 | 44194 | 12 |
|-------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |-------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| totalRewardsSupply | 324 | 324 | 324 | 324 | 36 | | totalRewardsSupply | 2324 | 2324 | 2324 | 2324 | 36 |
╰-------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯ ╰-------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯
╭---------------------------------------------------------------------+-----------------+-------+--------+-------+---------╮ ╭---------------------------------------------------------------------+-----------------+-------+--------+-------+---------╮
@@ -404,7 +458,7 @@
|---------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |---------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|---------------------------------------------------------------------+-----------------+-------+--------+-------+---------| |---------------------------------------------------------------------+-----------------+-------+--------+-------+---------|
| generate | 58554 | 58554 | 58554 | 58554 | 1 | | generate | 60554 | 60554 | 60554 | 60554 | 1 |
╰---------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯ ╰---------------------------------------------------------------------+-----------------+-------+--------+-------+---------╯
╭---------------------------------------------+-----------------+-------+--------+-------+---------╮ ╭---------------------------------------------+-----------------+-------+--------+-------+---------╮
@@ -418,11 +472,11 @@
|---------------------------------------------+-----------------+-------+--------+-------+---------| |---------------------------------------------+-----------------+-------+--------+-------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|---------------------------------------------+-----------------+-------+--------+-------+---------| |---------------------------------------------+-----------------+-------+--------+-------+---------|
| approve | 29075 | 31545 | 29183 | 46259 | 2676 | | approve | 29075 | 31546 | 29183 | 46259 | 2676 |
|---------------------------------------------+-----------------+-------+--------+-------+---------| |---------------------------------------------+-----------------+-------+--------+-------+---------|
| balanceOf | 561 | 1345 | 561 | 2561 | 4958 | | balanceOf | 2561 | 2561 | 2561 | 2561 | 4959 |
|---------------------------------------------+-----------------+-------+--------+-------+---------| |---------------------------------------------+-----------------+-------+--------+-------+---------|
| mint | 33964 | 37190 | 34072 | 68248 | 2685 | | mint | 33964 | 37192 | 34072 | 68248 | 2685 |
╰---------------------------------------------+-----------------+-------+--------+-------+---------╯ ╰---------------------------------------------+-----------------+-------+--------+-------+---------╯
╭-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╮ ╭-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╮
@@ -436,7 +490,7 @@
|-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| Function Name | Min | Avg | Median | Max | # Calls | | Function Name | Min | Avg | Median | Max | # Calls |
|-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| leave | 29 | 161076 | 161076 | 322248 | 334 | | leave | 26 | 161074 | 161074 | 322246 | 334 |
|-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------| |-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------|
| proxiableUUID | 308 | 308 | 308 | 308 | 1 | | proxiableUUID | 308 | 308 | 308 | 308 | 1 |
╰-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╯ ╰-----------------------------------------------------------------------------+-----------------+--------+--------+--------+---------╯

View File

@@ -1,141 +1,151 @@
AddRewardDistributorTest:testAddKarmaDistributorOnlyAdmin() (gas: 423055) AddRewardDistributorTest:testAddKarmaDistributorOnlyAdmin() (gas: 438055)
AddRewardDistributorTest:testAddRewardDistributorAsOtherAdmin() (gas: 165263) AddRewardDistributorTest:testAddRewardDistributorAsOtherAdmin() (gas: 182763)
AddRewardDistributorTest:testBalanceOf() (gas: 431293) AddRewardDistributorTest:testBalanceOf() (gas: 449293)
AddRewardDistributorTest:testBalanceOfWithNoSystemTotalKarma() (gas: 49655) AddRewardDistributorTest:testBalanceOfWithNoSystemTotalKarma() (gas: 69655)
AddRewardDistributorTest:testMintOnlyAdmin() (gas: 378769) AddRewardDistributorTest:testMintOnlyAdmin() (gas: 428769)
AddRewardDistributorTest:testRemoveKarmaDistributorOnlyOwner() (gas: 147308) AddRewardDistributorTest:testRemoveKarmaDistributorOnlyOwner() (gas: 162308)
AddRewardDistributorTest:testRemoveUnknownKarmaDistributor() (gas: 41630) AddRewardDistributorTest:testRemoveUnknownKarmaDistributor() (gas: 41630)
AddRewardDistributorTest:testTotalSupply() (gas: 339166) AddRewardDistributorTest:testTotalSupply() (gas: 359166)
AddRewardDistributorTest:testTransfersNotAllowed() (gas: 40285) AddRewardDistributorTest:testTransfersNotAllowed() (gas: 61785)
AddRewardDistributorTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 68325) AddRewardDistributorTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 68325)
EmergencyExitTest:test_CannotEnableEmergencyModeTwice() (gas: 93554) EmergencyExitTest:test_CannotEnableEmergencyModeTwice() (gas: 93554)
EmergencyExitTest:test_CannotLeaveBeforeEmergencyMode() (gas: 336067) EmergencyExitTest:test_CannotLeaveBeforeEmergencyMode() (gas: 336067)
EmergencyExitTest:test_EmergencyExitBasic() (gas: 427580) EmergencyExitTest:test_EmergencyExitBasic() (gas: 524580)
EmergencyExitTest:test_EmergencyExitMultipleUsers() (gas: 730615) EmergencyExitTest:test_EmergencyExitMultipleUsers() (gas: 937615)
EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 433110) EmergencyExitTest:test_EmergencyExitToAlternateAddress() (gas: 479110)
EmergencyExitTest:test_EmergencyExitWithLock() (gas: 433444) EmergencyExitTest:test_EmergencyExitWithLock() (gas: 452444)
EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 419310) EmergencyExitTest:test_EmergencyExitWithRewards() (gas: 484810)
EmergencyExitTest:test_OnlyOwnerCanEnableEmergencyMode() (gas: 39176) EmergencyExitTest:test_OnlyOwnerCanEnableEmergencyMode() (gas: 39176)
FuzzTests:testFuzz_AccrueMP(uint128,uint64,uint64) (runs: 1006, μ: 400351, ~: 368061) FuzzTests:testFuzz_AccrueMP(uint128,uint64,uint64) (runs: 1024, μ: 587151, ~: 549070)
FuzzTests:testFuzz_AccrueMP_Relock(uint128,uint64,uint64,uint64) (runs: 1006, μ: 501707, ~: 471734) FuzzTests:testFuzz_AccrueMP_Relock(uint128,uint64,uint64,uint64) (runs: 1024, μ: 812396, ~: 777234)
FuzzTests:testFuzz_EmergencyExit(uint256,uint256) (runs: 1001, μ: 497146, ~: 487267) FuzzTests:testFuzz_EmergencyExit(uint256,uint256) (runs: 1007, μ: 588350, ~: 578267)
FuzzTests:testFuzz_Lock(uint256,uint64) (runs: 1006, μ: 727489, ~: 726735) FuzzTests:testFuzz_Lock(uint256,uint64) (runs: 1025, μ: 961806, ~: 961235)
FuzzTests:testFuzz_Relock(uint256,uint64,uint64) (runs: 1006, μ: 409218, ~: 388725) FuzzTests:testFuzz_Relock(uint256,uint64,uint64) (runs: 1025, μ: 599078, ~: 574234)
FuzzTests:testFuzz_Rewards(uint256,uint256,uint256,uint16,uint16) (runs: 1001, μ: 599846, ~: 601205) FuzzTests:testFuzz_Rewards(uint256,uint256,uint256,uint16,uint16) (runs: 1001, μ: 650369, ~: 653205)
FuzzTests:testFuzz_Stake(uint256,uint64) (runs: 1006, μ: 311868, ~: 285086) FuzzTests:testFuzz_Stake(uint256,uint64) (runs: 1025, μ: 376001, ~: 346086)
FuzzTests:testFuzz_Unstake(uint128,uint64,uint16,uint128) (runs: 1006, μ: 501292, ~: 473125) FuzzTests:testFuzz_Unstake(uint128,uint64,uint16,uint128) (runs: 1024, μ: 806573, ~: 780622)
FuzzTests:testFuzz_UpdateVault(uint128,uint64,uint64) (runs: 1006, μ: 400374, ~: 368084) FuzzTests:testFuzz_UpdateVault(uint128,uint64,uint64) (runs: 1024, μ: 587174, ~: 549093)
IntegrationTest:testStakeFoo() (gas: 1362931) IntegrationTest:testStakeFoo() (gas: 2348931)
KarmaNFTTest:testApproveNotAllowed() (gas: 10507) KarmaNFTTest:testApproveNotAllowed() (gas: 10507)
KarmaNFTTest:testGetApproved() (gas: 10531) KarmaNFTTest:testGetApproved() (gas: 10531)
KarmaNFTTest:testIsApprovedForAll() (gas: 10705) KarmaNFTTest:testIsApprovedForAll() (gas: 10705)
KarmaNFTTest:testSafeTransferNotAllowed() (gas: 10688) KarmaNFTTest:testSafeTransferNotAllowed() (gas: 10688)
KarmaNFTTest:testSafeTransferWithDataNotAllowed() (gas: 10884) KarmaNFTTest:testSafeTransferWithDataNotAllowed() (gas: 10884)
KarmaNFTTest:testSetApprovalForAllNotAllowed() (gas: 8519) KarmaNFTTest:testSetApprovalForAllNotAllowed() (gas: 8519)
KarmaNFTTest:testSetMetadataGenerator() (gas: 1010377) KarmaNFTTest:testSetMetadataGenerator() (gas: 1012377)
KarmaNFTTest:testSetMetadataGeneratorRevert() (gas: 1006937) KarmaNFTTest:testSetMetadataGeneratorRevert() (gas: 1006937)
KarmaNFTTest:testTokenURI() (gas: 1105935) KarmaNFTTest:testTokenURI() (gas: 1112435)
KarmaNFTTest:testTransferNotAllowed() (gas: 10701) KarmaNFTTest:testTransferNotAllowed() (gas: 10701)
KarmaOwnershipTest:testAddKarmaDistributorOnlyAdmin() (gas: 423043) KarmaOwnershipTest:testAddKarmaDistributorOnlyAdmin() (gas: 438043)
KarmaOwnershipTest:testBalanceOf() (gas: 431293) KarmaOwnershipTest:testBalanceOf() (gas: 449293)
KarmaOwnershipTest:testBalanceOfWithNoSystemTotalKarma() (gas: 49677) KarmaOwnershipTest:testBalanceOfWithNoSystemTotalKarma() (gas: 69677)
KarmaOwnershipTest:testInitialOwner() (gas: 16039) KarmaOwnershipTest:testInitialOwner() (gas: 20539)
KarmaOwnershipTest:testMintOnlyAdmin() (gas: 378791) KarmaOwnershipTest:testMintOnlyAdmin() (gas: 428791)
KarmaOwnershipTest:testOwnershipTransfer() (gas: 76843) KarmaOwnershipTest:testOwnershipTransfer() (gas: 94343)
KarmaOwnershipTest:testRemoveKarmaDistributorOnlyOwner() (gas: 147229) KarmaOwnershipTest:testRemoveKarmaDistributorOnlyOwner() (gas: 162229)
KarmaOwnershipTest:testRemoveUnknownKarmaDistributor() (gas: 41618) KarmaOwnershipTest:testRemoveUnknownKarmaDistributor() (gas: 41618)
KarmaOwnershipTest:testTotalSupply() (gas: 339166) KarmaOwnershipTest:testTotalSupply() (gas: 359166)
KarmaOwnershipTest:testTransfersNotAllowed() (gas: 40285) KarmaOwnershipTest:testTransfersNotAllowed() (gas: 61785)
KarmaTest:testAddKarmaDistributorOnlyAdmin() (gas: 423021) KarmaTest:testAddKarmaDistributorOnlyAdmin() (gas: 438021)
KarmaTest:testBalanceOf() (gas: 431293) KarmaTest:testBalanceOf() (gas: 449293)
KarmaTest:testBalanceOfWithNoSystemTotalKarma() (gas: 49655) KarmaTest:testBalanceOfWithNoSystemTotalKarma() (gas: 69655)
KarmaTest:testMintOnlyAdmin() (gas: 378769) KarmaTest:testMintOnlyAdmin() (gas: 428769)
KarmaTest:testRemoveKarmaDistributorOnlyOwner() (gas: 147274) KarmaTest:testRemoveKarmaDistributorOnlyOwner() (gas: 162274)
KarmaTest:testRemoveUnknownKarmaDistributor() (gas: 41618) KarmaTest:testRemoveUnknownKarmaDistributor() (gas: 41618)
KarmaTest:testTotalSupply() (gas: 339166) KarmaTest:testTotalSupply() (gas: 359166)
KarmaTest:testTransfersNotAllowed() (gas: 40263) KarmaTest:testTransfersNotAllowed() (gas: 61763)
LeaveTest:test_LeaveShouldKeepFundsLockedInStakeVault() (gas: 9899411) LeaveTest:test_LeaveShouldKeepFundsLockedInStakeVault() (gas: 9938411)
LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 9865059) LeaveTest:test_LeaveShouldProperlyUpdateAccounting() (gas: 10011059)
LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 333238) LeaveTest:test_RevertWhenStakeManagerIsTrusted() (gas: 333238)
LeaveTest:test_TrustNewStakeManager() (gas: 9933491) LeaveTest:test_TrustNewStakeManager() (gas: 9944491)
LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1006, μ: 384564, ~: 384588) LockTest:test_LockFailsWithInvalidPeriod(uint256) (runs: 1025, μ: 384562, ~: 384588)
LockTest:test_LockFailsWithNoStake() (gas: 89700) LockTest:test_LockFailsWithNoStake() (gas: 89700)
LockTest:test_LockFailsWithZero() (gas: 343310) LockTest:test_LockFailsWithZero() (gas: 343310)
LockTest:test_LockMultipleTimesExceedMaxLock() (gas: 628421) LockTest:test_LockMultipleTimesExceedMaxLock() (gas: 746921)
LockTest:test_LockWithPriorLock() (gas: 566521) LockTest:test_LockWithPriorLock() (gas: 681021)
LockTest:test_LockWithoutPriorLock() (gas: 446388) LockTest:test_LockWithoutPriorLock() (gas: 521888)
LockTest:test_RevertWhenVaultToLockIsEmpty() (gas: 89700) LockTest:test_RevertWhenVaultToLockIsEmpty() (gas: 89700)
MaliciousUpgradeTest:test_UpgradeStackOverflowStakeManager() (gas: 1995193) MaliciousUpgradeTest:test_UpgradeStackOverflowStakeManager() (gas: 2056691)
MathTest:test_CalcAbsoluteMaxTotalMP() (gas: 5240) MathTest:test_CalcAbsoluteMaxTotalMP() (gas: 5240)
MathTest:test_CalcAccrueMP() (gas: 8599) MathTest:test_CalcAccrueMP() (gas: 8599)
MathTest:test_CalcBonusMP() (gas: 19244) MathTest:test_CalcBonusMP() (gas: 30744)
MathTest:test_CalcInitialMP() (gas: 5836) MathTest:test_CalcInitialMP() (gas: 5836)
MathTest:test_CalcMaxAccruedMP() (gas: 4886) MathTest:test_CalcMaxAccruedMP() (gas: 4886)
MathTest:test_CalcMaxTotalMP() (gas: 20006) MathTest:test_CalcMaxTotalMP() (gas: 31506)
MultipleVaultsStakeTest:test_StakeMultipleVaults() (gas: 801979) MultipleVaultsStakeTest:test_StakeMultipleVaults() (gas: 918979)
NFTMetadataGeneratorSVGTest:testGenerateMetadata() (gas: 92580) NFTMetadataGeneratorSVGTest:testGenerateMetadata() (gas: 92580)
NFTMetadataGeneratorSVGTest:testSetImageStrings() (gas: 60081) NFTMetadataGeneratorSVGTest:testSetImageStrings() (gas: 77581)
NFTMetadataGeneratorSVGTest:testSetImageStringsRevert() (gas: 35891) NFTMetadataGeneratorSVGTest:testSetImageStringsRevert() (gas: 35891)
NFTMetadataGeneratorURLTest:testGenerateMetadata() (gas: 108341) NFTMetadataGeneratorURLTest:testGenerateMetadata() (gas: 108341)
NFTMetadataGeneratorURLTest:testSetBaseURL() (gas: 50631) NFTMetadataGeneratorURLTest:testSetBaseURL() (gas: 59131)
NFTMetadataGeneratorURLTest:testSetBaseURLRevert() (gas: 36066) NFTMetadataGeneratorURLTest:testSetBaseURLRevert() (gas: 36066)
OverflowTest:testAddKarmaDistributorOnlyAdmin() (gas: 423043) OverflowTest:testAddKarmaDistributorOnlyAdmin() (gas: 438043)
OverflowTest:testBalanceOf() (gas: 431293) OverflowTest:testBalanceOf() (gas: 449293)
OverflowTest:testBalanceOfWithNoSystemTotalKarma() (gas: 49655) OverflowTest:testBalanceOfWithNoSystemTotalKarma() (gas: 69655)
OverflowTest:testMintOnlyAdmin() (gas: 378769) OverflowTest:testMintOnlyAdmin() (gas: 428769)
OverflowTest:testRemoveKarmaDistributorOnlyOwner() (gas: 147274) OverflowTest:testRemoveKarmaDistributorOnlyOwner() (gas: 162274)
OverflowTest:testRemoveUnknownKarmaDistributor() (gas: 41630) OverflowTest:testRemoveUnknownKarmaDistributor() (gas: 41630)
OverflowTest:testTotalSupply() (gas: 339166) OverflowTest:testTotalSupply() (gas: 359166)
OverflowTest:testTransfersNotAllowed() (gas: 40263) OverflowTest:testTransfersNotAllowed() (gas: 61763)
OverflowTest:test_RevertWhen_MintingCausesOverflow() (gas: 129464) OverflowTest:test_RevertWhen_MintingCausesOverflow() (gas: 129464)
OverflowTest:test_RevertWhen_SettingRewardCausesOverflow() (gas: 127792) OverflowTest:test_RevertWhen_SettingRewardCausesOverflow() (gas: 127792)
RemoveRewardDistributorTest:testAddKarmaDistributorOnlyAdmin() (gas: 423045) RLNTest:test_exit_fails_when_invalid_proof() (gas: 193235)
RemoveRewardDistributorTest:testBalanceOf() (gas: 431366) RLNTest:test_exit_fails_when_not_registered() (gas: 65339)
RemoveRewardDistributorTest:testBalanceOfWithNoSystemTotalKarma() (gas: 49633) RLNTest:test_exit_succeeds() (gas: 184871)
RemoveRewardDistributorTest:testMintOnlyAdmin() (gas: 378759) RLNTest:test_initial_state() (gas: 60571)
RemoveRewardDistributorTest:testRemoveKarmaDistributorOnlyOwner() (gas: 147298) RLNTest:test_register_fails_when_duplicate_identity_commitment() (gas: 129095)
RemoveRewardDistributorTest:testRemoveRewardDistributor() (gas: 132118) RLNTest:test_register_fails_when_index_exceeds_set_size() (gas: 2565352)
RemoveRewardDistributorTest:testRemoveRewardDistributorAsOtherAdmin() (gas: 203200) RLNTest:test_register_succeeds() (gas: 267452)
RLNTest:test_slash_fails_when_invalid_proof() (gas: 193297)
RLNTest:test_slash_fails_when_not_registered() (gas: 65317)
RLNTest:test_slash_succeeds() (gas: 185761)
RemoveRewardDistributorTest:testAddKarmaDistributorOnlyAdmin() (gas: 438045)
RemoveRewardDistributorTest:testBalanceOf() (gas: 449366)
RemoveRewardDistributorTest:testBalanceOfWithNoSystemTotalKarma() (gas: 69633)
RemoveRewardDistributorTest:testMintOnlyAdmin() (gas: 428759)
RemoveRewardDistributorTest:testRemoveKarmaDistributorOnlyOwner() (gas: 162298)
RemoveRewardDistributorTest:testRemoveRewardDistributor() (gas: 162118)
RemoveRewardDistributorTest:testRemoveRewardDistributorAsOtherAdmin() (gas: 242200)
RemoveRewardDistributorTest:testRemoveUnknownKarmaDistributor() (gas: 41636) RemoveRewardDistributorTest:testRemoveUnknownKarmaDistributor() (gas: 41636)
RemoveRewardDistributorTest:testTotalSupply() (gas: 339239) RemoveRewardDistributorTest:testTotalSupply() (gas: 359239)
RemoveRewardDistributorTest:testTransfersNotAllowed() (gas: 40263) RemoveRewardDistributorTest:testTransfersNotAllowed() (gas: 61763)
RemoveRewardDistributorTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 66507) RemoveRewardDistributorTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 66507)
SetRewardTest:testAddKarmaDistributorOnlyAdmin() (gas: 423077) SetRewardTest:testAddKarmaDistributorOnlyAdmin() (gas: 438077)
SetRewardTest:testBalanceOf() (gas: 431293) SetRewardTest:testBalanceOf() (gas: 449293)
SetRewardTest:testBalanceOfWithNoSystemTotalKarma() (gas: 49677) SetRewardTest:testBalanceOfWithNoSystemTotalKarma() (gas: 69677)
SetRewardTest:testMintOnlyAdmin() (gas: 378791) SetRewardTest:testMintOnlyAdmin() (gas: 428791)
SetRewardTest:testRemoveKarmaDistributorOnlyOwner() (gas: 147241) SetRewardTest:testRemoveKarmaDistributorOnlyOwner() (gas: 162241)
SetRewardTest:testRemoveUnknownKarmaDistributor() (gas: 41630) SetRewardTest:testRemoveUnknownKarmaDistributor() (gas: 41630)
SetRewardTest:testSetRewardAsAdmin() (gas: 134934) SetRewardTest:testSetRewardAsAdmin() (gas: 134934)
SetRewardTest:testSetRewardAsOperator() (gas: 126214) SetRewardTest:testSetRewardAsOperator() (gas: 143714)
SetRewardTest:testSetRewardAsOtherAdmin() (gas: 199420) SetRewardTest:testSetRewardAsOtherAdmin() (gas: 203920)
SetRewardTest:testTotalSupply() (gas: 339211) SetRewardTest:testTotalSupply() (gas: 359211)
SetRewardTest:testTransfersNotAllowed() (gas: 40307) SetRewardTest:testTransfersNotAllowed() (gas: 61807)
SetRewardTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 43559) SetRewardTest:test_RevertWhen_SenderIsNotDefaultAdmin() (gas: 43559)
SetRewardTest:test_RevertWhen_SenderIsNotOperator() (gas: 53332) SetRewardTest:test_RevertWhen_SenderIsNotOperator() (gas: 61832)
StakeManager_RewardsTest:testRewardsBalanceOf() (gas: 1281535) StakeManager_RewardsTest:testRewardsBalanceOf() (gas: 2712035)
StakeManager_RewardsTest:testSetRewards() (gas: 227100) StakeManager_RewardsTest:testSetRewards() (gas: 278100)
StakeManager_RewardsTest:testSetRewards_RevertsBadAmount() (gas: 63751) StakeManager_RewardsTest:testSetRewards_RevertsBadAmount() (gas: 63751)
StakeManager_RewardsTest:testSetRewards_RevertsBadDuration() (gas: 103509) StakeManager_RewardsTest:testSetRewards_RevertsBadDuration() (gas: 103509)
StakeManager_RewardsTest:testSetRewards_RevertsNotAuthorized() (gas: 39367) StakeManager_RewardsTest:testSetRewards_RevertsNotAuthorized() (gas: 39367)
StakeManager_RewardsTest:testTotalRewardsSupply() (gas: 746224) StakeManager_RewardsTest:testTotalRewardsSupply() (gas: 1280724)
StakeTest:test_StakeMultipleAccounts() (gas: 556308) StakeTest:test_StakeMultipleAccounts() (gas: 666808)
StakeTest:test_StakeMultipleAccountsAndRewards() (gas: 564800) StakeTest:test_StakeMultipleAccountsAndRewards() (gas: 721800)
StakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 942461) StakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 1324461)
StakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 571074) StakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 615074)
StakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 595232) StakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 645732)
StakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1528357) StakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1780357)
StakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 581504) StakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 691504)
StakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1124100) StakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1191100)
StakeTest:test_StakeOneAccount() (gas: 316362) StakeTest:test_StakeOneAccount() (gas: 390362)
StakeTest:test_StakeOneAccountAndRewards() (gas: 324917) StakeTest:test_StakeOneAccountAndRewards() (gas: 445417)
StakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 616802) StakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 825302)
StakeTest:test_StakeOneAccountReachingMPLimit() (gas: 503792) StakeTest:test_StakeOneAccountReachingMPLimit() (gas: 714792)
StakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 337583) StakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 381583)
StakeTest:test_StakeOneAccountWithMinLockUp() (gas: 338223) StakeTest:test_StakeOneAccountWithMinLockUp() (gas: 382223)
StakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 338268) StakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 382268)
StakeVaultMigrationTest:testMigrateToVault() (gas: 885152) StakeVaultMigrationTest:testMigrateToVault() (gas: 1157152)
StakeVaultMigrationTest:test_RevertWhenDestinationVaultIsNotRegistered() (gas: 162181) StakeVaultMigrationTest:test_RevertWhenDestinationVaultIsNotRegistered() (gas: 166681)
StakeVaultMigrationTest:test_RevertWhenMigrationVaultNotEmpty() (gas: 631911) StakeVaultMigrationTest:test_RevertWhenMigrationVaultNotEmpty() (gas: 631911)
StakeVaultMigrationTest:test_RevertWhenNotOwnerOfMigrationVault() (gas: 70563) StakeVaultMigrationTest:test_RevertWhenNotOwnerOfMigrationVault() (gas: 70563)
StakeVaultTest:testOwner() (gas: 15331) StakeVaultTest:testOwner() (gas: 15331)
@@ -143,31 +153,31 @@ StakingTokenTest:testOwner() (gas: 15331)
StakingTokenTest:testStakeToken() (gas: 13156) StakingTokenTest:testStakeToken() (gas: 13156)
TrustedCodehashAccessTest:test_RevertWhenProxyCloneCodehashNotTrusted() (gas: 2021691) TrustedCodehashAccessTest:test_RevertWhenProxyCloneCodehashNotTrusted() (gas: 2021691)
UnstakeTest:test_RevertWhen_FundsLocked() (gas: 461737) UnstakeTest:test_RevertWhen_FundsLocked() (gas: 461737)
UnstakeTest:test_StakeMultipleAccounts() (gas: 556287) UnstakeTest:test_StakeMultipleAccounts() (gas: 666787)
UnstakeTest:test_StakeMultipleAccountsAndRewards() (gas: 564844) UnstakeTest:test_StakeMultipleAccountsAndRewards() (gas: 721844)
UnstakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 942527) UnstakeTest:test_StakeMultipleAccountsMPIncreasesMaxMPDoesNotChange() (gas: 1324527)
UnstakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 571140) UnstakeTest:test_StakeMultipleAccountsWithMinLockUp() (gas: 615140)
UnstakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 595231) UnstakeTest:test_StakeMultipleAccountsWithRandomLockUp() (gas: 645731)
UnstakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1528413) UnstakeTest:test_StakeMultipleTimesDoesNotExceedsMaxMP() (gas: 1780413)
UnstakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 581459) UnstakeTest:test_StakeMultipleTimesWithLockIncreaseAtSameBlock() (gas: 691459)
UnstakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1124111) UnstakeTest:test_StakeMultipleTimesWithLockZeroAfterMaxLock() (gas: 1191111)
UnstakeTest:test_StakeOneAccount() (gas: 316384) UnstakeTest:test_StakeOneAccount() (gas: 390384)
UnstakeTest:test_StakeOneAccountAndRewards() (gas: 324916) UnstakeTest:test_StakeOneAccountAndRewards() (gas: 445416)
UnstakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 616801) UnstakeTest:test_StakeOneAccountMPIncreasesMaxMPDoesNotChange() (gas: 825301)
UnstakeTest:test_StakeOneAccountReachingMPLimit() (gas: 503772) UnstakeTest:test_StakeOneAccountReachingMPLimit() (gas: 714772)
UnstakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 337605) UnstakeTest:test_StakeOneAccountWithMaxLockUp() (gas: 381605)
UnstakeTest:test_StakeOneAccountWithMinLockUp() (gas: 338223) UnstakeTest:test_StakeOneAccountWithMinLockUp() (gas: 382223)
UnstakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 338268) UnstakeTest:test_StakeOneAccountWithRandomLockUp() (gas: 382268)
UnstakeTest:test_UnstakeBonusMPAndAccuredMP() (gas: 581839) UnstakeTest:test_UnstakeBonusMPAndAccuredMP() (gas: 754339)
UnstakeTest:test_UnstakeMultipleAccounts() (gas: 796850) UnstakeTest:test_UnstakeMultipleAccounts() (gas: 1037350)
UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 907371) UnstakeTest:test_UnstakeMultipleAccountsAndRewards() (gas: 1322871)
UnstakeTest:test_UnstakeOneAccount() (gas: 545178) UnstakeTest:test_UnstakeOneAccount() (gas: 759178)
UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 544489) UnstakeTest:test_UnstakeOneAccountAndAccruedMP() (gas: 719489)
UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 468681) UnstakeTest:test_UnstakeOneAccountAndRewards() (gas: 673681)
UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 570741) UnstakeTest:test_UnstakeOneAccountWithLockUpAndAccruedMP() (gas: 722241)
UpdateVaultTest:test_UpdateAccount() (gas: 2397378) UpdateVaultTest:test_UpdateAccount() (gas: 2587378)
UpgradeTest:test_RevertWhenNotOwner() (gas: 3696209) UpgradeTest:test_RevertWhenNotOwner() (gas: 3696209)
UpgradeTest:test_UpgradeStakeManager() (gas: 9769347) UpgradeTest:test_UpgradeStakeManager() (gas: 9855347)
VaultRegistrationTest:test_VaultRegistration() (gas: 63138) VaultRegistrationTest:test_VaultRegistration() (gas: 90138)
WithdrawTest:testOwner() (gas: 15365) WithdrawTest:testOwner() (gas: 15365)
WithdrawTest:test_CannotWithdrawStakedFunds() (gas: 348908) WithdrawTest:test_CannotWithdrawStakedFunds() (gas: 373408)

View File

@@ -6,21 +6,22 @@ import { DeploymentConfig } from "./DeploymentConfig.s.sol";
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {Verifier} from "../src/rln/Verifier.sol"; import { Groth16Verifier } from "../src/rln/Verifier.sol";
import { KarmaRLN } from "../src/rln/KarmaRLN.sol"; import { KarmaRLN } from "../src/rln/KarmaRLN.sol";
contract DeployKarmaScript is BaseScript { contract DeployKarmaScript is BaseScript {
function run() public returns (Karma, DeploymentConfig) { function run() public returns (KarmaRLN, DeploymentConfig) {
DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster); DeploymentConfig deploymentConfig = new DeploymentConfig(broadcaster);
(address deployer,) = deploymentConfig.activeNetworkConfig(); (address deployer,) = deploymentConfig.activeNetworkConfig();
uint256 depth = vm.envUint("DEPTH"); uint256 depth = vm.envUint("DEPTH");
address karmaAddress = vm.envAddress("KARMA_ADDRESS"); address karmaAddress = vm.envAddress("KARMA_ADDRESS");
vm.startBroadcast(deployer); vm.startBroadcast(deployer);
Groth16Verifier verifier = new Groth16Verifier(); address verifier = (address)(new Groth16Verifier());
// Deploy Karma logic contract // Deploy Karma logic contract
bytes memory initializeData = abi.encodeCall(KarmaRLN.initialize, (deployer, deployer, deployer, verifier, depth, karmaAddress)); bytes memory initializeData =
abi.encodeCall(KarmaRLN.initialize, (deployer, deployer, deployer, depth, verifier, karmaAddress));
address impl = address(new KarmaRLN()); address impl = address(new KarmaRLN());
// Create upgradeable proxy // Create upgradeable proxy
address proxy = address(new ERC1967Proxy(impl, initializeData)); address proxy = address(new ERC1967Proxy(impl, initializeData));

View File

@@ -7,5 +7,8 @@ interface IVerifier {
uint256[2][2] calldata b, uint256[2][2] calldata b,
uint256[2] calldata c, uint256[2] calldata c,
uint256[2] calldata input uint256[2] calldata input
) external view returns (bool); )
} external
view
returns (bool);
}

View File

@@ -22,44 +22,73 @@ pragma solidity 0.8.26;
contract Groth16Verifier { contract Groth16Verifier {
// Scalar field size // Scalar field size
uint256 constant r = 21888242871839275222246405745257275088548364400416034343698204186575808495617; uint256 constant r =
21_888_242_871_839_275_222_246_405_745_257_275_088_548_364_400_416_034_343_698_204_186_575_808_495_617;
// Base field size // Base field size
uint256 constant q = 21888242871839275222246405745257275088696311157297823662689037894645226208583; uint256 constant q =
21_888_242_871_839_275_222_246_405_745_257_275_088_696_311_157_297_823_662_689_037_894_645_226_208_583;
// Verification Key data // Verification Key data
uint256 constant alphax = 20491192805390485299153009773594534940189261866228447918068658471970481763042; uint256 constant alphax =
uint256 constant alphay = 9383485363053290200918347156157836566562967994039712273449902621266178545958; 20_491_192_805_390_485_299_153_009_773_594_534_940_189_261_866_228_447_918_068_658_471_970_481_763_042;
uint256 constant betax1 = 4252822878758300859123897981450591353533073413197771768651442665752259397132; uint256 constant alphay =
uint256 constant betax2 = 6375614351688725206403948262868962793625744043794305715222011528459656738731; 9_383_485_363_053_290_200_918_347_156_157_836_566_562_967_994_039_712_273_449_902_621_266_178_545_958;
uint256 constant betay1 = 21847035105528745403288232691147584728191162732299865338377159692350059136679; uint256 constant betax1 =
uint256 constant betay2 = 10505242626370262277552901082094356697409835680220590971873171140371331206856; 4_252_822_878_758_300_859_123_897_981_450_591_353_533_073_413_197_771_768_651_442_665_752_259_397_132;
uint256 constant gammax1 = 11559732032986387107991004021392285783925812861821192530917403151452391805634; uint256 constant betax2 =
uint256 constant gammax2 = 10857046999023057135944570762232829481370756359578518086990519993285655852781; 6_375_614_351_688_725_206_403_948_262_868_962_793_625_744_043_794_305_715_222_011_528_459_656_738_731;
uint256 constant gammay1 = 4082367875863433681332203403145435568316851327593401208105741076214120093531; uint256 constant betay1 =
uint256 constant gammay2 = 8495653923123431417604973247489272438418190587263600148770280649306958101930; 21_847_035_105_528_745_403_288_232_691_147_584_728_191_162_732_299_865_338_377_159_692_350_059_136_679;
uint256 constant deltax1 = 11551021181461167826461759140322976337427023987127500996455457136635486400849; uint256 constant betay2 =
uint256 constant deltax2 = 16440331697014556916876897072677669680121386347171004539353252116876383229648; 10_505_242_626_370_262_277_552_901_082_094_356_697_409_835_680_220_590_971_873_171_140_371_331_206_856;
uint256 constant deltay1 = 16935666883311644237478257793713075046951222500094443222621864730929684383196; uint256 constant gammax1 =
uint256 constant deltay2 = 15542122065551809636611024015159689732218122471819623718488423844152861811271; 11_559_732_032_986_387_107_991_004_021_392_285_783_925_812_861_821_192_530_917_403_151_452_391_805_634;
uint256 constant gammax2 =
10_857_046_999_023_057_135_944_570_762_232_829_481_370_756_359_578_518_086_990_519_993_285_655_852_781;
uint256 constant gammay1 =
4_082_367_875_863_433_681_332_203_403_145_435_568_316_851_327_593_401_208_105_741_076_214_120_093_531;
uint256 constant gammay2 =
8_495_653_923_123_431_417_604_973_247_489_272_438_418_190_587_263_600_148_770_280_649_306_958_101_930;
uint256 constant deltax1 =
11_551_021_181_461_167_826_461_759_140_322_976_337_427_023_987_127_500_996_455_457_136_635_486_400_849;
uint256 constant deltax2 =
16_440_331_697_014_556_916_876_897_072_677_669_680_121_386_347_171_004_539_353_252_116_876_383_229_648;
uint256 constant deltay1 =
16_935_666_883_311_644_237_478_257_793_713_075_046_951_222_500_094_443_222_621_864_730_929_684_383_196;
uint256 constant deltay2 =
15_542_122_065_551_809_636_611_024_015_159_689_732_218_122_471_819_623_718_488_423_844_152_861_811_271;
uint256 constant IC0x =
19_490_069_286_251_317_200_471_893_224_761_952_280_235_157_078_692_599_655_063_040_494_106_083_015_102;
uint256 constant IC0y =
15_613_730_057_977_833_735_664_106_983_317_680_013_118_142_165_231_654_768_046_521_650_638_333_652_991;
uint256 constant IC1x =
1_563_543_155_852_853_229_359_605_494_188_815_884_199_915_022_658_219_002_707_722_789_976_065_966_419;
uint256 constant IC1y =
858_819_375_930_654_753_672_617_171_465_307_097_688_802_650_498_051_619_587_167_586_479_724_200_799;
uint256 constant IC2x =
3_808_889_614_445_935_800_597_561_392_085_733_302_718_838_702_771_107_544_944_545_050_886_958_022_904;
uint256 constant IC2y =
13_293_649_293_049_947_010_793_838_294_353_767_499_934_999_769_633_605_908_974_566_715_226_392_122_400;
uint256 constant IC0x = 19490069286251317200471893224761952280235157078692599655063040494106083015102;
uint256 constant IC0y = 15613730057977833735664106983317680013118142165231654768046521650638333652991;
uint256 constant IC1x = 1563543155852853229359605494188815884199915022658219002707722789976065966419;
uint256 constant IC1y = 858819375930654753672617171465307097688802650498051619587167586479724200799;
uint256 constant IC2x = 3808889614445935800597561392085733302718838702771107544944545050886958022904;
uint256 constant IC2y = 13293649293049947010793838294353767499934999769633605908974566715226392122400;
// Memory data // Memory data
uint16 constant pVk = 0; uint16 constant pVk = 0;
uint16 constant pPairing = 128; uint16 constant pPairing = 128;
uint16 constant pLastMem = 896; uint16 constant pLastMem = 896;
function verifyProof(uint[2] calldata _pA, uint[2][2] calldata _pB, uint[2] calldata _pC, uint[2] calldata _pubSignals) public view returns (bool) { function verifyProof(
uint256[2] calldata _pA,
uint256[2][2] calldata _pB,
uint256[2] calldata _pC,
uint256[2] calldata _pubSignals
)
public
view
returns (bool)
{
assembly { assembly {
function checkField(v) { function checkField(v) {
if iszero(lt(v, q)) { if iszero(lt(v, q)) {
@@ -67,7 +96,7 @@ contract Groth16Verifier {
return(0, 0x20) return(0, 0x20)
} }
} }
// G1 function to multiply a G1 value(x,y) to value in an address // G1 function to multiply a G1 value(x,y) to value in an address
function g1_mulAccC(pR, x, y, s) { function g1_mulAccC(pR, x, y, s) {
let success let success
@@ -102,11 +131,10 @@ contract Groth16Verifier {
mstore(add(_pVk, 32), IC0y) mstore(add(_pVk, 32), IC0y)
// Compute the linear combination vk_x // Compute the linear combination vk_x
g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0))) g1_mulAccC(_pVk, IC1x, IC1y, calldataload(add(pubSignals, 0)))
g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32))) g1_mulAccC(_pVk, IC2x, IC2y, calldataload(add(pubSignals, 32)))
// -A // -A
mstore(_pPairing, calldataload(pA)) mstore(_pPairing, calldataload(pA))
@@ -132,7 +160,6 @@ contract Groth16Verifier {
mstore(add(_pPairing, 384), mload(add(pMem, pVk))) mstore(add(_pPairing, 384), mload(add(pMem, pVk)))
mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32)))) mstore(add(_pPairing, 416), mload(add(pMem, add(pVk, 32))))
// gamma2 // gamma2
mstore(add(_pPairing, 448), gammax1) mstore(add(_pPairing, 448), gammax1)
mstore(add(_pPairing, 480), gammax2) mstore(add(_pPairing, 480), gammax2)
@@ -149,7 +176,6 @@ contract Groth16Verifier {
mstore(add(_pPairing, 704), deltay1) mstore(add(_pPairing, 704), deltay1)
mstore(add(_pPairing, 736), deltay2) mstore(add(_pPairing, 736), deltay2)
let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20) let success := staticcall(sub(gas(), 2000), 8, _pPairing, 768, _pPairing, 0x20)
isOk := and(success, mload(_pPairing)) isOk := and(success, mload(_pPairing))
@@ -159,19 +185,18 @@ contract Groth16Verifier {
mstore(0x40, add(pMem, pLastMem)) mstore(0x40, add(pMem, pLastMem))
// Validate that all evaluations ∈ F // Validate that all evaluations ∈ F
checkField(calldataload(add(_pubSignals, 0))) checkField(calldataload(add(_pubSignals, 0)))
checkField(calldataload(add(_pubSignals, 32))) checkField(calldataload(add(_pubSignals, 32)))
checkField(calldataload(add(_pubSignals, 64))) checkField(calldataload(add(_pubSignals, 64)))
// Validate all evaluations // Validate all evaluations
let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem) let isValid := checkPairing(_pA, _pB, _pC, _pubSignals, pMem)
mstore(0, isValid) mstore(0, isValid)
return(0, 0x20) return(0, 0x20)
} }
} }
} }

View File

@@ -1,15 +1,13 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT // SPDX-License-Identifier: Apache-2.0 OR MIT
pragma solidity ^0.8.26; pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "forge-std/Test.sol"; import "forge-std/Test.sol";
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "../src/rln/KarmaRLN.sol"; import "../src/rln/KarmaRLN.sol";
import { IVerifier } from "../src/rln/IVerifier.sol"; import { IVerifier } from "../src/rln/IVerifier.sol";
/// @dev A mock verifier that allows toggling proof validity.
// A mock verifier which makes us skip the proof verification.
contract MockVerifier is IVerifier { contract MockVerifier is IVerifier {
bool public result; bool public result;
@@ -25,6 +23,7 @@ contract MockVerifier is IVerifier {
) )
external external
view view
override
returns (bool) returns (bool)
{ {
return result; return result;
@@ -36,199 +35,244 @@ contract MockVerifier is IVerifier {
} }
contract RLNTest is Test { contract RLNTest is Test {
event MemberRegistered(uint256 identityCommitment, uint256 messageLimit, uint256 index); KarmaRLN public rln;
event MemberWithdrawn(uint256 index); MockVerifier public verifier;
event MemberSlashed(uint256 index, address slasher);
Karma token; uint256 private constant DEPTH = 2; // for most tests
KarmaRLN rln; uint256 private constant SMALL_DEPTH = 1; // for “full” test
MockVerifier verifier;
uint256 depth = 20; // Sample identity commitments
uint256 identityCommitment0 = 1234; uint256 private identityCommitment0 = 1234;
uint256 identityCommitment1 = 5678; uint256 private identityCommitment1 = 5678;
uint256 private identityCommitment2 = 9999;
address adminAddr = makeAddr("admin"); // Sample SNARK proof (8element array)
address registerAddr = makeAddr("register"); uint256[8] private mockProof =
address slasherAddr = makeAddr("slasher");
address user0 = makeAddr("user0");
address user1 = makeAddr("user1");
uint256 messageLimit0 = 2;
uint256 messageLimit1 = 3;
uint256[8] mockProof =
[uint256(0), uint256(1), uint256(2), uint256(3), uint256(4), uint256(5), uint256(6), uint256(7)]; [uint256(0), uint256(1), uint256(2), uint256(3), uint256(4), uint256(5), uint256(6), uint256(7)];
function deployRLN(uint256 _depth) public returns (KarmaRLN) { // Roleholders
// Deploy KarmaRLN contract address private adminAddr;
bytes memory initializeData = abi.encodeCall(KarmaRLN.initialize, (adminAddr, registerAddr, slasherAddr, _depth, address(verifier), address(token))); address private registerAddr;
address private slasherAddr;
function setUp() public {
// Assign deterministic addresses
adminAddr = makeAddr("admin");
registerAddr = makeAddr("register");
slasherAddr = makeAddr("slasher");
// Deploy mock verifier
verifier = new MockVerifier();
// Deploy KarmaRLN via UUPS proxy with DEPTH = 2
rln = _deployRLN(DEPTH, address(verifier));
// Sanitycheck that roles were assigned correctly
assertTrue(rln.hasRole(rln.DEFAULT_ADMIN_ROLE(), adminAddr));
assertTrue(rln.hasRole(rln.REGISTER_ROLE(), registerAddr));
assertTrue(rln.hasRole(rln.SLASHER_ROLE(), slasherAddr));
}
/// @dev Deploys a new KarmaRLN instance (behind ERC1967Proxy).
function _deployRLN(uint256 depth, address verifierAddr) internal returns (KarmaRLN) {
bytes memory initData = abi.encodeCall(
KarmaRLN.initialize,
(
adminAddr,
slasherAddr,
registerAddr,
depth,
verifierAddr,
address(0) // token address unused in these tests
)
);
address impl = address(new KarmaRLN()); address impl = address(new KarmaRLN());
// Create upgradeable proxy address proxy = address(new ERC1967Proxy(impl, initData));
address proxy = address(new ERC1967Proxy(impl, initializeData));
return KarmaRLN(proxy); return KarmaRLN(proxy);
} }
function deployKarmaToken() public returns (Karma) { /* ---------- INITIAL STATE ---------- */
// Deploy Karma logic contract
bytes memory initializeData = abi.encodeCall(Karma.initialize, (adminAddr));
address impl = address(new Karma());
// Create upgradeable proxy
address proxy = address(new ERC1967Proxy(impl, initializeData));
return (Karma(proxy));
}
function setUp() public {
verifier = new MockVerifier();
token = deployKarmaToken();
rln = deployRLN();
}
function test_initial_state() public { function test_initial_state() public {
assertEq(rln.SET_SIZE(), 1 << depth); // SET_SIZE should be 2^DEPTH = 4
assertEq(address(rln.karma()), address(token)); assertEq(rln.SET_SIZE(), uint256(1) << DEPTH);
assertEq(address(rln.verifier()), address(verifier));
// No identities registered yet
assertEq(rln.identityCommitmentIndex(), 0); assertEq(rln.identityCommitmentIndex(), 0);
// members(...) should return (address(0), 0) for any commitment
(address user0, uint256 idx0) = _memberData(identityCommitment0);
assertEq(user0, address(0));
assertEq(idx0, 0);
// Verifier address matches
assertEq(address(rln.verifier()), address(verifier));
} }
/* register */ /* ---------- REGISTER ---------- */
function test_register_succeeds() public { function test_register_succeeds() public {
// Test: register one user // Register first identity
register(user0, identityCommitment0, messageLimit0); uint256 indexBefore = rln.identityCommitmentIndex();
// Test: register second user vm.startPrank(registerAddr);
register(user1, identityCommitment1, messageLimit1); vm.expectEmit(true, false, false, true);
emit KarmaRLN.MemberRegistered(identityCommitment0, indexBefore);
rln.register(identityCommitment0);
vm.stopPrank();
assertEq(rln.identityCommitmentIndex(), indexBefore + 1);
(address u0, uint256 i0) = _memberData(identityCommitment0);
assertEq(u0, registerAddr);
assertEq(i0, indexBefore);
// Register second identity
indexBefore = rln.identityCommitmentIndex();
vm.startPrank(registerAddr);
vm.expectEmit(true, false, false, true);
emit KarmaRLN.MemberRegistered(identityCommitment1, indexBefore);
rln.register(identityCommitment1);
vm.stopPrank();
assertEq(rln.identityCommitmentIndex(), indexBefore + 1);
(address u1, uint256 i1) = _memberData(identityCommitment1);
assertEq(u1, registerAddr);
assertEq(i1, indexBefore);
} }
function test_register_fails_when_index_exceeds_set_size() public { function test_register_fails_when_index_exceeds_set_size() public {
// Set size is (1 << smallDepth) = 2, and thus there can // Deploy a small RLN with depth = 1 => SET_SIZE = 2
// only be 2 members, otherwise reverts. KarmaRLN smallRLN = _deployRLN(SMALL_DEPTH, address(verifier));
uint256 smallDepth = 1; address smallRegister = registerAddr;
KarmaRLN smallRLN = deployRLN(smallDepth);
// Register the first user // Fill up both slots
vm.startPrank(registerAddr); vm.startPrank(smallRegister);
smallRLN.register(identityCommitment0, minimalDeposit); smallRLN.register(identityCommitment0);
smallRLN.register(identityCommitment1, minimalDeposit); smallRLN.register(identityCommitment1);
vm.stopPrank(); vm.stopPrank();
// Now tree (set) is full. Try register the third. It should revert.
uint256 identityCommitment2 = 9999; // Now the set is full (2 members). Attempt a third registration.
// `register` should revert vm.startPrank(smallRegister);
vm.expectRevert("KarmaRLN, register: set is full"); vm.expectRevert(bytes("RLN, register: set is full"));
smallRLN.register(identityCommitment2, minimalDeposit); smallRLN.register(identityCommitment2);
vm.stopPrank(); vm.stopPrank();
} }
function test_register_fails_when_duplicate_identity_commitment() public {
function test_register_fails_when_duplicate_identity_commitments() public { // Register once
// Register first with user0 with identityCommitment0
register(user0, identityCommitment0);
// Register again with user1 with identityCommitment0
vm.startPrank(registerAddr); vm.startPrank(registerAddr);
// `register` should revert rln.register(identityCommitment0);
vm.expectRevert("KarmaRLN, register: idCommitment already registered"); vm.stopPrank();
rln.register(identityCommitment0, rlnInitialTokenBalance);
// Attempt to register the same commitment again
vm.startPrank(registerAddr);
vm.expectRevert(bytes("RLN, register: idCommitment already registered"));
rln.register(identityCommitment0);
vm.stopPrank(); vm.stopPrank();
} }
/* ---------- EXIT ---------- */
function test_exit_succeeds() public { function test_exit_succeeds() public {
// Register first // Register the identity
register(user0, identityCommitment0); vm.startPrank(registerAddr);
// Withdraw user0 rln.register(identityCommitment0);
// Make sure proof verification is skipped vm.stopPrank();
assertEq(verifier.result(), true);
rln.withdraw(identityCommitment0, mockProof);
rln.exit(identityCommitment0);
checkUserIsDeleted(identityCommitment0); // Ensure mock verifier returns true by default
assertTrue(verifier.result());
// Call exit with a valid proof
vm.startPrank(registerAddr);
vm.expectEmit(false, false, false, true);
emit KarmaRLN.MemberExited(0);
rln.exit(identityCommitment0, mockProof);
vm.stopPrank();
// After exit, the member record should be cleared
(address u0, uint256 i0) = _memberData(identityCommitment0);
assertEq(u0, address(0));
assertEq(i0, 0);
} }
/* slash */ function test_exit_fails_when_not_registered() public {
// Attempt exit without prior registration
vm.startPrank(registerAddr);
vm.expectRevert(bytes("RLN, withdraw: member doesn't exist"));
rln.exit(identityCommitment1, mockProof);
vm.stopPrank();
}
function test_exit_fails_when_invalid_proof() public {
// Register the identity
vm.startPrank(registerAddr);
rln.register(identityCommitment0);
vm.stopPrank();
// Make proof invalid
verifier.changeResult(false);
assertFalse(verifier.result());
// Attempt exit with invalid proof
vm.startPrank(registerAddr);
vm.expectRevert(bytes("RLN, withdraw: invalid proof"));
rln.exit(identityCommitment0, mockProof);
vm.stopPrank();
}
/* ---------- SLASH ---------- */
function test_slash_succeeds() public { function test_slash_succeeds() public {
// Test: register and get slashed // Register the identity first
register(user0, identityCommitment0, messageLimit0); vm.startPrank(registerAddr);
(,, uint256 index) = rln.members(identityCommitment0); rln.register(identityCommitment1);
vm.startPrank(slasherAddr);
vm.expectEmit(true, true, false, true);
emit MemberSlashed(index, slashedReceiver);
// Slash and check balances
rln.slash(identityCommitment0, mockProof);
// Check the record of user0 has been deleted
vm.stopPrank(); vm.stopPrank();
checkUserIsDeleted(identityCommitment0);
// Test: register, withdraw, ang get slashed before release // Retrieve the assigned index
register(user1, identityCommitment1, messageLimit1); (, uint256 index1) = _memberData(identityCommitment1);
// Slash with a valid proof
vm.startPrank(slasherAddr); vm.startPrank(slasherAddr);
rln.slash(identityCommitment1, slashedReceiver, mockProof); vm.expectEmit(false, true, false, true);
emit KarmaRLN.MemberSlashed(index1, slasherAddr);
rln.slash(identityCommitment1, mockProof);
vm.stopPrank(); vm.stopPrank();
// Check the record of user1 has been deleted
checkUserIsDeleted(identityCommitment1); // After slash, the member record should be cleared
(address u1, uint256 i1) = _memberData(identityCommitment1);
assertEq(u1, address(0));
assertEq(i1, 0);
} }
function test_slash_fails_when_not_registered() public { function test_slash_fails_when_not_registered() public {
// It fails if the user is not registered yet // Attempt to slash a nonexistent identity
vm.startPrank(slasherAddr); vm.startPrank(slasherAddr);
vm.expectRevert("KarmaRLN, slash: member doesn't exist"); vm.expectRevert(bytes("RLN, slash: member doesn't exist"));
rln.slash(identityCommitment0, slashedReceiver, mockProof); rln.slash(identityCommitment0, mockProof);
vm.stopPrank(); vm.stopPrank();
} }
function test_slash_fails_when_invalid_proof() public { function test_slash_fails_when_invalid_proof() public {
// It fails if the proof is invalid // Register the identity
// Register first vm.startPrank(registerAddr);
register(user0, identityCommitment0); rln.register(identityCommitment0);
// Make sure mock verifier always return false vm.stopPrank();
// And thus the proof is always considered invalid
// Make proof invalid
verifier.changeResult(false); verifier.changeResult(false);
assertEq(verifier.result(), false); assertFalse(verifier.result());
vm.expectRevert("KarmaRLN, slash: invalid proof");
// Slash fails because of the invalid proof // Attempt to slash with invalid proof
vm.startPrank(slasherAddr); vm.startPrank(slasherAddr);
vm.expectRevert(bytes("RLN, slash: invalid proof"));
rln.slash(identityCommitment0, mockProof); rln.slash(identityCommitment0, mockProof);
vm.stopPrank(); vm.stopPrank();
} }
/* Helpers */ /* ========== HELPERS ========== */
function getRegisterAmount(uint256 messageLimit) public view returns (uint256) {
return messageLimit * minimalDeposit; /// @dev Returns (userAddress, index) for a given identityCommitment.
function _memberData(uint256 commitment) internal view returns (address userAddress, uint256 index) {
(userAddress, index) = rln.members(commitment);
return (userAddress, index);
} }
function register(address user, uint256 identityCommitment, uint256 messageLimit) public {
// Mint to user first
uint256 identityCommitmentIndexBefore = rln.identityCommitmentIndex();
// User approves to rln and calls register
vm.startPrank(registerAddr);
// Ensure event is emitted
vm.expectEmit(true, true, false, true);
emit MemberRegistered(identityCommitment, identityCommitmentIndexBefore);
rln.register(identityCommitment);
vm.stopPrank();
// KarmaRLN state
assertEq(rln.identityCommitmentIndex(), identityCommitmentIndexBefore + 1);
// User state
(address userAddress, uint256 index) = rln.members(identityCommitment);
assertEq(userAddress, user);
assertEq(index, identityCommitmentIndexBefore);
}
function checkUserIsDeleted(uint256 identityCommitment) public {
(address userAddress, uint256 index) = rln.members(identityCommitment);
assertEq(userAddress, address(0));
assertEq(index, 0);
}
} }