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

CHIA-193: Rust bindings to chiapos #439

Merged
merged 25 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions rust-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ link-cplusplus = "1.0.9"
[build-dependencies]
bindgen = "0.69.4"
cmake = "0.1.50"

[dev-dependencies]
hex = "0.4.3"
28 changes: 28 additions & 0 deletions rust-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ pub fn validate_proof(
mod tests {
use super::*;

#[test]
fn test_proofs() {
/*
* Generated by printing the inputs to validate_proof in tests/test_python_bindings.py
* Specifically, the test_k_21 function was adapted to append 100 lines to the file.
*/
let proofs = include_str!("../test_proofs.txt");
arvidn marked this conversation as resolved.
Show resolved Hide resolved

for line in proofs.lines() {
let mut parts = line.split(", ");
let seed = hex::decode(parts.next().unwrap()).unwrap();
let k = parts.next().unwrap().parse().unwrap();
let challenge = hex::decode(parts.next().unwrap()).unwrap();
let proof = hex::decode(parts.next().unwrap()).unwrap();
let quality = hex::decode(parts.next().unwrap()).unwrap();

let mut actual_quality = [0; 32];
assert!(validate_proof(
&seed.try_into().unwrap(),
k,
&challenge.try_into().unwrap(),
&proof,
&mut actual_quality
));
assert_eq!(actual_quality.as_slice(), quality);
arvidn marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[test]
fn test_empty_proof() {
let mut quality = [0; 32];
Expand Down
Loading
Loading