ERC-927 · Stagnant · ERC · 2018-03-12
ERC-927: Generalised authorisations
A proposed single authorization interface, canCall(owner, caller, callee, func), that any contract could use instead of reinventing ERC-20 approvals or ERC-777 operators. Stagnant.
What problem does it solve?
Many contracts let a third party act on a user's behalf. Examples include ERC-20 approve/transferFrom, ERC-777 operators, and ENS name controllers. Each standard designed its own version of this "Alice lets Bob do X" pattern. The versions are incompatible with each other, and users have to manage permissions separately in every contract.
ERC-927, by Nick Johnson, proposes one generic mechanism that all such contracts could share. It is inspired by DappHub's ds-auth and by OAuth.
How it works
Authorizations are stored by a per-user provider contract. Users register their provider in the address-metadata registry from ERC-926, which lives at a well-known address. The provider answers one question:
function canCall(address owner, address caller, address callee, bytes4 func)
external view returns (bool);
| Parameter | Meaning |
|---|---|
owner |
The user whose resource is being acted on. An approved call is treated as made by this address. |
caller |
Who is making the call right now (msg.sender). |
callee |
The contract being called, such as the token. |
func |
The 4-byte selector of the function being called. |
Flow: when Bob calls transferFrom(alice, ...) on a token, the token looks up Alice's provider in the ERC-926 registry. It then calls canCall(alice, bob, address(this), msg.sig) and reverts if the answer is false.
Providers should also offer a standard way to manage permissions:
function authoriseCaller(address owner, address caller, address callee, bytes4 func);
function revokeCaller(address owner, address caller, address callee, bytes4 func);
func == 0 means "all functions on callee". Only the owner, or someone the owner has authorized, may change the owner's settings.
Sample code
How a token might check permission before acting for someone else (illustrative):
interface IMetadataRegistry { function provider(address addr) external view returns (address); }
interface IAuthProvider {
function canCall(address owner, address caller, address callee, bytes4 func) external view returns (bool);
}
modifier authorised(address owner) {
if (msg.sender != owner) {
address p = REGISTRY.provider(owner); // ERC-926 lookup
require(p != address(0) &&
IAuthProvider(p).canCall(owner, msg.sender, address(this), msg.sig),
"not authorised");
}
_;
}
function transferFrom(address from, address to, uint256 v) external authorised(from) { /* ... */ }
Things to know
- This proposal is Stagnant and was never adopted. Its dependency ERC-926 is Stagnant too, and no registry or provider became standard.
- The spec has no reference implementation ("Example implementation TBD"). The
provider(address)lookup shown above is the registry function defined in ERC-926.REGISTRYstands for the registry's well-known address, which the spec does not give. - Permissions are per function selector, not per amount. On its own it cannot express "Bob may spend up to 100 tokens" the way an ERC-20 allowance does.
- In practice, the ecosystem moved toward signature-based approvals (ERC-2612 permit) and smart-contract accounts with their own permission modules, rather than one global authorization registry.