perf(csp): reduce allocations using in-place scalar operations#1593
Conversation
| VRight []*mathlib.Zr // cross scalar <f_R, wit_L> | ||
|
|
||
| Curve *mathlib.Curve | ||
| Left []*mathlib.G1 |
There was a problem hiding this comment.
why removing the comments on all these fields?
| challenges[i] = c | ||
| cSq := v.Curve.ModMul(c, c, v.Curve.GroupOrder) | ||
|
|
||
| // Update value: v' = c·v + VLeft[i] + c²·VRight[i] |
There was a problem hiding this comment.
why removing these comments?
|
@neetance , fantastic, thanks. Please, just restore the code comments unless they are not appropriate anymore, but I don't think so. Thanks 🙏 |
0011298 to
eaf7667
Compare
eaf7667 to
c0dd3e6
Compare
c0dd3e6 to
3a791b6
Compare
|
Hi @neetance , I have merged your PR on mathlib and created the tag |
3a791b6 to
0dec2d4
Compare
Signed-off-by: Ankit Basu <ankitbasu14@gmail.com>
Signed-off-by: Ankit Basu <ankitbasu14@gmail.com>
Signed-off-by: Ankit Basu <ankitbasu14@gmail.com>
0dec2d4 to
68e4117
Compare
|
@neetance , would you like to work on porting |
|
@adecaro yes sure sounds good to me 😄 |
Summary
This PR optimizes the CSP (Compressed Sigma Protocol) prover and verifier by reducing allocation overhead in scalar operations.
The changes are based on the mathlib optimizations (fr.Element-based Zr) and introduce in-place arithmetic and scratch reuse across the CSP proof methods.
Changes
Replace allocation-heavy operations:
ModAddMul->ModAddMul2InPlace/ModAddMul3InPlaceModMul->ModMulInPlaceIntroduce scratch variable reuse in verifier:
Optimize folding steps in prover:
Optimize
sVectorcomputation:Performance Improvement
The actual benchmark results given in the mathlib pr
Testing
All tests pass:
go test ./token/core/zkatdlog/nogh/v1/...Benchmarks executed successfully
No functional changes
Note
I modified the go.mod file to replace the actual mathlib library url with my current mathlib commit, which can be changed back to normal once the mathlib pr is merged
Let me know if this looks good
Thanks 🙏