Skip to content

Conversation

@asmaastarkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

asmaastarkware commented Dec 22, 2025

@asmaastarkware asmaastarkware marked this pull request as ready for review December 22, 2025 14:12
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from 5959058 to 333735c Compare December 22, 2025 14:30
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from 70fb297 to 178a8c3 Compare December 22, 2025 14:30
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from 333735c to c034f88 Compare December 22, 2025 15:03
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from 178a8c3 to d6d2d07 Compare December 23, 2025 12:35
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from c034f88 to e3f73d7 Compare December 23, 2025 12:35
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from d6d2d07 to 900acc4 Compare December 23, 2025 13:41
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from e3f73d7 to c228f4a Compare December 23, 2025 13:41
Copy link
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanl-starkware reviewed 1 file and all commit messages, and made 10 comments.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @asmaastarkware and @dafnamatsry).


crates/apollo_consensus/src/simulation_test.rs line 99 at r1 (raw file):

/// Generates a "fake" commitment for equivocation/conflict attacks.
fn fake_commitment_for_round(round: Round) -> ProposalCommitment {

Consider using existing proposal_commitment_for_round() fn, with an additional parameter

Code quote:

fake_commitment_for_round

crates/apollo_consensus/src/simulation_test.rs line 134 at r1 (raw file):

    round_stats: HashMap<(Round, ProposalCommitment), (HashSet<Vote>, bool)>,
    /// Tracks which voters have already voted for each round (to detect conflicts/duplicates).
    voter_first_vote: HashSet<(Round, ValidatorId)>,

Wouldn't it be easier to keep a HashMap with the value of commitment, to easily count equivocators?

Code quote:

HashSet<(Round, ValidatorId)>

crates/apollo_consensus/src/simulation_test.rs line 139 at r1 (raw file):

impl DiscreteEventSimulation {
    fn new(total_nodes: usize, honest_nodes: usize, seed: u64, keep_ratio: f64) -> Self {
        assert!(honest_nodes <= total_nodes, "honest_nodes must be <= total_nodes");

You can also verify: 0<= keep_ratio <= 1


crates/apollo_consensus/src/simulation_test.rs line 173 at r1 (raw file):

    /// Uses deterministic randomness based on node index and round.
    fn get_fault_type(&mut self, node_idx: usize, round: Round) -> FaultType {
        let node_idx_u64 = u64::try_from(node_idx).unwrap_or(0);

It should never be a problem, unless there's a bug.

Suggestion:

unwrap()

crates/apollo_consensus/src/simulation_test.rs line 184 at r1 (raw file):

        // Randomly select a fault type
        let fault_types = [

Suggestion:

const FAULT_TYPES: &[FaultType] = &[

crates/apollo_consensus/src/simulation_test.rs line 191 at r1 (raw file):

            FaultType::NonValidator,
        ];
        let idx = fault_rng.gen_range(0..fault_types.len());

use rand::seq::SliceRandom;

Suggestion:

let fault = *FAULT_TYPES.choose(&mut fault_rng).unwrap();

crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):

        // Handle leader proposal (only if leader is honest and not node 0)
        if leader_idx != 0 && leader_idx < self.honest_nodes {

Define as const

Code quote:

0

crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):

        // Handle leader proposal (only if leader is honest and not node 0)
        if leader_idx != 0 && leader_idx < self.honest_nodes {

If self.honest_nodes = 2, you want to allow leader_idx [1,2] to propose.

Suggestion:

<= 

crates/apollo_consensus/src/simulation_test.rs line 315 at r1 (raw file):

                self.schedule_prevote_and_precommit(node_id, round, proposal_commitment);
                let conflicting_commitment = Some(fake_commitment_for_round(round));
                self.schedule_prevote_and_precommit(node_id, round, conflicting_commitment);

Order of voting matters?
Consider sometimes sending the erroneous vote first

Code quote:

                self.schedule_prevote_and_precommit(node_id, round, proposal_commitment);
                let conflicting_commitment = Some(fake_commitment_for_round(round));
                self.schedule_prevote_and_precommit(node_id, round, conflicting_commitment);

crates/apollo_consensus/src/simulation_test.rs line 352 at r1 (raw file):

        if !self.validators.contains(&vote.voter) {
            return;
        }

Since you know how it was implemented, you can compare the id vs. TOTAL_NODES.
Current check is O(n)

Code quote:

        if !self.validators.contains(&vote.voter) {
            return;
        }

@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from c228f4a to a1c1a15 Compare December 24, 2025 07:56
Copy link
Contributor Author

@asmaastarkware asmaastarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asmaastarkware made 8 comments.
Reviewable status: 0 of 1 files reviewed, 10 unresolved discussions (waiting on @dafnamatsry and @matanl-starkware).


crates/apollo_consensus/src/simulation_test.rs line 99 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Consider using existing proposal_commitment_for_round() fn, with an additional parameter

Done.


crates/apollo_consensus/src/simulation_test.rs line 134 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Wouldn't it be easier to keep a HashMap with the value of commitment, to easily count equivocators?

For equivocation we count the first vote not the second.. the value doesn't matter


crates/apollo_consensus/src/simulation_test.rs line 139 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

You can also verify: 0<= keep_ratio <= 1

Done.


crates/apollo_consensus/src/simulation_test.rs line 173 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

It should never be a problem, unless there's a bug.

Done.


crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Define as const

Done.


crates/apollo_consensus/src/simulation_test.rs line 273 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

If self.honest_nodes = 2, you want to allow leader_idx [1,2] to propose.

Done.


crates/apollo_consensus/src/simulation_test.rs line 315 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Order of voting matters?
Consider sometimes sending the erroneous vote first

Done.


crates/apollo_consensus/src/simulation_test.rs line 352 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Since you know how it was implemented, you can compare the id vs. TOTAL_NODES.
Current check is O(n)

voter is a ContractAddress :(

Copy link
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@matanl-starkware reviewed 1 file and all commit messages, made 3 comments, and resolved 7 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @asmaastarkware and @dafnamatsry).


crates/apollo_consensus/src/simulation_test.rs line 352 at r1 (raw file):

Previously, asmaastarkware (asmaa-starkware) wrote…

voter is a ContractAddress :(

Maybe add TODO (keep validators as set)?


crates/apollo_consensus/src/simulation_test.rs line 309 at r2 (raw file):

            FaultType::EquivocatorRealFirst => {
                self.schedule_prevote_and_precommit(node_id, round, proposal_commitment);
                let conflicting_commitment = Some(proposal_commitment_for_round(round, true));

Consider moving outside the match, for clarity.

Code quote:

let conflicting_commitment = Some(proposal_commitment_for_round(round, true));

@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from a1c1a15 to 3d8e367 Compare December 24, 2025 10:04
Copy link
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanl-starkware reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @asmaastarkware and @dafnamatsry).

@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch 2 times, most recently from 5b94f3d to 42f99a2 Compare December 28, 2025 12:39
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from 1500d7a to 54525f0 Compare December 28, 2025 12:39
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from 42f99a2 to 3c5d331 Compare January 6, 2026 07:20
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch 2 times, most recently from 7834218 to db5fd8e Compare January 6, 2026 12:53
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from 3c5d331 to e4b0be8 Compare January 6, 2026 12:53
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from db5fd8e to 4af840c Compare January 7, 2026 11:42
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from e4b0be8 to bc1f76f Compare January 7, 2026 11:42
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from 4af840c to c367da5 Compare January 7, 2026 12:12
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch 3 times, most recently from 64d8ab3 to 8f7eded Compare January 8, 2026 11:56
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch from c367da5 to a9f614d Compare January 8, 2026 11:56
Copy link
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanl-starkware reviewed 1 file and all commit messages, made 3 comments, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @dafnamatsry).


crates/apollo_consensus/src/simulation_test.rs line 310 at r8 (raw file):

                let proposal_tick = (round_start_tick
                    + self.rng.gen_range(PROPOSAL_ARRIVAL_DELAY_RANGE))
                .min(round_start_tick + ROUND_DURATION);

No need to leave some spare time for the votes?

Code quote:

ROUND_DURATION

crates/apollo_consensus/src/simulation_test.rs line 434 at r8 (raw file):

        if let Some(commitment) = commitment {
            let key = (round, commitment);
            let entry = self.round_stats.entry(key).or_insert_with(|| (HashSet::new(), false));

Consider extracting to a helper function to be also used in track_precommit

Code quote:

            let key = (round, commitment);
            let entry = self.round_stats.entry(key).or_insert_with(|| (HashSet::new(), false));

crates/apollo_consensus/src/simulation_test.rs line 593 at r8 (raw file):

            if total_precommits >= THRESHOLD {
                Some((*r, *commitment, precommits.clone()))

I'm not sure the clone is necessary

Code quote:

.clone()

@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from 8f7eded to db4bef2 Compare January 11, 2026 11:09
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_drop_rate branch 2 times, most recently from 4e8a975 to c5575e4 Compare January 12, 2026 12:44
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from db4bef2 to eb1a9dd Compare January 12, 2026 12:44
Copy link
Collaborator

@dafnamatsry dafnamatsry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@dafnamatsry reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @asmaastarkware).

@asmaastarkware asmaastarkware changed the base branch from asmaa/sim_test/add_drop_rate to graphite-base/10964 January 14, 2026 12:08
@asmaastarkware asmaastarkware force-pushed the asmaa/sim_test/add_faulty_nodes branch from eb1a9dd to 16c30b1 Compare January 14, 2026 12:08
@asmaastarkware asmaastarkware changed the base branch from graphite-base/10964 to main-v0.14.1-committer January 14, 2026 12:08
@asmaastarkware asmaastarkware added this pull request to the merge queue Jan 14, 2026
Merged via the queue into main-v0.14.1-committer with commit 9f35e4b Jan 14, 2026
15 of 26 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants