A plausible, much faster path towards PQ-EL key rotation exists. And here's what it'll cost us

A deep analysis of SETCODEFROM vs. key rotation embedded within frames.

Thanks to Ben, Colin, Jochem and Toni for the discussions on this topic that lead here

I’m one of the four authors of SETCODEFROM, and for months I’ve argued that it’s how an Ethereum account should leave its ECDSA key behind: what it opens up, what it has to be careful with, what it leaves in client databases. This post is about why I’m now deeply reconsidering its inclusion in Hegotá, the fork after Glamsterdam, where frame transactions are scheduled and SETCODEFROM is only being considered.

Toni Wahrstätter has proposed something much smaller: let an EOA swap its key for a post-quantum one inside a frame transaction, with no wallet contract involved. I’ll call it set-key, after the operation it adds. It looks like a plausible, much faster path to post-quantum keys on the execution layer (PQ-EL), and it’s the reason I’m reconsidering. This is where I stand today. It isn’t a position of the EIP’s authors, and at least one of them wants SETCODEFROM in the fork.

The core argument I make is in the section What it’ll cost us. The sections before it explain how the two proposals work.

The problem: one address, one key

Figure 1: an EOA’s address comes from one secp256k1 key that it can’t change, and that key does three jobs. A post-quantum migration has to keep the address and take those jobs away from the key.

Everything you own on Ethereum points at an address, and an EOA’s address is derived from one secp256k1 key that it can never change. A quantum computer that computes that key from the public key gets all of it. Nobody knows when such a machine will exist, but moving every account takes years, so the way out has to ship long before. The job is narrow: keep the address, put another key in charge, and take the old key’s three jobs away.

Two roads out

Figure 2: both roads keep the address. SETCODEFROM turns the account into a contract; set-key leaves it run by the protocol’s default code.

Both roads keep the address. On the left the account receives a wallet’s code, and from then on that code decides what a valid transaction is. On the right the account has no wallet at all: it records a key, and the protocol checks its transactions against that key. The dashed line is the step from the right road to the left one, which a later fork could add.

Colours mean the same in every figure: amber is the old ECDSA key and anything still open or pending, green the new key and the set-key road, purple contract code and the SETCODEFROM road, blue the protocol’s own machinery.

There’s a third road, EIP-7851, written by two of my SETCODEFROM co-authors: the account keeps an EIP-7702 delegation and switches its key off. Hegotá declined it, and Toni closed his own extension of it in favour of set-key, so I leave it out. His write-up also sketches a frame that copies code into an EOA. That is one shape the second step could take.

Frames, in one picture

Both roads end in frame transactions, the transaction type that carries post-quantum signatures.

Figure 3: a frame transaction. Verifiers check signatures in PROOF frames, and an account without code gets the protocol’s default code, whose VERIFY only asks whether the right claim exists.

A frame transaction is a list of frames that run in order. PROOF frames hand a signature to a verifier, which checks it and records a claim: this key signed this transaction. The protocol has three verifiers built in, one of them post-quantum. A VERIFY frame is where the account approves. SENDER frames are the calls. An account without code can’t approve anything itself, so the protocol runs a default code for it, and today that default code approves when it finds a secp256k1 claim for the address.

That default code is exactly what I don’t like about set-key. For an account on the default code, we, in the protocol, have to specify every option it gets: what counts as its approval, how its key changes, which calls it answers. Its owner writes none of it. Even with set-key, the most they can bring is a verifier of their own, a contract that sees nothing but a hash and a proof. Everything else comes from our list, and each addition to that list is an EIP, code in every client and a hard fork. That’s complexity for us, a fork at a time, and constraints for them in between. Lose-lose, if you ask me.

Figure 4: the default code is a closed list that the protocol writes. Putting a rule on it takes an EIP, every client and a hard fork; an account that runs its own code needs none of them.

Set-key is a change to that default code: the green entries above.

Road 2 up close: set-key

Figure 5: the transaction that retires an ECDSA key, as in Example 1c of the proposal (‖ joins bytes end to end). The old key approves, the new key proves that you hold it, and the default code writes a pointer into the account’s code and a key ID into its storage.

One transaction, four frames. Both keys sign it. The default code approves it on the old key, as it would for any EOA. Then the last frame asks the default code to set the key: it checks that the new key really signed, stores an identifier of that key in the account’s storage, and writes a 23-byte pointer into the account’s code (the proposal calls it the default-code indicator, and an account that holds it a keyed account). The pointer says “the default code runs this account”, and it’s also what locks the old key out: an account that holds it can no longer send ordinary transactions (EIP-3607) or sign EIP-7702 delegations.

Figure 6: a keyed account afterwards. Its transactions carry one proof by the new key, the key can be replaced the same way, and the default code answers a fixed set of calls from contracts.

From then on every transaction carries one proof by the new key, and the key can be replaced the same way, by a key of any scheme that has a verifier. That includes secp256k1, so “keyed” doesn’t by itself mean “post-quantum”. Other contracts now see an account with code, so they call it where they wouldn’t call an EOA, and the default code answers a few of those calls: it accepts NFTs, and it answers ERC-1271 signature checks, though only inside a frame transaction that carries the proof.

Notice what isn’t in these two pictures: a wallet contract. All of this logic lives in the client.

Road 1 up close: SETCODEFROM

Figure 7: the same job with SETCODEFROM. An EIP-7702 authorization lets migration code run once as the account; it stores the new key and adopts a wallet’s code, which the account holds when the transaction ends.

SETCODEFROM is an EVM instruction. Code that runs it for its own account gives that account the code of another deployed contract when the transaction ends, for a flat fee whatever the size. The EIP calls this adopting the code. To migrate, an EOA signs an EIP-7702 authorization that lets migration code run once as the account: it stores the new key and adopts a wallet. After that the account is a contract, and EIP-3607 and EIP-7702 keep the old key out, as on the other road.

What both roads do to the old key

Figure 8: what the old key can still do after either migration. Both roads close the same three doors and leave the same two open.

Here the two roads hardly differ. Both take away the first two jobs of Figure 1, and both decide who approves frame transactions. Neither takes away the third job. A contract that checks a signature by calling ecrecover itself, as many token permits do, never looks at the account, so it keeps accepting the old key. EIP-8151 closes that. It’s being considered for Hegotá, it isn’t scheduled, and I don’t expect it to make this fork.

The same goes for a new contract that reads a secp256k1 claim in a frame transaction as the account’s approval, and for other chains, where the old key still owns the address. Nobody should read “retired” as “gone everywhere”.

Why I call the second road faster

Figure 9: what each proposal changes. SETCODEFROM reaches the EVM, the block format, sync and code storage; set-key stays inside EIP-8141.

Figure 10: the four ways this can turn out if set-key ships on time. Nobody knows which column is true, so the choice is which bad cell to risk.

What it’ll cost us

In a normal fork I wouldn’t hesitate: I’m convinced SETCODEFROM is simply the better design. (I co-wrote it, and I may be biased.) This isn’t a normal fork, and with what’s at stake I’m deeply reconsidering whether it belongs in Hegotá. If set-key takes its place, I think that would be a mistake made knowingly, as the price of a plausibly faster fork. This is the bill.

Figure 11: the trade. The left column is what Hegotá would get with set-key; the right column waits for a later fork.

Cost 1: the protocol takes a job that isn’t its own

With SETCODEFROM an account is code, and how it authenticates is its owner’s business: written in the EVM, replaceable without a fork. EIP-8141’s own motivation calls that “the original vision of account abstraction”. Had accounts already been code they could replace when the quantum question came up, the protocol’s part would have been small: make a new scheme cheap to verify, fix ecrecover (EIP-8151), and tell users to update their wallets.

Set-key puts the rest on the protocol: the list of Figure 4, and whatever accounts need next. We specify it, we answer for it, and we get it right in every client. None of that has to be our responsibility, and I think taking it on will bite us.

Figure 12: what a broken signature scheme asks of each side, if accounts were already code and with keyed accounts. The green lines are what set-key adds to the protocol’s side.

And we can’t put it down. The text says of a keyed account’s pointer that “nothing changes or removes” it. Toni says on the pull request that such an account “can become a programmable smart account still”, and that he’s “still happy to ship one of the two” ways he sees for it. Even then, something stays for every account that never takes that step. The proposal’s rationale says most of the default code could later become a contract at a reserved address; the pointer’s own rules, and the operation that sets a first key, can’t. SELFDESTRUCT went the same way: deprecated, cut down in 2024, and still in every client.

Cost 2: two kinds of account, with account abstraction live

With set-key, Ethereum keeps the split between EOAs and contracts even once it has account abstraction. There are still two kinds of account: contracts, whose code decides, and keyed accounts, for which every client decides the same way. The proposal’s rationale says a keyed account isn’t a new kind of account, because to contracts and tools it looks like an account with a delegation. To its owner, and to the wallet that signs for it, it is one.

Figure 13: set-key leaves two kinds of account, as today; SETCODEFROM leads to one. Below, the check of “one authentication method again”: false for the scheme, true for the rule.

Is that a single authentication method all over again? Half of it. The scheme is open: a keyed account names its verifier, one of the three built in or a small contract of its own, and can change it. The rule is fixed: the default code checks that one key approved, and nothing else. A daily limit, a time lock or a recovery delay isn’t something it can do, and if you lose the key you lose the account. The proposal’s answer is that an account that wants programmable validation “deploys or delegates to a smart account instead”. For an existing EOA that means a new address, or a delegation that its old key still controls.

Figure 14: who can use each road on day one. A tick is a yes (the note says how), an amber dash a yes at a cost, a grey dash outside the proposal’s scope.

On day one a plain EOA is better off with set-key: one transaction, nothing to wait for. An account that already uses an EIP-7702 wallet is worse off. It has to give the wallet up first, in a transaction of its own, and it can’t take it back afterwards. I’d rather set-key cleared the delegation itself.

Cost 3: it’s sticky

The cost that worries me most isn’t in any spec. To ship set-key, wallets, hardware signers, explorers and SDKs all have to learn keyed accounts. They will, because the quantum deadline leaves them no choice. Asking them to move again a fork or two later, for accounts that are already safe, is a different conversation. Nothing forces it.

Figure 15: two migrations. The quantum deadline pushes everyone over the first hill; nothing forces them over the second.

So “SETCODEFROM can come later” is true, and weaker than it sounds. Ben Adams, a co-author of EIP-8298, names the risk on the pull request: “another generation of legacy accounts”. That’s a fair description of the risk. Followed to its end, it’s an Ethereum where account abstraction is live and most existing accounts never use the programmable part of it, because they moved once, to keyed accounts, and nothing moved them again. That would be an absurd place to end up.

Cost 4: copies stay priced by the byte

SETCODEFROM does one more thing, which has nothing to do with keys: it gives an account code that already exists, for a flat fee. To see what that’s worth, I counted a year of contract creations on mainnet and checked them against an archive node. The method, the scripts and the results are in this post’s data folder.

Figure 16: a year of contract creations on mainnet, by number and by bytes. Nearly all of them are copies, and nearly all the copies are 45-byte proxies.

95.5% of the 23,971,596 contracts created in that year deployed code that had been deployed before, byte for byte. 89% of those copies are 45-byte proxies, which hold no logic and forward every call to a shared contract. Two XEN minting tools account for 62% of all copies.

Figure 17: the gas that pays for the code of a year’s copies: as paid, at EIP-8037’s price, and adopted with SETCODEFROM. Below the line, the same copies as full 64 KiB contracts.

Figure 18: how much of each block’s access list SETCODEFROM’s hash form would save, ranked by block, and what the lists would be if the copies were full contracts.

This is the lightest item on the bill. Deployments are small, most are copies, and each is paid once. Block access lists would hardly shrink either (Figure 18). Toni’s write-up has a point when it calls cheaper deployments “a weak argument”. What I don’t like is why the copies are pointers: a copy pays for every byte, EIP-8037 raises that price more than sevenfold in Glamsterdam (Figure 17), and one copy at the new 64 KiB limit would then cost 100 million gas, more than a block holds today. Adopted with SETCODEFROM, the code of a copy of any size costs about 12,000 gas. It’s not the end of the world. I still don’t like it.

Why I’m reconsidering anyway

Because of what the two columns of Figure 11 are made of. The left one is what Ethereum can’t afford to be late with: a way for existing accounts to take their transactions and their delegations away from secp256k1, in the same fork that brings the post-quantum verifier. The right one is what makes accounts better. None of it is closed off by waiting a fork, as long as a keyed account can still take code later. Whether it then does is the stickiness above.

Ben’s case is that SETCODEFROM is “how we get both”. If it could ship with no risk to the fork, I’d agree, and the bet of Figure 10 is my admission that I can’t show it couldn’t. But Hegotá already carries a new transaction type and a new signature scheme, and the agenda of the December 7 testing call has an item to consider removing all non-PQ EIPs from the execution-layer devnet. Of the two proposals, the one that changes more of the protocol is the one more likely to delay the fork, and that’s what I keep coming back to.

Set-key is dirty: a wallet in the client, and a pointer that stays. It’s also the simplest thing on the table, and the fastest to implement and ship inside frames. It pains me to say so.

Figure 19: the order I’m weighing: a key in this fork, code in a later one, and the door between them.

The second step wouldn’t have to be SETCODEFROM as it reads today. It would have to be possible, and it would have to be wanted. Whether a small version of it could ship in the same fork is a separate question.

What happens to SETCODEFROM

I can’t withdraw an EIP that has four authors, and this post doesn’t speak for the other three. Where I stand: I’m deeply reconsidering SETCODEFROM’s inclusion in Hegotá, with set-key in its place.

If it steps back, I’d keep the EIP, its tests and what its review taught me, and bring it back as the second step: the operation by which a keyed account takes code, the way a factory makes cheap copies, the way a contract upgrades in place. To me those are its widest uses. Retiring the key was the urgent one, and the urgent one may have a shorter road.


Web version: cperezz.github.io/articles/faster-path-pq-key-rotation