|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
#include <scalar_multiplication.hpp>
Classes | |
| struct | AffineAdditionData |
| Scratch space for batched affine point additions (one per thread) More... | |
| struct | BucketAccumulators |
| Affine bucket accumulators for the fast affine-trick Pippenger variant. More... | |
| struct | JacobianBucketAccumulators |
| Jacobian bucket accumulators for the safe Pippenger variant. More... | |
| struct | MSMData |
| Container for MSM input data passed between algorithm stages. More... | |
| struct | MSMWorkUnit |
| MSMWorkUnit describes an MSM that may be part of a larger MSM. More... | |
| struct | PointScheduleEntry |
| Packed point schedule entry: (point_index << 32) | bucket_index. More... | |
Public Types | |
| using | Element = typename Curve::Element |
| using | ScalarField = typename Curve::ScalarField |
| using | BaseField = typename Curve::BaseField |
| using | AffineElement = typename Curve::AffineElement |
| using | ThreadWorkUnits = std::vector< MSMWorkUnit > |
Static Public Member Functions | |
| static const AffineElement & | get_offset_generator () noexcept |
| static AffineElement | msm (std::span< const AffineElement > points, PolynomialSpan< const ScalarField > scalars, bool handle_edge_cases=false) noexcept |
| Main entry point for single MSM computation. | |
| static std::vector< AffineElement > | batch_multi_scalar_mul (std::span< std::span< const AffineElement > > points, std::span< std::span< ScalarField > > scalars, bool handle_edge_cases=true) noexcept |
| Compute multiple MSMs in parallel with work balancing. | |
| static uint32_t | get_num_rounds (size_t num_points) noexcept |
| static void | add_affine_points (AffineElement *points, const size_t num_points, typename Curve::BaseField *scratch_space) noexcept |
| Batch add n/2 independent point pairs using Montgomery's trick. | |
| static uint32_t | get_scalar_slice (const ScalarField &scalar, size_t round, size_t slice_size) noexcept |
| Extract c-bit slice from scalar for bucket index computation. | |
| static uint32_t | get_optimal_log_num_buckets (size_t num_points) noexcept |
| Compute optimal bits per slice by minimizing cost over c in [1, MAX_SLICE_BITS) | |
| static void | batch_accumulate_points_into_buckets (std::span< const uint64_t > point_schedule, std::span< const AffineElement > points, AffineAdditionData &affine_data, BucketAccumulators &bucket_data) noexcept |
| Process sorted point schedule into bucket accumulators using batched affine additions. | |
| template<typename BucketType > | |
| static Element | accumulate_buckets (BucketType &bucket_accumulators) noexcept |
| Reduce buckets to single point using running (suffix) sum from high to low: R = sum(k * B_k) | |
Static Public Attributes | |
| static constexpr size_t | NUM_BITS_IN_FIELD = ScalarField::modulus.get_msb() + 1 |
| static constexpr size_t | PIPPENGER_THRESHOLD = 16 |
| static constexpr size_t | AFFINE_TRICK_THRESHOLD = 128 |
| static constexpr size_t | MAX_SLICE_BITS = 20 |
| static constexpr size_t | PREFETCH_LOOKAHEAD = 32 |
| static constexpr size_t | PREFETCH_INTERVAL = 16 |
| static constexpr size_t | PREFETCH_INTERVAL_MASK = PREFETCH_INTERVAL - 1 |
| static constexpr size_t | BUCKET_ACCUMULATION_COST = 5 |
| static constexpr size_t | AFFINE_TRICK_SAVINGS_PER_OP = 5 |
| static constexpr size_t | JACOBIAN_Z_NOT_ONE_PENALTY = 5 |
| static constexpr size_t | INVERSION_TABLE_COST = 14 |
Private Member Functions | |
| __attribute__ ((always_inline)) static void process_single_point(size_t bucket | |
| if (has_accumulator) | |
| bucket_data bucket_exists | set (bucket, true) |
| __attribute__ ((always_inline)) static void process_bucket_pair(size_t lhs_bucket | |
| bucket_data bucket_exists | set (lhs_bucket,(has_bucket_accumulator &&buckets_match)||!do_affine_add) |
Static Private Member Functions | |
| static void | transform_scalar_and_get_nonzero_scalar_indices (std::span< ScalarField > scalars, std::vector< uint32_t > &nonzero_scalar_indices) noexcept |
| Convert scalars from Montgomery form and collect indices of nonzero scalars. | |
| static std::vector< ThreadWorkUnits > | get_work_units (std::span< std::span< ScalarField > > scalars, std::vector< std::vector< uint32_t > > &msm_scalar_indices) noexcept |
| Distribute multiple MSMs across threads with balanced point counts. | |
| static bool | use_affine_trick (size_t num_points, size_t num_buckets) noexcept |
| Decide if batch inversion saves work vs Jacobian additions. | |
| static Element | jacobian_pippenger_with_transformed_scalars (MSMData &msm_data) noexcept |
| Pippenger using Jacobian buckets (handles edge cases: doubling, infinity) | |
| static Element | affine_pippenger_with_transformed_scalars (MSMData &msm_data) noexcept |
| Pippenger using affine buckets with batch inversion (faster, no edge case handling) | |
Definition at line 19 of file scalar_multiplication.hpp.
| using bb::scalar_multiplication::MSM< Curve >::AffineElement = typename Curve::AffineElement |
Definition at line 24 of file scalar_multiplication.hpp.
| using bb::scalar_multiplication::MSM< Curve >::BaseField = typename Curve::BaseField |
Definition at line 23 of file scalar_multiplication.hpp.
| using bb::scalar_multiplication::MSM< Curve >::Element = typename Curve::Element |
Definition at line 21 of file scalar_multiplication.hpp.
| using bb::scalar_multiplication::MSM< Curve >::ScalarField = typename Curve::ScalarField |
Definition at line 22 of file scalar_multiplication.hpp.
| using bb::scalar_multiplication::MSM< Curve >::ThreadWorkUnits = std::vector<MSMWorkUnit> |
Definition at line 96 of file scalar_multiplication.hpp.
|
private |
|
private |
|
inlinestaticnoexcept |
Reduce buckets to single point using running (suffix) sum from high to low: R = sum(k * B_k)
Definition at line 244 of file scalar_multiplication.hpp.
|
staticnoexcept |
Batch add n/2 independent point pairs using Montgomery's trick.
Definition at line 238 of file scalar_multiplication.cpp.
|
staticprivatenoexcept |
Pippenger using affine buckets with batch inversion (faster, no edge case handling)
Definition at line 292 of file scalar_multiplication.cpp.
|
staticnoexcept |
Process sorted point schedule into bucket accumulators using batched affine additions.
Definition at line 347 of file scalar_multiplication.cpp.
|
staticnoexcept |
Compute multiple MSMs in parallel with work balancing.
Definition at line 437 of file scalar_multiplication.cpp.
|
inlinestaticnoexcept |
Definition at line 220 of file scalar_multiplication.hpp.
|
inlinestaticnoexcept |
Definition at line 71 of file scalar_multiplication.hpp.
|
staticnoexcept |
Compute optimal bits per slice by minimizing cost over c in [1, MAX_SLICE_BITS)
Definition at line 193 of file scalar_multiplication.cpp.
|
staticnoexcept |
Extract c-bit slice from scalar for bucket index computation.
Extract a slice of bits from a scalar for Pippenger bucket assignment.
Extracts bits [lo_bit, hi_bit) from the scalar's raw limb representation. The scalar must already be converted out of Montgomery form.
IMPORTANT RESTRICTIONS (optimized for Pippenger's specific usage pattern):
| scalar | The scalar field element (must be in non-Montgomery form) |
| round | The current Pippenger round (0 = most significant bits) |
| slice_size | Number of bits per slice |
Definition at line 167 of file scalar_multiplication.cpp.
|
staticprivatenoexcept |
Distribute multiple MSMs across threads with balanced point counts.
Definition at line 86 of file scalar_multiplication.cpp.
|
inlineprivate |
Definition at line 309 of file scalar_multiplication.hpp.
|
staticprivatenoexcept |
Pippenger using Jacobian buckets (handles edge cases: doubling, infinity)
Definition at line 252 of file scalar_multiplication.cpp.
|
staticnoexcept |
Main entry point for single MSM computation.
| handle_edge_cases | false (default): fast affine variant; true: safe Jacobian variant |
Definition at line 502 of file scalar_multiplication.cpp.
|
private |
|
private |
|
staticprivatenoexcept |
Convert scalars from Montgomery form and collect indices of nonzero scalars.
Definition at line 41 of file scalar_multiplication.cpp.
|
staticprivatenoexcept |
Decide if batch inversion saves work vs Jacobian additions.
Definition at line 214 of file scalar_multiplication.cpp.
|
private |
Definition at line 303 of file scalar_multiplication.hpp.
|
private |
Definition at line 328 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 60 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 38 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 57 of file scalar_multiplication.hpp.
|
private |
Definition at line 304 of file scalar_multiplication.hpp.
|
private |
Definition at line 329 of file scalar_multiplication.hpp.
|
private |
Definition at line 334 of file scalar_multiplication.hpp.
|
private |
Definition at line 344 of file scalar_multiplication.hpp.
|
private |
Definition at line 345 of file scalar_multiplication.hpp.
|
private |
Definition at line 335 of file scalar_multiplication.hpp.
|
private |
Definition at line 315 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 66 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 63 of file scalar_multiplication.hpp.
|
private |
Definition at line 339 of file scalar_multiplication.hpp.
|
private |
Definition at line 347 of file scalar_multiplication.hpp.
|
private |
Definition at line 326 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 41 of file scalar_multiplication.hpp.
|
private |
Definition at line 306 of file scalar_multiplication.hpp.
|
private |
Definition at line 331 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 26 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 34 of file scalar_multiplication.hpp.
|
private |
Definition at line 319 of file scalar_multiplication.hpp.
|
private |
Definition at line 302 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 47 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 48 of file scalar_multiplication.hpp.
|
staticconstexpr |
Definition at line 44 of file scalar_multiplication.hpp.
|
private |
Definition at line 325 of file scalar_multiplication.hpp.
|
private |
Definition at line 341 of file scalar_multiplication.hpp.
|
private |
Definition at line 348 of file scalar_multiplication.hpp.
|
private |
Definition at line 337 of file scalar_multiplication.hpp.
|
private |
Definition at line 327 of file scalar_multiplication.hpp.
|
private |
Definition at line 305 of file scalar_multiplication.hpp.
|
private |
Definition at line 330 of file scalar_multiplication.hpp.
|
private |
Definition at line 351 of file scalar_multiplication.hpp.