Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_mini.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
11
12using namespace bb;
13
16
17// Read uint256_t from raw bytes.
18// Don't use dereference casts, since the data may be not aligned and it causes segfault
19uint256_t read_uint256(const uint8_t* data, size_t buffer_size = 32)
20{
21 BB_ASSERT_LTE(buffer_size, 32U);
22
23 uint64_t parts[4] = { 0, 0, 0, 0 };
24
25 for (size_t i = 0; i < (buffer_size + 7) / 8; i++) {
26 size_t to_read = (buffer_size - i * 8) < 8 ? buffer_size - i * 8 : 8;
27 std::memcpy(&parts[i], data + i * 8, to_read);
28 }
29 return uint256_t(parts[0], parts[1], parts[2], parts[3]);
30}
31
32extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size)
33{
34 constexpr size_t NUM_LIMB_BITS = bb::TranslatorCircuitBuilder::NUM_LIMB_BITS;
35 constexpr size_t NUM_LAST_LIMB_BITS = bb::TranslatorCircuitBuilder::NUM_LAST_LIMB_BITS;
36 constexpr size_t WIDE_LIMB_BITS = bb::TranslatorCircuitBuilder::NUM_Z_BITS;
37 constexpr size_t WIDE_LIMB_BYTES = (WIDE_LIMB_BITS + 7) / 8;
38 constexpr size_t TOTAL_SIZE = 1 + 5 * sizeof(numeric::uint256_t) + 2 * WIDE_LIMB_BYTES;
39 if (size < (TOTAL_SIZE)) {
40 return 0;
41 }
42 size_t op = data[0] & 3;
43 EccOpCode op_code;
44 switch (op) {
45 case 3:
46 op_code = EccOpCode{ .eq = true, .reset = true };
47 break;
48 case 4:
49 op_code = EccOpCode{ .mul = true };
50 break;
51 case 8:
52 op_code = EccOpCode{ .add = true };
53 break;
54 default:
55 op_code = EccOpCode{};
56 break;
57 }
58
59 Fq p_x = Fq(read_uint256(data + 1));
60 Fr p_x_lo = uint256_t(p_x).slice(0, 2 * NUM_LIMB_BITS);
61 Fr p_x_hi = uint256_t(p_x).slice(2 * NUM_LIMB_BITS, 3 * NUM_LIMB_BITS + NUM_LAST_LIMB_BITS);
62
63 Fq p_y = Fq(read_uint256(data + sizeof(uint256_t) + 1));
64 Fr p_y_lo = uint256_t(p_y).slice(0, 2 * NUM_LIMB_BITS);
65 Fr p_y_hi = uint256_t(p_y).slice(2 * NUM_LIMB_BITS, 3 * NUM_LIMB_BITS + NUM_LAST_LIMB_BITS);
66
67 Fq v = Fq(read_uint256(data + 2 * sizeof(uint256_t) + 1));
68 Fq x = Fq(read_uint256(data + 3 * sizeof(uint256_t) + 1));
69 Fq previous_accumulator = Fq(read_uint256(data + 4 * sizeof(uint256_t) + 1));
70
71 Fr z_1 = Fr(read_uint256(data + 1 + 5 * sizeof(uint256_t), WIDE_LIMB_BYTES).slice(0, WIDE_LIMB_BITS));
72 Fr z_2 =
73 Fr(read_uint256(data + 1 + 5 * sizeof(uint256_t) + WIDE_LIMB_BYTES, WIDE_LIMB_BYTES).slice(0, WIDE_LIMB_BITS));
74
77 .x_lo = p_x_lo,
78 .x_hi = p_x_hi,
79 .y_lo = p_y_lo,
80 .y_hi = p_y_hi,
81 .z_1 = z_1,
82 .z_2 = z_2 },
83 previous_accumulator,
84 v,
85 x);
86
87 auto circuit_builder = bb::TranslatorCircuitBuilder(v, x);
88 circuit_builder.create_accumulation_gate(single_accumulation_step);
89 if (!TranslatorCircuitChecker::check(circuit_builder)) {
90 return 1;
91 }
92 return 0;
93}
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:129
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static AccumulationInput generate_witness_values(const UltraOp &ultra_op, const Fq &previous_accumulator, const Fq &batching_challenge_v, const Fq &evaluation_input_x)
Given the transcript values from the EccOpQueue, the values of the previous accumulator,...
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
bb::fq BaseField
Definition bn254.hpp:19
bb::fr ScalarField
Definition bn254.hpp:18
constexpr uint256_t slice(uint64_t start, uint64_t end) const
const std::vector< FF > data
Entry point for Barretenberg command-line interface.
C slice(C const &container, size_t start)
Definition container.hpp:9
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Defines the opcodes for ECC operations used in both the Ultra and ECCVM formats. There are three opco...
The accumulation input structure contains all the necessary values to initalize an accumulation gate ...
EccOpCode op_code
curve::BN254::BaseField Fq
int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
uint256_t read_uint256(const uint8_t *data, size_t buffer_size=32)
curve::BN254::ScalarField Fr