Add septic curve precompiles (SEPTIC_ADD, SEPTIC_DOUBLE, SEPTIC_SCALAR_MUL, SEPTIC_VERIFY)#2719
Open
sameepsi wants to merge 5 commits into
Open
Add septic curve precompiles (SEPTIC_ADD, SEPTIC_DOUBLE, SEPTIC_SCALAR_MUL, SEPTIC_VERIFY)#2719sameepsi wants to merge 5 commits into
sameepsi wants to merge 5 commits into
Conversation
Add precompiles for elliptic curve point addition and doubling on SP1's septic curve (y^2 = x^3 + 45x + 41z^3 over KoalaBear Fp7), using the existing SepticCurve implementation in sp1-hypercube. Memory layout is 7 u64 words (8-byte aligned) packing 14 KoalaBear u32 limbs (x0..x6, y0..y6). The minimal executor performs the real curve arithmetic via SepticCurve::add_incomplete/double. The full VM executor path is wired for compilation only — a Septic AIR and event recording will follow.
Performs a full 256-bit double-and-add scalar multiplication in a single syscall (~325x reduction vs. composing SEPTIC_ADD + SEPTIC_DOUBLE) by running the loop inside the executor. Adds the executor implementation, full-VM stub, gas/cost entries, the `SEPTIC_SCALAR_MUL = 0x136` syscall constant + asm wrapper, and a `SepticPoint::scalar_mul_single` guest API.
Computes `s*G + e*A` on the septic curve in a single syscall using Shamir's trick (~381 EC ops vs. ~651 for two independent scalar muls), reducing per-Schnorr-verify cost from ~5.2k to ~3k cycles. The generator `G` is pulled from `CURVE_CUMULATIVE_SUM_START` so the executor stays in sync with the rest of the codebase. Adds the executor implementation, full-VM stub, gas/cost entries, the `SEPTIC_VERIFY = 0x137` syscall constant + asm wrapper, and a `schnorr_compute(A, s, e)` guest API.
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.
Summary
This PR adds four precompiles for elliptic curve operations on SP1's own septic curve (y² = x³ + 45x + 41z³ over KoalaBear Fp7). These enable Schnorr signature verification using field-native arithmetic, eliminating the need for non-native 256-bit curve operations in signature-heavy applications.
All four precompiles have working executors (both minimal and full VM paths), guest-side APIs, and have been benchmarked extensively. AIR constraints are not implemented — this PR is submitted for review and collaboration on that final layer.
Motivation
We're building KalqiX, a CLOB-based DEX using SP1 for validity proofs. Each proof batch verifies 2,000 order signatures. With secp256k1 ecrecover, signature verification consumed 109M cycles (22% of the 500M budget) and 146.5M gas.
The septic curve is already used internally by SP1's memory argument (Hypercube). Its field arithmetic is native to the proof system — no limb decomposition, no non-native range checks, no carry propagation. We hypothesized that exposing it as a precompile would make signature verification dramatically cheaper.
Results
Benchmark: 2,000 Schnorr signature verifications in a single SP1 execution.
Gas reduction: 78% lower than secp256k1 (32.5M vs 146.5M). The gas metric reflects actual STARK trace area, which is the primary cost driver for proof generation.
Single-signature benchmarks:
Cryptographic Parameters
All parameters independently verified via SageMath and cross-checked against three points from the SP1 codebase (CURVE_CUMULATIVE_SUM_START, DIGEST_SUM_START, DUMMY_POINT).
What's Implemented
Four precompiles
SEPTIC_ADDSEPTIC_DOUBLESEPTIC_SCALAR_MULSEPTIC_VERIFYFiles changed
Syscall registration:
crates/core/executor/src/syscall_code.rs— four new SyscallCode variantscrates/core/executor/src/air.rs— four new RiscvAirId variantscrates/core/executor/src/artifacts/rv64im_costs.json— gas cost entriescrates/core/executor/src/vm/gas.rs— complexity mappingsMinimal executor (functional — used by execute() and mock prover):
crates/core/executor/src/minimal/precompiles/septic.rs— full implementations usingSepticCurvefromsp1-hypercubecrates/core/executor/src/minimal/ecall.rs— dispatchFull VM executor (compiles, no event recording):
crates/core/executor/src/vm/syscall/precompiles/septic.rs— stubs that drive memory access patternscrates/core/executor/src/vm/syscall.rs— dispatchGuest-side API:
crates/zkvm/entrypoint/src/syscalls/septic.rs— asm ecall wrapperscrates/zkvm/entrypoint/src/syscalls/mod.rs— syscall constantscrates/zkvm/lib/src/septic.rs—SepticPoint(add, double, scalar_mul, scalar_mul_single) +schnorr_computecrates/zkvm/lib/src/lib.rs— extern declarationsDesign notes
[u64; 7](14 KoalaBear u32 limbs packed two-per-u64 LE, 8-byte aligned). Scalars are[u64; 4](8 u32 limbs, 256-bit LE). Matches existing precompile alignment conventions.SepticCurvehas no native identity representation. All executors use aresult_setflag (same pattern as the guest-sidescalar_mulinsp1-lib). Scalar = 0 writes a zero sentinel.sp1_hypercube::septic_digest::CURVE_CUMULATIVE_SUM_START_{X,Y}— no constant duplication.What's NOT Implemented
AIR constraints. The precompile executors compute correct results, but there are no AIR chips to prove these computations in the STARK. This means:
execute()works ✓prove()will not work for programs that use these precompilesWe're submitting this as an RFC because:
The algebraic identity checks already exist.
septic_curve.rshassum_checker_xandsum_checker_y— the polynomial constraints that verify point operations. These are the core of what an AIR chip would prove.The curve arithmetic is field-native. Unlike secp256k1/Ed25519/P-256 (which require non-native limb decomposition, range checks, and carry propagation), the septic curve operates directly over KoalaBear. Each field element is a single trace column. This should make the AIR chip significantly simpler than existing EC precompile chips.
The Succinct team has deep expertise in SP1's AIR framework and has built all existing precompile chips. We believe collaboration on the AIR layer would produce a better result than an external implementation.
We're happy to collaborate on building the AIR constraints if there's interest.
How to Test
POC repository with full benchmarking harness: kalqix-poc
Broader Impact
Any SP1 application that verifies signatures can benefit from these precompiles — not just DEXs. Use cases include:
The Schnorr scheme on this curve provides ≥100 bits of security with prime group order and prime twist order. Session key registration (linking an ETH wallet to a septic Schnorr key) can be done via a single secp256k1 sign-message, verified once per batch using the existing SECP256K1_ADD precompile.