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

chore: test blackbox binary op instructions #5484

Merged
merged 20 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
59423e5
add simple acvm test for binary AND commutativity, add single-op solv…
michaeljklein Jul 11, 2024
ba58119
wip commutative tests for and/xor, converted and extended control flo…
michaeljklein Jul 11, 2024
bd36dc5
add handling for witness vs constant inputs, wip testing bigint's, ad…
michaeljklein Jul 12, 2024
1ed070e
add tests for zero l/r for AND, bigint generator/harness with a bunch…
michaeljklein Jul 16, 2024
6db5c25
add noir test program for too-large bigint, add method to generate tr…
michaeljklein Jul 18, 2024
822f6a9
cargo fmt, factor out opcode and input setup functions
michaeljklein Jul 18, 2024
741a572
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 18, 2024
df45f20
remove bigint and control flow tests
michaeljklein Jul 18, 2024
004016b
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 23, 2024
cd7ffbe
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 23, 2024
fc72df0
add f(x, x) tests, convert any::<T> to ': T', link to follow-up issue
michaeljklein Jul 23, 2024
a30e55f
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 23, 2024
6a2b4c5
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 24, 2024
605c1e9
remove redundant '_r' tests, fix associativity test
michaeljklein Jul 24, 2024
2ed945d
fix exponenet in field_element_ones
michaeljklein Jul 24, 2024
5d6deb5
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 25, 2024
df2804a
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 29, 2024
bddd985
use proptest-provided use_constant for xy/yz binary operations
michaeljklein Jul 29, 2024
7f3c15a
Merge branch 'master' into michaeljklein/test-binary-ops
michaeljklein Jul 30, 2024
5797c70
mark test as expected failure w/ linked issue, cargo clippy
michaeljklein Jul 30, 2024
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
59 changes: 59 additions & 0 deletions acvm-repo/acvm/tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use acvm_blackbox_solver::StubbedBlackBoxSolver;
use brillig_vm::brillig::HeapValueType;

use proptest::prelude::*;
use proptest::arbitrary::any;

// Reenable these test cases once we move the brillig implementation of inversion down into the acvm stdlib.

Expand Down Expand Up @@ -796,3 +797,61 @@ fn binary_operations() {

}

fn and_op() -> BlackBoxFuncCall<FieldElement> {
BlackBoxFuncCall::AND {
lhs: FunctionInput::witness(Witness(1), FieldElement::max_num_bits()),
rhs: FunctionInput::witness(Witness(2), FieldElement::max_num_bits()),
output: Witness(3),
}
}

fn xor_op() -> BlackBoxFuncCall<FieldElement> {
BlackBoxFuncCall::XOR {
lhs: FunctionInput::witness(Witness(1), FieldElement::max_num_bits()),
rhs: FunctionInput::witness(Witness(2), FieldElement::max_num_bits()),
output: Witness(3),
}
}

fn prop_assert_eq(op: BlackBoxFuncCall<FieldElement>, x: u128, y: u128) -> TestCaseResult {
let assertion: Result<_, TestCaseError> = prop_assert_eq!(solve_blackbox_func_call(op.clone(), x, y), solve_blackbox_func_call(op, y, x));
assertion?;
Ok(())
}


proptest! {

#[test]
fn and_commutative(x in any::<u128>(), y in any::<u128>()) {
michaeljklein marked this conversation as resolved.
Show resolved Hide resolved
let op = and_op();
prop_assert_commutes(op, x, y)
}

#[test]
fn xor_commutative(x in any::<u128>(), y in any::<u128>()) {
let op = xor_op();
prop_assert_eq!(solve_blackbox_func_call(op.clone(), x, y), solve_blackbox_func_call(op, y, x));
}

// #[test]
// fn and_associative(x in any::<u128>(), y in any::<u128>()) {
// let op = and_op();
// prop_assert_eq!(solve_blackbox_func_call(op.clone(), x, y), solve_blackbox_func_call(op, y, x));
// }


// // This currently panics due to the fact that we allow inputs which are greater than the field modulus,
// // automatically reducing them to fit within the canonical range.
// #[test]
// #[should_panic(expected = "serialized field element is not equal to input")]
// fn recovers_original_hex_string(hex in "[0-9a-f]{64}") {
// let fe: FieldElement::<ark_bn254::Fr> = FieldElement::from_hex(&hex).expect("should accept any 32 byte hex string");
// let output_hex = fe.to_hex();
//
// prop_assert_eq!(hex, output_hex, "serialized field element is not equal to input");
// }

}


Loading
Loading