ERC-7884 Write Redirection Router (Operation Router)
Draft · Other · created 2025-01-23
A protocol by which a smart contract, upon receiving a write request, announces in a standardized way that the handling of that request should be delegated to L1, to another contract on an L2 chain, or to an off-chain server.
Why it is needed
As the Ethereum ecosystem grows, data increasingly needs to be split across multiple locations such as L1, L2, and off-chain databases. Without a common way to indicate which write requests should go where, each contract handles this differently, and wallets or clients cannot automatically recognize and process it. There is also no standard way to authenticate that a request delegating storage off-chain really came from a legitimate user, forcing each service to build its own authentication scheme, which is inefficient.
What to implement
error FunctionNotSupported();: An error raised when getOperationHandler receives an encoded function call it cannot handle.error OperationHandledOnchain( uint256 chainId, address contractAddress );: An error indicating that a write operation must be handled by a designated contract on L1 or on a specific L2 chain.struct DomainData { string name; string version; uint64 chainId; address verifyingContract; }: A struct defining the domain for an EIP-712 typed signature, containing the contract name, version, chain ID, and the address of the contract the signature targets.struct MessageData { bytes data; address sender; uint256 expirationTimestamp; }: The message context for off-chain storage authentication, containing the original ABI-encoded function call, the requester's address, and an expiration time.error OperationHandledOffchain( DomainData sender, string url, MessageData data );: An error indicating that a write operation must be handed off to an off-chain entity, carrying EIP-712 domain information, the URL to request, and a message containing the authentication context.function getOperationHandler(bytes calldata encodedFunction) external view;: A view function that takes an ABI-encoded function call and determines the appropriate handler to process it.
In depth
A Structure That Uses revert as a Return Value
Although getOperationHandler is a view function, it conveys information not through an actual return value but by always reverting with an error. If the function is unsupported, it reverts with FunctionNotSupported; if a handling location exists, it reverts with OperationHandledOnchain or OperationHandledOffchain. The client wraps this call in a try/catch and reads the type and arguments of the reverted error to decide the next action. This applies the same pattern used in CCIP-Read (ERC-3668) to write operations.
On-chain Routing: OperationHandledOnchain
Used when a request must be handled by a contract on L1 itself or on another L2 chain. Only two values are returned, chainId and contractAddress, and the client uses this information to connect to that chain and send the actual write transaction to that contract. In the implementation example, when the selector is setAddress(bytes32,address), it routes to chain ID 10 (L2) and a specific address.
Off-chain Routing: OperationHandledOffchain and Authentication
When routing to an off-chain database, DomainData (the EIP-712 domain), url (the address to request), and MessageData (the original encoded data, the requester's address, and expiration time) are all returned together. The client signs this MessageData using EIP-712 and sends the request to that URL. The HTTP request path follows the /{sender}/{data}.json format used by ERC-3668, so the API behaves as if it were a contract.
Limitations with multicall
Because getOperationHandler determines the destination by looking at only a single encoded function it is given, transactions that need to go to different contracts at once, such as those bundled together via multicall, cannot be processed in a single call. In such cases, getOperationHandler must be called first for each call to determine its destination, and then the actual transactions must be sent sequentially to those destinations.
Backward compatibility
This standard adds only new interfaces that do not conflict with existing interfaces, uses only view functions for information queries, and can be implemented alongside existing storage methods, making it fully backward compatible.
Proposal status
This ERC is currently in Draft status, a proposal whose content may still change or be discussed further.
Things to watch out for
- Signature verification by the off-chain handler: The off-chain handler must verify the EIP-712 signature.
- Implementing access control: The off-chain handler must implement appropriate access control.
- Handling concurrent modifications: The off-chain handler must safely handle concurrent incoming modification requests.
- Request rate limiting and transport security: The off-chain handler must apply rate limiting to requests and use secure transport such as HTTPS for communication.
- Monitoring for anomalous patterns: It must monitor for abnormal patterns that could indicate an attack and implement appropriate error handling for failed transactions.