Repository navigation
feat: manual key rotation with privacy transaction - #1126
Open
jonesmarvin8 wants to merge 9 commits into
Open
jonesmarvin8 wants to merge 9 commits into
jonesmarvin8 wants to merge 9 commits into
Conversation
A key is now derived at (type, nonce, counter): key_seed = Sha256(DS_KEY_SEED || secret || type || nonce as 16 bytes LE || counter as 4 bytes LE). Ordinary keys use counter 0; a manual rotation moves to the next counter at the same nonce. signing_key, key_state and Signer::new are unchanged and use counter 0. signing_key_with_counter, key_state_with_counter and Signer::new_with_counter take a counter; at counter 0 each calls the original. A manually rotated key is stored on chain, so Signer::new_with_counter never prefixes the initial key past counter 0. Signer::counter reports the counter it signs with. BREAKING! Before: key_seed hashed no counter. After: the counter is always hashed, so every key and account id changes. Mitigation: recreate wallet storage and genesis configs. The pinned genesis keys in the docker configs are updated; the prebuilt sequencer fixture and devnet stake entries are not regenerated in this commit.
A message to an account's signature actor now reaches a native handler
instead of failing as an unknown program. SignatureMessage::SetKey
{ next } writes `next` as the account's key state, without advancing
its nonce: the write is an actor-state write applied through the public
diff, not a signer's rotation.
Only the signature program itself may send it. The sender is checked
before the message is decoded, so every foreign or public caller fails
with ForeignSender, whatever it sent. A key type must be an allowed
rotation target; is_allowed_rotation_target allows every type until a
scheme is blocked, and authenticate applies the same rule to a witness
rotation's next key (AuthError::DisallowedRotation).
A root call to the signature address is now a charged revert
(SetKeyFailed) instead of rejecting the block as UnknownProgram.
The signature program gains a guest-callable part. Its one message, ManualRotation, carries a secret, an account and a next key per entry. For each entry the guest checks that the secret owns the account, then sends SetKey to the account's signature actor, which the sequencer handles natively. Run privately in a privacy transaction, the secrets never leave the proof. The guest derives the account id itself: lee is host-only, so it copies key_seed and Schnorr key generation, and derives the x-only public key with k256. Known-answer tests pin lee, the wallet and the guest to one account id for a fixed secret. A one-account rotation takes about 3.6M cycles. The signature program's address is now signature_program_id(), the system_upgrader PDA for its name, so system_upgrader can upgrade the guest. The circuit and the loader no longer refuse it as a reserved address: a claim needs a header on chain, and every loader write needs system_upgrader's authorization. The prover's simulator handles a public SetKey natively, as settlement does. Program::handle_message_for_tests runs a guest on an input, for tests of a guest that public execution never reaches. BREAKING! Before: the signature program lived at [0xFC; 32]. After: it lives at its system_upgrader PDA, so every account's key slot moves, and every program's image id changes with the rebuilt artifacts. Mitigation: recreate genesis state. The prebuilt sequencer fixture and devnet configs are not regenerated in this commit.
…tem program The signature program's guest joins the core system programs, so every zone seeds it at genesis, mutable at its system_upgrader PDA, and system_upgrader's registry lists it with no upgrade pending. A committee-approved upgrade can then replace the guest; the native SetKey handling is unaffected. The upgrade-test helpers take a program name (staged_registering, apply_tx_for), so the signature program is scheduled and applied like any other. After an upgrade, the image id on chain is the new guest's, so settlement refuses a proof claiming the old one.
The signature guest is proven privately and its SetKey settles through the native handler: the key is installed without a nonce bump, the next transaction signs with it, a nonce-0 account is admitted by its initial key, two accounts rotate in one transaction, and the root's nullifier is spent. A replay, an unadmitted account and the old key are refused. A fresh private root with a public signer works as the public-payer mode. The public side sees the SetKey's sender as the signature program either way; a blinded presentation keeps the root's private account id out of the transaction.
jonesmarvin8
force-pushed
the
marvin/manual-key-rotation
branch
from
November 20, 2026 08:35
6eb37be to
201ccd8
Compare
The wallet signs with the key at (type, nonce, counter): counter 0 unless the account was rotated manually. current_signing_key finds the counter behind the stored key by deriving the keys at the account's nonce for counters 0 through MAX_ROTATIONS_PER_NONCE (1024) and comparing each with the stored key. It needs only the account's secret and its state on the sequencer, so any wallet holding the secret finds the key. A stored key the secret does not derive at the current nonce is an error naming `wallet account rotate-key`.
`wallet account rotate-key --account <id>... --fee-payer <private id>` replaces the keys of public accounts this wallet holds without signing with them, in one privacy transaction. The private fee payer's signature actor runs the signature guest, so the accounts' secrets stay in the proof and their nonces don't change. Each account moves to the Schnorr key at (nonce, counter + 1). A stored key its secret does not derive at the current nonce, as when a rotation lands after a signed transaction, is replaced at counter 1. After MAX_ROTATIONS_PER_NONCE rotations at a nonce, the account must sign before rotating again. Before proving, the wallet refuses an account it holds no secret for, a fee payer that isn't one of its private accounts, and a signature guest that differs from the one deployed.
Integration tests drive `wallet account rotate-key` end to end: a rotated account signs again at the same nonce, a second rotation at a nonce takes the next counter, two accounts rotate in one transaction, and a fresh account is rotated at nonce 0. The wallet finds each rotated key in the account's history on the indexer; without indexer_url, it refuses with an error naming the setting. The prebuilt sequencer fixture is regenerated: the circuit, the program images and every account id changed since it was built.
A public message to the signature program's address is handled natively, and only a SetKey from the program itself is accepted; run privately, its guest performs a manual rotation.
jonesmarvin8
force-pushed
the
marvin/manual-key-rotation
branch
from
November 20, 2026 09:13
201ccd8 to
57c62ed
Compare
jonesmarvin8
marked this pull request as ready for review
November 20, 2026 09:58
jonesmarvin8
requested review from
Arjentix,
Pravdyvy,
agureev,
erhant,
moudyellaz and
schouhy
as code owners
November 20, 2026 09:58
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.
🎯 Purpose
Lets a public account's key be rotated manually, without signing a transaction. The rotation runs privately in a privacy-preserving transaction, so the account's nonce does not change.
⚙️ Approach
SetKeynatively at the signature program's address. Only the signature program itself may send it, and it does not bump the nonce.system_upgraderPDA, and seed it at genesis as an upgradable system program.account rotate-key <accounts…> --fee-payer <private>. The wallet finds the current key locally: it derives the keys at the account's nonce for counters 0 through 1024 and compares them with the stored key, so no indexer is needed. If a rotation lands after a signed transaction (so its key belongs to the previous nonce),rotate-keyrecovers the account by rotating to counter 1.🧪 How to Test
RISC0_DEV_MODE=1 cargo nextest run -p integration_tests --test manual_rotationlee,lez/programs(manual_rotation) andwallet🔗 Dependencies
🔜 Future Work
N/A
📋 PR Completion Checklist
Mark only completed items. A complete PR should have all boxes ticked.