ERC-6315 · Review · ERC · 2023-01-11
ERC-6315: ERC-2771 Namespaced Account Abstraction
Extends ERC-2771 meta-transactions so each forwarder gets its own namespace of addresses, letting recipient contracts accept any forwarder without having to trust it.
What problem does it solve?
With ERC-2771, a relayer submits a user's signed request through a Forwarder contract, which appends the real sender's address to the calldata. The Recipient contract reads that address as the user. This only works if the Recipient trusts the Forwarder: a malicious forwarder could append any address and act as anyone. So every recipient must keep an allow-list of forwarders.
ERC-6315 removes that trust requirement. Instead of believing a forwarder about who the user is, the recipient treats each user as an address inside that forwarder's namespace: the pair (forwarder, address). A bad forwarder can then only affect accounts in its own namespace, never real accounts or other forwarders' users.
How it works
Detecting a namespaced call. On every call, the Recipient makes a STATICCALL to isNamespacedTransaction() on msg.sender:
- reverts or returns
false: a normal call. Sender =msg.sender, forwarder = zero address. - returns
true: a namespaced call. Sender = the address extracted from calldata as in ERC-2771, forwarder =msg.sender.
Balances, approvals and ownership are then keyed by (forwarder, sender). The zero forwarder is the ordinary, non-namespaced world.
Namespaced function variants. Every Recipient function with an address parameter must get a twin with Namespaced appended, where each address becomes two: forwarder and address. With forwarder = zero, the twin must behave exactly like the original. For ERC-20:
function transferNamespaced(address toForwarder, address toAddress, uint256 amount);
function approveNamespaced(address spenderForwarder, address spenderAddress, uint256 amount);
function transferFromNamespaced(address fromForwarder, address fromAddress,
address toForwarder, address toAddress, uint256 amount);
Interface detection. Recipients must implement ERC-165. For each registered interface ID, they also register a second ID: the XOR of the selectors of its Namespaced functions.
Sample code
Resolving the caller inside a recipient:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface INamespacedForwarder {
function isNamespacedTransaction() external view returns (bool);
}
abstract contract NamespacedRecipient {
function _caller() internal view returns (address forwarder, address sender) {
if (msg.sender.code.length > 0) {
try INamespacedForwarder(msg.sender).isNamespacedTransaction() returns (bool ns) {
if (ns && msg.data.length >= 20) {
// ERC-2771: last 20 bytes of calldata are the original sender
return (msg.sender, address(bytes20(msg.data[msg.data.length - 20:])));
}
} catch {}
}
return (address(0), msg.sender);
}
}
A token would then store balances as mapping(address forwarder => mapping(address account => uint256)).
Things to know
- Status is Review: details may still change.
- The trust model flips. Recipients no longer need to trust forwarders, but users must trust the forwarder whose namespace holds their assets.
- The same EOA under two different forwarders is two different accounts, which wallets and explorers need to display clearly.
- Already-deployed contracts cannot gain this without redeployment or upgrade. Standards that adopt it should publish both interface IDs but must not put
Namespacedfunctions into their base interface. - Smart contract accounts under ERC-4337 are the more widely used route to gasless and abstracted accounts today.