Repository navigation
Conversation
…ode & regen fixture
…p before proving it
0fa3d93 to
ab5c276
Compare
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…s signatures Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
… their vault deposits Co-Authored-By: Claude <noreply@anthropic.com>
…he vault's intake Co-Authored-By: Claude <noreply@anthropic.com>
…riber Co-Authored-By: Claude <noreply@anthropic.com>
…channel Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
| event = self.sequencer.next_event() => self.backlog.push_back(event), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
(Optional). A background driver requirement
What happens today
ZoneSequencer only makes progress inside next_event. Our sequencer owns it inside one actor. That actor's loop alternates between polling next_event and handling messages such as "publish this block":
Publishing means awaiting the node. Since the private UTXO ledger, fund_tx returns only after the node has proven a transfer, and a block with a program step also waits for the spend proof and our program proof. On CI runners we had a median of 5–8 s per publish against a 2 s block interval; a publish with a program step takes 7–13 s locally. While the actor awaits that, it is not in next_event, so the SDK processes no L1 blocks.
Publishing back to back, it never got a turn: the channel view stopped advancing and the zone froze.
What we did about it
- Every slow await runs through a helper that keeps polling
next_eventmeanwhile and queues what it returns:
logos-execution-zone/lez/sequencer/actors/bedrock/src/actor/publisher.rs
Lines 746 to 761 in f04df18
It wraps the funding call and the proving task:
logos-execution-zone/lez/sequencer/actors/bedrock/src/actor/publisher.rs
Lines 862 to 866 in f04df18
-
Our own
next_eventdrains that queue before asking the SDK again:
logos-execution-zone/lez/sequencer/actors/bedrock/src/actor/publisher.rs
Lines 175 to 180 in f04df18
-
Queueing reorders things: an event that arrived during the wait reaches our consumer after the publish it preceded, carrying a checkpoint taken before that publish. Storing it would put an older checkpoint over a newer one. So after funding we look at the queue, and if anything in it moved the channel we abandon the publish and rebuild the block:
logos-execution-zone/lez/sequencer/actors/bedrock/src/actor/publisher.rs
Lines 763 to 795 in f04df18
What it costs us
Piece 3 throws away finished proofs. Any L1 block that finalizes one of our earlier inscriptions counts as "the channel moved", and with a proof that takes longer than an L1 slot that is most of the time. In our end-to-end deposit test the first vault proof (13 s) was discarded this way and only the second went out.
What would help
If the SDK drove itself in its own task and handed events to us over a channel, pieces 1 and 2 would go away: the SDK would keep up with L1 no matter what the caller is awaiting. Piece 3 is about ordering, and one of these would remove it too:
- events and publish results delivered on one ordered stream, so a checkpoint is never older than the one before it; or
- a way to ask for the current checkpoint at any time, so we store the latest one and ignore the ones attached to queued events.
Why
Bedrock is moving to a private UTXO ledger (logos-lips #480 and #481, node PR logos-blockchain#3865). Three things LEZ's bridge relied on are gone:
CHANNEL_TRANSFERandtransfer_thresholdare removed, so deposits can't be pinned and the committee can't release notes.WITHDRAW_DELAY(86,400 slots).LEZ will instead hold bridged funds in a vault program: program notes that only a registered Groth16 proof can move. Each LEZ inscription carries a
ProgramStepthat takes in that block's deposits and pays out that block's withdrawals.This PR is the tracking branch for that work. It is a draft: the L1 side and the L2 program are built, the wiring between them is not.
How the bridge will work
Deposit, L1 to L2
/channel/deposit. The note stays under the holder's key./channel/step) for aProgramDepositstep paying the vault program, with its transfer proof. The step's inscription field carries the L2 recipient, and its intent commits to the vault's committee and that recipient.submitProgramDeposit).ProgramStep, which takes the value into a vault note.Withdrawal, L2 to L1
Withdrawnaming an L1 key. The tokens return to bridge custody on L2 and the program emits aWithdrawevent.ProgramStepin that block's inscription pays the amount out of vault notes to that key, as a channel note./channel/withdraw, after Bedrock's withdraw delay.Who builds what in a step. zone-sdk builds the program step from a description (the vault notes to consume, the note to keep, the payouts): it derives the nonces, nullifiers, root and Merkle paths, and proves Bedrock's
ZkProgramSpend, which covers nullifiers, commitments and value conservation. LEZ adds the vault's own Groth16 proof and the committee's signatures.The vault's rule, enforced by the registered circuit (
lez/vault_circuit) over Bedrock's three public inputsprogram_step_id,program_deposits_hashandop_id:The vault is a set of notes, not one. zone-sdk lets a step consume a program note only once it is four L1 blocks deep, so the note a step creates can't feed the next block's step. Each step consumes whichever spendable notes cover its payouts (at most 4), and a withdrawal can be included only when spendable notes cover it.
State of the branch
The bridge is off: nothing mints from L1 and every withdrawal is refused.
1f95999, node767cf96); old bridge removed from the sequencer and its storejust regenerate-bedrock-settings), test keys and fixture updatedDepositaccepted only in genesis. A later block that debits bridge custody is invalid for every node, which closes the forged-deposit half of #809VaultStep): describes the step for zone-sdk and proves itVaultDeposit::admit): decoding, intent, proofWithdrawon L2ProgramDepositin the block's inscription/channel/*callsBefore this can merge
dev.submitProgramDepositis atodo!()stub; it must call the admission instead.FIXME; it becomes a check against the spendable vault notes.Depositwith a zero amount, or paying custody itself, still writes its replay receipt. Two asserts in the program fix it (found in self-review, already possible ondev).How to review
Commit by commit, in four groups. Hashes are the ones after the rebase.
8456106,367eebd,a8ba3a8,bdc09e9,3e4b050. Mostly deletions; the sequencer core and its store lose the deposit queue, pinning and withdrawal reconciliation.8a810efand29d448a(circuit),7e49f61(registration),e68b8e4(step builder),f7425e4(deposit admission).ab2a4fb(withdrawals in the bridge program),a52ae71(interim builder guard),c7cbf7band83c8787(channel view freeze, described under "Test status"),ad94b6cand0f944fe(self-review fixes),9de54a3(CI).f43d54b(pin and harness),ab5c276(fixture),a6c0f4d(vault step rebuilt on zone-sdk's program inscriptions).a6c0f4dsupersedes most ofe68b8e4and reverts the intent salt ofad94b6c: the node's/channel/stepchooses the notes a deposit spends, so the depositor can't know a nullifier when it writes the intent.Open questions
Deposits with synthetic ids that no L1 deposit backs, while the vault starts empty. These tokens are indistinguishable from bridged ones, so a genesis holder can withdraw against other people's collateral and the last withdrawers find the vault short by the genesis supply. Refusing a withdrawal the vault can't pay keeps the chain live but is a fractional reserve. Before real funds, the founders must deposit the genesis supply on L1 and the genesis allocations must reference those deposits.channel_withdraw_delayof 86,400 slots, a day at one slot per second. An end-to-end test can't wait for the final release unless the template lowers it.zone-sdk todos
Requests for the zone-sdk team, in order of need.
ProgramNoteandProgramNotesView.SequencerHandle::program_notes()returns them, but PR 18 doesn't re-export them, so a caller can't name the type in its own signatures. We copy the fields into a type of our own for now.prepare_channel_configand the inscription preparation build separate transactions.next_eventdoes all of zone-sdk's work inside the caller's poll, so a caller that awaits anything slow freezes its channel view (see "Test status"). A background task handing events over a channel would remove the problem for every consumer.Depends on
logos-zone-sdkPR 18 (program steps built and proven by the sequencer), on top of the private UTXO integration and program registration branches. None is merged; the pinned revision will move./channel/deposit,/channel/stepand/channel/withdraw.Test status
Locally: workspace clippy is clean. Unit tests pass for the vault circuit (21), the bedrock actor (36), the sequencer core (177), the executor (59),
test_fixturesanddevnet_configs. Thebridgeintegration test passes on the new node (3 of 3). The rest of the integration suite and the cucumber suites were not run locally after the bump to PR 18.CI: it did not run between
b521db7and the rebase, because the branch conflicted withdev. It runs again now. On the first push after the rebase 27 jobs had passed, none had failed, when a newer push superseded the run.Channel view freeze when publishing is slow
The PUTXO node generates a proof for every
fund_tx, so funding a publish can take longer than the 2 s block interval on a slow machine. Before the fix, the sequencer then stopped following the channel and did not recover until restart:PublishBlockevery 2 s. If each takes longer than that, theBedrockActor's mailbox always holds the next one.next_eventis polled. The actor did not poll it during funding, and between publishes the waitingPublishBlockwon.Reproduced locally with
sequencer_stake_demoand the Bedrock container limited to 2 CPUs: publishes took 3 s after the second sequencer joined, no channel or turn event arrived for 12 minutes, both sequencers kept publishing on a stale view (539 blocks published, 45 indexed), the config change accrediting the joining key was resubmitted 255 times and never landed, and 187 L1 blocks were empty. It does not happen ondev, where funding needs no proof, nor on a fast machine.Fix, in two commits:
c7cbf7b: the publisher keeps polling zone-sdk while it waits on funding and queues the events.83c8787: if a queued event moved the channel, the publish is refused as "channel moved" and the turn is skipped. Without this the queued events reached the core after the publish, with checkpoints taken before it, and the store kept the older checkpoint (found in self-review).With both, at 1.2 CPUs (publishes around 3.8 s) the channel keeps moving, at a cost: 22 blocks published in 195 s with 61 skipped turns, against 33 in 156 s with 34 skips before the second commit.
sequencer_stake_demostill fails at that speed on its own 30 s wait for the config change, so some test deadlines may need widening.Self-review
Four reviewers read the branch against the pinned node and zone-sdk sources. What they found and where it went:
83c8787.provecould return a proof Bedrock rejects when given too few, too many or wrong signatures: fixed inad94b6c.ad94b6c.Withdrawdebiting only the signer, and the removal of the old bridge.🤖 Generated with Claude Code