ERC-7741 · Draft · ERC · 2024-06-03
ERC-7741: Authorize Operator
Adds a signature-based authorizeOperator function, modeled on ERC-2612 permit, so users can grant or revoke an operator on vaults and similar contracts without sending a transaction themselves.
What problem does it solve?
Many contracts, including ERC-6909 multi-tokens and ERC-7540 asynchronous vaults, use an operator model: an owner calls setOperator(operator, true) and the operator can then act on the owner's behalf. That call is an on-chain transaction, so the owner needs native gas on every chain where they want to set an operator, and it cannot be bundled atomically with the operator's first action.
ERC-7741 lets the owner sign an EIP-712 message off-chain instead. Anyone (typically the operator or a relayer) submits it, which enables meta-transactions and one-step "authorize and act" flows, much like ERC-2612 permit does for ERC-20 allowances.
How it works
It applies to any contract with the operator interface:
event OperatorSet(address indexed owner, address indexed operator, bool approved);
function setOperator(address operator, bool approved) external returns (bool);
function isOperator(address owner, address operator) external returns (bool);
and adds:
authorizeOperator(owner, operator, approved, nonce, deadline, signature): must revert if the deadline passed, if the nonce was used, or if the signature is not a valid EIP-712 signature by the owner. On success it marks the nonce used, sets the operator status, emitsOperatorSetand returnstrue.invalidateNonce(nonce): lets the owner cancel a signed authorization before it is used.authorizations(owner, nonce): whether a nonce has been used.DOMAIN_SEPARATOR(): the EIP-712 domain, unique per contract and chain.
The main difference from ERC-2612 is that nonce is a bytes32 rather than a sequential uint256, so authorizations are unordered: several can be outstanding at once and used in any order. Contracts must report support via ERC-165 interface ID 0xa9e50872. The reference implementation also verifies contract-account signatures with ERC-1271.
Sample code
Signing an authorization off-chain (ethers v6). The type string matches the reference implementation's typehash:
import { Wallet, hexlify, randomBytes } from "ethers";
const domain = { name: "MyVault", version: "1", chainId: 1, verifyingContract: vaultAddr };
const types = {
AuthorizeOperator: [
{ name: "controller", type: "address" },
{ name: "operator", type: "address" },
{ name: "approved", type: "bool" },
{ name: "nonce", type: "bytes32" },
{ name: "deadline", type: "uint256" },
],
};
const value = {
controller: owner.address,
operator: relayerAddr,
approved: true,
nonce: hexlify(randomBytes(32)), // unordered nonce
deadline: Math.floor(Date.now() / 1000) + 600,
};
const signature = await owner.signTypedData(domain, types, value);
// Anyone can now submit it:
await vault.authorizeOperator(
value.controller, value.operator, value.approved, value.nonce, value.deadline, signature,
);
The domain name and version must match what the target contract uses in its DOMAIN_SEPARATOR.
Things to know
- Status is Draft: names and the interface ID may still change.
- Operators usually have broad power over the owner's positions. Keep
deadlineas short as feasible so a leaked, unused signature expires quickly, and useinvalidateNonceto cancel ones you no longer want. - The reference implementation in the spec is explicitly incomplete pseudocode; do not deploy it as-is.
- The spec notes parameter names are interchangeable (ERC-6909 says
spenderwhere others sayoperator).