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// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8
10#include <memory>
11#include <unordered_map>
12#include <utility>
13
14namespace bb {
15
24template <typename Flavor> class MaliciousWitnessInjector {
25 public:
27 using FF = typename Flavor::FF;
29
31
32 private:
33 // Maps variable index to the "bad" value to be injected
34 std::unordered_map<uint32_t, FF> malicious_variable_map;
35
36 public:
46 uint32_t add_malicious_variable(const FF& good_val, const FF& bad_val)
47 {
48 uint32_t idx = builder.add_variable(good_val);
49 malicious_variable_map[idx] = bad_val;
50 return idx;
51 }
52
62 {
63 // Create good instance from original builder (this finalizes the circuit)
64 auto good_instance = std::make_shared<ProverInstance>(builder);
65
66 // Create bad instance
68 auto bad_instance = std::make_shared<ProverInstance>(bad_builder);
69
70 return { good_instance, bad_instance };
71 }
72
79 {
80 // Copy the builder
81 Builder bad_builder = builder;
82
83 // Inject faults into the copied builder's variables
84 auto& vars = const_cast<std::vector<FF>&>(bad_builder.get_variables());
85 for (const auto& [var_idx, bad_val] : malicious_variable_map) {
86 // Resolve through real_variable_index to handle copy constraints correctly
87 uint32_t real_idx = bad_builder.real_variable_index[var_idx];
88 vars[real_idx] = bad_val;
89 }
90
91 return bad_builder;
92 }
93};
94
95} // 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