-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change log: * Rename Execution to Call, and update IStandardExecutor * Update IPluginExecutor NatSpec * update IPluginManager * update name IPluginLoupe to IAccountLoupe * update IAccountLoupe interface to spec update 6 * update BaseModularAccount to PluginManagerInternals and clean it up * update IPlugin to match spec update 6 * add canSpendNativeToken support in code * re-arrange imports and inheritance * Remove uninstall field checking * Move exec hooks and permitted call hooks to hook group * perf: precompile contracts for faster test runs * Add post-only hooks and related tests * Update to use optimized test * Fix pre exec hook data in executeFromPlugin * Fix via-IR build & refactor * feat: allow overlapping hooks * feat: update ordering of associated post hook executions
- Loading branch information
1 parent
98bc1d7
commit 0cb269d
Showing
43 changed files
with
1,806 additions
and
798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
# Foundry build and cache directories | ||
out/ | ||
out-optimized/ | ||
cache/ | ||
node_modules/ | ||
|
||
# Coverage | ||
report/ | ||
lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule forge-std
updated
32 files
+48 −6 | .github/workflows/ci.yml | |
+29 −0 | .github/workflows/sync.yml | |
+1 −1 | foundry.toml | |
+1 −1 | lib/ds-test | |
+2 −2 | package.json | |
+5 −3 | src/Base.sol | |
+4 −3 | src/Script.sol | |
+91 −40 | src/StdAssertions.sol | |
+47 −26 | src/StdChains.sol | |
+284 −39 | src/StdCheats.sol | |
+20 −5 | src/StdInvariant.sol | |
+18 −14 | src/StdJson.sol | |
+54 −3 | src/StdStorage.sol | |
+333 −0 | src/StdStyle.sol | |
+92 −34 | src/StdUtils.sol | |
+7 −2 | src/Test.sol | |
+589 −167 | src/Vm.sol | |
+394 −382 | src/console2.sol | |
+216 −0 | src/mocks/MockERC20.sol | |
+221 −0 | src/mocks/MockERC721.sol | |
+13,248 −0 | src/safeconsole.sol | |
+258 −66 | test/StdAssertions.t.sol | |
+117 −48 | test/StdChains.t.sol | |
+321 −40 | test/StdCheats.t.sol | |
+10 −10 | test/StdError.t.sol | |
+27 −12 | test/StdMath.t.sol | |
+66 −34 | test/StdStorage.t.sol | |
+110 −0 | test/StdStyle.t.sol | |
+87 −34 | test/StdUtils.t.sol | |
+15 −0 | test/Vm.t.sol | |
+441 −0 | test/mocks/MockERC20.t.sol | |
+721 −0 | test/mocks/MockERC721.t.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.19; | ||
|
||
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol"; | ||
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol"; | ||
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
|
||
import {IAccountLoupe} from "../interfaces/IAccountLoupe.sol"; | ||
import {IPluginManager} from "../interfaces/IPluginManager.sol"; | ||
import {IStandardExecutor} from "../interfaces/IStandardExecutor.sol"; | ||
import { | ||
AccountStorage, | ||
getAccountStorage, | ||
getPermittedCallKey, | ||
HookGroup, | ||
toFunctionReferenceArray | ||
} from "../libraries/AccountStorage.sol"; | ||
import {FunctionReference} from "../libraries/FunctionReferenceLib.sol"; | ||
|
||
abstract contract AccountLoupe is IAccountLoupe { | ||
using EnumerableMap for EnumerableMap.Bytes32ToUintMap; | ||
using EnumerableSet for EnumerableSet.AddressSet; | ||
|
||
error ManifestDiscrepancy(address plugin); | ||
|
||
/// @inheritdoc IAccountLoupe | ||
function getExecutionFunctionConfig(bytes4 selector) | ||
external | ||
view | ||
returns (ExecutionFunctionConfig memory config) | ||
{ | ||
AccountStorage storage _storage = getAccountStorage(); | ||
|
||
if ( | ||
selector == IStandardExecutor.execute.selector || selector == IStandardExecutor.executeBatch.selector | ||
|| selector == UUPSUpgradeable.upgradeTo.selector | ||
|| selector == UUPSUpgradeable.upgradeToAndCall.selector | ||
|| selector == IPluginManager.installPlugin.selector | ||
|| selector == IPluginManager.uninstallPlugin.selector | ||
) { | ||
config.plugin = address(this); | ||
} else { | ||
config.plugin = _storage.selectorData[selector].plugin; | ||
} | ||
|
||
config.userOpValidationFunction = _storage.selectorData[selector].userOpValidation; | ||
|
||
config.runtimeValidationFunction = _storage.selectorData[selector].runtimeValidation; | ||
} | ||
|
||
/// @inheritdoc IAccountLoupe | ||
function getExecutionHooks(bytes4 selector) external view returns (ExecutionHooks[] memory execHooks) { | ||
execHooks = _getHooks(getAccountStorage().selectorData[selector].executionHooks); | ||
} | ||
|
||
/// @inheritdoc IAccountLoupe | ||
function getPermittedCallHooks(address callingPlugin, bytes4 selector) | ||
external | ||
view | ||
returns (ExecutionHooks[] memory execHooks) | ||
{ | ||
bytes24 key = getPermittedCallKey(callingPlugin, selector); | ||
execHooks = _getHooks(getAccountStorage().permittedCalls[key].permittedCallHooks); | ||
} | ||
|
||
/// @inheritdoc IAccountLoupe | ||
function getPreValidationHooks(bytes4 selector) | ||
external | ||
view | ||
returns ( | ||
FunctionReference[] memory preUserOpValidationHooks, | ||
FunctionReference[] memory preRuntimeValidationHooks | ||
) | ||
{ | ||
preUserOpValidationHooks = | ||
toFunctionReferenceArray(getAccountStorage().selectorData[selector].preUserOpValidationHooks); | ||
preRuntimeValidationHooks = | ||
toFunctionReferenceArray(getAccountStorage().selectorData[selector].preRuntimeValidationHooks); | ||
} | ||
|
||
/// @inheritdoc IAccountLoupe | ||
function getInstalledPlugins() external view returns (address[] memory pluginAddresses) { | ||
pluginAddresses = getAccountStorage().plugins.values(); | ||
} | ||
|
||
function _getHooks(HookGroup storage hooks) internal view returns (ExecutionHooks[] memory execHooks) { | ||
uint256 preExecHooksLength = hooks.preHooks.length(); | ||
uint256 postOnlyExecHooksLength = hooks.postOnlyHooks.length(); | ||
uint256 maxExecHooksLength = postOnlyExecHooksLength; | ||
|
||
// There can only be as many associated post hooks to run as there are pre hooks. | ||
for (uint256 i = 0; i < preExecHooksLength;) { | ||
(, uint256 count) = hooks.preHooks.at(i); | ||
unchecked { | ||
maxExecHooksLength += (count + 1); | ||
++i; | ||
} | ||
} | ||
|
||
// Overallocate on length - not all of this may get filled up. We set the correct length later. | ||
execHooks = new ExecutionHooks[](maxExecHooksLength); | ||
uint256 actualExecHooksLength; | ||
|
||
for (uint256 i = 0; i < preExecHooksLength;) { | ||
(bytes32 key,) = hooks.preHooks.at(i); | ||
FunctionReference preExecHook = FunctionReference.wrap(bytes21(key)); | ||
|
||
uint256 associatedPostExecHooksLength = hooks.associatedPostHooks[preExecHook].length(); | ||
if (associatedPostExecHooksLength > 0) { | ||
for (uint256 j = 0; j < associatedPostExecHooksLength;) { | ||
execHooks[actualExecHooksLength].preExecHook = preExecHook; | ||
(key,) = hooks.associatedPostHooks[preExecHook].at(j); | ||
execHooks[actualExecHooksLength].postExecHook = FunctionReference.wrap(bytes21(key)); | ||
|
||
unchecked { | ||
++actualExecHooksLength; | ||
++j; | ||
} | ||
} | ||
} else { | ||
execHooks[actualExecHooksLength].preExecHook = preExecHook; | ||
|
||
unchecked { | ||
++actualExecHooksLength; | ||
} | ||
} | ||
|
||
unchecked { | ||
++i; | ||
} | ||
} | ||
|
||
for (uint256 i = 0; i < postOnlyExecHooksLength;) { | ||
(bytes32 key,) = hooks.postOnlyHooks.at(i); | ||
execHooks[actualExecHooksLength].postExecHook = FunctionReference.wrap(bytes21(key)); | ||
|
||
unchecked { | ||
++actualExecHooksLength; | ||
++i; | ||
} | ||
} | ||
|
||
// Trim the exec hooks array to the actual length, since we may have overallocated. | ||
assembly ("memory-safe") { | ||
mstore(execHooks, actualExecHooksLength) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.