Convert more tests to Proptest#809
Open
daxpedda wants to merge 1 commit intodalek-cryptography:mainfrom
Open
Conversation
c463254 to
1c5ef0c
Compare
daxpedda
commented
Sep 1, 2025
| fn mul_base_clamped() { | ||
| let mut csprng = rand_core::OsRng; | ||
| #[property_test(config = ProptestConfig { cases: 50, .. ProptestConfig::default() })] | ||
| fn mul_base_clamped(b: EdwardsPoint, a: [[u8; 32]; 100]) { |
Contributor
Author
There was a problem hiding this comment.
I think this would be better split up into multiple tests, but I didn't know exactly how.
So here is a suggestion, let me know what you think:
/// Check that mul_base_clamped and mul_clamped agree
#[test]
fn mul_base_clamped_max() {
// Test that mul_base_clamped and mul_clamped agree on a large integer. Even after
// clamping, this integer is not reduced mod l.
let a_bytes = [0xff; 32];
assert_eq!(
EdwardsPoint::mul_base_clamped(a_bytes),
constants::ED25519_BASEPOINT_POINT.mul_clamped(a_bytes)
);
}
#[property_test]
fn mul_base_clamped(a_bytes: [u8; 32]) {
prop_assert_eq!(
EdwardsPoint::mul_base_clamped(a_bytes),
constants::ED25519_BASEPOINT_POINT.mul_clamped(a_bytes)
);
}
#[property_test(config = ProptestConfig { cases: 50, .. ProptestConfig::default() })]
#[cfg(feature = "precomputed-tables")]
fn mul_base_clamped_precomputed(b: EdwardsPoint, a_bytes: [u8; 32]) {
// Make a random curve point in the curve. Give it torsion to make things interesting.
let random_point = b + constants::EIGHT_TORSION[1];
// Make a basepoint table from the random point. We'll use this with mul_base_clamped
let random_table = EdwardsBasepointTableRadix256::create(&random_point);
prop_assert_eq!(
random_table.mul_base_clamped(a_bytes),
random_point.mul_clamped(a_bytes)
);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To make the code cleaner I implemented
Arbitraryfor various types where appropriate. The implementation is a bit naive because it simply maps by reducing instead of properly having a min/max implementation via a customValueTree.I also switched to the newer
#[property_test]instead ofproptest!.Follow-up from #806.