8000 [WIP] feature(rosenpass): integrate assert_tv and derandomize protocol.rs by aminfa · Pull Request #604 · rosenpass/rosenpass · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[WIP] feature(rosenpass): integrate assert_tv and derandomize protocol.rs #604

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

aminfa
Copy link
Contributor
@aminfa aminfa commented Feb 10, 2025

Here is a WIP solution to integrate the assert_tv crate and derandomize the protocol.rs module.

This PR is mainly meant as a starting point to explore how to make derandomization as non-disruptiv as possible and also not clutter the entire code-base with #cfg[ ] macros and feature flags.

The way derandomization would work is with the help of 3 macros:

  • #[test_vec(..)]: proc macro that wraps a test and sets up a test_vec environment, which is stored and later accessed through thread-local storage, and finilizes it at the end.
  • tv_const!(..): macro that defines a constant value in the test vector. When test vectors are initialized, these values are serialized from the observed runtime values. When test vectors are checked, these values are loaded and injected at runtime and replace random variables.
  • tv_output!(..): macro that checks a result with the one found in the test vector. When test vectors are initialized, these values are also serialized from the observed runtime values. In contrast, when test vectors are checked, the runtime values are compared with the values loaded from the test vector file. If they don't match it will error.

Here is a test_vec test: crypto_server_test_vectors.rs

You may run this test with the following command

cargo test --package rosenpass --test crypto_server_test_vectors crypto_server_test_vector_1 --features tv -- --exact --ignored

Test vectors are frozen as files and checked into the repository. For example: crypto_server_test_vector_1.json

You may run this test in init mode (by setting an env variable) to overwrite the values stores in this test vector file:

TEST_MODE=check cargo test --package rosenpass --test crypto_server_test_vectors crypto_server_test_vector_1 --features tv -- --exact --ignored

Let me know what you think about the proposal, what you like to see improved or changed, or if you have any questions.

@aparcar aparcar self-requested a review February 11, 2025 09:57
@blipp blipp self-requested a review February 11, 2025 14:08
Remove feature tv
Stream-line integration of test-vectors further: Now cargo test --all-features should work
Switched to released assert_tv version
@aminfa
Copy link
Contributor Author
aminfa commented Feb 11, 2025

I had noticed that the rosenpass CI uses --all-features option when testing, which would enable the tv feature flag that would compile in the entire test vector implementation, which would break existing working tests. (as false positives)

I have fixed this design error by removing the requirement to add a feature as a client of assert_tv. Now when testing the test vectors, you would need to enable the assert_tv/enabled feature flag instead.

cargo test --package rosenpass --test crypto_server_test_vectors crypto_server_test_vector_1 --features assert_tv/enabled -- --exact

This let to a more streamlined integration elsewhere as well and many #[cfg(..)] macros also disappeared.

Copy link
codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 58.53659% with 17 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@b1658b8). Learn more about missing BASE report.

Files with missing lines Patch % Lines
rosenpass/tests/crypto_server_test_vectors.rs 0.00% 17 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #604   +/-   ##
=======================================
  Coverage        ?   88.22%           
=======================================
  Files           ?      102           
  Lines           ?    12734           
  Branches        ?      240           
=======================================
  Hits            ?    11235           
  Misses          ?     1496           
  Partials        ?        3           

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

@phildremi
Copy link
Contributor

I had noticed that the rosenpass CI uses --all-features option when testing, which would enable the tv feature flag that would compile in the entire test vector implementation, which would break existing working tests. (as false positives)

I have fixed this design error by removing the requirement to add a feature as a client of assert_tv. Now when testing the test vectors, you would need to enable the assert_tv/enabled feature flag instead.

I'm not familiar with tv, but if specific flags should be set in some scenarios and not doing it will lead to failures - maybe CONTRIBUTING.md could be updated to explain this to new/potential contributors? It could link to the CI workflow as an authoritative reference if keeping both in sync is too much work (or the flags don't require much of an explanation).

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.

2 participants
0