From 4998901100d8a9e749d2e4a03cda910177286eaa Mon Sep 17 00:00:00 2001 From: Jay Paik Date: Thu, 10 Oct 2024 11:40:50 -0400 Subject: [PATCH] refactor: use reference-implementation's libraries (#228) --- gas/modular-account/ModularAccount.gas.t.sol | 4 +- .../ModularAccountBenchmarkBase.sol | 11 +- .../SemiModularAccount.gas.t.sol | 3 +- package.json | 3 +- pnpm-lock.yaml | 21 +-- remappings.txt | 3 +- src/account/ModularAccountBase.sol | 29 ++-- src/account/ModuleManagerInternals.sol | 9 +- src/account/SemiModularAccountBase.sol | 8 +- src/factory/AccountFactory.sol | 6 +- src/helpers/Constants.sol | 2 +- src/libraries/HookConfigLib.sol | 135 ------------------ src/libraries/MemManagementLib.sol | 4 +- src/libraries/ModuleEntityLib.sol | 35 ----- src/libraries/ValidationConfigLib.sol | 126 ---------------- src/modules/ModuleEIP712.sol | 29 ---- src/modules/ReplaySafeWrapper.sol | 38 ----- .../validation/ECDSAValidationModule.sol | 2 +- .../validation/WebauthnValidationModule.sol | 2 +- test/account/AccountReturnData.t.sol | 2 +- test/account/DeferredValidation.t.sol | 5 +- test/account/DirectCallsFromModule.t.sol | 13 +- test/account/GlobalValidationTest.t.sol | 2 +- test/account/HookOrdering.t.sol | 10 +- test/account/ModularAccount.t.sol | 12 +- test/account/ModularAccountView.t.sol | 14 +- test/account/MultiValidation.t.sol | 8 +- test/account/PerHookData.t.sol | 8 +- test/account/ReplaceModule.t.sol | 7 +- test/account/SelfCallAuthorization.t.sol | 9 +- .../SemiModularAccountDirectCall.t.sol | 9 +- test/account/UpgradeToSma.t.sol | 4 +- test/account/ValidationIntersection.t.sol | 8 +- test/libraries/HookConfigLib.t.sol | 67 --------- test/libraries/ModuleEntityLib.t.sol | 39 ----- test/libraries/ValidationConfigLib.t.sol | 112 --------------- test/mocks/modules/ReturnDataModuleMocks.sol | 6 +- test/modules/AllowlistModule.t.sol | 8 +- test/modules/ERC20TokenLimitModule.t.sol | 15 +- test/modules/NativeTokenLimitModule.t.sol | 17 +-- test/modules/TimeRangeModule.t.sol | 12 +- test/modules/WebauthnValidationModule.t.sol | 4 +- test/utils/AccountTestBase.sol | 8 +- test/utils/CustomValidationTestBase.sol | 6 +- test/utils/ModuleSignatureUtils.sol | 6 +- test/utils/StorageAccesses.sol | 3 +- 46 files changed, 154 insertions(+), 730 deletions(-) delete mode 100644 src/libraries/HookConfigLib.sol delete mode 100644 src/libraries/ModuleEntityLib.sol delete mode 100644 src/libraries/ValidationConfigLib.sol delete mode 100644 src/modules/ModuleEIP712.sol delete mode 100644 src/modules/ReplaySafeWrapper.sol delete mode 100644 test/libraries/HookConfigLib.t.sol delete mode 100644 test/libraries/ModuleEntityLib.t.sol delete mode 100644 test/libraries/ValidationConfigLib.t.sol diff --git a/gas/modular-account/ModularAccount.gas.t.sol b/gas/modular-account/ModularAccount.gas.t.sol index bf92fffa..725e13c5 100644 --- a/gas/modular-account/ModularAccount.gas.t.sol +++ b/gas/modular-account/ModularAccount.gas.t.sol @@ -1,13 +1,15 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; + import {Vm} from "forge-std/src/Vm.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {AccountFactory} from "../../src/factory/AccountFactory.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {ModularAccountBenchmarkBase} from "./ModularAccountBenchmarkBase.sol"; diff --git a/gas/modular-account/ModularAccountBenchmarkBase.sol b/gas/modular-account/ModularAccountBenchmarkBase.sol index 95c629cd..8ce83620 100644 --- a/gas/modular-account/ModularAccountBenchmarkBase.sol +++ b/gas/modular-account/ModularAccountBenchmarkBase.sol @@ -1,7 +1,15 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import { + HookConfig, + ModuleEntity, + ValidationConfig +} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {ValidationDataView} from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; @@ -10,9 +18,6 @@ import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {SemiModularAccountBytecode} from "../../src/account/SemiModularAccountBytecode.sol"; import {AccountFactory} from "../../src/factory/AccountFactory.sol"; import {FALLBACK_VALIDATION} from "../../src/helpers/Constants.sol"; -import {HookConfig, HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {AllowlistModule} from "../../src/modules/permissions/AllowlistModule.sol"; import {ERC20TokenLimitModule} from "../../src/modules/permissions/ERC20TokenLimitModule.sol"; import {TimeRangeModule} from "../../src/modules/permissions/TimeRangeModule.sol"; diff --git a/gas/modular-account/SemiModularAccount.gas.t.sol b/gas/modular-account/SemiModularAccount.gas.t.sol index 943d50f8..3f7b4fa9 100644 --- a/gas/modular-account/SemiModularAccount.gas.t.sol +++ b/gas/modular-account/SemiModularAccount.gas.t.sol @@ -1,13 +1,14 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {Vm} from "forge-std/src/Vm.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {AccountFactory} from "../../src/factory/AccountFactory.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {ModularAccountBenchmarkBase} from "./ModularAccountBenchmarkBase.sol"; diff --git a/package.json b/package.json index f555af0b..f9a28c5e 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,7 @@ "version": "v1.0.1", "dependencies": { "account-abstraction": "github:eth-infinitism/account-abstraction#v0.7.0", - "@erc6900/modular-account-libs": "github:erc6900/modular-account-libs#v0.8.0-rc.1", - "@erc6900/reference-implementation": "github:erc6900/reference-implementation#v0.8.0-rc.3", + "@erc6900/reference-implementation": "github:erc6900/reference-implementation#v0.8.0-rc.4", "solady": "github:Vectorized/solady#v0.0.237" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9e0c3ae6..224f56b6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,9 @@ importers: .: dependencies: - '@erc6900/modular-account-libs': - specifier: github:erc6900/modular-account-libs#v0.8.0-rc.1 - version: https://codeload.github.com/erc6900/modular-account-libs/tar.gz/b63b1a872acdc92972a66f43dd17187f4ceafc97 '@erc6900/reference-implementation': - specifier: github:erc6900/reference-implementation#v0.8.0-rc.3 - version: https://codeload.github.com/erc6900/reference-implementation/tar.gz/188bc4d8319714913738cda547facd0ccb732ead + specifier: github:erc6900/reference-implementation#v0.8.0-rc.4 + version: https://codeload.github.com/erc6900/reference-implementation/tar.gz/690bdf49ddd5b234c518445477972eedec1f9bb6 account-abstraction: specifier: github:eth-infinitism/account-abstraction#v0.7.0 version: accountabstraction@https://codeload.github.com/eth-infinitism/account-abstraction/tar.gz/d99245ddb2d7bde4d2132757c4394818f1d11da0(ethers@5.7.2)(hardhat@2.22.10(typescript@4.9.5))(lodash@4.17.21)(typechain@5.2.0(typescript@4.9.5)) @@ -42,13 +39,9 @@ packages: resolution: {integrity: sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==} engines: {node: '>=6.9.0'} - '@erc6900/modular-account-libs@https://codeload.github.com/erc6900/modular-account-libs/tar.gz/b63b1a872acdc92972a66f43dd17187f4ceafc97': - resolution: {tarball: https://codeload.github.com/erc6900/modular-account-libs/tar.gz/b63b1a872acdc92972a66f43dd17187f4ceafc97} - version: 0.8.0-rc.1 - - '@erc6900/reference-implementation@https://codeload.github.com/erc6900/reference-implementation/tar.gz/188bc4d8319714913738cda547facd0ccb732ead': - resolution: {tarball: https://codeload.github.com/erc6900/reference-implementation/tar.gz/188bc4d8319714913738cda547facd0ccb732ead} - version: 0.8.0-rc.3 + '@erc6900/reference-implementation@https://codeload.github.com/erc6900/reference-implementation/tar.gz/690bdf49ddd5b234c518445477972eedec1f9bb6': + resolution: {tarball: https://codeload.github.com/erc6900/reference-implementation/tar.gz/690bdf49ddd5b234c518445477972eedec1f9bb6} + version: 0.8.0-rc.4 '@ethereumjs/rlp@4.0.1': resolution: {integrity: sha512-tqsQiBQDQdmPWE1xkkBq4rlSW5QZpLOUJ5RJh2/9fug+q9tnUhuZoVLk7s0scUIKTOzEtR72DFBXI4WiZcMpvw==} @@ -1813,9 +1806,7 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.1.0 - '@erc6900/modular-account-libs@https://codeload.github.com/erc6900/modular-account-libs/tar.gz/b63b1a872acdc92972a66f43dd17187f4ceafc97': {} - - '@erc6900/reference-implementation@https://codeload.github.com/erc6900/reference-implementation/tar.gz/188bc4d8319714913738cda547facd0ccb732ead': {} + '@erc6900/reference-implementation@https://codeload.github.com/erc6900/reference-implementation/tar.gz/690bdf49ddd5b234c518445477972eedec1f9bb6': {} '@ethereumjs/rlp@4.0.1': {} diff --git a/remappings.txt b/remappings.txt index a39d85fa..6dd0d1c2 100644 --- a/remappings.txt +++ b/remappings.txt @@ -1,5 +1,4 @@ ds-test/=lib/forge-std/lib/ds-test/src/ -@erc6900/modular-account-libs/=node_modules/@erc6900/modular-account-libs/src/ @eth-infinitism/account-abstraction/=node_modules/account-abstraction/contracts/ account-abstraction/=node_modules/account-abstraction/contracts/ @openzeppelin/=lib/openzeppelin-contracts/ @@ -10,4 +9,4 @@ forge-gas-snapshot/=lib/forge-gas-snapshot/src/ forge-std/=lib/forge-std/ webauthn-sol/=lib/webauthn-sol/ FreshCryptoLib/=lib/webauthn-sol/lib/FreshCryptoLib/solidity/src/ -openzeppelin-contracts/=lib/webauthn-sol/lib/openzeppelin-contracts/ \ No newline at end of file +openzeppelin-contracts/=lib/webauthn-sol/lib/openzeppelin-contracts/ diff --git a/src/account/ModularAccountBase.sol b/src/account/ModularAccountBase.sol index e0c4cfa6..803ec1d0 100644 --- a/src/account/ModularAccountBase.sol +++ b/src/account/ModularAccountBase.sol @@ -1,39 +1,36 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {IAccountExecute} from "@eth-infinitism/account-abstraction/interfaces/IAccountExecute.sol"; -import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; -import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; - -import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol"; -import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol"; -import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; -import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; -import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; - -import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol"; - import {IExecutionHookModule} from "@erc6900/reference-implementation/interfaces/IExecutionHookModule.sol"; import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; import { Call, + HookConfig, IModularAccount, ModuleEntity, ValidationConfig } from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {IValidationHookModule} from "@erc6900/reference-implementation/interfaces/IValidationHookModule.sol"; import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IValidationModule.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; +import {IAccountExecute} from "@eth-infinitism/account-abstraction/interfaces/IAccountExecute.sol"; +import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; +import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; +import {IERC1155Receiver} from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol"; +import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol"; +import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; +import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; +import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; +import {UUPSUpgradeable} from "solady/utils/UUPSUpgradeable.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../helpers/Constants.sol"; import {_coalescePreValidation, _coalesceValidation} from "../helpers/ValidationResHelpers.sol"; - import {ExecutionLib} from "../libraries/ExecutionLib.sol"; -import {HookConfig, HookConfigLib} from "../libraries/HookConfigLib.sol"; import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol"; import {MemManagementLib} from "../libraries/MemManagementLib.sol"; -import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol"; import {SparseCalldataSegmentLib} from "../libraries/SparseCalldataSegmentLib.sol"; -import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol"; import {AccountStorage, getAccountStorage, toSetValue} from "./AccountStorage.sol"; import {AccountStorageInitializable} from "./AccountStorageInitializable.sol"; import {BaseAccount} from "./BaseAccount.sol"; diff --git a/src/account/ModuleManagerInternals.sol b/src/account/ModuleManagerInternals.sol index 46ebbc61..61e9d48c 100644 --- a/src/account/ModuleManagerInternals.sol +++ b/src/account/ModuleManagerInternals.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; - import {IExecutionHookModule} from "@erc6900/reference-implementation/interfaces/IExecutionHookModule.sol"; import { ExecutionManifest, @@ -17,15 +15,16 @@ import { import {IModule} from "@erc6900/reference-implementation/interfaces/IModule.sol"; import {IValidationHookModule} from "@erc6900/reference-implementation/interfaces/IValidationHookModule.sol"; import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IValidationModule.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; +import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import {MAX_PRE_VALIDATION_HOOKS} from "../helpers/Constants.sol"; import {ExecutionLib} from "../libraries/ExecutionLib.sol"; -import {HookConfigLib} from "../libraries/HookConfigLib.sol"; import {KnownSelectorsLib} from "../libraries/KnownSelectorsLib.sol"; import {LinkedListSet, LinkedListSetLib} from "../libraries/LinkedListSetLib.sol"; import {MemManagementLib} from "../libraries/MemManagementLib.sol"; -import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol"; import {AccountStorage, ExecutionData, ValidationData, getAccountStorage, toSetValue} from "./AccountStorage.sol"; abstract contract ModuleManagerInternals is IModularAccount { diff --git a/src/account/SemiModularAccountBase.sol b/src/account/SemiModularAccountBase.sol index 17431b15..b17611f5 100644 --- a/src/account/SemiModularAccountBase.sol +++ b/src/account/SemiModularAccountBase.sol @@ -1,20 +1,16 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {IModularAccount, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; - -import {IModularAccount, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID, FALLBACK_VALIDATION} from "../helpers/Constants.sol"; - import {SignatureType} from "../helpers/SignatureType.sol"; -import {ModuleEntityLib} from "../libraries/ModuleEntityLib.sol"; - import {SemiModularKnownSelectorsLib} from "../libraries/SemiModularKnownSelectorsLib.sol"; import {ModularAccountBase} from "./ModularAccountBase.sol"; diff --git a/src/factory/AccountFactory.sol b/src/factory/AccountFactory.sol index a24050ce..ebac2804 100644 --- a/src/factory/AccountFactory.sol +++ b/src/factory/AccountFactory.sol @@ -1,17 +1,15 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; - import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {LibClone} from "solady/utils/LibClone.sol"; import {ModularAccount} from "../account/ModularAccount.sol"; import {SemiModularAccountBytecode} from "../account/SemiModularAccountBytecode.sol"; -import {ValidationConfigLib} from "../libraries/ValidationConfigLib.sol"; - -import {LibClone} from "solady/utils/LibClone.sol"; contract AccountFactory is Ownable { ModularAccount public immutable ACCOUNT_IMPL; diff --git a/src/helpers/Constants.sol b/src/helpers/Constants.sol index 6b3f6f5f..90cbd499 100644 --- a/src/helpers/Constants.sol +++ b/src/helpers/Constants.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {ModuleEntity} from "../libraries/ModuleEntityLib.sol"; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; // Index marking the start of the data for the validation function. uint8 constant RESERVED_VALIDATION_DATA_INDEX = type(uint8).max; diff --git a/src/libraries/HookConfigLib.sol b/src/libraries/HookConfigLib.sol deleted file mode 100644 index 4f6593b1..00000000 --- a/src/libraries/HookConfigLib.sol +++ /dev/null @@ -1,135 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -import {HookConfig, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - -// Hook types: -// Exec hook: bools for hasPre, hasPost -// Validation hook: no bools - -// Hook fields: -// module address -// entity ID -// hook type -// if exec hook: hasPre, hasPost - -// Hook config is a packed representation of a hook function and flags for its configuration. -// Layout: -// 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________________ // Address -// 0x________________________________________BBBBBBBB________________ // Entity ID -// 0x________________________________________________CC______________ // Hook Flags - -// Hook flags layout: -// 0b00000___ // unused -// 0b_____A__ // hasPre (exec only) -// 0b______B_ // hasPost (exec only) -// 0b_______C // hook type (0 for exec, 1 for validation) - -library HookConfigLib { - // Hook type constants - // Exec has no bits set - bytes32 internal constant _HOOK_TYPE_EXEC = bytes32(uint256(0)); - // Validation has 1 in the 25th byte - bytes32 internal constant _HOOK_TYPE_VALIDATION = bytes32(uint256(1) << 56); - - // Exec hook flags constants - // Pre hook has 1 in 4's bit in the 25th byte - bytes32 internal constant _EXEC_HOOK_HAS_PRE = bytes32(uint256(1) << 58); - // Post hook has 1 in 2's bit in the 25th byte - bytes32 internal constant _EXEC_HOOK_HAS_POST = bytes32(uint256(1) << 57); - - function packValidationHook(ModuleEntity _hookFunction) internal pure returns (HookConfig) { - return - HookConfig.wrap(bytes25(bytes25(ModuleEntity.unwrap(_hookFunction)) | bytes25(_HOOK_TYPE_VALIDATION))); - } - - function packValidationHook(address _module, uint32 _entityId) internal pure returns (HookConfig) { - return HookConfig.wrap( - bytes25( - // module address stored in the first 20 bytes - bytes25(bytes20(_module)) - // entityId stored in the 21st - 24th byte - | bytes25(bytes24(uint192(_entityId))) | bytes25(_HOOK_TYPE_VALIDATION) - ) - ); - } - - function packExecHook(ModuleEntity _hookFunction, bool _hasPre, bool _hasPost) - internal - pure - returns (HookConfig) - { - return HookConfig.wrap( - bytes25( - bytes25(ModuleEntity.unwrap(_hookFunction)) - // | bytes25(_HOOK_TYPE_EXEC) // Can omit because exec type is 0 - | bytes25(_hasPre ? _EXEC_HOOK_HAS_PRE : bytes32(0)) - | bytes25(_hasPost ? _EXEC_HOOK_HAS_POST : bytes32(0)) - ) - ); - } - - function packExecHook(address _module, uint32 _entityId, bool _hasPre, bool _hasPost) - internal - pure - returns (HookConfig) - { - return HookConfig.wrap( - bytes25( - // module address stored in the first 20 bytes - bytes25(bytes20(_module)) - // entityId stored in the 21st - 24th byte - | bytes25(bytes24(uint192(_entityId))) - // | bytes25(_HOOK_TYPE_EXEC) // Can omit because exec type is 0 - | bytes25(_hasPre ? _EXEC_HOOK_HAS_PRE : bytes32(0)) - | bytes25(_hasPost ? _EXEC_HOOK_HAS_POST : bytes32(0)) - ) - ); - } - - function unpackValidationHook(HookConfig _config) internal pure returns (ModuleEntity _hookFunction) { - bytes25 configBytes = HookConfig.unwrap(_config); - _hookFunction = ModuleEntity.wrap(bytes24(configBytes)); - } - - function unpackExecHook(HookConfig _config) - internal - pure - returns (ModuleEntity _hookFunction, bool _hasPre, bool _hasPost) - { - bytes25 configBytes = HookConfig.unwrap(_config); - _hookFunction = ModuleEntity.wrap(bytes24(configBytes)); - _hasPre = configBytes & _EXEC_HOOK_HAS_PRE != 0; - _hasPost = configBytes & _EXEC_HOOK_HAS_POST != 0; - } - - function module(HookConfig _config) internal pure returns (address) { - return address(bytes20(HookConfig.unwrap(_config))); - } - - function entityId(HookConfig _config) internal pure returns (uint32) { - return uint32(bytes4(HookConfig.unwrap(_config) << 160)); - } - - function moduleEntity(HookConfig _config) internal pure returns (ModuleEntity) { - return ModuleEntity.wrap(bytes24(HookConfig.unwrap(_config))); - } - - // Check if the hook is a validation hook - // If false, it is an exec hook - function isValidationHook(HookConfig _config) internal pure returns (bool) { - return HookConfig.unwrap(_config) & _HOOK_TYPE_VALIDATION != 0; - } - - // Check if the exec hook has a pre hook - // Undefined behavior if the hook is not an exec hook - function hasPreHook(HookConfig _config) internal pure returns (bool) { - return HookConfig.unwrap(_config) & _EXEC_HOOK_HAS_PRE != 0; - } - - // Check if the exec hook has a post hook - // Undefined behavior if the hook is not an exec hook - function hasPostHook(HookConfig _config) internal pure returns (bool) { - return HookConfig.unwrap(_config) & _EXEC_HOOK_HAS_POST != 0; - } -} diff --git a/src/libraries/MemManagementLib.sol b/src/libraries/MemManagementLib.sol index 3adcb8db..4ca367ec 100644 --- a/src/libraries/MemManagementLib.sol +++ b/src/libraries/MemManagementLib.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {HookConfig} from "./HookConfigLib.sol"; -import {LinkedListSet, LinkedListSetLib, SENTINEL_VALUE, SetValue} from "./LinkedListSetLib.sol"; +import {HookConfig} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {ExecutionData, ValidationData} from "../account/AccountStorage.sol"; +import {LinkedListSet, LinkedListSetLib, SENTINEL_VALUE, SetValue} from "./LinkedListSetLib.sol"; library MemManagementLib { function loadExecHooks(ExecutionData storage execData, ValidationData storage valData) diff --git a/src/libraries/ModuleEntityLib.sol b/src/libraries/ModuleEntityLib.sol deleted file mode 100644 index f7544109..00000000 --- a/src/libraries/ModuleEntityLib.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - -library ModuleEntityLib { - // Magic value for hooks that should always revert. - ModuleEntity internal constant _PRE_HOOK_ALWAYS_DENY = ModuleEntity.wrap(bytes24(uint192(2))); - - function pack(address addr, uint32 entityId) internal pure returns (ModuleEntity) { - return ModuleEntity.wrap(bytes24(bytes20(addr)) | bytes24(uint192(entityId))); - } - - function unpack(ModuleEntity fr) internal pure returns (address addr, uint32 entityId) { - bytes24 underlying = ModuleEntity.unwrap(fr); - addr = address(bytes20(underlying)); - entityId = uint32(bytes4(underlying << 160)); - } - - function isEmpty(ModuleEntity fr) internal pure returns (bool) { - return ModuleEntity.unwrap(fr) == bytes24(0); - } - - function notEmpty(ModuleEntity fr) internal pure returns (bool) { - return ModuleEntity.unwrap(fr) != bytes24(0); - } - - function eq(ModuleEntity a, ModuleEntity b) internal pure returns (bool) { - return ModuleEntity.unwrap(a) == ModuleEntity.unwrap(b); - } - - function notEq(ModuleEntity a, ModuleEntity b) internal pure returns (bool) { - return ModuleEntity.unwrap(a) != ModuleEntity.unwrap(b); - } -} diff --git a/src/libraries/ValidationConfigLib.sol b/src/libraries/ValidationConfigLib.sol deleted file mode 100644 index 99d77087..00000000 --- a/src/libraries/ValidationConfigLib.sol +++ /dev/null @@ -1,126 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -import {ModuleEntity, ValidationConfig} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - -// Validation flags layout: -// 0b00000___ // unused -// 0b_____A__ // isGlobal -// 0b______B_ // isSignatureValidation -// 0b_______C // isUserOpValidation -type ValidationFlags is uint8; - -// Validation config is a packed representation of a validation function and flags for its configuration. -// Layout: -// 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________________ // Address -// 0x________________________________________BBBBBBBB________________ // Entity ID -// 0x________________________________________________CC______________ // validation flags -// 0x__________________________________________________00000000000000 // unused - -// Validation flags layout: -// 0b00000___ // unused -// 0b_____A__ // isGlobal -// 0b______B_ // isSignatureValidation -// 0b_______C // isUserOpValidation - -library ValidationConfigLib { - // is user op validation flag stored in last bit of the 25th byte - bytes32 internal constant _VALIDATION_FLAG_IS_USER_OP = bytes32(uint256(1) << 56); - // is signature validation flag stored in second to last bit of the 25th byte - bytes32 internal constant _VALIDATION_FLAG_IS_SIGNATURE = bytes32(uint256(1) << 57); - // is global flag stored in the third to last bit of the 25th byte - bytes32 internal constant _VALIDATION_FLAG_IS_GLOBAL = bytes32(uint256(1) << 58); - - function pack( - ModuleEntity _validationFunction, - bool _isGlobal, - bool _isSignatureValidation, - bool _isUserOpValidation - ) internal pure returns (ValidationConfig) { - return ValidationConfig.wrap( - bytes25( - bytes25(ModuleEntity.unwrap(_validationFunction)) - | bytes25(bytes32(_isGlobal ? _VALIDATION_FLAG_IS_GLOBAL : bytes32(0))) - | bytes25(bytes32(_isSignatureValidation ? _VALIDATION_FLAG_IS_SIGNATURE : bytes32(0))) - | bytes25(bytes32(_isUserOpValidation ? _VALIDATION_FLAG_IS_USER_OP : bytes32(0))) - ) - ); - } - - function pack( - address _module, - uint32 _entityId, - bool _isGlobal, - bool _isSignatureValidation, - bool _isUserOpValidation - ) internal pure returns (ValidationConfig) { - return ValidationConfig.wrap( - bytes25( - // module address stored in the first 20 bytes - bytes25(bytes20(_module)) - // entityId stored in the 21st - 24th byte - | bytes25(bytes24(uint192(_entityId))) - | bytes25(bytes32(_isGlobal ? _VALIDATION_FLAG_IS_GLOBAL : bytes32(0))) - | bytes25(bytes32(_isSignatureValidation ? _VALIDATION_FLAG_IS_SIGNATURE : bytes32(0))) - | bytes25(bytes32(_isUserOpValidation ? _VALIDATION_FLAG_IS_USER_OP : bytes32(0))) - ) - ); - } - - function unpackUnderlying(ValidationConfig config) - internal - pure - returns (address _module, uint32 _entityId, ValidationFlags flags) - { - bytes25 configBytes = ValidationConfig.unwrap(config); - _module = address(bytes20(configBytes)); - _entityId = uint32(bytes4(configBytes << 160)); - flags = ValidationFlags.wrap(uint8(configBytes[24])); - } - - function unpack(ValidationConfig config) - internal - pure - returns (ModuleEntity _validationFunction, ValidationFlags flags) - { - bytes25 configBytes = ValidationConfig.unwrap(config); - _validationFunction = ModuleEntity.wrap(bytes24(configBytes)); - flags = ValidationFlags.wrap(uint8(configBytes[24])); - } - - function module(ValidationConfig config) internal pure returns (address) { - return address(bytes20(ValidationConfig.unwrap(config))); - } - - function entityId(ValidationConfig config) internal pure returns (uint32) { - return uint32(bytes4(ValidationConfig.unwrap(config) << 160)); - } - - function moduleEntity(ValidationConfig config) internal pure returns (ModuleEntity) { - return ModuleEntity.wrap(bytes24(ValidationConfig.unwrap(config))); - } - - function isGlobal(ValidationConfig config) internal pure returns (bool) { - return ValidationConfig.unwrap(config) & _VALIDATION_FLAG_IS_GLOBAL != 0; - } - - function isGlobal(ValidationFlags flags) internal pure returns (bool) { - return ValidationFlags.unwrap(flags) & 0x04 != 0; - } - - function isSignatureValidation(ValidationConfig config) internal pure returns (bool) { - return ValidationConfig.unwrap(config) & _VALIDATION_FLAG_IS_SIGNATURE != 0; - } - - function isSignatureValidation(ValidationFlags flags) internal pure returns (bool) { - return ValidationFlags.unwrap(flags) & 0x02 != 0; - } - - function isUserOpValidation(ValidationConfig config) internal pure returns (bool) { - return ValidationConfig.unwrap(config) & _VALIDATION_FLAG_IS_USER_OP != 0; - } - - function isUserOpValidation(ValidationFlags flags) internal pure returns (bool) { - return ValidationFlags.unwrap(flags) & 0x01 != 0; - } -} diff --git a/src/modules/ModuleEIP712.sol b/src/modules/ModuleEIP712.sol deleted file mode 100644 index ebc8e3c8..00000000 --- a/src/modules/ModuleEIP712.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -// A base for modules that use EIP-712 structured data signing. -// -// Unlike other EIP712 libraries, this mixin uses the salt field to hold the account address. -// -// It omits the name and version from the EIP-712 domain, as modules are intended to be deployed as -// immutable singletons, thus a different versions and instances would have a different module address. -// -// Due to depending on the account address to calculate the domain separator, this abstract contract does not -// implement EIP-5267, as the domain retrieval function does not provide a parameter to use for the account address -// (internally the verifyingContract), and the computed `msg.sender` for an `eth_call` without an override is -// address(0). -abstract contract ModuleEIP712 { - // keccak256( - // "EIP712Domain(uint256 chainId,address verifyingContract,bytes32 salt)" - // ) - bytes32 private constant _DOMAIN_SEPARATOR_TYPEHASH = - 0x71062c282d40422f744945d587dbf4ecfd4f9cfad1d35d62c944373009d96162; - - function _domainSeparator(address account) internal view returns (bytes32) { - return keccak256( - abi.encode( - _DOMAIN_SEPARATOR_TYPEHASH, block.chainid, address(this), bytes32(uint256(uint160(account))) - ) - ); - } -} diff --git a/src/modules/ReplaySafeWrapper.sol b/src/modules/ReplaySafeWrapper.sol deleted file mode 100644 index 59c9f954..00000000 --- a/src/modules/ReplaySafeWrapper.sol +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.26; - -import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; - -import {ModuleEIP712} from "./ModuleEIP712.sol"; - -// A contract mixin for modules that wish to use EIP-712 to wrap the hashes sent to the EIP-1271 function -// `isValidSignature`. -// This makes signatures generated by owners of contract accounts non-replayable across multiple accounts owned by -// the same owner. -abstract contract ReplaySafeWrapper is ModuleEIP712 { - // keccak256("ReplaySafeHash(bytes32 hash)") - bytes32 private constant _REPLAY_SAFE_HASH_TYPEHASH = - 0x294a8735843d4afb4f017c76faf3b7731def145ed0025fc9b1d5ce30adf113ff; - - /// @notice Wraps a hash in an EIP-712 envelope to prevent cross-account replay attacks. - /// Uses the ModuleEIP712 domain separator, which includes the chainId, module address, and account address. - /// @param account The account that will validate the message hash. - /// @param hash The hash to wrap. - /// @return The the replay-safe hash, computed by wrapping the input hash in an EIP-712 struct. - function replaySafeHash(address account, bytes32 hash) public view virtual returns (bytes32) { - return MessageHashUtils.toTypedDataHash({ - domainSeparator: _domainSeparator(account), - structHash: _hashStruct(hash) - }); - } - - function _hashStruct(bytes32 hash) internal pure virtual returns (bytes32) { - bytes32 res; - assembly ("memory-safe") { - mstore(0x00, _REPLAY_SAFE_HASH_TYPEHASH) - mstore(0x20, hash) - res := keccak256(0x00, 0x40) - } - return res; - } -} diff --git a/src/modules/validation/ECDSAValidationModule.sol b/src/modules/validation/ECDSAValidationModule.sol index 0f9e813d..b8700be4 100644 --- a/src/modules/validation/ECDSAValidationModule.sol +++ b/src/modules/validation/ECDSAValidationModule.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {ReplaySafeWrapper} from "@erc6900/reference-implementation/modules/ReplaySafeWrapper.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol"; import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; @@ -12,7 +13,6 @@ import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IV import {SignatureType} from "../../helpers/SignatureType.sol"; import {BaseModule} from "../BaseModule.sol"; -import {ReplaySafeWrapper} from "../ReplaySafeWrapper.sol"; /// @title ECSDA Validation /// @author ERC-6900 Authors diff --git a/src/modules/validation/WebauthnValidationModule.sol b/src/modules/validation/WebauthnValidationModule.sol index 97a54b13..86f02d30 100644 --- a/src/modules/validation/WebauthnValidationModule.sol +++ b/src/modules/validation/WebauthnValidationModule.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {ReplaySafeWrapper} from "@erc6900/reference-implementation/modules/ReplaySafeWrapper.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {IERC165} from "@openzeppelin/contracts/interfaces/IERC165.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; @@ -9,7 +10,6 @@ import {WebAuthn} from "webauthn-sol/src/WebAuthn.sol"; import {IModule} from "@erc6900/reference-implementation/interfaces/IModule.sol"; import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IValidationModule.sol"; import {BaseModule} from "@erc6900/reference-implementation/modules/BaseModule.sol"; -import {ReplaySafeWrapper} from "@erc6900/reference-implementation/modules/ReplaySafeWrapper.sol"; /// @title Webauthn Validation /// @author Alchemy diff --git a/test/account/AccountReturnData.t.sol b/test/account/AccountReturnData.t.sol index 0ddb9bfd..e48e6a97 100644 --- a/test/account/AccountReturnData.t.sol +++ b/test/account/AccountReturnData.t.sol @@ -3,9 +3,9 @@ pragma solidity ^0.8.26; import {Call} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../../src/helpers/Constants.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import { RegularResultContract, diff --git a/test/account/DeferredValidation.t.sol b/test/account/DeferredValidation.t.sol index b494bb87..a38af8dc 100644 --- a/test/account/DeferredValidation.t.sol +++ b/test/account/DeferredValidation.t.sol @@ -1,14 +1,15 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntity, ValidationConfig} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {ModularAccount} from "../../src/account/ModularAccount.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; import {CODELESS_ADDRESS} from "../utils/TestConstants.sol"; diff --git a/test/account/DirectCallsFromModule.t.sol b/test/account/DirectCallsFromModule.t.sol index 5ab19625..51b19e0d 100644 --- a/test/account/DirectCallsFromModule.t.sol +++ b/test/account/DirectCallsFromModule.t.sol @@ -1,13 +1,18 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; -import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import { + Call, + IModularAccount, + ModuleEntity, + ValidationConfig +} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../../src/helpers/Constants.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {DirectCallModule} from "../mocks/modules/DirectCallModule.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; import {CODELESS_ADDRESS} from "../utils/TestConstants.sol"; diff --git a/test/account/GlobalValidationTest.t.sol b/test/account/GlobalValidationTest.t.sol index 3af95528..89569538 100644 --- a/test/account/GlobalValidationTest.t.sol +++ b/test/account/GlobalValidationTest.t.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {ModularAccount} from "../../src/account/ModularAccount.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; diff --git a/test/account/HookOrdering.t.sol b/test/account/HookOrdering.t.sol index cbb1b98c..ccfffc5a 100644 --- a/test/account/HookOrdering.t.sol +++ b/test/account/HookOrdering.t.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; - import { ExecutionManifest, ManifestExecutionHook } from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; +import {ModuleEntity, ValidationConfig} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; +import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../../src/helpers/Constants.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {HookOrderCheckerModule} from "../mocks/modules/HookOrderCheckerModule.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; diff --git a/test/account/ModularAccount.t.sol b/test/account/ModularAccount.t.sol index 94232f66..42f32b6b 100644 --- a/test/account/ModularAccount.t.sol +++ b/test/account/ModularAccount.t.sol @@ -3,23 +3,23 @@ pragma solidity ^0.8.26; import {console} from "forge-std/src/Test.sol"; +import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; +import {Call} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ExecutionDataView} from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol"; import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; -import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; -import {Call} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; -import {ExecutionDataView} from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol"; - import {ModularAccount} from "../../src/account/ModularAccount.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {ModuleManagerInternals} from "../../src/account/ModuleManagerInternals.sol"; import {SemiModularAccountBytecode} from "../../src/account/SemiModularAccountBytecode.sol"; -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {ECDSAValidationModule} from "../../src/modules/validation/ECDSAValidationModule.sol"; + import {Counter} from "../mocks/Counter.sol"; import {ComprehensiveModule} from "../mocks/modules/ComprehensiveModule.sol"; import {MockExecutionInstallationModule} from "../mocks/modules/MockExecutionInstallationModule.sol"; diff --git a/test/account/ModularAccountView.t.sol b/test/account/ModularAccountView.t.sol index 02b5463d..ab582a69 100644 --- a/test/account/ModularAccountView.t.sol +++ b/test/account/ModularAccountView.t.sol @@ -1,16 +1,18 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; -import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; - -import {HookConfig, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import { + HookConfig, + IModularAccount, + ModuleEntity +} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import { ExecutionDataView, ValidationDataView } from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol"; - -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; import {ComprehensiveModule} from "../mocks/modules/ComprehensiveModule.sol"; import {CustomValidationTestBase} from "../utils/CustomValidationTestBase.sol"; diff --git a/test/account/MultiValidation.t.sol b/test/account/MultiValidation.t.sol index 43a7225d..d01f6a13 100644 --- a/test/account/MultiValidation.t.sol +++ b/test/account/MultiValidation.t.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {IModularAccount, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; -import {IModularAccount, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {ECDSAValidationModule} from "../../src/modules/validation/ECDSAValidationModule.sol"; + import {AccountTestBase} from "../utils/AccountTestBase.sol"; import {CODELESS_ADDRESS, TEST_DEFAULT_VALIDATION_ENTITY_ID} from "../utils/TestConstants.sol"; diff --git a/test/account/PerHookData.t.sol b/test/account/PerHookData.t.sol index aeedb480..2e9110ea 100644 --- a/test/account/PerHookData.t.sol +++ b/test/account/PerHookData.t.sol @@ -1,15 +1,17 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {SparseCalldataSegmentLib} from "../../src/libraries/SparseCalldataSegmentLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; + import {Counter} from "../mocks/Counter.sol"; import {MockAccessControlHookModule} from "../mocks/modules/MockAccessControlHookModule.sol"; import {CustomValidationTestBase} from "../utils/CustomValidationTestBase.sol"; diff --git a/test/account/ReplaceModule.t.sol b/test/account/ReplaceModule.t.sol index 86c81838..787ad5c5 100644 --- a/test/account/ReplaceModule.t.sol +++ b/test/account/ReplaceModule.t.sol @@ -11,12 +11,13 @@ import { Call, IModularAccount, ModuleEntity } from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {IValidationHookModule} from "@erc6900/reference-implementation/interfaces/IValidationHookModule.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {ECDSAValidationModule} from "../../src/modules/validation/ECDSAValidationModule.sol"; + import {MockModule} from "../mocks/modules/MockModule.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; diff --git a/test/account/SelfCallAuthorization.t.sol b/test/account/SelfCallAuthorization.t.sol index e911bcc5..c643a4a8 100644 --- a/test/account/SelfCallAuthorization.t.sol +++ b/test/account/SelfCallAuthorization.t.sol @@ -1,15 +1,16 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {IAccountExecute} from "@eth-infinitism/account-abstraction/interfaces/IAccountExecute.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; -import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; + import {ComprehensiveModule} from "../mocks/modules/ComprehensiveModule.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; diff --git a/test/account/SemiModularAccountDirectCall.t.sol b/test/account/SemiModularAccountDirectCall.t.sol index 4ca5c3d7..b29dd098 100644 --- a/test/account/SemiModularAccountDirectCall.t.sol +++ b/test/account/SemiModularAccountDirectCall.t.sol @@ -1,13 +1,16 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntity, ValidationConfig} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; + import {ModularAccount} from "../../src/account/ModularAccount.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {SemiModularAccountBase} from "../../src/account/SemiModularAccountBase.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../../src/helpers/Constants.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; + import {MockSMADirectFallbackModule} from "../mocks/modules/MockSMADirectFallbackModule.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; diff --git a/test/account/UpgradeToSma.t.sol b/test/account/UpgradeToSma.t.sol index b424baff..aacf2e23 100644 --- a/test/account/UpgradeToSma.t.sol +++ b/test/account/UpgradeToSma.t.sol @@ -2,6 +2,9 @@ pragma solidity ^0.8.26; import {LightAccount} from "@alchemy/light-account/src/LightAccount.sol"; + +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; @@ -13,7 +16,6 @@ import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; import {SemiModularAccountBase} from "../../src/account/SemiModularAccountBase.sol"; import {SemiModularAccountStorageOnly} from "../../src/account/SemiModularAccountStorageOnly.sol"; import {FALLBACK_VALIDATION} from "../../src/helpers/Constants.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; import {CODELESS_ADDRESS} from "../utils/TestConstants.sol"; diff --git a/test/account/ValidationIntersection.t.sol b/test/account/ValidationIntersection.t.sol index bc2c35bd..33f706e4 100644 --- a/test/account/ValidationIntersection.t.sol +++ b/test/account/ValidationIntersection.t.sol @@ -1,12 +1,14 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; + import { MockBaseUserOpValidationModule, MockUserOpValidation1HookModule, diff --git a/test/libraries/HookConfigLib.t.sol b/test/libraries/HookConfigLib.t.sol deleted file mode 100644 index f03b087b..00000000 --- a/test/libraries/HookConfigLib.t.sol +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.26; - -import {HookConfig, ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; -import {Test} from "forge-std/src/Test.sol"; - -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; - -contract HookConfigLibTest is Test { - using ModuleEntityLib for ModuleEntity; - using HookConfigLib for HookConfig; - - // Tests the packing and unpacking of a hook config with a randomized state - - function testFuzz_hookConfig_packingUnderlying( - address addr, - uint32 entityId, - bool isValidation, - bool hasPre, - bool hasPost - ) public pure { - HookConfig hookConfig; - - if (isValidation) { - hookConfig = HookConfigLib.packValidationHook(addr, entityId); - } else { - hookConfig = HookConfigLib.packExecHook(addr, entityId, hasPre, hasPost); - } - - assertEq(hookConfig.module(), addr, "module mismatch"); - assertEq(hookConfig.entityId(), entityId, "entityId mismatch"); - assertEq(hookConfig.isValidationHook(), isValidation, "isValidation mismatch"); - - if (!isValidation) { - assertEq(hookConfig.hasPreHook(), hasPre, "hasPre mismatch"); - assertEq(hookConfig.hasPostHook(), hasPost, "hasPost mismatch"); - } - } - - function testFuzz_hookConfig_packingModuleEntity( - ModuleEntity hookFunction, - bool isValidation, - bool hasPre, - bool hasPost - ) public pure { - HookConfig hookConfig; - - if (isValidation) { - hookConfig = HookConfigLib.packValidationHook(hookFunction); - } else { - hookConfig = HookConfigLib.packExecHook(hookFunction, hasPre, hasPost); - } - - assertEq( - ModuleEntity.unwrap(hookConfig.moduleEntity()), - ModuleEntity.unwrap(hookFunction), - "moduleEntity mismatch" - ); - assertEq(hookConfig.isValidationHook(), isValidation, "isValidation mismatch"); - - if (!isValidation) { - assertEq(hookConfig.hasPreHook(), hasPre, "hasPre mismatch"); - assertEq(hookConfig.hasPostHook(), hasPost, "hasPost mismatch"); - } - } -} diff --git a/test/libraries/ModuleEntityLib.t.sol b/test/libraries/ModuleEntityLib.t.sol deleted file mode 100644 index 9c08a182..00000000 --- a/test/libraries/ModuleEntityLib.t.sol +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.26; - -import {Test} from "forge-std/src/Test.sol"; - -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; - -contract ModuleEntityLibTest is Test { - using ModuleEntityLib for ModuleEntity; - - function testFuzz_moduleEntity_packing(address addr, uint32 entityId) public pure { - // console.log("addr: ", addr); - // console.log("entityId: ", vm.toString(entityId)); - ModuleEntity fr = ModuleEntityLib.pack(addr, entityId); - // console.log("packed: ", vm.toString(ModuleEntity.unwrap(fr))); - (address addr2, uint32 entityId2) = ModuleEntityLib.unpack(fr); - // console.log("addr2: ", addr2); - // console.log("entityId2: ", vm.toString(entityId2)); - assertEq(addr, addr2); - assertEq(entityId, entityId2); - } - - function testFuzz_moduleEntity_operators(ModuleEntity a, ModuleEntity b) public pure { - assertTrue(a.eq(a)); - assertTrue(b.eq(b)); - - if (ModuleEntity.unwrap(a) == ModuleEntity.unwrap(b)) { - assertTrue(a.eq(b)); - assertTrue(b.eq(a)); - assertFalse(a.notEq(b)); - assertFalse(b.notEq(a)); - } else { - assertTrue(a.notEq(b)); - assertTrue(b.notEq(a)); - assertFalse(a.eq(b)); - assertFalse(b.eq(a)); - } - } -} diff --git a/test/libraries/ValidationConfigLib.t.sol b/test/libraries/ValidationConfigLib.t.sol deleted file mode 100644 index e9ea9864..00000000 --- a/test/libraries/ValidationConfigLib.t.sol +++ /dev/null @@ -1,112 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity ^0.8.26; - -import {Test} from "forge-std/src/Test.sol"; - -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import { - ValidationConfig, ValidationConfigLib, ValidationFlags -} from "../../src/libraries/ValidationConfigLib.sol"; - -contract ValidationConfigLibTest is Test { - using ModuleEntityLib for ModuleEntity; - using ValidationConfigLib for *; - - // Tests the packing and unpacking of a validation config with a randomized state - - function testFuzz_validationConfig_packingUnderlying( - address module, - uint32 entityId, - bool isGlobal, - bool isSignatureValidation, - bool isUserOpValidation - ) public pure { - ValidationConfig validationConfig = - ValidationConfigLib.pack(module, entityId, isGlobal, isSignatureValidation, isUserOpValidation); - - // Test unpacking underlying - (address module2, uint32 entityId2, ValidationFlags flags2) = validationConfig.unpackUnderlying(); - - assertEq(module, module2, "module mismatch"); - assertEq(entityId, entityId2, "entityId mismatch"); - assertEq(isGlobal, flags2.isGlobal(), "isGlobal mismatch"); - assertEq(isSignatureValidation, flags2.isSignatureValidation(), "isSignatureValidation mismatch"); - assertEq(isUserOpValidation, flags2.isUserOpValidation(), "isUserOpValidation mismatch"); - - // Test unpacking to ModuleEntity - - ModuleEntity expectedModuleEntity = ModuleEntityLib.pack(module, entityId); - - (ModuleEntity validationFunction, ValidationFlags flags3) = validationConfig.unpack(); - - assertEq( - ModuleEntity.unwrap(validationFunction), - ModuleEntity.unwrap(expectedModuleEntity), - "validationFunction mismatch" - ); - assertEq(isGlobal, flags3.isGlobal(), "isGlobal mismatch"); - assertEq(isSignatureValidation, flags3.isSignatureValidation(), "isSignatureValidation mismatch"); - assertEq(isUserOpValidation, flags3.isUserOpValidation(), "isUserOpValidation mismatch"); - - // Test individual view functions - - assertEq(validationConfig.module(), module, "module mismatch"); - assertEq(validationConfig.entityId(), entityId, "entityId mismatch"); - assertEq( - ModuleEntity.unwrap(validationConfig.moduleEntity()), - ModuleEntity.unwrap(expectedModuleEntity), - "moduleEntity mismatch" - ); - assertEq(validationConfig.isGlobal(), isGlobal, "isGlobal mismatch"); - assertEq(validationConfig.isSignatureValidation(), isSignatureValidation, "isSignatureValidation mismatch"); - assertEq(validationConfig.isUserOpValidation(), isUserOpValidation, "isUserOpValidation mismatch"); - } - - function testFuzz_validationConfig_packingModuleEntity( - ModuleEntity validationFunction, - bool isGlobal, - bool isSignatureValidation, - bool isUserOpValidation - ) public pure { - ValidationConfig validationConfig = - ValidationConfigLib.pack(validationFunction, isGlobal, isSignatureValidation, isUserOpValidation); - - // Test unpacking underlying - - (address expectedModule, uint32 expectedEntityId) = validationFunction.unpack(); - - (address module, uint32 entityId, ValidationFlags flags2) = validationConfig.unpackUnderlying(); - - assertEq(expectedModule, module, "module mismatch"); - assertEq(expectedEntityId, entityId, "entityId mismatch"); - assertEq(isGlobal, flags2.isGlobal(), "isGlobal mismatch"); - assertEq(isSignatureValidation, flags2.isSignatureValidation(), "isSignatureValidation mismatch"); - assertEq(isUserOpValidation, flags2.isUserOpValidation(), "isUserOpValidation mismatch"); - - // Test unpacking to ModuleEntity - - (ModuleEntity validationFunction2, ValidationFlags flags3) = validationConfig.unpack(); - - assertEq( - ModuleEntity.unwrap(validationFunction), - ModuleEntity.unwrap(validationFunction2), - "validationFunction mismatch" - ); - assertEq(isGlobal, flags3.isGlobal(), "isGlobal mismatch"); - assertEq(isSignatureValidation, flags3.isSignatureValidation(), "isSignatureValidation mismatch"); - assertEq(isUserOpValidation, flags3.isUserOpValidation(), "isUserOpValidation mismatch"); - - // Test individual view functions - - assertEq(validationConfig.module(), expectedModule, "module mismatch"); - assertEq(validationConfig.entityId(), expectedEntityId, "entityId mismatch"); - assertEq( - ModuleEntity.unwrap(validationConfig.moduleEntity()), - ModuleEntity.unwrap(validationFunction), - "validationFunction mismatch" - ); - assertEq(validationConfig.isGlobal(), isGlobal, "isGlobal mismatch"); - assertEq(validationConfig.isSignatureValidation(), isSignatureValidation, "isSignatureValidation mismatch"); - assertEq(validationConfig.isUserOpValidation(), isUserOpValidation, "isUserOpValidation mismatch"); - } -} diff --git a/test/mocks/modules/ReturnDataModuleMocks.sol b/test/mocks/modules/ReturnDataModuleMocks.sol index 53f9bbbb..6bfc695e 100644 --- a/test/mocks/modules/ReturnDataModuleMocks.sol +++ b/test/mocks/modules/ReturnDataModuleMocks.sol @@ -1,8 +1,6 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; -import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; - import { ExecutionManifest, IExecutionModule, @@ -10,10 +8,10 @@ import { } from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; import {IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {IValidationModule} from "@erc6900/reference-implementation/interfaces/IValidationModule.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../../../src/helpers/Constants.sol"; -import {ModuleEntityLib} from "../../../src/libraries/ModuleEntityLib.sol"; - import {BaseModule} from "../../../src/modules/BaseModule.sol"; import {ModuleSignatureUtils} from "../../utils/ModuleSignatureUtils.sol"; diff --git a/test/modules/AllowlistModule.t.sol b/test/modules/AllowlistModule.t.sol index 94ecad2b..2c6f8a47 100644 --- a/test/modules/AllowlistModule.t.sol +++ b/test/modules/AllowlistModule.t.sol @@ -1,13 +1,13 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; -import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; - +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {Call} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {AllowlistModule} from "../../src/modules/permissions/AllowlistModule.sol"; import {Counter} from "../mocks/Counter.sol"; diff --git a/test/modules/ERC20TokenLimitModule.t.sol b/test/modules/ERC20TokenLimitModule.t.sol index 32190f13..82fe3861 100644 --- a/test/modules/ERC20TokenLimitModule.t.sol +++ b/test/modules/ERC20TokenLimitModule.t.sol @@ -1,20 +1,19 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {MockERC20} from "../mocks/MockERC20.sol"; -import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; -import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; - import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; +import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; +import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity} from "../../src/libraries/ModuleEntityLib.sol"; -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {ERC20TokenLimitModule} from "../../src/modules/permissions/ERC20TokenLimitModule.sol"; +import {MockERC20} from "../mocks/MockERC20.sol"; import {MockModule} from "../mocks/modules/MockModule.sol"; import {AccountTestBase} from "../utils/AccountTestBase.sol"; import {CODELESS_ADDRESS} from "../utils/TestConstants.sol"; diff --git a/test/modules/NativeTokenLimitModule.t.sol b/test/modules/NativeTokenLimitModule.t.sol index 29d45647..be149d5d 100644 --- a/test/modules/NativeTokenLimitModule.t.sol +++ b/test/modules/NativeTokenLimitModule.t.sol @@ -1,24 +1,21 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; +import { + Call, IModularAccount, ModuleEntity +} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {ModularAccount} from "../../src/account/ModularAccount.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {ModuleEntity} from "../../src/libraries/ModuleEntityLib.sol"; - -import {ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; - -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; - import {NativeTokenLimitModule} from "../../src/modules/permissions/NativeTokenLimitModule.sol"; import {MockDeployment} from "../mocks/MockDeployment.sol"; import {MockModule} from "../mocks/modules/MockModule.sol"; -import {ExecutionManifest} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol"; -import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; - import {AccountTestBase} from "../utils/AccountTestBase.sol"; contract NativeTokenLimitModuleTest is AccountTestBase { diff --git a/test/modules/TimeRangeModule.t.sol b/test/modules/TimeRangeModule.t.sol index 7acded00..d803a04a 100644 --- a/test/modules/TimeRangeModule.t.sol +++ b/test/modules/TimeRangeModule.t.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; -import {_packValidationData} from "@eth-infinitism/account-abstraction/core/Helpers.sol"; -import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; -import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; - +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; import { HookConfig, ValidationDataView } from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol"; +import {HookConfigLib} from "@erc6900/reference-implementation/libraries/HookConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {_packValidationData} from "@eth-infinitism/account-abstraction/core/Helpers.sol"; +import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; +import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol"; -import {HookConfigLib} from "../../src/libraries/HookConfigLib.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; import {TimeRangeModule} from "../../src/modules/permissions/TimeRangeModule.sol"; import {CustomValidationTestBase} from "../utils/CustomValidationTestBase.sol"; diff --git a/test/modules/WebauthnValidationModule.t.sol b/test/modules/WebauthnValidationModule.t.sol index 8b5a713c..4d084fdd 100644 --- a/test/modules/WebauthnValidationModule.t.sol +++ b/test/modules/WebauthnValidationModule.t.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.26; -import {ModuleEntityLib} from "@erc6900/reference-implementation/helpers/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "@erc6900/reference-implementation/helpers/ValidationConfigLib.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {WebAuthn} from "webauthn-sol/src/WebAuthn.sol"; diff --git a/test/utils/AccountTestBase.sol b/test/utils/AccountTestBase.sol index 99dbd6b7..220c1828 100644 --- a/test/utils/AccountTestBase.sol +++ b/test/utils/AccountTestBase.sol @@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; -import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import { + Call, IModularAccount, ModuleEntity +} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {EntryPoint} from "@eth-infinitism/account-abstraction/core/EntryPoint.sol"; import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; @@ -11,8 +15,6 @@ import {SemiModularAccountBytecode} from "../../src/account/SemiModularAccountBy import {AccountFactory} from "../../src/factory/AccountFactory.sol"; import {DIRECT_CALL_VALIDATION_ENTITYID} from "../../src/helpers/Constants.sol"; import {FALLBACK_VALIDATION} from "../../src/helpers/Constants.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {ECDSAValidationModule} from "../../src/modules/validation/ECDSAValidationModule.sol"; import {ModuleSignatureUtils} from "./ModuleSignatureUtils.sol"; diff --git a/test/utils/CustomValidationTestBase.sol b/test/utils/CustomValidationTestBase.sol index 40f04de3..6727f6bb 100644 --- a/test/utils/CustomValidationTestBase.sol +++ b/test/utils/CustomValidationTestBase.sol @@ -1,11 +1,13 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.26; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; import {ModularAccount} from "../../src/account/ModularAccount.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; + import {AccountTestBase} from "./AccountTestBase.sol"; /// @dev This test contract base is used to test custom validation logic. diff --git a/test/utils/ModuleSignatureUtils.sol b/test/utils/ModuleSignatureUtils.sol index 35153e31..930c3aaa 100644 --- a/test/utils/ModuleSignatureUtils.sol +++ b/test/utils/ModuleSignatureUtils.sol @@ -1,14 +1,14 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.26; +import {ModuleEntity, ValidationConfig} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; +import {ModuleEntityLib} from "@erc6900/reference-implementation/libraries/ModuleEntityLib.sol"; +import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol"; import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; import {ModularAccount} from "../../src/account/ModularAccount.sol"; import {SemiModularAccountBytecode} from "../../src/account/SemiModularAccountBytecode.sol"; - import {RESERVED_VALIDATION_DATA_INDEX} from "../../src/helpers/Constants.sol"; -import {ModuleEntity, ModuleEntityLib} from "../../src/libraries/ModuleEntityLib.sol"; -import {ValidationConfig, ValidationConfigLib} from "../../src/libraries/ValidationConfigLib.sol"; import {ECDSAValidationModule} from "../../src/modules/validation/ECDSAValidationModule.sol"; import {Vm} from "forge-std/src/Vm.sol"; diff --git a/test/utils/StorageAccesses.sol b/test/utils/StorageAccesses.sol index a648f1fc..f2d01053 100644 --- a/test/utils/StorageAccesses.sol +++ b/test/utils/StorageAccesses.sol @@ -4,8 +4,9 @@ pragma solidity ^0.8.26; import {Vm} from "forge-std/src/Vm.sol"; import {console} from "forge-std/src/console.sol"; +import {ModuleEntity} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol"; + import {_ACCOUNT_STORAGE_SLOT} from "../../src/account/AccountStorage.sol"; -import {ModuleEntity} from "../../src/libraries/ModuleEntityLib.sol"; // solhint-disable no-console library StorageAccesses {