Skip to content

fix: fix critical audit from ag#614

Open
Lchangliang wants to merge 6 commits intomainfrom
dev-0316-critical
Open

fix: fix critical audit from ag#614
Lchangliang wants to merge 6 commits intomainfrom
dev-0316-critical

Conversation

@Lchangliang
Copy link
Contributor

@Lchangliang Lchangliang commented Mar 18, 2026

  1. Prevention of Liveness and Panic Vulnerabilities (Consensus)

Delayed QC Aggregation Panic Fix (pending_votes.rs): Replaced a panic! with graceful error handling (VoteReceptionResult::ErrorAddingVote) when a delayed Quorum Certificate (QC) aggregation is triggered with insufficient voting power. This prevents the consensus from crashing upon receiving stale or maliciously delayed votes.
Rotating Proposer Safety (rotating_proposer_election.rs): Added strict assertions during RotatingProposer initialization to guarantee that the proposer set is not empty and contiguous_rounds > 0, neutralizing potential division-by-zero or out-of-bounds panics.
2. Prevention of Undefined Behavior (UB) in Concurrency (gravity_node)

Safe Environment Variables (

main.rs
): Moved the conditional evaluation and mutation of RUST_BACKTRACE to the absolute start of

main()
before any threads are spawned. This mitigates a known Undefined Behavior (UB) caused by calling std::env::set_var in a multithreaded environment.
3. Data Recovery and State Sync Improvements (api/bootstrap.rs & api/consensus_mempool_handler.rs)

Optimized Block Buffer Initialization: Completely refactored the recovery exit condition during init_block_buffer_manager. Instead of an ad-hoc flag, the loop now intelligently breaks once the block_number_to_block_id map length fulfills the required range

(latest_block_number - start_block_number + 1)
, significantly improving boot/sync performance.
Unhandled Channel Logs: Added explicit .is_none() error logging internally if the persist_notifiers channel silently closes during commit_blocks or commit_ledger, averting silent transaction processing failures.
Save Transaction Robustness: Properly handled the

Err
result returned by self.inner.db.writer.save_transactions(...) during the commit_ledger sequence, actively logging any database storage faults.
4. Block Parent Resolution Safety (block_buffer_manager.rs)

Integer Underflow Protection: Safeguarded the block parent lookup mechanism by using checked_sub(1). When evaluating block_number == 0 (the genesis block edge-case), it skips looking up parent mappings and inherently relies on the canonically provided parent_id, averting subtraction underflow crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant