Skip to content

Fix security-review findings on #692 (Petri block signing) - #1043

Draft
hackobi wants to merge 4 commits into
petrifrom
claude/fix-node-pr692
Draft

hackobi wants to merge 4 commits into
petrifrom
claude/fix-node-pr692

Conversation

@hackobi

@hackobi hackobi commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Fixes for the security-review findings on #692 (Petri). This PR targets the petri branch, so merging it adds these commits to #692.

# Severity Finding Status Commit
1 critical Members signed any proposed hash from any shard member Fixed: refuse if the claimed proposer isn't the authenticated sender or isn't the secretary; sign only a hash equal to our own compiled candidate d85522f0
2 high Secretary quorum counted signatures from keys outside the shard Fixed: only shard ∪ {self} count; petri_submitBlockHash refuses non-shard senders 00831e27
3 high Docs and tests said verify-then-sign, but the code accepted and signed Fixed: the code now verifies before signing, and the docs and tests were corrected d85522f0, 2902874d, db4472b3
6 medium Unit tests didn't import production consensus code Partly fixed: new testing/petri/blockHashSigning.test.ts uses the production modules and real ed25519 signatures 2902874d
4 medium Secretary election depends on each node's local online-peer view Not fixed: getShard predates this PR. After fix 1, divergent views cost liveness instead of safety –
5 medium Secretary collection and failover code has no callers Not fixed: wire it in or delete it (Phase 9 decision) –

Note: Petri is enabled by default (src/config/defaults.ts). Please confirm that's intended for mainnet.

Tests: bun test testing/petri/blockHashSigning.test.ts: 6 pass (5 of these fail before the fix). bun test testing/petri/: 224 pass, 1 fail. That failure exists before the change too.

🤖 Generated with Claude Code

The Petri branch of manageProposeBlockHash signed any hash from any shard
member (accept-and-sign). Block compilation is now deterministic, so the
branch can use verify-then-sign instead:

- refuse when the claimed proposer differs from the authenticated sender
- refuse when the proposer is not the elected secretary
- fall through to the existing candidate comparison, so we only sign a
  hash equal to the block we compiled ourselves

getSecretaryIdentity is exported so the election logic is shared.
broadcastBlockHash added every valid (identity, signature) pair a responder
returned, so one responder could pad its reply with signatures from keys
outside the shard and push the secretary over the BFT threshold. Only
identities in the shard (plus our own) are now accepted.

petri_submitBlockHash likewise refuses submissions from senders that are
not in the shard.
Add blockHashSigning.test.ts, which imports manageProposeBlockHash and
broadcastBlockHash and uses real ed25519 signatures. It covers hash
mismatch, non-secretary proposer, sender spoofing, missing candidate, the
matching-hash happy path, and quorum padding with non-shard keys.

Remove the 'Verify-then-sign model' tests that compared string literals
without calling the signing code, and correct the finalizer comment.
consensus.md and VADEMECUM.md still described the accept-and-sign model
that the signing fix replaced. Also drop the uint8ArrayToHex import that
the removed accept-and-sign branch used.
@coderabbitai

coderabbitai Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hackobi

hackobi commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Automated launch review: needs-changes at db4472b

An automated reviewer checked this PR for the Demos mainnet launch, using public research on how established chains handle the same problem. Each finding cites the code at this head. If a finding is wrong, reply here with the reason.

  1. [low] Member path accepts signatures from non-shard identities

    manageProposeBlockHash copies every validly signed entry from the incoming validationData into candidateBlock and returns it, with no shard ∪ {secretary} membership check. The secretary now filters these, so the quorum is not inflated. Still, the member's rejection of non-member signatures is not enforced or tested, unlike CometBFT's addVote.

    Code: src/libs/consensus/v2/routines/manageProposeBlockHash.ts:111-134

  2. [low] Proposer/sender binding fails open when sender is falsy

    sender && sender !== peerId skips the check when sender is undefined or ''. The parameter is optional. A '' sender appears to throw earlier, at manageConsensusRoutines L50, but the security check should reject a missing sender explicitly.

    Code: src/libs/consensus/v2/routines/manageProposeBlockHash.ts:18-18, src/libs/consensus/v2/routines/manageProposeBlockHash.ts:55-55

  3. [info] Threshold denominator may double-count self (pre-existing)

    finalizeBlock uses shard.length+1. manageConsensusRoutines requires our own id to be in getShard output, which suggests the shard already includes us. If so, the threshold is stricter than intended (liveness, not safety). The diff does not touch this.

    Code: src/libs/consensus/petri/block/petriBlockFinalizer.ts:56-57, src/libs/network/manageConsensusRoutines.ts:103-104

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