Skip to content

Commit

Permalink
rename validationId to entityId
Browse files Browse the repository at this point in the history
  • Loading branch information
fangting-alchemy committed Jul 11, 2024
1 parent 9a037b9 commit 2aa4fc4
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 176 deletions.
8 changes: 4 additions & 4 deletions src/account/PluginManagerInternals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ abstract contract PluginManagerInternals is IPluginManager {
function _addValidationFunction(address plugin, ManifestValidation memory mv) internal {
AccountStorage storage _storage = getAccountStorage();

FunctionReference validationFunction = FunctionReferenceLib.pack(plugin, mv.validationId);
FunctionReference validationFunction = FunctionReferenceLib.pack(plugin, mv.entityId);

if (mv.isDefault) {
_storage.validationData[validationFunction].isGlobal = true;
Expand All @@ -99,7 +99,7 @@ abstract contract PluginManagerInternals is IPluginManager {
function _removeValidationFunction(address plugin, ManifestValidation memory mv) internal {
AccountStorage storage _storage = getAccountStorage();

FunctionReference validationFunction = FunctionReferenceLib.pack(plugin, mv.validationId);
FunctionReference validationFunction = FunctionReferenceLib.pack(plugin, mv.entityId);

_storage.validationData[validationFunction].isGlobal = false;
_storage.validationData[validationFunction].isSignatureValidation = false;
Expand Down Expand Up @@ -183,7 +183,7 @@ abstract contract PluginManagerInternals is IPluginManager {
for (uint256 i = 0; i < length; ++i) {
ManifestExecutionHook memory mh = manifest.executionHooks[i];
EnumerableSet.Bytes32Set storage execHooks = _storage.selectorData[mh.executionSelector].executionHooks;
FunctionReference hookFunction = FunctionReferenceLib.pack(plugin, mh.validationId);
FunctionReference hookFunction = FunctionReferenceLib.pack(plugin, mh.entityId);
_addExecHooks(execHooks, hookFunction, mh.isPreHook, mh.isPostHook);
}

Expand Down Expand Up @@ -223,7 +223,7 @@ abstract contract PluginManagerInternals is IPluginManager {
uint256 length = manifest.executionHooks.length;
for (uint256 i = 0; i < length; ++i) {
ManifestExecutionHook memory mh = manifest.executionHooks[i];
FunctionReference hookFunction = FunctionReferenceLib.pack(plugin, mh.validationId);
FunctionReference hookFunction = FunctionReferenceLib.pack(plugin, mh.entityId);
EnumerableSet.Bytes32Set storage execHooks = _storage.selectorData[mh.executionSelector].executionHooks;
_removeExecHooks(execHooks, hookFunction, mh.isPreHook, mh.isPostHook);
}
Expand Down
60 changes: 28 additions & 32 deletions src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ contract UpgradeableModularAccount is
error NativeTokenSpendingNotPermitted(address plugin);
error NonCanonicalEncoding();
error NotEntryPoint();
error PostExecHookReverted(address plugin, uint32 validationId, bytes revertReason);
error PreExecHookReverted(address plugin, uint32 validationId, bytes revertReason);
error PreRuntimeValidationHookFailed(address plugin, uint32 validationId, bytes revertReason);
error PostExecHookReverted(address plugin, uint32 entityId, bytes revertReason);
error PreExecHookReverted(address plugin, uint32 entityId, bytes revertReason);
error PreRuntimeValidationHookFailed(address plugin, uint32 entityId, bytes revertReason);
error RequireUserOperationContext();
error RuntimeValidationFunctionMissing(bytes4 selector);
error RuntimeValidationFunctionReverted(address plugin, uint32 validationId, bytes revertReason);
error RuntimeValidationFunctionReverted(address plugin, uint32 entityId, bytes revertReason);
error SelfCallRecursionDepthExceeded();
error SignatureValidationInvalid(address plugin, uint32 validationId);
error UnexpectedAggregator(address plugin, uint32 validationId, address aggregator);
error SignatureValidationInvalid(address plugin, uint32 entityId);
error UnexpectedAggregator(address plugin, uint32 entityId, address aggregator);
error UnrecognizedFunction(bytes4 selector);
error UserOpValidationFunctionMissing(bytes4 selector);
error ValidationDoesNotApply(bytes4 selector, address plugin, uint32 validationId, bool isGlobal);
error ValidationDoesNotApply(bytes4 selector, address plugin, uint32 entityId, bool isGlobal);
error ValidationSignatureSegmentMissing();
error SignatureSegmentOutOfOrder();

Expand Down Expand Up @@ -343,15 +343,13 @@ contract UpgradeableModularAccount is

FunctionReference sigValidation = FunctionReference.wrap(bytes24(signature));

(address plugin, uint32 validationId) = sigValidation.unpack();
(address plugin, uint32 entityId) = sigValidation.unpack();
if (!_storage.validationData[sigValidation].isSignatureValidation) {
revert SignatureValidationInvalid(plugin, validationId);
revert SignatureValidationInvalid(plugin, entityId);
}

if (
IValidation(plugin).validateSignature(validationId, msg.sender, hash, signature[24:])
== _1271_MAGIC_VALUE
) {
if (IValidation(plugin).validateSignature(entityId, msg.sender, hash, signature[24:]) == _1271_MAGIC_VALUE)
{
return _1271_MAGIC_VALUE;
}
return _1271_INVALID;
Expand Down Expand Up @@ -434,13 +432,13 @@ contract UpgradeableModularAccount is
userOp.signature = "";
}

(address plugin, uint32 validationId) = preUserOpValidationHooks[i].unpack();
(address plugin, uint32 entityId) = preUserOpValidationHooks[i].unpack();
uint256 currentValidationData =
IValidationHook(plugin).preUserOpValidationHook(validationId, userOp, userOpHash);
IValidationHook(plugin).preUserOpValidationHook(entityId, userOp, userOpHash);

if (uint160(currentValidationData) > 1) {
// If the aggregator is not 0 or 1, it is an unexpected value
revert UnexpectedAggregator(plugin, validationId, address(uint160(currentValidationData)));
revert UnexpectedAggregator(plugin, entityId, address(uint160(currentValidationData)));
}
validationData = _coalescePreValidation(validationData, currentValidationData);
}
Expand All @@ -453,8 +451,8 @@ contract UpgradeableModularAccount is

userOp.signature = signatureSegment.getBody();

(address plugin, uint32 validationId) = userOpValidationFunction.unpack();
uint256 currentValidationData = IValidation(plugin).validateUserOp(validationId, userOp, userOpHash);
(address plugin, uint32 entityId) = userOpValidationFunction.unpack();
uint256 currentValidationData = IValidation(plugin).validateUserOp(entityId, userOp, userOpHash);

if (preUserOpValidationHooks.length != 0) {
// If we have other validation data we need to coalesce with
Expand Down Expand Up @@ -501,32 +499,30 @@ contract UpgradeableModularAccount is
currentAuthData = "";
}

(address hookPlugin, uint32 hookValidationId) = preRuntimeValidationHooks[i].unpack();
(address hookPlugin, uint32 hookEntityId) = preRuntimeValidationHooks[i].unpack();
try IValidationHook(hookPlugin).preRuntimeValidationHook(
hookValidationId, msg.sender, msg.value, callData, currentAuthData
hookEntityId, msg.sender, msg.value, callData, currentAuthData
)
// forgefmt: disable-start
// solhint-disable-next-line no-empty-blocks
{} catch (bytes memory revertReason) {
// forgefmt: disable-end
revert PreRuntimeValidationHookFailed(hookPlugin, hookValidationId, revertReason);
revert PreRuntimeValidationHookFailed(hookPlugin, hookEntityId, revertReason);
}
}

if (authSegment.getIndex() != _RESERVED_VALIDATION_DATA_INDEX) {
revert ValidationSignatureSegmentMissing();
}

(address plugin, uint32 validationId) = runtimeValidationFunction.unpack();
(address plugin, uint32 entityId) = runtimeValidationFunction.unpack();

try IValidation(plugin).validateRuntime(
validationId, msg.sender, msg.value, callData, authSegment.getBody()
)
try IValidation(plugin).validateRuntime(entityId, msg.sender, msg.value, callData, authSegment.getBody())
// forgefmt: disable-start
// solhint-disable-next-line no-empty-blocks
{} catch (bytes memory revertReason) {
// forgefmt: disable-end
revert RuntimeValidationFunctionReverted(plugin, validationId, revertReason);
revert RuntimeValidationFunctionReverted(plugin, entityId, revertReason);
}
}

Expand Down Expand Up @@ -571,14 +567,14 @@ contract UpgradeableModularAccount is
internal
returns (bytes memory preExecHookReturnData)
{
(address plugin, uint32 validationId) = preExecHook.unpack();
try IExecutionHook(plugin).preExecutionHook(validationId, msg.sender, msg.value, data) returns (
(address plugin, uint32 entityId) = preExecHook.unpack();
try IExecutionHook(plugin).preExecutionHook(entityId, msg.sender, msg.value, data) returns (
bytes memory returnData
) {
preExecHookReturnData = returnData;
} catch (bytes memory revertReason) {
// TODO: same issue with EP0.6 - we can't do bytes4 error codes in plugins
revert PreExecHookReverted(plugin, validationId, revertReason);
revert PreExecHookReverted(plugin, entityId, revertReason);
}
}

Expand All @@ -596,11 +592,11 @@ contract UpgradeableModularAccount is
continue;
}

(address plugin, uint32 validationId) = postHookToRun.postExecHook.unpack();
(address plugin, uint32 entityId) = postHookToRun.postExecHook.unpack();
// solhint-disable-next-line no-empty-blocks
try IExecutionHook(plugin).postExecutionHook(validationId, postHookToRun.preExecHookReturnData) {}
try IExecutionHook(plugin).postExecutionHook(entityId, postHookToRun.preExecHookReturnData) {}
catch (bytes memory revertReason) {
revert PostExecHookReverted(plugin, validationId, revertReason);
revert PostExecHookReverted(plugin, entityId, revertReason);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/FunctionReferenceLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ library FunctionReferenceLib {
// Magic value for hooks that should always revert.
FunctionReference internal constant _PRE_HOOK_ALWAYS_DENY = FunctionReference.wrap(bytes24(uint192(2)));

function pack(address addr, uint32 validationId) internal pure returns (FunctionReference) {
return FunctionReference.wrap(bytes24(bytes20(addr)) | bytes24(uint192(validationId)));
function pack(address addr, uint32 entityId) internal pure returns (FunctionReference) {
return FunctionReference.wrap(bytes24(bytes20(addr)) | bytes24(uint192(entityId)));
}

function unpack(FunctionReference fr) internal pure returns (address addr, uint32 validationId) {
function unpack(FunctionReference fr) internal pure returns (address addr, uint32 entityId) {
bytes24 underlying = FunctionReference.unwrap(fr);
addr = address(bytes20(underlying));
validationId = uint32(bytes4(underlying << 160));
entityId = uint32(bytes4(underlying << 160));
}

function isEmpty(FunctionReference fr) internal pure returns (bool) {
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/ValidationConfigLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ library ValidationConfigLib {
);
}

function pack(address _plugin, uint32 _validationId, bool _isGlobal, bool _isSignatureValidation)
function pack(address _plugin, uint32 _entityId, bool _isGlobal, bool _isSignatureValidation)
internal
pure
returns (ValidationConfig)
Expand All @@ -37,8 +37,8 @@ library ValidationConfigLib {
bytes26(
// plugin address stored in the first 20 bytes
bytes26(bytes20(_plugin))
// validationId stored in the 21st - 24th byte
| bytes26(bytes32(uint256(_validationId) << 168))
// entityId stored in the 21st - 24th byte
| bytes26(bytes32(uint256(_entityId) << 168))
// isGlobal flag stored in the 25th byte
| bytes26(bytes32(_isGlobal ? uint256(1) << 56 : 0))
// isSignatureValidation flag stored in the 26th byte
Expand All @@ -50,11 +50,11 @@ library ValidationConfigLib {
function unpackUnderlying(ValidationConfig config)
internal
pure
returns (address _plugin, uint32 _validationId, bool _isGlobal, bool _isSignatureValidation)
returns (address _plugin, uint32 _entityId, bool _isGlobal, bool _isSignatureValidation)
{
bytes26 configBytes = ValidationConfig.unwrap(config);
_plugin = address(bytes20(configBytes));
_validationId = uint32(bytes4(configBytes << 160));
_entityId = uint32(bytes4(configBytes << 160));
_isGlobal = uint8(configBytes[24]) == 1;
_isSignatureValidation = uint8(configBytes[25]) == 1;
}
Expand All @@ -74,7 +74,7 @@ library ValidationConfigLib {
return address(bytes20(ValidationConfig.unwrap(config)));
}

function validationId(ValidationConfig config) internal pure returns (uint32) {
function entityId(ValidationConfig config) internal pure returns (uint32) {
return uint32(bytes4(ValidationConfig.unwrap(config) << 160));
}

Expand Down
12 changes: 6 additions & 6 deletions src/interfaces/IExecutionHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ pragma solidity ^0.8.25;
import {IPlugin} from "./IPlugin.sol";

interface IExecutionHook is IPlugin {
/// @notice Run the pre execution hook specified by the `validationId`.
/// @notice Run the pre execution hook specified by the `entityId`.
/// @dev To indicate the entire call should revert, the function MUST revert.
/// @param validationId An identifier that routes the call to different internal implementations, should there
/// @param entityId An identifier that routes the call to different internal implementations, should there
/// be
/// more than one.
/// @param sender The caller address.
/// @param value The call value.
/// @param data The calldata sent.
/// @return Context to pass to a post execution hook, if present. An empty bytes array MAY be returned.
function preExecutionHook(uint32 validationId, address sender, uint256 value, bytes calldata data)
function preExecutionHook(uint32 entityId, address sender, uint256 value, bytes calldata data)
external
returns (bytes memory);

/// @notice Run the post execution hook specified by the `validationId`.
/// @notice Run the post execution hook specified by the `entityId`.
/// @dev To indicate the entire call should revert, the function MUST revert.
/// @param validationId An identifier that routes the call to different internal implementations, should there
/// @param entityId An identifier that routes the call to different internal implementations, should there
/// be
/// more than one.
/// @param preExecHookData The context returned by its associated pre execution hook.
function postExecutionHook(uint32 validationId, bytes calldata preExecHookData) external;
function postExecutionHook(uint32 entityId, bytes calldata preExecHookData) external;
}
4 changes: 2 additions & 2 deletions src/interfaces/IPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ManifestExecutionFunction {

// todo: do we need these at all? Or do we fully switch to `installValidation`?
struct ManifestValidation {
uint32 validationId;
uint32 entityId;
bool isDefault;
bool isSignatureValidation;
bytes4[] selectors;
Expand All @@ -24,7 +24,7 @@ struct ManifestValidation {
struct ManifestExecutionHook {
// TODO(erc6900 spec): These fields can be packed into a single word
bytes4 executionSelector;
uint32 validationId;
uint32 entityId;
bool isPreHook;
bool isPostHook;
}
Expand Down
16 changes: 8 additions & 8 deletions src/interfaces/IValidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interface
import {IPlugin} from "./IPlugin.sol";

interface IValidation is IPlugin {
/// @notice Run the user operation validationFunction specified by the `validationId`.
/// @param validationId An identifier that routes the call to different internal implementations, should there
/// @notice Run the user operation validationFunction specified by the `entityId`.
/// @param entityId An identifier that routes the call to different internal implementations, should there
/// be
/// more than one.
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function validateUserOp(uint32 validationId, PackedUserOperation calldata userOp, bytes32 userOpHash)
function validateUserOp(uint32 entityId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
returns (uint256);

/// @notice Run the runtime validationFunction specified by the `validationId`.
/// @notice Run the runtime validationFunction specified by the `entityId`.
/// @dev To indicate the entire call should revert, the function MUST revert.
/// @param validationId An identifier that routes the call to different internal implementations, should there
/// @param entityId An identifier that routes the call to different internal implementations, should there
/// be
/// more than one.
/// @param sender The caller address.
/// @param value The call value.
/// @param data The calldata sent.
/// @param authorization Additional data for the validation function to use.
function validateRuntime(
uint32 validationId,
uint32 entityId,
address sender,
uint256 value,
bytes calldata data,
Expand All @@ -36,14 +36,14 @@ interface IValidation is IPlugin {

/// @notice Validates a signature using ERC-1271.
/// @dev To indicate the entire call should revert, the function MUST revert.
/// @param validationId An identifier that routes the call to different internal implementations, should there
/// @param entityId An identifier that routes the call to different internal implementations, should there
/// be
/// more than one.
/// @param sender the address that sent the ERC-1271 request to the smart account
/// @param hash the hash of the ERC-1271 request
/// @param signature the signature of the ERC-1271 request
/// @return the ERC-1271 `MAGIC_VALUE` if the signature is valid, or 0xFFFFFFFF if invalid.
function validateSignature(uint32 validationId, address sender, bytes32 hash, bytes calldata signature)
function validateSignature(uint32 entityId, address sender, bytes32 hash, bytes calldata signature)
external
view
returns (bytes4);
Expand Down
Loading

0 comments on commit 2aa4fc4

Please sign in to comment.