Skip to content

Commit

Permalink
Update ERC-6900: spec update 6
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
fangting-alchemy authored Dec 1, 2023
1 parent a42f510 commit 4f6d6ad
Showing 1 changed file with 76 additions and 37 deletions.
113 changes: 76 additions & 37 deletions ERCS/erc-6900.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Each step is modular, supporting different implementations for each execution fu

**Modular Smart Contract Accounts** **MAY** implement

- `IPluginLoupe.sol` to support visibility in plugin configuration on-chain.
- `IAccountLoupe.sol` to support visibility in plugin configuration on-chain.

**Plugins** **MUST** implement

Expand Down Expand Up @@ -123,8 +123,14 @@ interface IPluginManager {
uint8 postExecHookFunctionId;
}
event PluginInstalled(address indexed plugin, bytes32 manifestHash);
event PluginUninstalled(address indexed plugin, bytes32 manifestHash, bool onUninstallSucceeded);
event PluginInstalled(
address indexed plugin,
bytes32 manifestHash,
FunctionReference[] dependencies,
InjectedHook[] injectedHooks
);
event PluginUninstalled(address indexed plugin, bool indexed callbacksSucceeded);
/// @notice Install a plugin to the modular account.
/// @param plugin The plugin to install.
Expand Down Expand Up @@ -168,29 +174,29 @@ Standard execute functions SHOULD check whether the call's target implements the
**If the target is a plugin, the call SHOULD revert.** This prevents accidental misconfiguration or misuse of plugins (both installed and uninstalled).

```solidity
struct Execution {
struct Call {
// The target contract for account to execute.
address target;
// The value for the execution.
// The value for the call.
uint256 value;
// The call data for the execution.
// The call data for the call.
bytes data;
}
interface IStandardExecutor {
/// @notice Standard execute method.
/// @dev If the target is a plugin, the call SHOULD revert.
/// @param target The target contract for account to execute.
/// @param value The value for the execution.
/// @param data The call data for the execution.
/// @param value The value for the call.
/// @param data The call data for the call.
/// @return The return data from the call.
function execute(address target, uint256 value, bytes calldata data) external payable returns (bytes memory);
/// @notice Standard executeBatch method.
/// @dev If the target is a plugin, the call SHOULD revert.
/// @param executions The array of executions.
/// @param calls The array of calls.
/// @return An array containing the return data from the calls.
function executeBatch(Execution[] calldata executions) external payable returns (bytes[] memory);
function executeBatch(Call[] calldata calls) external payable returns (bytes[] memory);
}
```

Expand Down Expand Up @@ -220,40 +226,63 @@ interface IPluginExecutor {
}
```

#### `IPluginLoupe.sol`
#### `IAccountLoupe.sol`

Plugin inspection interface. Modular Smart Contract Accounts **MAY** implement this interface to support visibility in plugin configuration on-chain.

```solidity
// Treats the first 20 bytes as an address, and the last byte as a function identifier.
type FunctionReference is bytes21;
interface IPluginLoupe {
// Config for a Plugin Execution function
interface IAccountLoupe {
/// @notice Config for an execution function, given a selector
struct ExecutionFunctionConfig {
address plugin;
FunctionReference userOpValidationFunction;
FunctionReference runtimeValidationFunction;
}
/// @notice Pre and post hooks for a given selector
/// @dev It's possible for one of either `preExecHook` or `postExecHook` to be empty
struct ExecutionHooks {
FunctionReference preExecHook;
FunctionReference postExecHook;
}
/// @notice Gets the validation functions and plugin address for a selector
/// @dev If the selector is a native function, the plugin address will be the address of the account
/// @param selector The selector to get the configuration for
/// @return The configuration for this selector
function getExecutionFunctionConfig(bytes4 selector) external view returns (ExecutionFunctionConfig memory);
/// @notice Gets the pre and post execution hooks for a selector
/// @param selector The selector to get the hooks for
/// @return The pre and post execution hooks for this selector
function getExecutionHooks(bytes4 selector) external view returns (ExecutionHooks[] memory);
/// @notice Gets the pre and post permitted call hooks applied for a plugin calling this selector
/// @param callingPlugin The plugin that is calling the selector
/// @param selector The selector the plugin is calling
/// @return The pre and post permitted call hooks for this selector
function getPermittedCallHooks(address callingPlugin, bytes4 selector)
external
view
returns (ExecutionHooks[] memory);
function getPreUserOpValidationHooks(bytes4 selector) external view returns (FunctionReference[] memory);
function getPreRuntimeValidationHooks(bytes4 selector) external view returns (FunctionReference[] memory);
/// @notice Gets the pre user op and runtime validation hooks associated with a selector
/// @param selector The selector to get the hooks for
/// @return preUserOpValidationHooks The pre user op validation hooks for this selector
/// @return preRuntimeValidationHooks The pre runtime validation hooks for this selector
function getPreValidationHooks(bytes4 selector)
external
view
returns (
FunctionReference[] memory preUserOpValidationHooks,
FunctionReference[] memory preRuntimeValidationHooks
);
/// @notice Gets an array of all installed plugins
/// @return The addresses of all installed plugins
function getInstalledPlugins() external view returns (address[] memory);
}
```
Expand Down Expand Up @@ -379,11 +408,6 @@ enum ManifestAssociatedFunctionType {
PRE_HOOK_ALWAYS_DENY
}
struct ManifestExecutionFunction {
bytes4 selector;
string[] permissions;
}
// For functions of type `ManifestAssociatedFunctionType.DEPENDENCY`, the MSCA MUST find the plugin address
// of the function at `dependencies[dependencyIndex]` during the call to `installPlugin(config)`.
struct ManifestFunction {
Expand All @@ -403,41 +427,56 @@ struct ManifestExecutionHook {
ManifestFunction postExecHook;
}
struct PluginManifest {
struct ManifestExternalCallPermission {
address externalAddress;
bool permitAnySelector;
bytes4[] selectors;
}
struct SelectorPermission {
bytes4 functionSelector;
string permissionDescription;
}
/// @dev A struct holding fields to describe the plugin in a purely view context. Intended for front end clients.
struct PluginMetadata {
// A human-readable name of the plugin.
string name;
// The version of the plugin, following the semantic versioning scheme.
string version;
// The author field SHOULD be a username representing the identity of the user or organization
// that created this plugin.
string author;
// String desciptions of the relative sensitivity of specific functions. The selectors MUST be selectors for
// functions implemented by this plugin.
SelectorPermission[] permissionDescriptors;
}
/// @dev A struct describing how the plugin should be installed on a modular account.
struct PluginManifest {
// List of ERC-165 interfaceIds to add to account to support introspection checks.
bytes4[] interfaceIds;
// If this plugin depends on other plugins' validation functions and/or hooks, the interface IDs of
// those plugins MUST be provided here, with its position in the array matching the `dependencyIndex`
// members of `ManifestFunction` structs used in the manifest.
bytes4[] dependencyInterfaceIds;
// Execution functions defined in this plugin to be installed on the MSCA.
ManifestExecutionFunction[] executionFunctions;
// Native functions or execution functions already installed on the MSCA that this plugin will be
// able to call.
bytes4[] executionFunctions;
// Plugin execution functions already installed on the MSCA that this plugin will be able to call.
bytes4[] permittedExecutionSelectors;
// External contract calls that this plugin will be able to make.
bool permitAnyExternalContract;
// Boolean to indicate whether the plugin can call any external contract addresses.
bool permitAnyExternalAddress;
// Boolean to indicate whether the plugin needs access to spend native tokens of the account.
bool canSpendNativeToken;
ManifestExternalCallPermission[] permittedExternalCalls;
ManifestAssociatedFunction[] userOpValidationFunctions;
ManifestAssociatedFunction[] runtimeValidationFunctions;
ManifestAssociatedFunction[] preUserOpValidationHooks;
ManifestAssociatedFunction[] preRuntimeValidationHooks;
ManifestExecutionHook[] executionHooks;
ManifestExecutionHook[] permittedCallHooks;
}
```

### Expected behavior
Expand Down Expand Up @@ -474,7 +513,7 @@ The function MUST store the plugin's permitted function selectors and external c
The function MUST parse through the execution functions, validation functions, and hooks in the manifest and add them to the modular account after resolving each `ManifestFunction` type.

- Each function selector MUST be added as a valid execution function on the modular account. If the function selector has already been added or matches the selector of a native function, the function SHOULD revert.
- If an associated function that is to be added already exists, the function SHOULD revert.
- If a validation function is to be added to a selector that already has that type of validation function, the function SHOULD revert.

Next, the function MUST call the plugin's `onInstall` callback with the data provided in the `installData` parameter. This serves to initialize the plugin state for the modular account. If `onInstall` reverts, the `installPlugin` function MUST revert.

Expand All @@ -493,11 +532,11 @@ The function MUST revert if the plugin is not installed on the modular account.
The function SHOULD perform the following checks:

- Revert if the hash of the manifest used at install time does not match the computed Keccak-256 hash of the plugin's current manifest. This prevents unclean removal of plugins that attempt to force a removal of a different plugin configuration than the one that was originally approved by the client for installation. To allow for removal of such plugins, the modular account MAY implement the capability for the manifest to be encoded in the config field as a parameter.
- Revert if there is at least 1 other installed plugin that depends on execution functions, validation functions, or hooks added by this plugin. Plugins used as dependencies must not be uninstalled while dependent plugins exist.
- Revert if there is at least 1 other installed plugin that depends on validation functions or hooks added by this plugin. Plugins used as dependencies must not be uninstalled while dependent plugins exist.

The function SHOULD update account storage to reflect the uninstall via inspection functions, such as those defined by `IPluginLoupe`. Each dependency's record SHOULD also be updated to reflect that it has no longer has this plugin as a dependent.
The function SHOULD update account storage to reflect the uninstall via inspection functions, such as those defined by `IAccountLoupe`. Each dependency's record SHOULD also be updated to reflect that it has no longer has this plugin as a dependent.

The function MUST remove records for the plugin's dependencies, injected permitted call hooks, permitted function selectors, and external contract calls. The hooks to remove MUST be exactly the same as what was provided during installation. It is up to the implementing modular account to decide how to keep this invariant. The config parameter field MAY be used.
The function MUST remove records for the plugin's dependencies, injected permitted call hooks, permitted function selectors, and permitted external calls. The hooks to remove MUST be exactly the same as what was provided during installation. It is up to the implementing modular account to decide how to keep this invariant. The config parameter field MAY be used.

The function MUST parse through the execution functions, validation functions, and hooks in the manifest and remove them from the modular account after resolving each `ManifestFunction` type.

Expand Down Expand Up @@ -550,7 +589,7 @@ No backward compatibility issues found.

## Reference Implementation

See `https://github.com/alchemyplatform/ERC-6900-Ref-Implementation`
See `https://github.com/erc6900/reference-implementation`

## Security Considerations

Expand Down

0 comments on commit 4f6d6ad

Please sign in to comment.