Optimize bn128 precompiled contracts #1
Draft
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.
What does this PR do?
This PR optimizes
BN128Addition
,BN128Multiplication
, andBN128Pairing
precompiled contracts by using arkworks implementation of bn128 operations. This PR usesLibarkworksWrapper
introduced in zkBob/zksnark-java-sdk#1.Why are these changes required?
The native implementation of these precompiles is relatively slow. In general, this hinders on-chain zkSNARKs verification and, consequently, makes zk-based apps almost unfeasible (tronprotocol#4311). With this PR (or a similar approach), these applications become viable.
It is important to note that these changes are not propose to solve a specific problem of ZkBob but rather enable a whole class of applications and protocols based on elliptic curve cryptography and pairings in particular. The possibilities brought by ZKP are not limited to privacy focused protocols , some other examples are zk based auth for AA wallets, light clients, zk based bridges, computational integrity enforcing contracts etc
This PR has been tested by:
Follow up
Extra details
I've added some benchmarks before (https://github.com/zkBob/java-tron/tree/bn128-native-bench) and after modifications (https://github.com/zkBob/java-tron/tree/bn128-arkworks-bench). The results can be found below.
The average time of operations before (Intel(R) Core(TM) i7-10750H CPU, 32 GB RAM):
The average time of operations after: