Ristretto Precomputed MSM Switcher - #1007
Open
Daeinar wants to merge 1 commit into
Open
Conversation
`RistrettoPrecomputation` keeps the static points next to the tables and chooses per call: Straus over the tables while `static + 3 * dynamic <= 600`, otherwise one plain MSM over the chained static and dynamic inputs, so callers no longer fall back themselves. The bound is a heuristic fitted on an (S, D) grid with `benches/mixed_msm.rs` (dalek primitives timed directly, M2 Max): the crossover lies at about 600 static points with no dynamic ones, 490 with 32 and 245 with 128, and with 512 dynamic points the plain MSM wins at every static size. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
@jonas-lj 👆 Ready for your review. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the review of #989 (#989 (comment)): the decision whether a mixed MSM should use the precomputed tables or a plain MSM moves from the caller into
RistrettoPrecomputation.What changes
RistrettoPrecomputationstores the static points next to dalek's tables (dalek exposes no way to recover them).mixed_multi_scalar_mulruns Straus over the tables whilestatic + DYNAMIC_POINT_WEIGHT * dynamic <= MAX_STRAUS_POINTS(3, 600) and otherwise one plain MSM over the chained static and dynamic inputs, with no concatenation.MixedMultiScalarMul::mixed_multi_scalar_muldoc: the implementation falls back itself; callers need not choose.test_precomputed_multiscalar_mulcovers the fallback in both directions (static-heavy and dynamic-heavy) with the same length checks.benches/mixed_msm.rstimes the two dalek primitives over a grid of static sizes (powers of two and midpoints, 64..2048) and dynamic sizes (0, 32, 128, 512); it is how the constants were fitted and how they would be retuned on another machine.Why a weighted rule
Straus over the tables is linear in the static count with a flat per-point cost, Pippenger's per-point cost falls with size, and the crossover sits far below what operation counts predict (the 7.7 KB per-point tables fall out of cache). Dynamic points shift the crossover: a dynamic point costs a per-call table and projective additions, about three static points' worth. Measured crossovers on an M2 Max with dense scalars: ~600 static points at D = 0, ~490 at D = 32, ~245 at D = 128; at D = 512 the plain MSM wins at every static size. Least-squares fit
589 - 2.7 D, rounded to the two constants. Near the crossover the two paths are within a few percent of each other, so a threshold misplaced by ~50 points costs under 1%.A simpler design, deciding at
precomputeby static count alone and skipping the tables above it, regressed BP++ 64-bit x32 proving by 5.5%: its static-only MSMs still profit from the tables at 521 points while the verifier's mixed call does not.Impact
BP++ (#989) keeps the decisions its hand-written fallback made (tables for all its provers and for verifiers up to 64-bit x16, plain MSM for the 64-bit x32 verifier) and will drop its own fallback arm once this lands. No other callers of the precomputation exist yet.
🤖 Generated with Claude Code