Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [QS-S3] Minor gas optimizations and consistency #305

Merged
merged 2 commits into from
Nov 23, 2024
Merged

Conversation

adamegyed
Copy link
Contributor

Motivation

Addresses QS-S3.

Solution

  • Changing i++ to++i and similarly for j does not affect the gas usage when compiling with via-ir. This PR changes it anyways to be consistent across the codebase.
  • ExecutionInstallDelegate is now pulled in as a constructor parameter, to be able to reuse across implementations.
  • executeBatch is updated with unrolled cases for whether or not return data is needed.
  • Moving the declaration of bytes calldata currentAuthSegment does not change gas usage, so it is kept as-is.
  • ModularAccountBase.isValidSignature() is marked external for consitency, though this does not change gas usage.
  • SemiModularAccountBase._hashStructReplaySafeHash() is kept as-is to avoid other colliding function names.
  • The change to ModuleManagerInternals._installValidation() is done, though this also does not result in a gas difference.

@adamegyed adamegyed requested a review from a team November 22, 2024 23:51
Copy link

octane-security-app bot commented Nov 22, 2024

Summary by Octane

New Contracts

No new contracts were added in this PR.

Updated Contracts

  • ModularAccountBenchmarkBase.sol: The smart contract now supports an ExecutionInstallDelegate for enhanced modular account execution and bytecode deployment.
  • AccountBase.sol: Updated constructor parameter naming for clarity.
  • ModularAccount.sol: The smart contract now includes an ExecutionInstallDelegate for enhanced execution installation during initialization.
  • ModularAccountBase.sol: Key modifications include initializing with an ExecutionInstallDelegate and making isValidSignature an external function.
  • ModuleManagerInternals.sol: The smart contract modification refactors how ValidationStorage is accessed, streamlining the retrieval process for module entities.
  • SemiModularAccount7702.sol: The smart contract now includes an ExecutionInstallDelegate in the constructor for enhanced functionality and delegation.
  • SemiModularAccountBase.sol: Added ExecutionInstallDelegate for modular construction and initialization in the constructor.
  • SemiModularAccountBytecode.sol: The smart contract now includes "ExecutionInstallDelegate" integration and an updated constructor for enhanced modular functionality.
  • SemiModularAccountStorageOnly.sol: Added ExecutionInstallDelegate to constructor for enhanced execution management in SemiModularAccountStorageOnly.
  • ExecutionLib.sol: Modified loop iteration in post hook execution for optimization.
  • AllowlistModule.sol: The for-loop increment in functions changed from i++ to ++i for optimization.
  • NativeTokenLimitModule.sol: Increment iteration style changed in loops within batch execution logic.
  • AccountTestBase.sol: Incorporated ExecutionInstallDelegate for enhanced execution management in account deployment processes.
  • OptimizedTest.sol: Modifications include adding ExecutionInstallDelegate for deploying accounts, enhancing modular account creation, and adding deployment functions.

🔗 Commit Hash: 4cd254a

"Runtime_Erc20Transfer": "78454",
"Runtime_InstallSessionKey_Case1": "423148",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer note: I'm not sure why, but this changed after moving ExecutionInstallDelegate from being deployed in the constructor to being set as an immutable. Curiously, it does not affect the user op path for the install.

Copy link

github-actions bot commented Nov 22, 2024

Contract sizes:

 | Contract                      | Runtime Size (B) | Initcode Size (B) | Runtime Margin (B) | Initcode Margin (B) |
 |-------------------------------|------------------|-------------------|--------------------|---------------------|
 | AccountFactory                |            6,121 |             6,595 |             18,455 |              42,557 |
 | AllowlistModule               |            9,553 |             9,580 |             15,023 |              39,572 |
 | ExecutionInstallDelegate      |            5,947 |             5,993 |             18,629 |              43,159 |
-| ModularAccount                |           22,401 |            29,480 |              2,175 |              19,672 |
+| ModularAccount                |           22,481 |            23,537 |              2,095 |              25,615 |
 | NativeFunctionDelegate        |              560 |               587 |             24,016 |              48,565 |
 | NativeTokenLimitModule        |            4,498 |             4,525 |             20,078 |              44,627 |
 | PaymasterGuardModule          |            1,845 |             1,872 |             22,731 |              47,280 |
-| SemiModularAccount7702        |           23,315 |            30,387 |              1,261 |              18,765 |
-| SemiModularAccountBytecode    |           23,797 |            30,876 |                779 |              18,276 |
-| SemiModularAccountStorageOnly |           24,279 |            31,358 |                297 |              17,794 |
+| SemiModularAccount7702        |           23,395 |            24,444 |              1,181 |              24,708 |
+| SemiModularAccountBytecode    |           23,877 |            24,933 |                699 |              24,219 |
+| SemiModularAccountStorageOnly |           24,359 |            25,415 |                217 |              23,737 |
 | SingleSignerValidationModule  |            3,646 |             3,673 |             20,930 |              45,479 |
 | TimeRangeModule               |            2,085 |             2,112 |             22,491 |              47,040 |
 | WebAuthnValidationModule      |            7,854 |             7,881 |             16,722 |              41,271 |

Code coverage:

File % Lines % Statements % Branches % Funcs
src/account/AccountBase.sol 100.00% (8/8) 100.00% (7/7) 100.00% (2/2) 100.00% (4/4)
src/account/AccountStorageInitializable.sol 100.00% (19/19) 100.00% (26/26) 100.00% (5/5) 100.00% (2/2)
src/account/ModularAccount.sol 100.00% (2/2) 100.00% (2/2) 100.00% (0/0) 100.00% (2/2)
src/account/ModularAccountBase.sol 99.02% (302/305) 96.34% (368/382) 78.33% (47/60) 97.30% (36/37)
src/account/ModularAccountView.sol 95.00% (38/40) 96.30% (52/54) 80.00% (4/5) 100.00% (5/5)
src/account/ModuleManagerInternals.sol 95.08% (58/61) 96.20% (76/79) 62.50% (5/8) 100.00% (3/3)
src/account/SemiModularAccount7702.sol 0.00% (0/6) 0.00% (0/6) 0.00% (0/1) 0.00% (0/3)
src/account/SemiModularAccountBase.sol 89.06% (57/64) 92.31% (84/91) 68.75% (11/16) 100.00% (15/15)
src/account/SemiModularAccountBytecode.sol 100.00% (6/6) 100.00% (7/7) 100.00% (1/1) 100.00% (2/2)
src/account/SemiModularAccountStorageOnly.sol 80.00% (4/5) 83.33% (5/6) 100.00% (0/0) 50.00% (1/2)
src/account/TokenReceiver.sol 33.33% (1/3) 33.33% (1/3) 100.00% (0/0) 33.33% (1/3)
src/factory/AccountFactory.sol 84.78% (39/46) 87.10% (54/62) 50.00% (3/6) 62.50% (10/16)
src/helpers/ExecutionInstallDelegate.sol 88.14% (52/59) 89.47% (68/76) 25.00% (2/8) 100.00% (7/7)
src/helpers/NativeFunctionDelegate.sol 100.00% (22/22) 100.00% (42/42) 100.00% (0/0) 100.00% (1/1)
src/libraries/ExecutionLib.sol 99.64% (276/277) 98.89% (268/271) 90.91% (30/33) 100.00% (24/24)
src/libraries/KnownSelectorsLib.sol 100.00% (16/16) 100.00% (34/34) 100.00% (0/0) 100.00% (2/2)
src/libraries/LinkedListSetLib.sol 94.00% (47/50) 96.25% (77/80) 66.67% (4/6) 100.00% (8/8)
src/libraries/MemManagementLib.sol 100.00% (54/54) 100.00% (70/70) 100.00% (0/0) 100.00% (12/12)
src/libraries/ModuleInstallCommonsLib.sol 57.14% (8/14) 42.11% (8/19) 75.00% (3/4) 100.00% (3/3)
src/modules/ModuleBase.sol 100.00% (13/13) 94.12% (16/17) 100.00% (2/2) 100.00% (3/3)
src/modules/permissions/AllowlistModule.sol 86.05% (74/86) 85.71% (96/112) 78.26% (18/23) 50.00% (9/18)
src/modules/permissions/NativeTokenLimitModule.sol 90.91% (40/44) 91.80% (56/61) 100.00% (13/13) 66.67% (8/12)
src/modules/permissions/PaymasterGuardModule.sol 83.33% (10/12) 82.35% (14/17) 66.67% (2/3) 71.43% (5/7)
src/modules/permissions/TimeRangeModule.sol 88.89% (16/18) 85.19% (23/27) 100.00% (5/5) 87.50% (7/8)
src/modules/validation/SingleSignerValidationModule.sol 92.00% (23/25) 81.58% (31/38) 62.50% (5/8) 90.00% (9/10)
src/modules/validation/WebAuthnValidationModule.sol 61.11% (11/18) 66.67% (18/27) 100.00% (3/3) 60.00% (6/10)
Total 93.95% (1196/1273) 93.01% (1503/1616) 77.83% (165/212) 84.47% (185/219)

Copy link

octane-security-app bot commented Nov 22, 2024

Overview

Vulnerabilities found: 6                                                                                

Detailed findings

src/account/ModularAccount.sol

src/account/ModularAccountBase.sol

src/modules/permissions/AllowlistModule.sol


🔗 Commit Hash: 4cd254a
🛡️ Octane Dashboard: All vulnerabilities

Copy link
Collaborator

jaypaik commented Nov 23, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

@jaypaik jaypaik merged commit e7ea249 into develop Nov 23, 2024
7 checks passed
@jaypaik jaypaik deleted the adam/fix-qs-s3 branch November 23, 2024 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants