perf(csp): optimize range proof prover with native gnark arithmetic - #1679
Merged
adecaro merged 1 commit intoMay 7, 2026
Merged
Conversation
Signed-off-by: Ankit Basu <ankitbasu14@gmail.com>
SurbhiAgarwal1
pushed a commit
to SurbhiAgarwal1/fabric-token-sdk
that referenced
this pull request
May 13, 2026
…FDT-Panurus#1679) Signed-off-by: Ankit Basu <ankitbasu14@gmail.com>
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.
closes #1675
Description
Currently, the CSP Range Proof generation (
Provefunction inrp.go) heavily relies onmathlib.Zrscalar operations for building linear forms, computing inner products, and generating blinded witnesses. Becausemathlibwrapsgnark-crypto, every scalar multiplication or addition executed in these O(n) loops requiresbig.Intobject allocations and round-trip conversions.This PR bypasses the
mathlib.Zrabstraction during the heaviest cryptographic loops in the Prover, dispatching directly to the underlyinggnark-cryptoMontgomery form arithmetic for supported curves (BN254andBLS12-381).Changes
rp_native.go):nativeRPBuildLF: Constructs the aggregated linear form natively.nativeRPInnerProduct: Computes inner products natively.nativeRPBlindWitness: Computes the blinded witness and evaluations using native field arithmetic.rp.go): Modified the CSP prover to check for curve compatibility viamath.DispatchCurveand route the heavyverifierandcsp.goentirely untouched to preserve current validation stability.Benchmarks
I ran the
TestParallelBFProverfor the csp range proof process and got the following results:Before:
After:
We can observe that the
allocs/opnumber went down from 14151 to 13166, a total of 985 allocs(~7% decrease)the other metrics remain stable with no visible regression
Let me know if this is good 🙏