Skip to content

fix: keep peg-in instances from stalling on lagging backends and missed messages - #542

Merged
eigmax merged 2 commits into
devfrom
audit/19-instance-liveness
Nov 16, 2026
Merged

eigmax merged 2 commits into
devfrom
audit/19-instance-liveness

Conversation

@KSlashh

@KSlashh KSlashh commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Audit items L16, L18, L19, L21, L23. Open against dev.

Answering with unsettled inputs (L19). A committee member answers a peg-in request once. Any input the Bitcoin backend did not know, or that a mempool transaction spent, made the request permanently invalid, and the member never answered. The input check now runs in the answer job: only a spend by a confirmed transaction rejects the request (the rule #516 uses for the scan). An unknown outpoint or a mempool spend retries the job every 30 seconds. Leaving UserInited cancels it.

Underivable peg-in txids (L21). Entering CommitteesAnswered, the node derives the Prepare, Confirm and Cancel txids from the answers. When that failed it only logged a warning: the instance stayed in CommitteesAnswered with no Prepare txid, was rescanned every block and never moved. The derivation only uses the stored row and the answers, so it cannot succeed later. The instance now goes to NoEnoughCommitteesAnswered and raises pegin_txids_underivable. A request whose own fields cannot make the peg-in transactions (no inputs, inputs short of amount plus fees, fees past MAX_MONEY) is now rejected before answering: the node builds them with a placeholder committee key, since the key does not change what can be built. What is left for the derivation to fail on is a bad answer (a pubkey off the curve or shared by two members, which the contract accepts). A member who sends one could block the peg-in just as well by not signing, since every member who answered must sign.

T0 gate without a Prepare height (L23). When the scan had not stored the Prepare height yet, the signing gate was open, so a node with a lagging scan could sign after T0. The gate now looks up the Prepare on Bitcoin: confirmed, T0 counts from its block; not confirmed or not seen, the gate is open because T0 cannot have passed. With no Prepare txid at all the gate returns an error and the job retries instead of signing.

Partial signatures after the Confirm broadcast (L18). Entering RelayerL1Broadcasted closed every Confirm-phase delivery, including the member's PeginConfirmPartialSig. That message carries the endorsement postPeginData needs from every member, so a relayer that missed one could never post. Only the PeginConfirmNonce and PeginConfirmNonceConsensus rows close there now; the partial signature keeps being resent until RelayerL2Minted or a failure closes the phase.

Parked instances in the scan (L16). Instances in CommitteesAnswered or Timeout that never move again shared the Bitcoin scan's page with the live ones. They now page separately (instance_btc_scan_parked), so each tick scans one page of live instances and one page of parked ones.

Tests: the answer waits for an unknown or mempool-spent input and rejects a confirmed conflicting spend; answers that yield no txids fail the instance; a request with no inputs, short inputs or overflowing fees is not answered; the T0 gate without a stored height asks Bitcoin (no txid: error, unconfirmed: open, confirmed: closed past T0); the partial-signature delivery stays open after the Confirm broadcast; parked statuses are paged apart. Two instance tests now use answers that derive valid txids. Node tests, clippy with -D warnings and fmt pass.

The test coverage and validation notes above are from the zkm PR notes. Branch scope and diff formatting were checked locally; builds and tests were not rerun during publication.

@eigmax
eigmax force-pushed the audit/19-instance-liveness branch from 8e0bb33 to d12fe4c Compare November 16, 2026 07:50
@eigmax
eigmax merged commit 34060fd into dev Nov 16, 2026
4 checks passed
@eigmax
eigmax deleted the audit/19-instance-liveness branch November 16, 2026 08:26
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.

3 participants