Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
secp256r1_fake_glv_decomposition.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
22
23#include <cassert>
24#include <cstdint>
25#include <cstring>
26
29
30extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size)
31{
32 // Need 32 bytes for one scalar.
33 if (Size < 32) {
34 return 0;
35 }
36
37 // Reconstruct s mod n from raw bytes (interpret little-endian into uint256_t, fr constructor reduces).
38 uint64_t limbs[4]{};
39 for (size_t i = 0; i < 4; ++i) {
40 std::memcpy(&limbs[i], Data + i * 8, sizeof(uint64_t));
41 }
42 const uint256_t s_raw(limbs[0], limbs[1], limbs[2], limbs[3]);
43 const fr s = fr(s_raw);
44
46
47 // Size bounds: both |alpha| and |beta| must fit in 128 bits (in fact < sqrt(n) < 2^128).
48 constexpr uint256_t bound = uint256_t(1) << 128;
49 assert(decomp.alpha < bound && "secp256r1 fake-GLV: alpha >= 2^128");
50 assert(decomp.beta_abs < bound && "secp256r1 fake-GLV: |beta| >= 2^128");
51
52 // Congruence: beta_signed * s ≡ alpha (mod n).
53 const fr beta_abs_fr(decomp.beta_abs);
54 const fr beta_signed = decomp.beta_is_negative ? -beta_abs_fr : beta_abs_fr;
55 const fr lhs = beta_signed * s;
56 const fr rhs(decomp.alpha);
57 assert(lhs == rhs && "secp256r1 fake-GLV: beta_signed * s != alpha (mod n)");
58
59 // Degenerate s = 0 must return (0, 1, false) so the caller's substitution path is well-defined.
60 if (s == fr::zero()) {
61 assert(decomp.alpha == uint256_t(0));
62 assert(decomp.beta_abs == uint256_t(1));
63 assert(decomp.beta_is_negative == false);
64 }
65
66 return 0;
67}
field< FrParams > fr
fake_glv_decomposition compute_secp256r1_fake_glv_decomposition(const ::bb::secp256r1::fr &s)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
bb::VectorAffineElementPushSpan< BaseParams > lhs
bb::VectorAffineElementPushSpan< BaseParams > rhs
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
static constexpr field zero()