ERC-7710 Smart Contract Delegation

Draft · Accounts & wallets · created 2024-05-20

Defines a common interface for delegating authority to a smart contract or EOA and for using that delegation. A single signature can create a delegation with a defined policy scope, allowing another party to act on the user's behalf without repeated signing.

Why it is needed

Today, for one contract to use another contract's functionality or to split up permissions, the permissions must either be hardcoded into the code in advance or a separate intermediary contract dedicated to that one task must be built. This makes development more complex, takes more time, and increases the gas cost of deployment and execution. Once such a permission structure is set, it is hard to change to meet new requirements, and it is also difficult to dynamically grant only a limited set of permissions. From the user's perspective, having to sign a message every time they interact is a significant inconvenience for apps that are used frequently or need to run automatically. This standard aims to let a single signature create a long-lived session and policy-limited delegation, reducing the number of user interactions while keeping the meaning of each interaction clear.

In depth

Five Roles

The Delegator is the smart contract that can create delegations. The Delegation Manager is the contract that verifies a delegation's authority and calls the delegator to execute the action; it implements the ERC7710Manager interface. Multiple delegation managers with different implementations can exist, and a contract account can even be its own delegation manager. A delegation is the granting of authority to another address to perform a specific action. The delegate is the smart contract, smart contract account, or EOA that has the right to use the delegation, and the redeemer is the delegate that is actually using the delegation.

Parameters of redeemDelegations and Atomicity

The delegation manager must implement redeemDelegations. _permissionContexts is an array of bytes containing the authority to execute a specific action on behalf of the delegator, and its internal structure is defined by the delegation manager implementation. _modes and _executionCallDatas are arrays of mode and executionCalldata as defined in the Execution Behavior section of ERC-7579. mode encodes the execution style, such as a single call or a batch call, and executionCallData encodes the execution data, which typically includes the target, value, and to address. The three arrays must be interpreted as a list of (_permissionContexts[i], _modes[i], _executionCallDatas[i]) tuples, and must revert if the array lengths differ. Each tuple represents one delegation redemption, and the implementation must guarantee atomicity across the batch.

Why No Specific Interface Is Required of the Delegator

The previous version of the spec defined an action as an Action tuple of (target, value, data), and required the delegator to implement an execution interface called executeDelegatedAction(Action _action) that the delegation manager would call. This approach was incompatible with existing smart accounts unless they happened to implement that interface, and since Action could only encode a single call, complex executions such as batching, delegatecall, or CREATE2 were not possible. For this reason, the current spec requires no specific interface of the delegator at all. Instead, it relies on the delegation manager calling the delegator correctly, and on the delegator constructing _permissionContexts only for delegation managers it knows will call it correctly. The execution interface adopted here is the one from ERC-7579, which solved a similar problem for modular smart accounts.

Obtaining a Delegation Is Out of Scope

The process by which a delegate obtains a delegation is deliberately left out of scope for this ERC. This ERC only covers the interface for using a delegation and the verification of delegated authority. The way delegations are requested and issued can be implemented in various ways depending on the use case, for example using another protocol such as ERC-7715. Separating these concerns keeps the way delegations are created flexible while keeping the interface for using delegations consistent. This proposal is also compatible with ERC-4337, but ERC-4337 is not required for implementation.

Checking Authority via Simulation

This interface has no separate method for querying delegated authority. Instead, a dApp SHOULD simulate a call to redeemDelegations with the intended parameters before executing the action, and use the result to determine whether the delegation will succeed. If the simulation fails, the user can be asked for new or renewed permissions. This approach provides a stronger guarantee than having a query method on the delegation manager, because it verifies the entire execution context rather than simply trusting a claim made by the delegation manager.

Reference implementation

A minimal reference implementation focused on delegation usage is provided as Example7710Manager. A full delegation manager reference implementation, the MetaMask Delegation Framework, includes features such as EIP-712 signature verification for delegations, support for both EOA signatures and contract signatures (ERC-1271), caveat enforcement for granular delegation control, batch delegation processing, and delegation revocation mechanisms. It demonstrates one way to build a robust delegation system while adhering to this standard's interface requirements.

Still in draft stage

This proposal is in Draft status, so its content may change going forward. The Security Considerations section also still carries a note that further discussion is needed, so it is advisable to check the latest version before implementing.

Things to watch out for

Original ERC · ← ERCs