Pre-ERC: Adoption Profile and Reference Kernel for EOAs Adopting Code via SETCODEFROM

Follow-up to the deposit points from @Zealynx (#17) and @Revinand (#18): I’ve opened a discussion in the OP specs repo, asking whether a deposit whose from holds regular code on L2 should fail once EIP-8298 is adopted (mint kept, nothing executed). Nothing is exploitable today; it’s a question about how a rollup would take 8298 on.

I’ll note any answer here.

PoC-1 is up: GitHub - nezu511/setcodefrom-adoption-poc · GitHub (commit 1ad1351). It runs the v2.7 migration guard and Route A (7702 + Migrator) on EELS, using the EIP-8298 and EIP-8151 implementations from execution-specs#3769 (CPerezz) and #3860, filled against two trees: EIP-8298 + EIP-8151, and EIP-8298 only. 246 tests pass on the first and 238 on the second (8 skipped, which only make sense once the migration completes).

What it shows:

  • With both EIPs, one type-4 transaction completes and emits Migrated; afterwards the old key’s ecrecover returns empty output and the new key validates.
  • Without EIP-8151, the same migration reverts at P4 and the account keeps its delegation to Migrator; the old key still works.
  • FM1, FM3, FM4, FM5 and FM6 each have tests. The guard adopting a self-recovering wallet is asserted too (“inputs, not quality”).

One gap in v2.7 itself: P3 only requires that the initialize call didn’t revert. Code whose fallback succeeds for every selector passes P1–P4 with nothing initialized, and without a further check the PoC’s Migrator completed the migration of such code and emitted Migrated. A Safe with no fallback handler set has the same shape, going by its source (the PoC doesn’t run Safe). The PoC now has Migrator require that R4’s record equals EXTCODEHASH(this) after initialize, and it refuses such code with NotInitialized. This is a v2.8 candidate and not in the posts yet, so P3 in the first post is weaker than it reads until I revise it. The check reads the record; it doesn’t judge the code.

Not covered: EIP-8141 (so no VERIFY, R2, FM2 or FM7), Route B, R4’s lock and R6. The PoC kernel is not conforming code. For Route B, finish is a separate contract and frames don’t pass return data, so the same check would need a getter on the account. Is a second interface on the account acceptable, or is there another way to check it?

Corrections welcome, especially where a test pins a choice the draft leaves open (the README lists them).

Agree the record check belongs in P3 for v2.8.

On Route B, I’d take the getter. One view that returns R4’s record is cheap, and wallets get the same check for simulation and for reading an account later. The other option I see is initialize calling MigrationCheck to mark itself done, but transient storage is gone by frame 4, so that needs a persistent slot in the guard and makes every conforming code call the guard during initialize. One extra view looks like the smaller cost.

Two details if you add it. Have finish read it with a STATICCALL, so it still writes nothing in the account. And it’s weaker than the slot read Migrator does in Route A, since the adopted code answers it itself. That’s fine for what P3 has to catch: a fallback that just succeeds doesn’t return the account’s own code hash, so finish still refuses it.

1 Like

For PoC-2, could the FM2 tests require a state-changing action authorized by the new key in a fresh transaction through the actual VERIFY or relay path? EIP-8141’s execution approval covers subsequent SENDER frames, so an action under the migration transaction’s original approval would not demonstrate that the adopted validator works.

A useful negative case would have registration and ERC-1271 succeed while the execution entry point fails. P1–P4 and the initialization-record check could pass, but the separate transaction would expose the unusable account. Could the wallet simulation requirement explicitly require this separate action and become a MUST before submitting an irreversible migration?

1 Like

Thanks @Zealynx, I’ll take the getter for Route B. In v2.8 it goes in the Route B details: finish calls initializedCodeHash() on the account with STATICCALL and requires 32 bytes of output equal to EXTCODEHASH(account). Otherwise it reverts, which undoes the adoption with the rest of the batch. The length check matters: a fallback that just succeeds returns nothing, and an assembly finish that skipped it would compare whatever its buffer held, the same trap as in P1.

On it being weaker than the slot read: agreed for code that lies, since it answers for itself, but that’s a question of which code hash the wallet offers, not something P3 can settle. For a stale record it’s the other way round. If an earlier delegate left the new code’s hash in R4’s slot, a permissive fallback passes Route A’s slot read, but has no getter to answer with. Route A will close that by also reading the slot before SETCODEFROM and requiring it to differ from the signed code hash. It won’t require the slot to be empty, since an earlier initialization can legitimately leave a different hash there.

For now only Route B needs the view; it’s still informative and needs ethereum/EIPs#12506. Whether the profile requires it of all adopted code will be settled before the conformance suite is published, since adding a requirement later would change the verdict on code hashes already checked. Wallets don’t need it either way: the slot is fixed, so they can read it directly with eth_getStorageAt.

Thanks @Revinand, yes to both.

PoC-2. The FM2 tests will send a fresh frame transaction in the next block, signed with the new key: its VERIFY frame has to approve, and a SENDER frame has to change state (a probe that records its caller). As you say, an action inside the migration transaction would prove nothing, since execution approval covers every later SENDER frame. Your negative case goes in as written: registration proofs and ERC-1271 pass but VERIFY doesn’t approve, so the migration emits Migrated and passes the record check, and the second transaction is invalid. I’ll add the case where VERIFY approves but the execution entry fails. EELS’s eips/bogota/eip-8298 and eip-8151 branches both build on the EIP-8141 branch, so PoC-2 will merge the two and run real frame transactions with all three EIPs. It also made me notice that “the new key validates” in my PoC post meant only that ERC-1271 accepts it.

Simulation as a MUST. Agreed, with two changes from the current text.

  • It has to bind the signed parts, not submission. In a sponsored migration the executor sends the outer transaction, so the wallet’s last irreversible act is handing over ownerSig and the 7702 authorization.
  • The separate transaction is signed with the real new key, so it must never reach a network, and it should be useless even if it does: after the real migration, one built the ordinary way would be valid on the real chain.

For v2.8:

Wallets MUST NOT let any signed part of a migration leave the wallet until a fork simulation passes: the whole migration, then a separate state-changing transaction authorized by the new key through VERIFY or the relay path. That transaction MUST stay in the wallet, be bound to the chain’s ID, and be one that chain can never include.

The details would go in the first reply. A pass means the second transaction is valid and every SENDER frame has status 1, or UserOperationEvent.success on a relay path, since handleOps doesn’t revert when the operation fails, plus the expected state change; ERC-1271 passing doesn’t count. One way to make it unincludable is to sign it with a legacy nonce of 2^63 and set the account’s nonce to that on the fork. On the real chain the account’s nonce grows by one per transaction or CREATE, so it can’t get there in practice, and the chain ID in the signature rules out other chains.

I’ve revised the first two posts (v2.8 in the edit history; the previous version is v2.7). Here is what changed and where it came from.

Layout

  • The first post now holds every MUST and definition, each under a stable number: R1–R9 for adopted code, V1–V4 for verifiers, M1–M7 for Migrator and MigrationCheck, W1–W16 for wallets. The first reply is split into sections S1–S16 that explain and hold only SHOULDs the first post points to; where the two differ, the first post is correct. Section numbers won’t change in later revisions.
  • Moved from the first post to the first reply: P1/P4 details (S3), Route A details other than the pseudo-code (S4), the typed-data notes (S2), the code and wallet SHOULDs (S8, S9, S10), bridge details (S14) and “where I looked” (S1). The EIP-8298 Security Considerations draft is gone from the first reply, since ethereum/EIPs#12564 merged it.

Typed data (S2). The type strings are now exact EIP-712 encodeType strings. v2.7 printed them with a space after each comma, which hash to different values; my PoC already used the exact form. Please copy the strings from the first post.

Type v2.7 (as printed) v2.8
Migration 0xd9df33a2… (with spaces) 0x88bf991d…
Registration 0x203bc3c8… (with spaces); 0x268a9e0b… (3 fields, exact) 0x0189d872… (adds verifierCodeHash)
RegistrationAnyChain – 0xfb677071… (chain-free, with deadline)

From this thread

  • @Zealynx (#12, #14, #17). verifierCodeHash in Registration, checked by initialize (R4). Registration proofs are chain-bound by default; the opt-in chain-free form RegistrationAnyChain carries a mandatory deadline (W11, S2). Q10 is settled. Arbitrum and Scroll are in S11. W11 now asks for a deadline the user has seen and accepted instead of the “finite” deadline I wrote in #19, since every uint256 is finite; its length stays a wallet matter.
  • @Revinand (#18, #24). The OP Stack ordering problem is W12 and S11. One change from my #20: the “retired” display no longer requires the L2 migration’s own block to have an L1 origin at or past M, but any later finalized block; a wallet that submitted before the origin reached M would otherwise show “pending” forever. What “retired” guarantees is unchanged. Simulation is now a MUST (W7), with a change from my #26 described below. Your regression test is in S11 and the nested-replacement test in S15.
  • @colinlyguo. Q1 and Q2 stay settled.

Simulation (W7, S9), changed from #26. The gate moves from “leave the wallet” to “sign with the old key”. Nothing the old key signs exists until the new key has acted, through VERIFY or the relay path, on the state the migration would leave; so “leave the wallet” needs no definition. The whole migration is no longer simulated first: what only that caught is now closed on-chain (Migrator checks its guard’s code, M5; initialize is all-or-revert and context-independent, R4) or by rule (the fork must apply the chain’s rules, W7). Simulating the whole migration stays as a SHOULD after signing (S9), which is also what catches Route B frames built outside the table.

From building PoC-1 (nezu511/setcodefrom-adoption-poc)

  • A missing guard passed silently. A call to an address without code succeeds, so on a chain with Migrator but no MigrationCheck, anyone could have migrated an account left delegated to Migrator, with an intent of their own. v2.8 has Migrator create its guard in its constructor, and migrate revert unless the address it recorded for the guard, the one it calls rather than p.check, holds code with the recorded hash (M5). Requiring code matters when runtime code is placed without its constructor: a compiler’s deployedBytecode leaves the immutables zero, and a plain hash comparison would then compare 0 with 0. Before signing, wallets compare both code hashes at a finalized block with values they have checked against M1–M7 (W8), and a chain that places the contracts without running their constructors must place the code the constructors would have returned (Preinstalls). In Route B the source now comes from the guard’s factory, so a missing guard reverts the adoption (W10, S5). Nothing was exploitable: EIP-8298 is live on no chain. The PoC fix is in commit 3a979bc.
  • P3 checks R4’s record (M7, announced in #22 and #25; PoC commits 1ad1351 and 43a0579): Migrator reads R4’s slot before SETCODEFROM and after initialize; Route B’s finish reads it through initializedCodeHash().

Route B is now marked provisional: its parts of M1, M7 and W10 may change with ethereum/EIPs#12506, which is still open.

Requirements that changed or were added (in short)

  • Typed data: keyHash is keccak256(key); scope bits other than 0x1 and 0x2 make initialize revert (new).
  • Terms: a registration proof is the key holder’s consent, not an authorization.
  • R4: the lock now comes first; “treats as authorities only what this initialization wrote” extends to modules, hooks, handlers and implementation targets; proofs are all-or-revert, and initialize installs the same authorities whatever the gas, value, ORIGIN, balance, block or foreign transient storage.
  • R5: new authorities get R4’s proof checks (verifier code hash, deadline).
  • R6: “a self-call” is gone from the allowed paths; with the outermost-call rule it could never succeed. The nesting count only sees frames of conforming code, and replacing non-conforming code is outside what the profile guarantees (S14).
  • R9 (new): outside a frame transaction, ORIGIN == ADDRESS carries no authority except for initialize (deposits).
  • V1–V4: the verifier rules, numbered; V4 (fixed scheme, empty return is failure) is new.
  • M1–M7: the guard’s behavior, numbered; M5 (stated as a property: the address it recorded for the guard, not p.check, holds code with the recorded hash) and M7 are new.
  • Preinstalls (new): a chain that skips the constructors places the code they would have returned, not a compiler’s deployedBytecode. A canonical deployment at a deterministic address will be published; Q12 now asks whether conformance should be limited to it.
  • W2 adds verifiers by code hash and R5/R6 changes; W5 (control from on-chain state), W6 (checked code hashes only), W7 (simulation, MUST), W8 (compare both code hashes at a finalized block with values checked against M1–M7; no chain ID 0, both MUST), W9, W10, W11, W12, W13, W14, W15, W16 are new; the former SHOULDs they replace are gone.
  • Q14 (seal for unused chains) is in S16.

The sections of the first reply can be linked directly, e.g. S9.