Skip to content

feat(inlines): add P-256 (secp256r1) inline instructions and ECDSA example#1381

Open
sagar-a16z wants to merge 6 commits intomainfrom
sagar/p256
Open

feat(inlines): add P-256 (secp256r1) inline instructions and ECDSA example#1381
sagar-a16z wants to merge 6 commits intomainfrom
sagar/p256

Conversation

@sagar-a16z
Copy link
Copy Markdown
Contributor

Adds jolt-inlines-p256 crate with field mul/square/div inlines for both the base field and scalar field, plus a Fake GLV advice inline for efficient ECDSA verification (~283K cycles).

Uses "Fake GLV" (Latincrypt 2025) to decompose 256-bit scalars into 128-bit pairs via half-GCD, enabling 4-scalar Shamir's trick without an endomorphism. Handles the dense 4-limb modular complement (vs secp256k1's 1-limb) and the a=-3 curve parameter.

Includes examples/p256-ecdsa-verify with an RFC 6979 test vector.

@socket-security
Copy link
Copy Markdown

socket-security bot commented Mar 27, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedalloy-eips@​1.8.2 ⏵ 1.7.310010093100100
Updatedenv_logger@​0.11.10 ⏵ 0.11.99910093100100

View full report

Copy link
Copy Markdown
Collaborator

@0xAndoroid 0xAndoroid left a comment

Choose a reason for hiding this comment

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

Review from automated code review agents.

…ample

Adds jolt-inlines-p256 crate with field mul/square/div inlines for both
the base field and scalar field, plus a Fake GLV advice inline for
efficient ECDSA verification (~283K cycles).

Uses "Fake GLV" (Latincrypt 2025) to decompose 256-bit scalars into
128-bit pairs via half-GCD, enabling 4-scalar Shamir's trick without
an endomorphism. Handles the dense 4-limb modular complement (vs
secp256k1's 1-limb) and the a=-3 curve parameter.

Includes examples/p256-ecdsa-verify with an RFC 6979 test vector.
- Extract half-GCD decomposition to shared fake_glv.rs module
- Switch host field ops from BigUint to ark_secp256r1 types
- Fix scalar field comments: wq → wn (use n for scalar order)
- Remove unused Sign imports after fake_glv extraction
Move 13 multiply-accumulate helper methods (mac_low, mac_high,
mac_low_w_carry, mac_high_w_carry, mac_low_conditional,
mac_high_conditional, m2ac_low, m2ac_high, m2ac_low_w_carry,
m2ac_high_w_carry, adc, adc_w_carry, add_conditional) from the P256
sequence builder to a shared MulAccExt trait in jolt-inlines-sdk.

These helpers are byte-for-byte identical between secp256k1 and P-256.
The secp256k1 crate can adopt MulAccExt in a follow-up.
Replace the near-identical P256Fq and P256Fr structs (~580 lines of
copy-paste) with a single generic P256Field<C: P256FieldConfig>.
The config trait captures the five differences: modulus, funct3 opcodes,
error variant, canonicality check, and host arkworks dispatch.

P256Fq = P256Field<FqConfig>, P256Fr = P256Field<FrConfig>.
Public API unchanged — all downstream code compiles without modification.
sdk.rs: 1115 → 943 lines (-172).
- Extract limbs_to_nbiguint, nbiguint_to_limbs, MulqType, decode_sign_word,
  emit_advice_stores to jolt-inlines-sdk for cross-crate reuse
- Update P-256, secp256k1, and grumpkin to use shared utilities
- Remove dead constants P256_BASEFIELD_NEG_MODULUS, P256_SCALARFIELD_NEG_ORDER
- Remove section separator comments from P-256 sdk.rs
- Fix misleading RFC 6979 comment in example and tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants