Skip to content

Midnight Bridge Implementation - #106

Draft
ladislavdubravsky wants to merge 21 commits into
feature/midnight-privacyfrom
feature/midnight-bridge
Draft

Midnight Bridge Implementation#106
ladislavdubravsky wants to merge 21 commits into
feature/midnight-privacyfrom
feature/midnight-bridge

Conversation

@ladislavdubravsky

Copy link
Copy Markdown
Collaborator

Depends on https://github.com/dcSpark/midnight-l2-contracts, which is checked out here as a submodule.

Skip building the C++ attestation client if the Azure Guest Attestation
header is absent; emit a cargo warning. Document in README that local
dev with mock attestation does not require the SDK.
optional_index_db_url() now returns None for sqlite:/sqlite3: URLs
(since this provider uses PgPool). Log when SQLite is detected and
document that commitment-tree sync then uses rollup REST endpoints.
…ement)

Implement executor HTTP client and call it from the TEE manager:
- After computing batch_hash: POST /commit-batch (commitBatch on L1).
- After attestation and publishing to DA: POST /build-signatures then
  POST /finalize-batch (finalizeBatch on L1).

Config: tee_configuration.executor_url and rollup_id_hex (optional; when
unset, no L1 calls). Executor holds sequencer/finalizer keys; rollup
only calls the HTTP API.
New contract storage model at `midnight-l2-contracts`, indexer at ledger-v7.
…tion

The rollup now owns the full L1 Bridge contract lifecycle: it auto-
deploys the contract on genesis (using print-genesis-info to compute the
deterministic state root and batch hash), spawns the executor service as
a child process, persists the contract address, and tears everything
down on shutdown. This replaces the previous manual workflow.
After a crash or shutdown between commitBatch and finalizeBatch, the L1
Bridge contract rejects new commits with COMMIT_OUT_OF_ORDER. Persist
BatchPublicDataV1Full to pending_finalize.json after each successful
commit and complete finalization automatically on startup or during
graceful shutdown, making the rollup resilient to mid-cycle interruptions.
…settlement resilience

- Bridge worker automatically relays L2→L1 withdrawal proofs to the executor's
  POST /relay-withdraw-night-with-proof after each batch finalization, with
  persistent cursor tracking and root-mismatch guard.

- Wire STF's MidnightWithdrawals.withdraw_root into BatchPublicDataV1 via the
  prover querying the rollup REST API, breaking the circular dependency where
  the L1 contract only had the empty tree root.

- Add TEE batch settlement resilience: L1 state resync before each commit
  (handles committed-but-not-finalized, cursor drift, prev_batch_hash mismatch),
  exponential backoff on failures, and diagnostic logging.

- Add sov-cli binary to rollup-ligero (required due to ed25519-dalek version
  mismatch between Risc0 and Ligero adapters).

- Fix sender_bytes zero-padding for 28-byte addresses in MidnightWithdrawals.

- Add withdrawRoot to executor /state endpoint (bridge-cli TS).

- Update MIDNIGHT_BRIDGE.md with deposit and withdrawal CLI walkthroughs.
… add executor timeout

- When the L1 state resync detects the contract is ahead of our cursor (e.g.
  after a transient executor error where the L1 tx actually succeeded), return
  early from process_stf_info instead of using the current proof. The proof was
  generated for the now-skipped batch range and its initial_state_root won't
  chain from L1's new lastFinalizedStateRoot, causing BAD_PREV_STATE_ROOT.

- Add 180s timeout to the executor HTTP client so the rollup fails fast and can
  recover via resync when the Midnight SDK hangs on response parsing.

- Log a "Sending request to executor service" line before each executor call
  so it's clear when the rollup is blocked on the executor vs idle.

- Log batch state roots from the prover for diagnostics.

- Promote withdrawal relay state and root-mismatch guard logs back to info so
  the relay loop's progress is visible without enabling debug logging.

- Fix prover's message_queue_hash lookup to use last_processed_l1_index instead
  of nextCrossDomainMessageIndex-1, fixing BAD_MESSAGE_QUEUE_HASH after deposits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant