|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Verify gate patterns match actual relation constraints via perturbation testing. More...
#include "gate_patterns.hpp"#include "barretenberg/flavor/mega_flavor.hpp"#include "barretenberg/relations/databus_lookup_relation.hpp"#include "barretenberg/relations/delta_range_constraint_relation.hpp"#include "barretenberg/relations/elliptic_relation.hpp"#include "barretenberg/relations/logderiv_lookup_relation.hpp"#include "barretenberg/relations/memory_relation.hpp"#include "barretenberg/relations/non_native_field_relation.hpp"#include "barretenberg/relations/poseidon2_external_relation.hpp"#include "barretenberg/relations/poseidon2_internal_relation.hpp"#include "barretenberg/relations/relation_parameters.hpp"#include "barretenberg/relations/ultra_arithmetic_relation.hpp"#include <gtest/gtest.h>#include <set>Go to the source code of this file.
Typedefs | |
| using | FF = fr |
| using | Entities = MegaFlavor::AllValues |
Functions | |
| Entities | get_random_entities () |
| FF & | get_wire (Entities &entities, Wire wire) |
| Selectors | make_selectors (const Entities &entities, int64_t gate_selector_value) |
| std::set< Wire > | get_pattern_wires (const GatePattern &pattern, const Selectors &selectors) |
| Get the set of wires that a pattern claims are constrained. | |
| template<typename Relation > | |
| std::set< Wire > | get_actually_constrained_wires (const Entities &entities, const auto ¶meters) |
| Get the set of wires that actually affect a relation's output. | |
| template<typename Relation > | |
| void | verify_pattern (const GatePattern &pattern, auto configure_selectors) |
| Generic test: verify a pattern matches what the relation actually constrains. | |
| TEST (PatternTest, Arithmetic1) | |
| TEST (PatternTest, Arithmetic2) | |
| TEST (PatternTest, Arithmetic3) | |
| TEST (PatternTest, Arithmetic3WithQmZero) | |
| TEST (PatternTest, EllipticAdd) | |
| TEST (PatternTest, EllipticDouble) | |
| TEST (PatternTest, DeltaRange) | |
| TEST (PatternTest, NNFLimbAccum1) | |
| TEST (PatternTest, NNFLimbAccum2) | |
| TEST (PatternTest, NNFProduct1) | |
| TEST (PatternTest, NNFProduct2) | |
| TEST (PatternTest, NNFProduct3) | |
| TEST (PatternTest, MemoryRamRomAccess) | |
| TEST (PatternTest, MemoryRamTimestamp) | |
| TEST (PatternTest, MemoryRomConsistency) | |
| TEST (PatternTest, MemoryRamConsistency) | |
| TEST (PatternTest, Poseidon2Internal) | |
| TEST (PatternTest, Poseidon2External) | |
| TEST (PatternTest, LookupBasic) | |
| TEST (PatternTest, LookupWithShiftedWires) | |
| TEST (PatternTest, DatabusRead) | |
| TEST (PatternTest, DetectOverConstrained) | |
| Verify detection of OVER-constrained pattern (claims more wires than relation uses) | |
| TEST (PatternTest, DetectUnderConstrained) | |
| Verify detection of UNDER-constrained pattern (misses wires that relation uses) | |
Verify gate patterns match actual relation constraints via perturbation testing.
A wire is constrained by a relation if and only if perturbing that wire changes the relation's output. We test this empirically by:
Definition in file gate_patterns.test.cpp.
| using Entities = MegaFlavor::AllValues |
Definition at line 31 of file gate_patterns.test.cpp.
Definition at line 30 of file gate_patterns.test.cpp.
| std::set< Wire > get_actually_constrained_wires | ( | const Entities & | entities, |
| const auto & | parameters | ||
| ) |
Get the set of wires that actually affect a relation's output.
This is the ground truth: perturb each wire and see if the output changes.
Definition at line 98 of file gate_patterns.test.cpp.
| std::set< Wire > get_pattern_wires | ( | const GatePattern & | pattern, |
| const Selectors & | selectors | ||
| ) |
Get the set of wires that a pattern claims are constrained.
Definition at line 81 of file gate_patterns.test.cpp.
| Entities get_random_entities | ( | ) |
Definition at line 33 of file gate_patterns.test.cpp.
Definition at line 42 of file gate_patterns.test.cpp.
Definition at line 65 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| Arithmetic1 | |||
| ) |
Definition at line 153 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| Arithmetic2 | |||
| ) |
Definition at line 158 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| Arithmetic3 | |||
| ) |
Definition at line 163 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| Arithmetic3WithQmZero | |||
| ) |
Definition at line 168 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| DatabusRead | |||
| ) |
Definition at line 323 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| DeltaRange | |||
| ) |
Definition at line 194 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| DetectOverConstrained | |||
| ) |
Verify detection of OVER-constrained pattern (claims more wires than relation uses)
When q_arith==3, the multiplication term q_m * w_l * w_r is disabled (scaled by q_arith - 3 = 0). So w_r is only constrained via the linear term q_2 * w_r. A pattern that includes w_r whenever q_m != 0 (without checking q_arith != 3) over-constrains when q_arith=3, q_m!=0, q_2=0.
Definition at line 343 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| DetectUnderConstrained | |||
| ) |
Verify detection of UNDER-constrained pattern (misses wires that relation uses)
The RAM consistency relation (q_3 != 0) constrains all 8 wires. A pattern that only extracts 6 wires (omitting w_l and w_r) under-constrains.
Definition at line 390 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| EllipticAdd | |||
| ) |
Definition at line 176 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| EllipticDouble | |||
| ) |
Definition at line 185 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| LookupBasic | |||
| ) |
Definition at line 301 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| LookupWithShiftedWires | |||
| ) |
Definition at line 312 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| MemoryRamConsistency | |||
| ) |
Definition at line 281 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| MemoryRamRomAccess | |||
| ) |
Definition at line 254 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| MemoryRamTimestamp | |||
| ) |
Definition at line 263 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| MemoryRomConsistency | |||
| ) |
Definition at line 272 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| NNFLimbAccum1 | |||
| ) |
Definition at line 199 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| NNFLimbAccum2 | |||
| ) |
Definition at line 210 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| NNFProduct1 | |||
| ) |
Definition at line 221 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| NNFProduct2 | |||
| ) |
Definition at line 232 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| NNFProduct3 | |||
| ) |
Definition at line 243 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| Poseidon2External | |||
| ) |
Definition at line 295 of file gate_patterns.test.cpp.
| TEST | ( | PatternTest | , |
| Poseidon2Internal | |||
| ) |
Definition at line 289 of file gate_patterns.test.cpp.
| void verify_pattern | ( | const GatePattern & | pattern, |
| auto | configure_selectors | ||
| ) |
Generic test: verify a pattern matches what the relation actually constrains.
| configure_selectors | Lambda that configures entity selectors and returns the gate selector field value |
Definition at line 134 of file gate_patterns.test.cpp.