3#include "./eccvm_builder_types.hpp"
5namespace proof_system {
9 using CycleGroup =
typename Flavor::CycleGroup;
10 using FF =
typename Flavor::FF;
11 using Element =
typename CycleGroup::element;
12 using AffineElement =
typename CycleGroup::affine_element;
14 static constexpr size_t NUM_WNAF_SLICES = proof_system_eccvm::NUM_WNAF_SLICES;
15 static constexpr size_t WNAF_SLICES_PER_ROW = proof_system_eccvm::WNAF_SLICES_PER_ROW;
16 static constexpr size_t WNAF_SLICE_BITS = proof_system_eccvm::WNAF_SLICE_BITS;
28 bool point_transition =
false;
32 AffineElement precompute_accumulator{ 0, 0 };
33 AffineElement precompute_double{ 0, 0 };
36 static std::vector<PrecomputeState> compute_precompute_state(
39 std::vector<PrecomputeState> precompute_state;
43 static constexpr size_t num_rows_per_scalar = NUM_WNAF_SLICES / WNAF_SLICES_PER_ROW;
46 static_assert(WNAF_SLICES_PER_ROW == 4);
48 for (
const auto& entry : ecc_muls) {
49 const auto& slices = entry.wnaf_slices;
52 const Element point = entry.base_point;
53 const Element d2 = point.dbl();
55 for (
size_t i = 0; i < num_rows_per_scalar; ++i) {
57 const int slice0 = slices[i * WNAF_SLICES_PER_ROW];
58 const int slice1 = slices[i * WNAF_SLICES_PER_ROW + 1];
59 const int slice2 = slices[i * WNAF_SLICES_PER_ROW + 2];
60 const int slice3 = slices[i * WNAF_SLICES_PER_ROW + 3];
62 const int slice0base2 = (slice0 + 15) / 2;
63 const int slice1base2 = (slice1 + 15) / 2;
64 const int slice2base2 = (slice2 + 15) / 2;
65 const int slice3base2 = (slice3 + 15) / 2;
68 row.s1 = slice0base2 >> 2;
69 row.s2 = slice0base2 & 3;
70 row.s3 = slice1base2 >> 2;
71 row.s4 = slice1base2 & 3;
72 row.s5 = slice2base2 >> 2;
73 row.s6 = slice2base2 & 3;
74 row.s7 = slice3base2 >> 2;
75 row.s8 = slice3base2 & 3;
76 bool last_row = (i == num_rows_per_scalar - 1);
78 row.skew = last_row ? entry.wnaf_skew :
false;
80 row.scalar_sum = scalar_sum;
84 const int row_chunk = slice3 + slice2 * (1 << 4) + slice1 * (1 << 8) + slice0 * (1 << 12);
86 bool chunk_negative = row_chunk < 0;
88 scalar_sum = scalar_sum << (WNAF_SLICE_BITS * WNAF_SLICES_PER_ROW);
90 scalar_sum -=
static_cast<uint64_t
>(-row_chunk);
92 scalar_sum +=
static_cast<uint64_t
>(row_chunk);
94 row.round =
static_cast<uint32_t
>(i);
95 row.point_transition = last_row;
99 ASSERT(scalar_sum - entry.wnaf_skew == entry.scalar);
102 row.precompute_double = d2;
104 row.precompute_accumulator = entry.precomputed_table[proof_system_eccvm::POINT_TABLE_SIZE - 1 - i];
105 precompute_state.emplace_back(row);
108 return precompute_state;
Definition: uint256.hpp:25
Definition: precomputed_tables_builder.hpp:7
Definition: precomputed_tables_builder.hpp:18
Definition: eccvm_builder_types.hpp:36