Comments (5)
I got similar results when using substrate-bn
. I tried arkworks
as is, and also patched it by using this approach (mentioned above) that relies on the mulmod
precompile.
Here are the results (copied the table from @m-kus for a better comparison):
Operation | substrate-bn | arkworks | arkworks (patched) |
---|---|---|---|
G1 decoding (uncompressed) | 10,194 | n/a | n/a |
G1 encoding | 119,182 | n/a | n/a |
G1 addition | 30,034 | 17,134 | 3,964 |
G1 multiplication | 1,735,257 | 4,494,212 (?) | 918,631 |
G2 decoding (uncompressed) | 27,958,488 | n/a | n/a |
G2 encoding | 162,243 | n/a | n/a |
G2 addition | 104,122 | 49,403 | 17,109 |
G2 multiplication | 31,221,329 | 13,965,273 | 4,667,998 |
Miller loop | 33,175,157 | 16,487,911 | 6,391,641 |
Final exponentiation | 45,323,747 | 16,875,843 | 8,165,645 |
Note: there's a precompile for sw points addition, and when using it directly, the cycle count for "G1 addition" drops to ~1k.
I'll post a link to the benchmark repo in the next days.
from sp1.
I was able to patch substrate-bn
and switch from Montogomery form to the plain representation while keeping the same API. The final results are:
Operation | substrate-bn | substrate-bn-sp1 (patched) |
---|---|---|
G1 decoding (uncompressed) | 10,194 | 2,022 |
G1 encoding | 119,182 | 101,621 |
G1 addition | 30,034 | 5,301 |
G1 multiplication | 1,735,257 | 402,823 |
G2 decoding (uncompressed) | 27,958,488 | 7,798,137 |
G2 encoding | 162,243 | 117,460 |
G2 addition | 104,122 | 31,819 |
G2 multiplication | 31,221,329 | 8,644,149 |
Miller loop | 33,175,157 | 9,449,627 |
Final exponentiation | 45,323,747 | 14,574,801 |
revm_precompile::bn128::run_add |
168,171 | 113,580 |
revm_precompile::bn128::run_mul |
1,865,971 | 506,454 |
revm_precompile::bn128::run_pair |
213,099,695 | 63,800,732 |
Patched substrate-bn
crate: m-kus/substrate-bn-sp1#1
Benchmark sources: https://github.com/m-kus/sp1-bn254-benchmark
from sp1.
Also some helpful context from the folks at Nebra around whether to accelerate substrate-bn
or swap in an arkworks
implementation which might be easier to accelerate with sys_bigint
. They already have a branch that adds a backend to arkworks
with sys_bigint
that can be seen here.
...[substrate-bn] seems to have montgomery representation hard-coded into it. This was also the case with the halo2 code, which was the other lib I considered. Given the mulmod syscall, which works with plain bigints (non-montgomery), it seemed like sticking with plain representation would be the best (IIRC it's only muls that benefit from Montgomery form, so it would add unnecessary overhead inside the VM if we kept that form). The arkworks impl has a "backend" component factored out, so it seemed easiest to just provide a plain (non-Montgomery) backend.
from sp1.
@puma314 Should the revm profiling example code be done here or in the revm codebase?
from sp1.
I got some rough numbers (single sample) generated with https://github.com/m-kus/sp1-bn254-benchmark
Operation | # cycles |
---|---|
G1 decoding (uncompressed) | 10,194 |
G1 encoding | 119,182 |
G1 addition | 30,034 |
G1 multiplication | 1,735,257 |
G2 decoding (uncompressed) | 27,958,488 |
G2 encoding | 162,243 |
G2 addition | 104,122 |
G2 multiplication | 31,221,329 |
Miller loop | 33,175,157 |
Final exponentiation | 45,323,747 |
Substrate BN is widely used (and will probably continue to be used since it's time/battle tested) and ZK friendliness might not be enough incentive to swap to arkworks I guess, given that it's extra work (I might be wrong though)
from sp1.
Related Issues (20)
- Implement an optimized SP1 Serializer HOT 2
- SP1PublicValues handling for the aggregation proof
- Provide a user-friendly error message when Cargo.toml is not found HOT 1
- Invalid Poseidon2 Chip Test Case HOT 1
- Bug: underconstrained uint256_div HOT 1
- Self-modifying code? HOT 2
- Deviations from Risc-V spec HOT 2
- add more meaningful github actions
- "verify" feature not unlocking the verify_sp1_proof precompile
- Improve CLI HOT 1
- Installation failure "No such file or directory (os error 2)" HOT 1
- Go / macOS CoreFoundation link error when building `gnark-ffi` HOT 2
- sp1up: set specific version HOT 2
- cargo prove --version showing commit hash, but not the more friendly tagged version (ex: testnet-1.0.4) HOT 1
- Fibbonacci problem (fresh from sp1-template) OOMs when proving HOT 1
- Plonk bn254 artifacts take extremely long time to load HOT 1
- Is normal that the program gets segmentfault when we run in debug mode? HOT 1
- Dockerfile for executing a sp1 script HOT 2
- Plonky3 EVM verifier? HOT 1
- v1.0.6-testnet: constraint #1685 is not satisfied HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sp1.