Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
failure_test_utils.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <memory>
5#include <unordered_map>
6#include <utility>
7
8namespace bb {
9
18template <typename Flavor> class MaliciousWitnessInjector {
19 public:
21 using FF = typename Flavor::FF;
23
25
26 private:
27 // Maps variable index to the "bad" value to be injected
28 std::unordered_map<uint32_t, FF> malicious_variable_map;
29
30 public:
40 uint32_t add_malicious_variable(const FF& good_val, const FF& bad_val)
41 {
42 uint32_t idx = builder.add_variable(good_val);
43 malicious_variable_map[idx] = bad_val;
44 return idx;
45 }
46
56 {
57 // Create good instance from original builder (this finalizes the circuit)
58 auto good_instance = std::make_shared<ProverInstance>(builder);
59
60 // Create bad instance
62 auto bad_instance = std::make_shared<ProverInstance>(bad_builder);
63
64 return { good_instance, bad_instance };
65 }
66
73 {
74 // Copy the builder
75 Builder bad_builder = builder;
76
77 // Inject faults into the copied builder's variables
78 auto& vars = const_cast<std::vector<FF>&>(bad_builder.get_variables());
79 for (const auto& [var_idx, bad_val] : malicious_variable_map) {
80 // Resolve through real_variable_index to handle copy constraints correctly
81 uint32_t real_idx = bad_builder.real_variable_index[var_idx];
82 vars[real_idx] = bad_val;
83 }
84
85 return bad_builder;
86 }
87};
88
89} // namespace bb
typename Curve::ScalarField FF
ECCVMCircuitBuilder CircuitBuilder
Test utility for injecting malicious witness values to test failure modes.
Builder create_builder_with_malicious_witnesses()
Create a copy of the builder with malicious values injected.
std::pair< std::shared_ptr< ProverInstance >, std::shared_ptr< ProverInstance > > create_instances()
Create two prover instances, one based on the good witness values and one based on the malicious valu...
typename Flavor::CircuitBuilder Builder
uint32_t add_malicious_variable(const FF &good_val, const FF &bad_val)
Add a "good" variable to the builder and specify a malicious value to inject later.
std::unordered_map< uint32_t, FF > malicious_variable_map
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13