ERC-1207 DAuth Permission Delegation Standard (DAuth Access Delegation Standard)
Stagnant · Accounts & wallets · created 2018-07-10
A standard that lets a smart contract delegate access to its own assets or data to another contract within a defined scope and time period, without handing over its private key.
Why it is needed
Existing smart contracts only assume a situation where a user signs directly with their own private key to call a function. If you want a repeated task like a token transfer or approval to be handled by another contract, such as an automation service, on the user's behalf, the only options were to obtain a signature every time or to hand over the private key, both of which carried heavy security risks and were cumbersome. On the web, OAuth solves this kind of delegation problem through a centralized server, but Ethereum has no common specification for delegating permissions between contracts, so every project had to build its own ad hoc workaround. DAuth fills this gap by providing a standard interface that lets a contract delegate only specific functions to another contract for a specific period, without a private key, and revoke that delegation at any time.
What to implement
struct AuthInfo { string[] funcNames; uint expireAt; }: A struct holding a user's permission information, including the list of functions the delegated contract can call and the expiration time.mapping(address => mapping(address => AuthInfo)) userAuth;: Maps a (grantor address, grantee contract address) pair to the corresponding permission information (AuthInfo).string[] callableFuncNames;: The full list of methods that other contracts are allowed to call.function updateCallableFuncNames(string _invokes) public returns (bool success);: The resource contract administrator updates the list of callable functions allowed for a client contract.function verify(address _authorizer, string _invoke) internal returns (bool success);: Checks whether a client contract has permission to call a specific function.function grant(address _grantee, string _invokes, uint _expireAt) public returns (bool success);: A user delegates access to their resources to a client contract.function regrant(address _grantee, string _invokes, uint _expireAt) public returns (bool success);: Changes an existing delegation for a client contract.function revoke(address _grantee) public returns (bool success);: Deletes a delegation for a client contract.event Grant(address _authorizer, address _grantee, string _invokes, uint _expireAt);: An event emitted when grant or regrant is processed successfully.event Revoke(address _authorizer, address _grantee);: An event emitted when a specific delegation is revoked successfully.
In depth
The AuthInfo struct and permission scope
AuthInfo consists of funcNames (the list of function names the delegated contract is allowed to call) and expireAt (an expiration timestamp in seconds). A single delegation is scoped so that it is valid only for specific functions and only until a specific point in time.
The userAuth mapping structure
userAuth has the form mapping(address => mapping(address => AuthInfo)), mapping a (grantor address, grantee contract address) pair to the corresponding AuthInfo object. This lets a single user grant different scopes of permission to multiple contracts independently.
The roles of callableFuncNames and verify
callableFuncNames is the full list of methods that other contracts are allowed to call. Per the specification, every callable function included in this list must verify the caller's permission. The internal verify function takes the authorizer's address and the name of the method being invoked (_invoke) to check permission, and must either return success or throw; no other outcome is allowed.
grant·regrant·revoke
grant (required) takes the _grantee address, a space-separated string of callable method names (_invokes), and an expiration time (_expireAt) to create a delegation, and must emit a Grant event on success. regrant (optional) changes an existing delegation using the same arguments. revoke (required) takes only the _grantee address and deletes that delegation, and must emit a Revoke event on success. For grant, verify, and revoke, no outcome other than returning success or throwing is allowed.
Callable functions implemented via an overload pattern
Every public/external function intended to support delegation must be implemented together as two overloaded versions. One is the standard method called directly by the user, and the other is a grantee-facing method with the same name plus an added authorizer address parameter. In the specification's approve example, the grantee-facing approve(_spender, _value, _authorizer) checks permission via verify(_authorizer, "approve") and then executes the internal _approve logic treating the authorizer as the caller.
Design rationale that differs from OAuth
According to the Rationale, because on Ethereum all storage is transparently public and msg.sender can be trusted, DAuth does not need to issue a separate access_token the way OAuth does. Instead, it only needs to record the fact of a user's grant as an (authorizer, grantee) pair, which the document explains makes the structure simpler and more trustworthy.
Proposal status
This ERC is in Stagnant status. It is a proposal that is no longer being actively discussed and has stalled, so it may be changed or may never be adopted.