fix(tempo): KeyAuthorization encoder never enforced the TIP-1049 admin/account pairing - #437
Closed
gomesalexandre wants to merge 1 commit into
Closed
Conversation
…n/account pairing toTuple/toRpc happily encoded isAdmin: true with no account onto the wire, even though the OneOf-typed shape requires both or neither. A caller bypassing the TS type (raw wire input, a non-TS caller, or any `as any`) could produce that orphan shape. fromTuple/fromRpc deliberately tolerate and drop an orphan admin marker on decode -- a deleted code comment in git history confirms this is intentional forward-compat, not a bug, so decode is left untouched. The gap is one-sided: ox itself should never *produce* wire bytes it wouldn't accept as valid input, since a decode/re-encode round trip on such a shape silently drops isAdmin, changing hash()/getSignPayload() before vs after. Adds assertAdminBinding(), called from from()/toTuple()/toRpc(), which throws MissingAdminAccountError only for the unstable direction (isAdmin: true, no account). The reverse -- account set, isAdmin omitted or false -- is a normal account-scoped non-admin key and already round-trips stably, so it's left permitted. Every real (non-doc-comment) call site that serializes a KeyAuthorization (Transaction.ts, TransactionRequest.ts, TxEnvelopeTempo.ts) goes through toRpc/toTuple, so this closes the gap at every reachable production path. New tests compose the encoder and decoder on the same object (unlike the existing suite, where every encoder fixture already pairs the two fields correctly, and the decoder's orphan-shape tests use hand-built tuple/RPC literals that never came out of the real encoder) -- so they would have caught this before it shipped.
|
@gomesalexandre is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
gomesalexandre
marked this pull request as ready for review
September 1, 2026 19:39
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
what
KeyAuthorization.toTuple/toRpcnever enforced the TIP-1049 invariant thataccountandisAdminare paired (documented right above the type: "either both are specified or neither"). A caller bypassing theOneOftype — raw wire input, a non-TypeScript caller, or anyas any— could constructisAdmin: truewith noaccount, and the encoder would happily put it on the wire.fromTuple/fromRpcalready tolerate this shape on decode and silently drop the orphanisAdminmarker. That's intentional, not a bug — a deleted comment still visible in git history says so explicitly:So decode is left untouched. The actual gap is one-sided: ox itself should never produce wire bytes it wouldn't accept as valid input. A decode → re-encode round trip on an orphan-shaped authorization silently drops
isAdmin, which changeshash()/getSignPayload()before vs after — sincehash()is exactlykeccak256(rlp(toTuple(auth))).repro (before this fix)
fix
Adds
assertAdminBinding(), called fromfrom(),toTuple(), andtoRpc(). It throwsMissingAdminAccountErroronly for the unstable direction —isAdmin: truewith noaccount. The reverse (accountset,isAdmin: falseor omitted) is a normal account-scoped non-admin key, already round-trips stably today, and stays permitted:Verified every real (non-doc-comment) call site that serializes a
KeyAuthorizationgoes throughtoRpc/toTuple—Transaction.ts:366,TransactionRequest.ts:263,TxEnvelopeTempo.ts:730— so this closes the gap at every reachable production path, not just the module's own entry points.why the existing tests didn't catch it
The
admin keys (TIP-1049)describe block has 12 tests, but every one of them tests only one side in isolation:isAdminandaccounttogether (from({ ..., isAdmin: true, account })).fromTuple: drops orphan isAdmin without account,fromRpc: drops orphan isAdmin without account) build the orphan tuple/RPC object as a hand-written literal — never from the real encoder's own output.So the two sides were pinned independently and never composed: nothing ran
toTuple(x)→fromTuple(...)on an object the encoder itself produced from an orphan input. The new tests do exactly that composition, plus directtoTuple/toRpc/fromrejection tests, plus a control confirming a legitimate paired shape and anisAdmin: falseaccount-only shape both still round-trip stably.severity, honestly
tsc --strictrejects the orphan shape viaOneOf) — reachable only viaas any, a union-collapsing spread, or a non-TypeScript caller.src/tempo/**), not a demonstrated live incident — shipping it now closes a real gap before it can bite anyone once this ships and gets more traffic.receipts
Genuine red-before/green-after: stashed just
src/tempo/KeyAuthorization.ts(kept the new tests), reran — exactly the 3 new "throws" tests failed withsnapshot function didn't throw/ the actual round-trip instability, all 100 others passed. Restored the fix, all 103 pass.Full
src/tempo/suite (pnpm test src/tempo/): 687 passed, 37 skipped — the 2 failing files (e2e.test.ts,multisig.e2e.test.ts) fail identically on unmodifiedmaintoo (anafterAlltrying tofetcha stop endpoint on a localnet node that isn't running in this sandbox —ECONNRESET, not a code regression). Confirmed by stashing and re-running against cleanmain.review note
Ran Codex adversarially against this diff. It made real partial progress before I had to stop it — most usefully, it caught that my test file didn't type-check under the actual
tsc -b/check:typescommand CI runs (I'd initially only runtsc --noEmitagainst the maintsconfig.json, which excludes test files;test/tsconfig.jsonis stricter and correctly rejected my first draft of the account-only test, which omittedisAdmin— theOneOftype requires both keys together on that branch, soisAdmin: falseis the only type-legal way to express "account-scoped, not admin"). Fixed and reverified against the realtsc -b. It didn't reach a final verdict before I stopped it, so I finished the remaining checks myself (the call-site sweep above).