Skip to content
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

use property based testing #718

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ceno_zkvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tracing-subscriber.workspace = true

clap = { version = "4.5", features = ["derive"] }
generic_static = "0.2"
proptest = "1.5.0"
rand.workspace = true
tempfile = "3.14"
thread_local = "1.1"
Expand Down
11 changes: 6 additions & 5 deletions ceno_zkvm/src/instructions/riscv/slt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ mod test {

use rand::Rng;

use proptest::prelude::*;

use super::*;
use crate::{
circuit_builder::{CircuitBuilder, ConstraintSystem},
Expand Down Expand Up @@ -244,10 +246,9 @@ mod test {

#[test]
fn test_sltu_random() {
let mut rng = rand::thread_rng();
let a: u32 = rng.gen();
let b: u32 = rng.gen();
verify::<SltuOp>("random 1", a, b, (a < b) as u32);
verify::<SltuOp>("random 2", b, a, (a >= b) as u32);
proptest::proptest!(|(a in any::<u32>(), b in any::<u32>())| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for taking this on!

Please see #667 for something similar.

The main difference is any::<u32> picks from all u32 uniformly at random, but that PR is slightly more clever about the sampling.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I missed looking at that, sorry

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries. I didn't advertise enough, I guess.

verify::<SltuOp>("random 1", a, b, (a < b) as u32);
verify::<SltuOp>("random 2", b, a, (a >= b) as u32);
});
}
}