Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
acir_format::TestClassWithPredicate< Base > Class Template Reference

Test class for ACIR constraints that contain a predicate. More...

#include <test_class_predicate.hpp>

Public Types

using Builder = Base::Builder
 
using InvalidWitness = Base::InvalidWitness
 
using InvalidWitnessTarget = InvalidWitness::Target
 
using AcirConstraint = Base::AcirConstraint
 

Static Public Member Functions

static void update_witness_based_on_predicate (AcirConstraint &constraint, WitnessVector &witness_values, const Predicate< InvalidWitnessTarget > &mode)
 Update the constraint and the witness based on the predicate.
 
static std::pair< AcirConstraint, WitnessVectorgenerate_constraints (const Predicate< InvalidWitnessTarget > &mode)
 Generate constraints and witness values based on the predicate and the invalidation target.
 
static std::tuple< bool, bool, std::string > test_constraints (const PredicateTestCase &test_case, const InvalidWitnessTarget &invalid_witness_target)
 General purpose testing function. It generates the test based on the predicate and invalidation target.
 
template<typename Flavor >
static std::vector< size_t > test_vk_independence ()
 Test vk generation is independent of the witness values supplied.
 
static void test_constant_true (InvalidWitnessTarget default_invalid_witness_target)
 Test all cases in which the predicate is a constant holding the value true.
 
static void test_witness_true (InvalidWitnessTarget default_invalid_witness_target)
 Test all cases in which the predicate is a witness holding the value true.
 
static void test_witness_false ()
 Test all invalid witness cases for the witness false predicate case.
 
static void test_witness_false_slow ()
 Test all invalid witness cases for the witness false predicate case (slow comprehensive version).
 
static std::vector< std::string > test_invalid_witnesses ()
 Test all invalid witness targets across all predicate cases (comprehensive matrix test).
 

Detailed Description

template<TestBaseWithPredicate Base>
class acir_format::TestClassWithPredicate< Base >

Test class for ACIR constraints that contain a predicate.

Definition at line 95 of file test_class_predicate.hpp.

Member Typedef Documentation

◆ AcirConstraint

template<TestBaseWithPredicate Base>
using acir_format::TestClassWithPredicate< Base >::AcirConstraint = Base::AcirConstraint

Definition at line 100 of file test_class_predicate.hpp.

◆ Builder

template<TestBaseWithPredicate Base>
using acir_format::TestClassWithPredicate< Base >::Builder = Base::Builder

Definition at line 97 of file test_class_predicate.hpp.

◆ InvalidWitness

template<TestBaseWithPredicate Base>
using acir_format::TestClassWithPredicate< Base >::InvalidWitness = Base::InvalidWitness

Definition at line 98 of file test_class_predicate.hpp.

◆ InvalidWitnessTarget

template<TestBaseWithPredicate Base>
using acir_format::TestClassWithPredicate< Base >::InvalidWitnessTarget = InvalidWitness::Target

Definition at line 99 of file test_class_predicate.hpp.

Member Function Documentation

◆ generate_constraints()

template<TestBaseWithPredicate Base>
static std::pair< AcirConstraint, WitnessVector > acir_format::TestClassWithPredicate< Base >::generate_constraints ( const Predicate< InvalidWitnessTarget > &  mode)
inlinestatic

Generate constraints and witness values based on the predicate and the invalidation target.

Definition at line 134 of file test_class_predicate.hpp.

◆ test_constant_true()

template<TestBaseWithPredicate Base>
static void acir_format::TestClassWithPredicate< Base >::test_constant_true ( InvalidWitnessTarget  default_invalid_witness_target)
inlinestatic

Test all cases in which the predicate is a constant holding the value true.

When the predicate is a constant true, the constraint is always active and must be satisfied. This test verifies two scenarios:

  1. With valid witnesses (no invalidation): the circuit should succeed
  2. With invalid witnesses (using default_invalid_witness_target): the circuit should fail
Parameters
default_invalid_witness_targetInvalidation target to be used to check that the circuit fails when witnesses are invalid.

Definition at line 243 of file test_class_predicate.hpp.

◆ test_constraints()

template<TestBaseWithPredicate Base>
static std::tuple< bool, bool, std::string > acir_format::TestClassWithPredicate< Base >::test_constraints ( const PredicateTestCase test_case,
const InvalidWitnessTarget invalid_witness_target 
)
inlinestatic

General purpose testing function. It generates the test based on the predicate and invalidation target.

In a real flow, we have: Noir --> ACIR --> Bytes --> AcirFormat (via circuit_buf_to_acir_format) --> Builder We simulate the above flow by generating an AcirConstraint (one of the constraints stored in an AcirFormat struct), rewinding it into its Acir::Opcode form (which is the output of the byte deserialization step in the diagram above), and then feeding it into circuit_serde_to_acir_format as an Acir::Circuit with a single opcode. The function circuit_buf_to_acir_format internally calls circuit_serde_to_acir_format after having deserialized the byte buffer to an Acir::Circuit, so the flow in this test is the same as the real flow, minus the byte serialization/deserialization. The rationale for doing the rewinding is ensuring that barretenberg internally tests circuit_serde_to_acir_format, which would otherwise only be tested via the tests in acir_tests.

Definition at line 158 of file test_class_predicate.hpp.

◆ test_invalid_witnesses()

template<TestBaseWithPredicate Base>
static std::vector< std::string > acir_format::TestClassWithPredicate< Base >::test_invalid_witnesses ( )
inlinestatic

Test all invalid witness targets across all predicate cases (comprehensive matrix test).

This is a comprehensive test that creates a matrix of all combinations:

  • Predicate cases: ConstantTrue, WitnessTrue, WitnessFalse
  • Invalid witness targets: None, and all constraint-specific invalidation targets

Expected behavior:

  • When predicate is TRUE (constant or witness) and target is None: circuit succeeds (valid witnesses)
  • When predicate is TRUE (constant or witness) and target is NOT None: circuit fails (invalid witnesses detected)
  • When predicate is FALSE and target is ANY value: circuit succeeds
Returns
std::vector<std::string> List of error messages from the builder for each test case.

Definition at line 382 of file test_class_predicate.hpp.

◆ test_vk_independence()

template<TestBaseWithPredicate Base>
template<typename Flavor >
static std::vector< size_t > acir_format::TestClassWithPredicate< Base >::test_vk_independence ( )
inlinestatic

Test vk generation is independent of the witness values supplied.

This function tests that the verification key is deterministic and independent of the witness values by going through the full ACIR flow.

Template Parameters
Flavor

Definition at line 183 of file test_class_predicate.hpp.

◆ test_witness_false()

template<TestBaseWithPredicate Base>
static void acir_format::TestClassWithPredicate< Base >::test_witness_false ( )
inlinestatic

Test all invalid witness cases for the witness false predicate case.

When the predicate is a witness set to false, the constraint is disabled and should not fail regardless of witness validity. This test iterates through ALL invalid witness targets (None, and all specific invalidation cases) and verifies that the circuit succeeds in every case when predicate = false.

Definition at line 309 of file test_class_predicate.hpp.

◆ test_witness_false_slow()

template<TestBaseWithPredicate Base>
static void acir_format::TestClassWithPredicate< Base >::test_witness_false_slow ( )
inlinestatic

Test all invalid witness cases for the witness false predicate case (slow comprehensive version).

This is an extended version of test_witness_false that performs double verification:

For each invalid witness target:

  1. First pass (predicate = false): Verifies the circuit succeeds with invalid witnesses when predicate is false
  2. Second pass (predicate = true): Verifies the SAME invalid witness configuration would fail if the predicate were true

The second pass validates that our invalidation logic is actually creating invalid inputs. Useful for debugging.

Definition at line 336 of file test_class_predicate.hpp.

◆ test_witness_true()

template<TestBaseWithPredicate Base>
static void acir_format::TestClassWithPredicate< Base >::test_witness_true ( InvalidWitnessTarget  default_invalid_witness_target)
inlinestatic

Test all cases in which the predicate is a witness holding the value true.

When the predicate is a witness set to true, the constraint is active and must be satisfied. This test verifies two scenarios:

  1. With valid witnesses (no invalidation): the circuit should succeed
  2. With invalid witnesses (using default_invalid_witness_target): the circuit should fail
Parameters
default_invalid_witness_targetInvalidation target to be used to check that the circuit fails when witnesses are invalid.

Definition at line 278 of file test_class_predicate.hpp.

◆ update_witness_based_on_predicate()

template<TestBaseWithPredicate Base>
static void acir_format::TestClassWithPredicate< Base >::update_witness_based_on_predicate ( AcirConstraint constraint,
WitnessVector witness_values,
const Predicate< InvalidWitnessTarget > &  mode 
)
inlinestatic

Update the constraint and the witness based on the predicate.

Parameters
constraint
witness_values
mode
forced_invalidationIf true, forces the witness to be invalidated even if the predicate is not witness false. Used to check that the circuit fails if the predicate is witness true and witnesses are invalid.

Definition at line 111 of file test_class_predicate.hpp.


The documentation for this class was generated from the following file: