Skip to content

chore: unify splitting scalars interface#20805

Merged
notnotraju merged 10 commits intomerge-train/barretenbergfrom
rk/splitting-scalars-unify
Mar 4, 2026
Merged

chore: unify splitting scalars interface#20805
notnotraju merged 10 commits intomerge-train/barretenbergfrom
rk/splitting-scalars-unify

Conversation

@notnotraju
Copy link
Contributor

In bb, we use the scalar splitting for a few fields: the base and scalar fields of BN254, as well as the scalar field of secp256k1. Formerly, in the latter, we used a "384-bit" shift. This is unnecessary: rounding was not the main difference. (The difference is in the former fields, the GLV lattice basis is unusually short, which implies that the scalar splitting can be taken to both have 128 bits; for secp256k1::fr, neither statement is true, and indeed the scalars can have as much as 129 bits. In this branch, then, we return field elements.)

The interfaces have been unified, as much as they can.

notnotraju and others added 5 commits February 19, 2026 10:47
…alar multiplication

Tests for the negative-k2 bug in split_into_endomorphism_scalars (Fr and Fq),
plus EC-level scalar multiplication tests (g1 and grumpkin) showing the bug
produces wrong points. Includes endomorphism_scalars.py for deriving the
boundary scalars.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…and changed the tests to be regression tests accordingly.
…d secpk1 (to at least generate parameters)
static constexpr uint64_t endo_g2_hihi = 0xE4437ED6010E8828ULL;
// 256-bit-shift constants: g1 = floor((-b1) * 2^256 / r), g2 = floor(b2 * 2^256 / r)
// See endomorphism_scalars.py compute_splitting_constants() for derivation.
static constexpr uint64_t endo_g1_lo = 0x6F547FA90ABFE4C4ULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need new constants here

* hold k2. This function will be called in either the BN254 base/scalar field
* or the generic, secp256k1 branch.
*/
static field compute_endomorphism_k2(const field& input)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generic shared method which uses mul_512, computes a sort of raw k2.

@notnotraju notnotraju force-pushed the rk/splitting-scalars-unify branch from fa5c62f to 2dd7c69 Compare February 24, 2026 12:48
@notnotraju notnotraju force-pushed the rk/splitting-scalars-unify branch from 2dd7c69 to f9be7ca Compare February 24, 2026 12:48
* The result is a raw (non-Montgomery) `field` whose low 128-or-129 bits
* hold k2. This function will be called in either the BN254 base/scalar field
* or the generic, secp256k1 branch.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both branches call this method now.

};
}

static void split_into_endomorphism_scalars_384(const field& input, field& k1_out, field& k2_out)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely not necessary. fixed constants accordingly.

@notnotraju notnotraju requested a review from suyash67 February 24, 2026 17:14
Base automatically changed from rk/splitting-scalars-edge-case to merge-train/barretenberg February 27, 2026 11:57
Copy link
Contributor

@suyash67 suyash67 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work!

…ases for fq and fr are so close to each other
@notnotraju notnotraju self-assigned this Mar 4, 2026
@notnotraju notnotraju added the bberg-int-audit All things related to barretenberg internal audit label Mar 4, 2026
@notnotraju notnotraju merged commit b6bfdc7 into merge-train/barretenberg Mar 4, 2026
20 checks passed
@notnotraju notnotraju deleted the rk/splitting-scalars-unify branch March 4, 2026 17:48
github-merge-queue bot pushed a commit that referenced this pull request Mar 6, 2026
BEGIN_COMMIT_OVERRIDE
fix: add -g0 to zig presets to eliminate 11GB debug info bloat (#21071)
fix: resolve flaky p2p_client test race condition on ARM64 (#21088)
chore: remove domain iteration macros and address backing memory race
(#20988)
fix: [ECCVM] added domain separation for the multiset equality check.
(#20352)
feat: hybrid CRS hash verification — 8MB chunks, parallel, span-based
(#21113)
chore: unify splitting scalars interface (#20805)
chore: add a unique id to each origin tag (#20924)
chore: Native curve audit (#20936)
chore: Update bootstrap in test vk haven't changed script (#21153)
fix: use reduced form in WASM FromMontgomeryForm test (#21164)
chore: erase ephemeral secrets from memory in schnorr and aes (#21106)
chore: suppress clangd target triple version diagnostic (#21180)
feat: Optimise new claim calculation (#21179)
docs: add Quick Start build instructions to barretenberg README (#20951)
feat: batched chonk verification (#21083)
fix: link libc++ instead of libstdc++ for Rust FFI on Linux (#21203)
fix: [ECCVM] in the transcript table, no-ops force the next accumulator
to be 0. (#20849)
fix: resolve merge-train conflict with next (zig wrapper scripts + -g0)
(#21201)
fix: [ECCVM] rare edge case completeness issue when `z1 == 0` but `z2 !=
0` (#20858)
fix: use actual data extent for CommitmentKey in HypernovaDeciderProver
(#21206)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bberg-int-audit All things related to barretenberg internal audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants