Skip to content

test: flaky test for DamgardEtAl#3399

Merged
SimonRastikian merged 6 commits into
mainfrom
fix/proposal-gen-damgard-n-bound
Jun 1, 2026
Merged

test: flaky test for DamgardEtAl#3399
SimonRastikian merged 6 commits into
mainfrom
fix/proposal-gen-damgard-n-bound

Conversation

@SimonRastikian

Copy link
Copy Markdown
Contributor

Closes #3398

@claude

claude Bot commented May 29, 2026

Copy link
Copy Markdown

PR title type suggestion: This PR changes only test files, so the type prefix should probably be test: instead of fix:.
Suggested title: test: fix flaky test for DamgardEtAl

@claude

claude Bot commented May 29, 2026

Copy link
Copy Markdown

Pull request overview

This PR addresses flaky test test_onboarding_jobs (issue #3398) by enforcing a participant-count floor of 3 in gen_valid_params_proposal. Previously the function could sample n_old_participants = 2 with max_added = 0, producing parameters that violate DamgardEtAl's n >= 2t - 1 constraint. The fix introduces a min_added floor so the resulting participant count is always >= 3, mirroring what gen_threshold_params already does.

Changes:

  • Compute min_added from n_old_participants so the proposed n is at least 3
  • Update sampling of max_added to respect the new floor

Reviewed changes

Per-file summary
File Description
crates/contract/src/state/test_utils.rs Adds a min_added floor to gen_valid_params_proposal so generated proposals always have n >= 3.

Findings

Blocking (must fix before merge):

  • crates/contract/src/state/test_utils.rs:42-65The file contains unresolved git merge conflict markers (<<<<<<< Updated upstream, =======, >>>>>>> Stashed changes). The file as committed will not compile. You need to pick one of the two alternatives and remove all conflict markers. The two variants differ in approach:

    • Upstream variant: sample max_added from min_added..min_added + 10 (shifts the whole range up).
    • Stashed variant: sample max_added from 0..10 then clamp via .max(min_added) (preserves the original [0, 10) range and only nudges the lowest values).

    The PR description / comment text suggests the "Stashed" variant was the intended one ("Clamping after sampling keeps the original [0, 10) range and only nudges the lowest values up when they'd produce an invalid n"), but either is functionally adequate — please resolve and force-push a clean diff. After resolution the diff should be ~5–10 lines, not 23.

Non-blocking (nits, follow-ups, suggestions):

  • crates/contract/src/state/test_utils.rs:56-60 — Minor: min_added could be written 3usize.saturating_sub(n_old_participants) for terser intent, though the current form is clear enough.
  • Consider adding a focused unit test that exercises the n_old_participants == 2 path (e.g., by constructing params with current_k = 2, current_n = 2) to lock in the regression and avoid relying on the probabilistic test_onboarding_jobs to catch a future reintroduction.

⚠️ Issues found

@SimonRastikian SimonRastikian changed the title Fix: flaky test for DamgardEtAl fix: flaky test for DamgardEtAl May 29, 2026
@claude

claude Bot commented May 29, 2026

Copy link
Copy Markdown

PR title type suggestion: This PR changes only test files, so the type prefix should be test: instead of fix:.

Suggested title: test: fix flaky test for DamgardEtAl

@claude

claude Bot commented May 29, 2026

Copy link
Copy Markdown

PR title type suggestion: Since this PR only changes test files, the type prefix should be test: instead of fix:.

Suggested title: test: fix flaky test for DamgardEtAl

@claude

claude Bot commented May 31, 2026

Copy link
Copy Markdown

PR title type suggestion: This PR changes only test utilities, so the type prefix should probably be test: instead of fix:.
Suggested title: test: fix flaky test for DamgardEtAl

@SimonRastikian SimonRastikian changed the title fix: flaky test for DamgardEtAl test: flaky test for DamgardEtAl May 31, 2026
@claude

claude Bot commented May 31, 2026

Copy link
Copy Markdown

PR title type suggestion: This PR changes only test utilities, so the type prefix should probably be test: instead of fix:.

Suggested title: test: fix flaky test for DamgardEtAl

@SimonRastikian SimonRastikian enabled auto-merge May 31, 2026 23:28
DSharifi
DSharifi previously approved these changes Jun 1, 2026

@DSharifi DSharifi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@gilcu3 gilcu3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should start by making the test generator deterministic, and then ensure that it generates a valid set of parameters for all our schemes more naturally, without having to patch values after they were generated

Comment thread crates/contract/src/state/test_utils.rs Outdated
Comment on lines +43 to +54
// Floor the proposal's participant count at 3 so the result is compatible
// with every protocol — `DamgardEtAl` requires `n >= 2t - 1`, which forces
// `n >= 3` even at the minimum `t = 2`. `gen_threshold_params` enforces
// the same floor for the initial params; this keeps the proposal
// consistent. Clamping after sampling keeps the original `[0, 10)` range
// and only nudges the lowest values up when they'd produce an invalid n.
let min_added = if n_old_participants < 3 {
3_i32.saturating_sub(n_old_participants.try_into().unwrap())
} else {
0
};
let max_added = max_added.max(min_added.try_into().unwrap());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if DamgardEtAl requires $n \geq 3$ then how can we have n_old_participants < 3? I think the fix proposed is very convoluted and does not really solve part of the issue, which is that this test is not deterministic

@SimonRastikian SimonRastikian Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

n_old_participants is computed as follows.
Where

   let current_k = params.threshold().value() as usize;
   let current_n = params.participants().len();
  let n_old_participants: usize = rng.gen_range(current_k..current_n + 1);

It could happen that
current_k = t = 2 and current_n = n = 3. As you see this can indeed imply that n_old_participants = 2.

@gilcu3 gilcu3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@SimonRastikian SimonRastikian added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit 065a341 Jun 1, 2026
25 of 26 checks passed
@SimonRastikian SimonRastikian deleted the fix/proposal-gen-damgard-n-bound branch June 1, 2026 11:03
@SimonRastikian SimonRastikian self-assigned this Jun 15, 2026
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.

Flaky test_onboarding_jobs

3 participants