How it works · Explanation
Engagement Registry
The Engagement Registry records three things about an ERC-8004 agent: the provider that runs it, the clients it works for and the period of each engagement, and where to find evidence about the runtime that holds its wallet key. A provider is recorded only with its own consent (its signature, or its own transaction), and an engagement only with the client’s. Engagements cannot be backdated and are never deleted; ending one only shortens it.
There is one registry per chain, bound at deployment to one Identity Registry. It has no owner, no administrator, no
upgrade path and no payable function. The interface in src/IEngagementRegistry.sol is a proposed extension to
ERC-8004, and this contract is its reference implementation. The rules it
enforces are the ones below and in the tests; the extension has not been submitted as an ERC yet, so the interface
may still change.
The registry is not deployed on any mainnet.
Interface
Section titled “Interface”A signed consent is an EIP-712 signature under the domain name EngagementRegistry, version 1, the chain id and
the registry’s address (DOMAIN_SEPARATOR()), over one of two types:
Provider(uint256 agentId,address provider,address owner,uint256 nonce,uint256 deadline)Engagement(uint256 agentId,address client,address provider,uint64 start,uint64 end,bytes32 termsHash,uint256 nonce,uint256 deadline)| Function | Who may call it | What it does |
|---|---|---|
setProvider(agentId, provider, nonce, deadline, signature) |
The agent’s owner or an approved address | Names the provider. It takes the provider’s Provider signature unless the provider is the caller, and deletes the agent’s runtime record |
unsetProvider(agentId) |
The provider, the owner or an approved address | Removes the provider record |
openEngagement(agentId, client, start, end, termsURI, termsHash, nonce, deadline, clientSignature) |
The agent’s current provider | Records an engagement and returns its id. It takes the client’s Engagement signature unless the client is the provider. A start of 0 means now, an end of 0 means open-ended |
endEngagement(engagementId) |
The client, the engagement’s provider, the current provider, the owner or an approved address | Sets the end to now, or to the start if the engagement has not begun |
setRuntime(agentId, evidenceType, measurement, evidenceURI, evidenceHash) |
The agent’s current provider | Records runtime evidence, bound to the agent’s current wallet |
Anyone can read:
| Function | Returns |
|---|---|
providerOf(agentId) |
The provider, or zero while another owner holds the agent |
getEngagement(engagementId) |
The stored engagement: agent, client, provider, start, end, openedAt and terms hash |
getAgentEngagements(agentId), getClientEngagements(client) |
Every engagement id of the agent or the client, oldest first |
isEngaged(agentId, client, timestamp) |
Whether an engagement of that client with that agent covers the time |
bindingOf(agentId) |
keccak256(abi.encode(chainid, identityRegistry, agentId, agentWallet)) |
runtimeOf(agentId) |
The evidence type, measurement, evidence hash, binding and time recorded, or empty values while the record does not apply |
nonceUsed(signer, nonce) |
Whether the signer’s nonce is spent |
getIdentityRegistry(), DOMAIN_SEPARATOR() |
The bound Identity Registry, and the EIP-712 domain separator |
The terms URI and the evidence URI are emitted and not stored, so readers take them from the events.
| Event | Emitted by | Indexed |
|---|---|---|
ProviderSet(agentId, provider, owner) |
setProvider |
All three |
ProviderUnset(agentId, provider, unsetBy) |
unsetProvider |
All three |
EngagementOpened(engagementId, agentId, client, provider, start, end, termsURI, termsHash) |
openEngagement, with the stored start |
engagementId, agentId, client |
EngagementEnded(engagementId, agentId, endedBy, end) |
endEngagement |
engagementId, agentId, endedBy |
RuntimeSet(agentId, provider, evidenceType, measurement, evidenceURI, evidenceHash, binding) |
setRuntime |
agentId, provider |
| Error | When |
|---|---|
NotAuthorized |
The caller may not make this call |
ZeroAddress |
A zero provider or client, an agent with no wallet in setRuntime, or a zero Identity Registry at deployment |
NoProvider |
The agent has no current provider |
InvalidSignature |
The signature is not the signer’s |
SignatureExpired |
The block’s time is past the signature’s deadline |
NonceUsed |
The signer has spent that nonce |
InvalidTerm |
The start is in the past, or the end is not after the start |
UnknownEngagement |
No engagement has that id |
AlreadyEnded |
The engagement has ended, or was ended before it began |
Invariants
Section titled “Invariants”The handler drives the registry and the Identity Registry with random sequences of calls. Each run starts with a signed provider and an open engagement on each of three agents. The handler names, replaces and removes providers; opens engagements with every kind of term; ends them; records evidence; and resubmits signatures that were already used. Signatures come in valid, forged, expired, high-s and wrong-length forms, and callers include owners, approved addresses, operators, providers, clients and strangers. Between those calls it transfers agents, changes approvals and wallets, switches a contract signer’s answer off and on, moves time forward and sends ether. Three calls in four are built to succeed, which gives every run records to check. The fourth draws each input from its full range, so every error keeps coming up.
Before each call the handler predicts the outcome from a ghost copy of the registry: success with its event, or the exact error. A call that reverts where success was predicted, succeeds where an error was predicted, or reverts with other data than the predicted error fails the run. After every call these hold:
- Engagement ids run 1, 2, 3 with no gaps. Each id appears exactly once, in order, in its agent’s list and in its client’s list. No id is reused and no engagement is deleted.
- A stored engagement never changes its
agentId,client,provider,start,openedAtortermsHash. endonly moves from zero, or from a later time, to an earlier or equal time.startis never beforeopenedAt, andendis zero or not beforestart.- A spent (signer, nonce) pair is never accepted again, and
nonceUsedmatches the ghost copy for every signer and nonce in play. providerOfis zero whenever the agent’s owner differs from the owner stored with the record, and is the stored provider otherwise.runtimeOfreturns empty values unless the record was written after the current provider was named, by that provider, and its binding is the current binding. Otherwise it returns the record exactly. Naming any provider, the same one included, deletes the record.isEngagedagrees with a brute-force scan of the ghost copy for every agent, every client and every boundary time.- The registry never holds ether.
A run of 100 calls averages about 16 provider changes, 15 engagements opened, 14 ended and 17 evidence records. At the end of each run the suite requires at least one of each and at least 20 writes in all, so a run in which the calls stop succeeding fails.
mutation-test.sh checks that the suites notice a wrong contract. In a scratch copy it makes 43 deliberate changes,
one at a time, and runs every suite against each: nonces not checked or not spent, signatures or deadlines not
checked, a deadline off by one, high s allowed, any ERC-1271 success accepted, backdating allowed, ids reused, an
engagement never stored, an end never written, an inclusive end, the wrong party allowed to end an engagement, remove
a provider or record evidence, evidence kept when a provider is named, runtimeOf ignoring its provider or its
binding, a fixed chain id, events with the wrong values, and a payable, delegating or self-destructing function added,
among others. Each change makes at least one test fail, and the script exits with an error if one does not.
Security notes
Section titled “Security notes”Replay. Every consent is an EIP-712 signature over a domain that names the chain id and this registry’s address, and the domain is recomputed on every call. A signature therefore does not work on another registry, on another chain, or after a fork changes the chain id. The two message types have different type hashes, and each carries the agent, the parties, a nonce and a deadline. The fuzz tests change each of those fields in turn and every change is refused.
Malleability. When the registry recovers a signature itself, it refuses a high s and any v other than 27 or
28. A malleated copy would be useless in any case, because the first use spends the nonce. For a contract signer,
including an EIP-7702 account, the registry passes the bytes through unchanged, and the account decides what to
accept.
ERC-1271. isValidSignature is called with STATICCALL, so the signer cannot write anything, including through
a call back into the registry (tested). A signer that reverts, returns fewer than 32 bytes, returns any other word or
burns all its gas is refused. A signer that returns huge data or burns gas costs only the sender of the transaction,
who chose to name that contract. The answer is read once, when the record is written, and changing it later changes
nothing stored.
EIP-7702. An account with delegated code is checked by ECDSA first, so its own key always works. If that check fails, the account’s code is asked. An account that delegates to code which accepts anything lets anyone sign for it. That is the account’s choice, as it is for any smart account.
Unbounded lists. isEngaged scans the agent’s list, and getAgentEngagements and getClientEngagements return
whole lists. Only the agent’s provider can add to an agent’s list. A client’s list grows only with that client’s
signature, or when a provider engages itself. A provider can bloat its own agent’s list with self-engagements at
about 212,000 gas each, and each one adds about 4,740 gas to isEngaged for that agent. Pushing that call past a
32 million gas limit takes about 6,750 engagements, roughly 1.4 billion gas or 0.03 ETH at the 0.02 gwei Robinhood
Chain charged in November 2026. The only party that loses is the one relying on that agent’s isEngaged. A contract that
treats a failed isEngaged as “not engaged” can be fooled by the agent’s own provider, so contracts should read one
engagement by id with getEngagement, and off-chain readers should index the events.
Stolen signatures. A provider’s signature can only be submitted by the agent’s owner or an approved address,
for that agent and that owner. Someone who copies it from the mempool and submits it first writes exactly the record
the owner was about to write, and the owner’s own transaction then fails with NonceUsed. A client’s signature can
only be submitted by the provider it names, for the agent it names. Either way the thief gains nothing and costs the
victim at most one failed transaction.
The Identity Registry. On Robinhood Chain it is an upgradeable (UUPS) proxy at
0x8004A169FB4a3325136EB29fA0ceB6D2e539a432. In November 2026 its upgrade rights sat with the address
0x547289319C3e6aedB179C0b8e8aF0B5ACd062603, which has no contract code, so a single key controls them. This
registry trusts it for owners, approvals and wallets. An upgrade could make any address the owner or an approved
address of any agent. That address could then name itself provider, open engagements with itself as client, record
evidence, remove provider records and end (shorten) any engagement. An upgrade could also retire every provider and
runtime record at once by changing what ownerOf or getAgentWallet return, bring old provider records back, or
make every read and write that consults it revert. Even then, ending by the client or the stored provider keeps
working, as do all reads of stored engagements. No upgrade can change a stored engagement except to shorten it,
delete one, backdate one, record a provider or client that did not sign, or reuse a nonce
(test_hostileIdentityUpgradeCannotRewriteRecordsOrForgeConsent).
Agents that do not exist. ownerOf reverts for an id that was never minted. Such an agent has no records, so
providerOf returns zero, runtimeOf returns empty values and setProvider reverts with the Identity Registry’s
error. The live Identity Registry cannot burn agents. If an upgrade added burning, a burned agent’s providerOf and
runtimeOf would revert while a record exists; its client and its stored provider could still end engagements, and
the provider could still remove itself.
Time. Times are uint64 seconds, which last until the year 584 billion. Past that, the registry refuses every
new engagement (tested). “No backdating” is measured against the block’s timestamp, which Robinhood Chain’s sequencer
sets within the rollup’s limits.
Ether. There is no payable function, receive or fallback, so any transfer of ether to the registry reverts.
Records that can come back. Naming a provider deletes the agent’s runtime record, so evidence recorded under one
provider never returns when that provider is named again; this costs setProvider about 11,000 gas. Two changes in
the Identity Registry cannot be seen from here. A provider record is suspended while another
owner holds the agent and applies again if the stored owner holds it again, so a provider that stops running a
transferred agent should call unsetProvider. Evidence is void while the agent’s wallet differs from the one it is
bound to and counts again if that wallet returns, so readers should treat any change of agentWallet after setAt
as retiring it.
For contributors
Section titled “For contributors”Layout
Section titled “Layout”| Path | What it holds |
|---|---|
src/EngagementRegistry.sol, src/IEngagementRegistry.sol |
The contract and its interface |
test/EngagementRegistry.t.sol |
Every rule of the interface and its reference values, 75 tests. It depends on nothing else in test/ |
test/EngagementRegistry.fuzz.t.sol |
47 fuzz tests, at least one for each external function |
test/EngagementRegistry.security.t.sol |
21 tests for the security notes above |
test/EngagementRegistry.invariant.t.sol |
The stateful invariant suite and its handler |
test/mocks/ |
An Identity Registry that answers like the one on Robinhood Chain, and ERC-1271 signers that misbehave in every way the tests need |
lib/forge-std/ |
forge-std v1.16.2, src/ only, under its MIT or Apache-2.0 licence |
.gas-snapshot |
forge snapshot output for the spec, fuzz and security suites |
mutation-test.sh |
Makes 43 deliberate changes to the contract, one at a time, and checks that each one makes a test fail |
Running the tests
Section titled “Running the tests”forge test # about 2 min: 1,024 runs per fuzz test, 256 invariant runs of 100 callsFOUNDRY_PROFILE=deep forge test # 20,000 runs per fuzz test, 1,024 invariant runs of 250 callsforge test --gas-reportforge snapshot --no-match-path test/EngagementRegistry.invariant.t.sol --fuzz-seed 0x5a -j 1 --check./mutation-test.sh # about 25 min: every deliberate change, each against every suiteFrom the repository root, npm run contracts:test runs forge test, and npm run abi rebuilds the contract and
regenerates src/abi. The snapshot covers the spec, security and fuzz suites. The fuzz statistics in it repeat
exactly with a fixed seed on one thread; more threads draw the inputs in a different order. The invariant suite
reports calls rather than gas and is left out.
Build and verification
Section titled “Build and verification”foundry.toml pins everything that reaches the compiler: solc 0.8.28, EVM target prague (forge’s default changes
between releases), the optimizer at 200 runs, no IR pipeline, and explicit remappings with auto-detection off (so a
library added to lib/ cannot change the metadata). The CBOR metadata stays in the bytecode with its IPFS hash
(bytecode_hash = "ipfs", cbor_metadata = true). Sourcify needs that hash for an exact match, and it changes only
when a source file or a pinned setting changes. src/abi/engagement-registry.bytecode.ts is byte for byte what
forge build produces; npm run abi regenerates it after any change to src/.
The runtime code uses PUSH0 and MCOPY. A read-only eth_call on Robinhood Chain in November 2026 showed that the chain
executes both.
Deploying
Section titled “Deploying”cd contracts && forge build && cd ..DEPLOY_RPC_URL=… DEPLOYER_KEY=… SHIPPED_MAINNET_GO=yes node ops/deploy-registry.tsOn every chain but an anvil node the script refuses to send without SHIPPED_MAINNET_GO=yes. It also refuses if
src/abi differs from the build in contracts/out, and if name() on the Identity Registry is not AgentIdentity.
After the deploy it checks that the registry is bound to the right Identity Registry and that the code at the new
address is the build’s runtime code with the Identity Registry address written into its immutable. It writes
contracts/deployments/4663.json (address, block, transaction, code hash, compiler, EVM target) and prints the
Sourcify command:
cd contracts && forge verify-contract --chain 4663 --verifier sourcify <address> \ src/EngagementRegistry.sol:EngagementRegistry --constructor-args <abi-encoded identity registry>The deploy was rehearsed on an anvil fork of Robinhood Chain against the live Identity Registry, with a throwaway key.
The script wrote deployments/local-4663.json (local records are gitignored) and its code check passed. A
separate solc --standard-json compile from the metadata alone produced byte-identical code and identical
metadata, and the CBOR in the deployed code carries the IPFS hash of that metadata, which is what Sourcify compares
for an exact match. Sourcify lists chain 4663 as supported.
Gas from transaction receipts on that fork. The figures include the 21,000 base cost; the L1 data fee on Robinhood Chain comes on top.
| Call | Gas |
|---|---|
| Deploy | 1,929,127 |
setProvider, signed by the provider |
119,999 |
setProvider, owner names itself |
91,260 |
setProvider, over a provider that had recorded evidence |
54,608 |
openEngagement, client’s first with this agent |
297,452 |
openEngagement, later ones |
246,267 |
openEngagement, provider as its own client |
212,120 |
setRuntime |
162,242 |
endEngagement |
35,669 |
unsetProvider |
27,073 |
isEngaged, per engagement in the agent’s list (cold read) |
about 4,740 |