-
Notifications
You must be signed in to change notification settings - Fork 225
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
Host-optimized pairing cryptography with the Barreto-Naehrig curve #4852
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks nice.
- We should add Prior Work acknowledgement either in the PR comment or the source code itself.
- There ought to be WASM test cases that invoke these host functions ... and emit costs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a small nitpick.
/// A point on the alt_bn128 curve. | ||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] | ||
#[repr(C, packed)] | ||
pub struct G1([u8; 32]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the types are pub
, should we give them some more descriptive names? (Also applies to Fr
and Fq
below.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is standard for Elliptic Curve notation, renaming them would confuse those who already have experience with this kind of math.
I think documentation would be more appropriate to make this accessible to everyone.
Closing for now |
This PR implements host-optimized pairing cryptography with the Barreto-Naehrig curve.
There are three new Wasm host functions:
casper_alt_bn128_add
- Adds two points on the alt_bn128 elliptic curve.casper_alt_bn128_mul
- Multiply a point on the alt_bn128 elliptic curve by a scalar.casper_alt_bn128_pairing
- Performs a batched pairing check on the alt_bn128 elliptic curve.Functionality
Prior art
This work results from extensive internal research and is a foundation for implementing various zero-knowledge proof verifiers on Casper Network i.e. risc0, sp1, and others. This is compatible with alt_bn128 EVM precompiles (ecAdd, ecMul, ecPairing). The code is also inspired by other Rust implementations of EVM precompiles including
aurora-engine
andrust-ethereum
.Costs
Comparison of using a
bn
crate compiled to Wasm vs using the same functionality through host functions.alt_bn128_add
alt_bn128_mul
alt_bn128_pairing
Based on these results functions each
alt_bn128_*
will have a base cost of 1_000_000 motes, with the addition thatalt_bn128_pairing
function will have a dynamic cost depending on the amount of curves being paired.Closes #4858