-
Notifications
You must be signed in to change notification settings - Fork 8
fix: verify block and attestation signatures before processing #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🤖 Kimi Code ReviewSecurity & Correctness Issues1. Missing signature verification in
Fix: Either:
2. Race condition in BlockChainServer (lib.rs:297-305)
Fix: Consider acquiring a lock on the store during both pre-check and processing, or move signature verification into Performance & Design Issues3. Double state lookup (store.rs:165-170)
Fix: Consider passing the parent state to Code Quality4. Test modification creates inconsistency (signature_spectests.rs:55-65)
5. Error handling inconsistency
Recommendations
Automated review by Kimi (Moonshot AI) · custom prompt |
🤖 Codex Code ReviewFindings
If you want, I can suggest a small refactor to make signature verification mandatory and reuse the parent state lookup. Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewNow I have enough context to provide a comprehensive review. Let me compile my findings: PR #113 Code Review: Verify block and attestation signatures before processingSummaryThis PR adds signature pre-checking for blocks received from the network before processing them. The main changes move signature verification earlier in the pipeline to fail fast on invalid signatures. Critical Issues1. Redundant State Retrieval in
|
Greptile OverviewGreptile SummaryThis PR factors block signature verification into a new The main integration points are:
Confidence Score: 2/5
|
| Filename | Overview |
|---|---|
| crates/blockchain/src/lib.rs | Adds an external-block signature precheck before processing in BlockChainServer::on_block(); however signature verification is now inconsistent across call paths because local blocks still bypass the precheck and store::on_block() no longer verifies signatures. |
| crates/blockchain/src/store.rs | Introduces precheck_block_signatures() and removes signature verification from on_block(); this makes on_block() accept blocks without cryptographic verification unless every caller remembers to precheck first. |
| crates/blockchain/tests/signature_spectests.rs | Updates signature spec tests to call precheck_block_signatures() before on_block(); test harness still reflects the new split but can mask missing verification in other call paths. |
Sequence Diagram
sequenceDiagram
participant P2P as P2P Layer
participant BC as BlockChainServer (lib.rs)
participant ST as store.rs
participant FS as Forkchoice Store
P2P->>BC: NewBlock(SignedBlockWithAttestation)
BC->>BC: check parent exists
alt parent missing
BC->>P2P: FetchBlock(parent_root)
BC->>BC: queue as pending
else parent exists
BC->>ST: precheck_block_signatures(&Store, &signed_block)
alt signatures invalid
ST-->>BC: Err(StoreError)
BC-->>P2P: (drop block)
else signatures ok
ST-->>BC: Ok(())
BC->>ST: on_block(&mut Store, signed_block)
ST->>FS: state_transition + insert block/state
ST->>FS: update_head + process attestations
ST-->>BC: Ok(())
end
end
Note over BC,ST: Local proposal path currently calls store::on_block() via process_block() without precheck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 2 comments
Additional Comments (2)
Fix: either reintroduce the signature check inside Also appears in: Prompt To Fix With AIThis is a comment left during a code review.
Path: crates/blockchain/src/store.rs
Line: 337:379
Comment:
**Signature verification skipped**
`on_block()` no longer verifies signatures (verification was moved to `precheck_block_signatures()`), but `on_block()` is still callable directly (e.g. from tests and any other internal callers) and now accepts blocks without any cryptographic checks. This is a real behavior change: any caller that forgets to invoke `precheck_block_signatures()` first will import invalid blocks into the store.
Fix: either reintroduce the signature check inside `on_block()` (and optionally keep `precheck_block_signatures()` as an early fast-fail), or make `on_block()` private and expose a single public API that always performs prechecks before state transition.
Also appears in: `crates/blockchain/tests/signature_spectests.rs:63-64` (calls `on_block()` after an optional precheck).
How can I resolve this? If you propose a fix, please make it concise.
This new precheck is only applied in the external Prompt To Fix With AIThis is a comment left during a code review.
Path: crates/blockchain/src/lib.rs
Line: 286:304
Comment:
**Inconsistent signature enforcement**
This new precheck is only applied in the external `BlockChainServer::on_block()` path, but locally-built blocks go straight through `process_block()` (which calls `store::on_block()`) without any signature verification. If signature verification is meant to be an invariant, it should live in `store::on_block()` (or `process_block()`), not just in one call-site; otherwise local vs external blocks are treated differently and `store::on_block()` remains unsafe for other callers.
How can I resolve this? If you propose a fix, please make it concise. |
Closes #78
NOTE: this PR's changes are unreviewed