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 Base = Base_
 
using Builder = Base::Builder
 
using InvalidWitness = Base::InvalidWitness
 
using InvalidWitnessTarget = InvalidWitness::Target
 
using AcirConstraint = Base::AcirConstraint
 

Static Public Member Functions

static std::pair< AcirConstraint, WitnessVectorupdate_witness_based_on_predicate (const AcirConstraint &constraint, const WitnessVector &witness_values, const Predicate< InvalidWitnessTarget > &mode)
 Update the constraint and the witness based on the predicate.
 
static std::tuple< bool, bool, std::string > test_constraints (AcirConstraint &constraint, WitnessVector &witness_values, const PredicateTestCase &test_case, const InvalidWitnessTarget &invalid_witness_target)
 General purpose testing function. It tests the contraints 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 100 of file test_class_predicate.hpp.

Member Typedef Documentation

◆ AcirConstraint

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

Definition at line 106 of file test_class_predicate.hpp.

◆ Base

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

Definition at line 102 of file test_class_predicate.hpp.

◆ Builder

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

Definition at line 103 of file test_class_predicate.hpp.

◆ InvalidWitness

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

Definition at line 104 of file test_class_predicate.hpp.

◆ InvalidWitnessTarget

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

Definition at line 105 of file test_class_predicate.hpp.

Member Function Documentation

◆ 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 255 of file test_class_predicate.hpp.

◆ test_constraints()

template<TestBaseWithPredicate Base_>
static std::tuple< bool, bool, std::string > acir_format::TestClassWithPredicate< Base_ >::test_constraints ( AcirConstraint constraint,
WitnessVector witness_values,
const PredicateTestCase test_case,
const InvalidWitnessTarget invalid_witness_target 
)
inlinestatic

General purpose testing function. It tests the contraints 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.

Note
The constraint and witness values must be copied otherwise this would affect later calls to this function

Definition at line 159 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 414 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 186 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 331 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 363 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 295 of file test_class_predicate.hpp.

◆ update_witness_based_on_predicate()

template<TestBaseWithPredicate Base_>
static std::pair< AcirConstraint, WitnessVector > acir_format::TestClassWithPredicate< Base_ >::update_witness_based_on_predicate ( const AcirConstraint constraint,
const 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.
Note
The constraint and witness values must be copied otherwise this would affect later calls to this function

Definition at line 119 of file test_class_predicate.hpp.


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