Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_circuit_builder.fuzzer.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
9
14extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
15{
16 // Parse the queue and challenges
17 auto parsing_result = parse_and_construct_opqueue(data, size);
18 if (!parsing_result.has_value()) {
19 return 0;
20 }
21 auto [batching_challenge, x, op_queue] = parsing_result.value();
22 // Construct the circuit
23 auto circuit_builder = TranslatorCircuitBuilder(batching_challenge, x, op_queue);
24
25 Fq x_inv = x.invert();
26 auto op_accumulator = Fq(0);
27 auto p_x_accumulator = Fq(0);
28 auto p_y_accumulator = Fq(0);
29 auto z_1_accumulator = Fq(0);
30 auto z_2_accumulator = Fq(0);
31 // Compute the batched evaluation of polynomials (multiplying by inverse to go from lower to higher)
32 const auto& eccvm_ops = op_queue->get_eccvm_ops();
33 for (const auto& ecc_op : eccvm_ops) {
34 op_accumulator = op_accumulator * x_inv + ecc_op.op_code.value();
35 p_x_accumulator = p_x_accumulator * x_inv + ecc_op.base_point.x;
36 p_y_accumulator = p_y_accumulator * x_inv + ecc_op.base_point.y;
37 z_1_accumulator = z_1_accumulator * x_inv + ecc_op.z1;
38 z_2_accumulator = z_2_accumulator * x_inv + ecc_op.z2;
39 }
40 Fq x_pow = x.pow(eccvm_ops.size() - 1);
41
42 // Multiply by an appropriate power of x to get rid of the inverses
43 [[maybe_unused]] Fq result =
44 ((((z_2_accumulator * batching_challenge + z_1_accumulator) * batching_challenge + p_y_accumulator) *
45 batching_challenge +
46 p_x_accumulator) *
47 batching_challenge +
48 op_accumulator) *
49 x_pow;
50
51 // The data is malformed, so just call check_circuit, but ignore the output
52 if (!TranslatorCircuitChecker::check(circuit_builder)) {
53 return 1;
54 }
55 return 0;
56}
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
const std::vector< MemoryValue > data
BB_INLINE constexpr field pow(const uint256_t &exponent) const noexcept
constexpr field invert() const noexcept
Contains common procedures used by the circuit builder fuzzer and the composer fuzzer.
std::optional< std::tuple< Fq, Fq, std::shared_ptr< ECCOpQueue > > > parse_and_construct_opqueue(const unsigned char *data, size_t size)
Try to parse out the batching and evaluating challenges and then the ECCOpQueue from the data.
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
A very primitive fuzzing harness, no interesting mutations, just parse and throw at the circuit build...