Skip to content

Conversation

@gilcu3
Copy link
Contributor

@gilcu3 gilcu3 commented Nov 17, 2025

Closes #107

  • This removes the usage of non-determinism from the code-base, except from the integration tests. I believe using OsRng in these files is preferred, as currently they are the closest we have to usage examples.
  • It checks that the results of the main functions in the crate are deterministic, which covers all functions (albeit indirectly). I think this is good enough atm.
  • This PR is meant to be merged after the test_utils refactor Simon/test utils folder #217. It should not have any conflict with the snapshots Simon/snapshots #218
  • This PR had no choice but slightly breaking the API of test_utils, as some functions were using OsRng internally, and now expect the RNG as a parameter.

@gilcu3 gilcu3 linked an issue Nov 17, 2025 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2025

Codecov Report

❌ Patch coverage is 93.70861% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.33%. Comparing base (24238cd) to head (8bee803).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/test_utils/test_generators.rs 0.00% 24 Missing ⚠️
src/ecdsa/robust_ecdsa/test.rs 87.03% 0 Missing and 7 partials ⚠️
src/ecdsa/ot_based_ecdsa/test.rs 92.85% 0 Missing and 3 partials ⚠️
src/test_utils/mockrng.rs 25.00% 3 Missing ⚠️
src/crypto/polynomials.rs 98.21% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
+ Coverage   88.07%   88.33%   +0.25%     
==========================================
  Files          48       48              
  Lines        9201     9488     +287     
  Branches     9201     9488     +287     
==========================================
+ Hits         8104     8381     +277     
- Misses        652      662      +10     
  Partials      445      445              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gilcu3 gilcu3 marked this pull request as ready for review November 18, 2025 10:17
@gilcu3 gilcu3 requested a review from netrome November 18, 2025 10:17
@gilcu3 gilcu3 mentioned this pull request Nov 19, 2025
@gilcu3 gilcu3 requested a review from DSharifi November 19, 2025 09:01
DSharifi
DSharifi previously approved these changes Nov 19, 2025
Copy link

@DSharifi DSharifi left a comment

Choose a reason for hiding this comment

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

Thanks a lot for these changes! :)

Copy link
Contributor Author

@gilcu3 gilcu3 Nov 19, 2025

Choose a reason for hiding this comment

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

we might want to address this ugliness (and lack of efficiency, as afaik we send this over the wire) here. The bad part is that this would be a breaking change :| (incompatible with nodes running other version type)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would this exist?
I am unsure whether I really enjoy it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the file was proposed by @netrome as a better way to make snapshot tests on determinism.

My comment here refers to the serialization of the CKD types, which is defined by the underlying lib

@gilcu3 gilcu3 force-pushed the 107-deterministic-unit-tests branch from d36be11 to aac3704 Compare November 19, 2025 19:06
DSharifi
DSharifi previously approved these changes Nov 19, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR removes non-deterministic RNG usage from the codebase by replacing OsRng with a seeded MockCryptoRng in tests. It adds deterministic test coverage using snapshot testing (via the insta crate) to verify that key cryptographic operations produce consistent outputs. The changes also update the test_utils API to accept RNG parameters instead of using OsRng internally, which is a minor breaking change to the test utilities API.

Key changes:

  • Modified MockCryptoRng to implement SeedableRng trait for better RNG control
  • Updated test utility functions (run_keygen, run_refresh, run_reshare, etc.) to accept RNG parameters
  • Added deterministic snapshot tests for keygen, refresh, and reshare operations across multiple signature schemes
  • Added insta dependency for snapshot testing

Reviewed Changes

Copilot reviewed 49 out of 50 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/test_utils.rs Added SeedableRng implementation to MockCryptoRng and updated helper functions to accept RNG parameters
src/dkg.rs Refactored test functions to return results and accept RNG parameters for deterministic testing
src/eddsa/test.rs Added deterministic tests with snapshot assertions and updated existing tests to use seeded RNG
src/ecdsa/mod.rs Added deterministic snapshot tests for ECDSA keygen/refresh/reshare operations
src/ecdsa/robust_ecdsa/*.rs Updated all tests to use deterministic RNG instead of OsRng
src/ecdsa/ot_based_ecdsa/*.rs Updated OT-based ECDSA tests to use seeded RNG for determinism
src/confidential_key_derivation/*.rs Added deterministic tests and updated existing tests to use seeded RNG
src/crypto/*.rs Updated cryptographic proof tests to use MockCryptoRng instead of OsRng
benches/*.rs Updated benchmarks to use MockCryptoRng for consistency
Cargo.toml/Cargo.lock Added insta dependency for snapshot testing
snapshots/*.snap Added snapshot files capturing deterministic outputs of key operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@barakeinav1
Copy link

I did a brief review (loved your use of 42) . but I don't feel I have any useful feedback here.
I can approve as a rubber stamp, or you can wait for another reviewer.
let me know.

@gilcu3
Copy link
Contributor Author

gilcu3 commented Nov 20, 2025

I did a brief review (loved your use of 42) . but I don't feel I have any useful feedback here. I can approve as a rubber stamp, or you can wait for another reviewer. let me know.

I think is fine to approve even without feedback, as this was a second review after quite a few review changes yesterday. Anyway it will change a little bit after another PR is merged and I rebase this one, so I will ask for the rubber stamp then.

@gilcu3 gilcu3 force-pushed the 107-deterministic-unit-tests branch from aac3704 to 91e267c Compare November 20, 2025 15:00
@gilcu3 gilcu3 force-pushed the 107-deterministic-unit-tests branch 2 times, most recently from f30481e to 2f5fae7 Compare November 20, 2025 16:17
chore: added support for refresh and reshare

chore: added eddsa and ckd support

feat: add support for ecdsa

feat: make all tests deterministic

fix: address nits

feat: do determinism tests independently, use cargo-insta

fix: minor after rebase

fix: rebase fixes

fix: minor
@gilcu3 gilcu3 force-pushed the 107-deterministic-unit-tests branch from 2f5fae7 to 8bee803 Compare November 20, 2025 16:37
@gilcu3 gilcu3 requested review from DSharifi and barakeinav1 and removed request for netrome November 20, 2025 16:38
barakeinav1
barakeinav1 previously approved these changes Nov 20, 2025
SimonRastikian
SimonRastikian previously approved these changes Nov 20, 2025
Copy link
Contributor

@SimonRastikian SimonRastikian left a comment

Choose a reason for hiding this comment

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

Should be good overall,
Couple of comments about rng traits. Also I am not a big fan of the added files...

Copy link
Contributor

Choose a reason for hiding this comment

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

Why would this exist?
I am unsure whether I really enjoy it.

@gilcu3 gilcu3 removed the request for review from DSharifi November 21, 2025 06:50
netrome
netrome previously approved these changes Nov 21, 2025
@netrome netrome dismissed stale reviews from SimonRastikian, barakeinav1, and themself via 12becff November 21, 2025 08:46
@netrome netrome force-pushed the 107-deterministic-unit-tests branch from 12becff to 8bee803 Compare November 21, 2025 08:47
@netrome netrome merged commit 5d09fb4 into main Nov 21, 2025
6 checks passed
@netrome netrome deleted the 107-deterministic-unit-tests branch November 21, 2025 08:47
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.

Deterministic unit tests

7 participants