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: [], 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
9
14extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
15{
16 // Parse the queue and challenges
17 // TODO(https://github.com/AztecProtocol/barretenberg/issues/869): composer generates the initial challenge through
18 // FS, so we have to do that, too
19 auto parsing_result = parse_and_construct_opqueue(data, size);
20 if (!parsing_result.has_value()) {
21 return 0;
22 }
23 auto [batching_challenge, x, op_queue] = parsing_result.value();
24 // Construct the circuit
25 auto circuit_builder = TranslatorCircuitBuilder(batching_challenge, x, op_queue);
26
27 Fq x_inv = x.invert();
28 auto op_accumulator = Fq(0);
29 auto p_x_accumulator = Fq(0);
30 auto p_y_accumulator = Fq(0);
31 auto z_1_accumulator = Fq(0);
32 auto z_2_accumulator = Fq(0);
33 // Compute the batched evaluation of polynomials (multiplying by inverse to go from lower to higher)
34 const auto& eccvm_ops = op_queue->get_eccvm_ops();
35 for (const auto& ecc_op : eccvm_ops) {
36 op_accumulator = op_accumulator * x_inv + ecc_op.op_code.value();
37 p_x_accumulator = p_x_accumulator * x_inv + ecc_op.base_point.x;
38 p_y_accumulator = p_y_accumulator * x_inv + ecc_op.base_point.y;
39 z_1_accumulator = z_1_accumulator * x_inv + ecc_op.z1;
40 z_2_accumulator = z_2_accumulator * x_inv + ecc_op.z2;
41 }
42 Fq x_pow = x.pow(eccvm_ops.size() - 1);
43
44 // Multiply by an appropriate power of x to get rid of the inverses
45 [[maybe_unused]] Fq result =
46 ((((z_2_accumulator * batching_challenge + z_1_accumulator) * batching_challenge + p_y_accumulator) *
47 batching_challenge +
48 p_x_accumulator) *
49 batching_challenge +
50 op_accumulator) *
51 x_pow;
52
53 // The data is malformed, so just call check_circuit, but ignore the output
54 if (!TranslatorCircuitChecker::check(circuit_builder)) {
55 return 1;
56 }
57 return 0;
58}
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< FF > data
BB_INLINE constexpr field pow(const uint256_t &exponent) const noexcept
constexpr field invert() const noexcept
bb::fq Fq
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...