Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize bn128 precompiled contracts #1

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

Conversation

AllFi
Copy link
Collaborator

@AllFi AllFi commented Aug 31, 2023

What does this PR do?
This PR optimizes BN128Addition, BN128Multiplication, and BN128Pairing precompiled contracts by using arkworks implementation of bn128 operations. This PR uses LibarkworksWrapper 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:

  • Unit Tests
  • Manual Testing

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):

BN128Addition: 66387 ns
BN128Multiplication: 3553350 ns
BN128Pairing (10 pairs): 101565419 ns

The average time of operations after:

BN128Addition: 11576 ns
BN128Multiplication: 181301 ns
BN128Pairing (10 pairs): 3285601 ns

@AllFi AllFi changed the title Add draft of precompiles Optimize bn128 precompiled contracts Sep 6, 2023
Copy link

@EvgenKor EvgenKor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants