Feature/bn128 montgomery multiplication #3
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
BN128Multiplication
, andBN128Pairing
precompiled contracts by implementing Montgomery form arithmetic. It is worth mentioning that this PR makesBN128Addition
a little bit slower because of the overhead of the conversion to and from the Montgomery form.Why are these changes required?
The current 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). This PR is aiming to mitigate this issue.
This PR is far worse than tronprotocol#5507 in terms of optimization but it doesn't require JNI and doesn't introduce a lot of changes in the implementation.
This PR has been tested by:
Follow up
Extra details
I've performed some benchmarks before and after these modifications. The results are below:
The average time of operations before (Intel(R) Core(TM) i7-10750H CPU, 32 GB RAM):
The average time of operations after: