Skip to content

Commit

Permalink
fix: rename ValidationData and ExecutionData
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypaik committed Oct 15, 2024
1 parent 0848a8c commit 4ea67a7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 82 deletions.
8 changes: 4 additions & 4 deletions src/account/AccountStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {LinkedListSet, SetValue} from "../libraries/LinkedListSetLib.sol";
bytes32 constant _ACCOUNT_STORAGE_SLOT = 0xc531f081ecdb5a90f38c197521797881a6e5c752a7d451780f325a95f8b91f45;

// Represents data associated with a specifc function selector.
struct ExecutionData {
struct ExecutionStorage {
// The module that implements this execution function.
// If this is a native function, the address must remain address(0).
address module;
Expand All @@ -24,7 +24,7 @@ struct ExecutionData {
LinkedListSet executionHooks;
}

struct ValidationData {
struct ValidationStorage {
// Whether or not this validation can be used as a global validation function.
bool isGlobal;
// Whether or not this validation is allowed to validate ERC-1271 signatures.
Expand All @@ -50,8 +50,8 @@ struct AccountStorage {
uint8 initialized;
bool initializing;
// Execution functions and their associated functions
mapping(bytes4 selector => ExecutionData) executionData;
mapping(ModuleEntity validationFunction => ValidationData) validationData;
mapping(bytes4 selector => ExecutionStorage) executionStorage;
mapping(ModuleEntity validationFunction => ValidationStorage) validationStorage;
// For ERC165 introspection
mapping(bytes4 => uint256) supportedIfaces;
mapping(uint256 => bool) deferredActionNonceUsed;
Expand Down
32 changes: 16 additions & 16 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ abstract contract ModularAccountBase is
/// @dev We route calls to execution functions based on incoming msg.sig
/// @dev If there's no module associated with this function selector, revert
fallback(bytes calldata) external payable returns (bytes memory) {
address execModule = getAccountStorage().executionData[msg.sig].module;
address execModule = getAccountStorage().executionStorage[msg.sig].module;
if (execModule == address(0)) {
revert UnrecognizedFunction(msg.sig);
}
Expand Down Expand Up @@ -216,7 +216,7 @@ abstract contract ModularAccountBase is
ModuleEntity userOpValidationFunction = ModuleEntity.wrap(bytes24(userOp.signature[:24]));

HookConfig[] memory validationAssocExecHooks =
MemManagementLib.loadExecHooks(getAccountStorage().validationData[userOpValidationFunction]);
MemManagementLib.loadExecHooks(getAccountStorage().validationStorage[userOpValidationFunction]);

PHCallBuffer callBuffer;
if (validationAssocExecHooks.length > 0) {
Expand Down Expand Up @@ -297,7 +297,7 @@ abstract contract ModularAccountBase is

// If runtime validation passes, run exec hooks associated with the validator
HookConfig[] memory validationAssocExecHooks =
MemManagementLib.loadExecHooks(getAccountStorage().validationData[runtimeValidationFunction]);
MemManagementLib.loadExecHooks(getAccountStorage().validationStorage[runtimeValidationFunction]);

PHCallBuffer phCallBuffer;
if (validationAssocExecHooks.length > 0) {
Expand Down Expand Up @@ -483,7 +483,7 @@ abstract contract ModularAccountBase is
// `executeUserOp`. This check must be here because if context isn't passed, we can't tell in execution
// which hooks should have ran.
if (
getAccountStorage().validationData[validationFunction].executionHookCount > 0
getAccountStorage().validationStorage[validationFunction].executionHookCount > 0
&& bytes4(userOp.callData[:4]) != this.executeUserOp.selector
) {
revert RequireUserOperationContext();
Expand Down Expand Up @@ -561,7 +561,7 @@ abstract contract ModularAccountBase is

// Do preUserOpValidation hooks
HookConfig[] memory preUserOpValidationHooks =
MemManagementLib.loadValidationHooks(getAccountStorage().validationData[userOpValidationFunction]);
MemManagementLib.loadValidationHooks(getAccountStorage().validationStorage[userOpValidationFunction]);

UOCallBuffer userOpCallBuffer;
if (!_validationIsNative(userOpValidationFunction) || preUserOpValidationHooks.length > 0) {
Expand Down Expand Up @@ -615,7 +615,7 @@ abstract contract ModularAccountBase is
) internal returns (RTCallBuffer) {
// run all preRuntimeValidation hooks
HookConfig[] memory preRuntimeValidationHooks =
MemManagementLib.loadValidationHooks(getAccountStorage().validationData[runtimeValidationFunction]);
MemManagementLib.loadValidationHooks(getAccountStorage().validationStorage[runtimeValidationFunction]);

RTCallBuffer callBuffer;
if (!_validationIsNative(runtimeValidationFunction) || preRuntimeValidationHooks.length > 0) {
Expand Down Expand Up @@ -671,7 +671,7 @@ abstract contract ModularAccountBase is
// and the selector isn't public.
if (
msg.sender != address(_ENTRY_POINT) && msg.sender != address(this)
&& !_storage.executionData[msg.sig].skipRuntimeValidation
&& !_storage.executionStorage[msg.sig].skipRuntimeValidation
) {
ModuleEntity directCallValidationKey =
ModuleEntityLib.pack(msg.sender, DIRECT_CALL_VALIDATION_ENTITYID);
Expand All @@ -682,7 +682,7 @@ abstract contract ModularAccountBase is

// Validation hooks
HookConfig[] memory preRuntimeValidationHooks =
MemManagementLib.loadValidationHooks(_storage.validationData[directCallValidationKey]);
MemManagementLib.loadValidationHooks(_storage.validationStorage[directCallValidationKey]);

uint256 preRuntimeValidationHooksLength = preRuntimeValidationHooks.length;
if (preRuntimeValidationHooksLength > 0) {
Expand All @@ -702,12 +702,12 @@ abstract contract ModularAccountBase is

//Load all execution hooks: both associated with the selector and the validation function.
execHooks = MemManagementLib.loadExecHooks(
_storage.executionData[msg.sig], _storage.validationData[directCallValidationKey]
_storage.executionStorage[msg.sig], _storage.validationStorage[directCallValidationKey]
);
} else {
// If the sender is the entry point or the account itself, or the selector is public, this indicates
// that validation was done elsewhere. We only need to run selector-associated execution hooks.
execHooks = MemManagementLib.loadExecHooks(_storage.executionData[msg.sig]);
execHooks = MemManagementLib.loadExecHooks(_storage.executionStorage[msg.sig]);
}

PHCallBuffer preHookCallBuffer;
Expand All @@ -729,7 +729,7 @@ abstract contract ModularAccountBase is
) internal virtual returns (uint256) {
AccountStorage storage _storage = getAccountStorage();

if (!_storage.validationData[userOpValidationFunction].isUserOpValidation) {
if (!_storage.validationStorage[userOpValidationFunction].isUserOpValidation) {
(address module, uint32 entityId) = userOpValidationFunction.unpack();
revert UserOpValidationInvalid(module, entityId);
}
Expand All @@ -753,7 +753,7 @@ abstract contract ModularAccountBase is
returns (bytes4)
{
HookConfig[] memory preSignatureValidationHooks =
MemManagementLib.loadValidationHooks(getAccountStorage().validationData[sigValidation]);
MemManagementLib.loadValidationHooks(getAccountStorage().validationStorage[sigValidation]);

SigCallBuffer sigCallBuffer;
if (!_validationIsNative(sigValidation) || preSignatureValidationHooks.length > 0) {
Expand Down Expand Up @@ -788,7 +788,7 @@ abstract contract ModularAccountBase is
(hash); // unused in ModularAccountBase, but used in SemiModularAccountBase
AccountStorage storage _storage = getAccountStorage();

if (!_storage.validationData[sigValidation].isSignatureValidation) {
if (!_storage.validationStorage[sigValidation].isSignatureValidation) {
(address module, uint32 entityId) = sigValidation.unpack();
revert SignatureValidationInvalid(module, entityId);
}
Expand All @@ -811,11 +811,11 @@ abstract contract ModularAccountBase is
return true;
}

return getAccountStorage().executionData[selector].allowGlobalValidation;
return getAccountStorage().executionStorage[selector].allowGlobalValidation;
}

function _isValidationGlobal(ModuleEntity validationFunction) internal view virtual returns (bool) {
return getAccountStorage().validationData[validationFunction].isGlobal;
return getAccountStorage().validationStorage[validationFunction].isGlobal;
}

function _checkIfValidationAppliesCallData(
Expand Down Expand Up @@ -1049,7 +1049,7 @@ abstract contract ModularAccountBase is
view
returns (bool)
{
return getAccountStorage().validationData[validationFunction].selectors.contains(toSetValue(selector));
return getAccountStorage().validationStorage[validationFunction].selectors.contains(toSetValue(selector));
}

function _computeDeferredValidationInstallTypedDataHash(
Expand Down
26 changes: 13 additions & 13 deletions src/account/ModularAccountView.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@erc6900/reference-implementation/interfaces/IModularAccountView.sol";

import {MemManagementLib} from "../libraries/MemManagementLib.sol";
import {ExecutionData, ValidationData, getAccountStorage} from "./AccountStorage.sol";
import {ExecutionStorage, ValidationStorage, getAccountStorage} from "./AccountStorage.sol";

abstract contract ModularAccountView is IModularAccountView {
/// @inheritdoc IModularAccountView
Expand All @@ -29,12 +29,12 @@ abstract contract ModularAccountView is IModularAccountView {
data.module = address(this);
data.allowGlobalValidation = true;
} else {
ExecutionData storage executionData = getAccountStorage().executionData[selector];
data.module = executionData.module;
data.skipRuntimeValidation = executionData.skipRuntimeValidation;
data.allowGlobalValidation = executionData.allowGlobalValidation;
ExecutionStorage storage executionStorage = getAccountStorage().executionStorage[selector];
data.module = executionStorage.module;
data.skipRuntimeValidation = executionStorage.skipRuntimeValidation;
data.allowGlobalValidation = executionStorage.allowGlobalValidation;

HookConfig[] memory hooks = MemManagementLib.loadExecHooks(executionData);
HookConfig[] memory hooks = MemManagementLib.loadExecHooks(executionStorage);
MemManagementLib.reverseArr(hooks);
data.executionHooks = hooks;
}
Expand All @@ -47,18 +47,18 @@ abstract contract ModularAccountView is IModularAccountView {
override
returns (ValidationDataView memory data)
{
ValidationData storage validationData = getAccountStorage().validationData[validationFunction];
data.isGlobal = validationData.isGlobal;
data.isSignatureValidation = validationData.isSignatureValidation;
data.isUserOpValidation = validationData.isUserOpValidation;
data.validationHooks = MemManagementLib.loadValidationHooks(validationData);
ValidationStorage storage validationStorage = getAccountStorage().validationStorage[validationFunction];
data.isGlobal = validationStorage.isGlobal;
data.isSignatureValidation = validationStorage.isSignatureValidation;
data.isUserOpValidation = validationStorage.isUserOpValidation;
data.validationHooks = MemManagementLib.loadValidationHooks(validationStorage);
MemManagementLib.reverseArr(data.validationHooks);

HookConfig[] memory hooks = MemManagementLib.loadExecHooks(validationData);
HookConfig[] memory hooks = MemManagementLib.loadExecHooks(validationStorage);
MemManagementLib.reverseArr(hooks);
data.executionHooks = hooks;

bytes4[] memory selectors = MemManagementLib.loadSelectors(validationData);
bytes4[] memory selectors = MemManagementLib.loadSelectors(validationStorage);
MemManagementLib.reverseArr(selectors);
data.selectors = selectors;
}
Expand Down
Loading

0 comments on commit 4ea67a7

Please sign in to comment.