ERC-5050 NFT Interaction Action Protocol (Interactive NFTs with Modular Environments)
Stagnant · NFTs & multi-token · created 2021-04-18
This standard defines a common messaging format for exchanging user initiated "actions" between tokens such as NFTs, making it possible for anyone to build interoperable, game like logic in which tokens interact with each other and share state.
Why it is needed
Token standards such as EIP-721 and EIP-1155 only express ownership, and do not define how to transmit or process interactions between tokens, such as attacks, duels, or combinations. As a result, every game or digital identity project that wanted to implement inter-token interactions had to build actions in its own way, and wallets or aggregation services had no way to automatically discover which contracts supported which interactions. In addition, when an interaction required shared state, such as hit points in a combat game, there was no standardized way to decide which contract would manage that state or how both sides could verify it in a trustworthy way, forcing each project to design this from scratch.
What to implement
function sendAction(Action memory action) external payable;: Sends the specified Action to the intended recipient. The sending contract's address and msg.sender are automatically set as the action's sender information.function isValid(bytes32 _hash, uint256 _nonce) external returns (bool);: Checks whether an action is valid using its hash and nonce. When an action passes through the sending, receiving, and state contracts, the state contract uses this function to request verification from the sending contract.function sendableActions() external view returns (string[] memory);: Returns, as a string, the list of actions this contract can send. Off-chain services use this to query supported features.function setApprovalForAllActions(address _operator, bool _approved) external;: Grants or revokes permission for a third party (operator) to perform all actions on behalf of msg.sender.function getApprovedForAction(address _account, bytes4 _action) external view returns (address);: Queries the approved address for a specific account-action combination. Returns the zero address if none is approved.function isApprovedForAllActions(address _account, address _operator) external view returns (bool);: Checks whether a specific address is an approved operator allowed to perform all actions on behalf of an account.function onActionReceived(Action calldata action, uint256 _nonce) external payable;: The function by which the receiving contract and the state contract process a received action.function receivableActions() external view returns (string[] memory);: Returns, as a string, the list of actions this contract can receive.function interfaceURI(bytes4 _action) external view returns (string);: Returns a custom user interface URI for a specific action (Interactive extension).function setControllerApproval(address _controller, bytes4 _action, bool _approved) external;: Approves or revokes a controller that can skip the EIP-5050 verification process and force processing for a specific action.function setControllerApprovalForAll(address _controller, bool _approved) external;: Approves or revokes a controller that can force process all actions without going through the verification process.function isApprovedController(address _controller, bytes4 _action) external view returns (bool);: Checks whether a specific address is an approved controller for the given action.
In depth
The Action struct and how it is sent
The Action struct consists of selector (bytes4(keccak256(action_key))), user (sender address), from/to (Object struct: _address and _tokenId), state (state contract address), and data (free form bytes). When sendAction() is called, fromContract is automatically filled with the sending contract's address (address(this)), and the from field is filled with msg.sender. The action starts at the sending contract and is passed in order to the contract specified by to, and then, if specified, to the state contract.
Hash and nonce based verification
When an action passes through all three contracts, fromContract, to, and state, the state contract requests verification from the sending contract via isValid(hash, nonce). Before starting to process the action, the sending contract computes a hash of the action that includes the nonce and records it in storage, and the state contract computes the same hash from the action it received and checks it along with the nonce. This approach was chosen instead of a signed message to avoid both the UX burden of requiring the user to perform a separate signature and a separate transaction submission, and the gas cost of signature verification.
A design that treats the sending token as a trusted party
This standard openly acknowledges the limitation that, aside from tx.origin, the receiving and state contracts have no way to directly verify the sending account. Instead, it treats the sending contract (token) as the "prime mover," leaving it up to the receiving contract's policy to decide which actions to accept and how to process them. High value actions can be restricted in the state contract based on reputation, or access can be limited with allow/deny lists, and the Controllable extension allows a trusted controller to process the action chain on the sender's behalf instead.
The role of the State Contract
Using a state contract for an action is not mandatory; between token contracts, or between a user and a single token contract, each side only needs to manage its own state. On the other hand, specifying a state contract allows arbitrary sending and receiving contracts to share a single state environment designated by the user. Each Object can have its own action processing logic, but final confirmation of an action must always be handled by the state contract, making the state contract the "source of truth." A receiving contract can force the use of a specific state contract, provide a default that the token holder can change, or use it as a bridge connected to a state contract on another chain.
Action naming convention and selectors
Actions are advertised as human readable strings (e.g. "spells.cast"), while actual processing uses a selector obtained by taking the keccak256 hash of that string and using its first 4 bytes. A dot (.) separates namespaces (e.g. the "cast" action in the "spells" namespace), and an arrow (>) specifies ordering (e.g. "settle>build" means settle must be received before build). sendableActions() and receivableActions() return this list of strings so that off-chain services can parse supported features.
The Controllable extension
The Controllable extension allows a trusted controller address to force action processing while bypassing EIP-5050's standard validity checks. setControllerApproval()/setControllerApprovalForAll() approve a controller for a specific action or for all actions; a contract that supports a controller must ignore validation related require/revert statements and must not pass the action on to the next contract in the chain. This can be used for backward compatibility with existing, non-upgradeable deployed contracts, or for cross-chain action bridging.
Backward compatibility and metadata updates
Token contracts that are already deployed and cannot be upgraded are incompatible with this standard unless they use the proxy registry extension. The proxy can be implemented by adapting the EIP-1820 registry so that the EIP-173 contract owner can call setManager(). In addition, an NFT whose metadata changes as a result of an interaction can also implement the EIP-4906 event emitter to announce the change.
A proposal still stalled
This ERC's status is Stagnant, meaning the proposal is no longer actively progressing. Its content may change or may never be adopted.
Things to watch out for
- Cannot natively verify sender identity: Because actions are passed from one contract to another, the receiving contract has no way to verify on-chain whether the entity that called the sending contract actually matches the action.from address.
- Design limitation of using hash verification instead of signatures: To remove the burden of requiring users to produce a signature and send a transaction for every single action, this protocol uses hash-based verification instead of signed messages. This design assumes the sending contract (the token) is a trusted party and does not strictly verify user identity.