-
Notifications
You must be signed in to change notification settings - Fork 39
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
Switch from ark-bn254 to matterlabs/pairing (BFT-325) #28
Conversation
# Conflicts: # node/Cargo.lock # node/libs/crypto/src/bn254/tests.rs
# Conflicts: # node/Cargo.lock # node/deny.toml # node/libs/crypto/Cargo.toml # node/libs/crypto/src/bn254/hash.rs
Pending matter-labs/pairing#11 to be merged. |
node/libs/crypto/src/bn254/mod.rs
Outdated
@@ -25,52 +27,66 @@ pub mod hash; | |||
mod testonly; | |||
|
|||
/// Type safety wrapper around a scalar value. | |||
#[derive(Debug, PartialEq)] |
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 SecretKey
is sensitive information, it makes sense to manually define Debug
so that it only outputs the corresponding public key.
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.
+1
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.
use other private key types in crypto crate as example
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.
Fixed here: d0eeea4
.map(Self) | ||
.context("failed to decode secret key") | ||
let mut fr_repr = FrRepr::default(); | ||
fr_repr.read_be(Cursor::new(bytes))?; |
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.
- Nit:
Cursor
is not strictly necessary here;std::io::Read
is implemented for&mut &[u8]
as well (i.e., a shared reference to bytes, where the reference itself can change). Thus, you can declaremut bytes: &[u8]
and callfr_repr.read_be(&mut bytes)
and maybe check that all bytes were read. - Is big-endian encoding canonical for BN254 (i.e., used in other implementations)? Or is there no convention? I'm not entirely sure, but the
ark
implementation looks little-endian, although the Go one by Consensys is big-endian.
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.
- Nit:
Cursor
is not strictly necessary here;std::io::Read
is implemented for&mut &[u8]
as well (i.e., a shared reference to bytes, where the reference itself can change). Thus, you can declaremut bytes: &[u8]
and callfr_repr.read_be(&mut bytes)
and maybe check that all bytes were read.
Right it's not necessary. Simply removing it seems to be enough.
- Is big-endian encoding canonical for BN254 (i.e., used in other implementations)? Or is there no convention? I'm not entirely sure, but the
ark
implementation looks little-endian, although the Go one by Consensys is big-endian.
I'm not sure, but I don't think that there is a convention regarding the endianness.
node/libs/crypto/src/bn254/mod.rs
Outdated
@@ -25,52 +27,66 @@ pub mod hash; | |||
mod testonly; | |||
|
|||
/// Type safety wrapper around a scalar value. | |||
#[derive(Debug, PartialEq)] |
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.
Don't implement PartialEq for private key. Always compare corresponding public keys instead.
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.
What about this: e3074cb?
Switching bn254 implementation from crates/ark-bn254 to matter-labs/pairing due to compatibility issues of zksync-era with the former.
Notes:
bn254::tests::byte_fmt_correctness
tests were added, previously not coveredTODO:
bn254::tests::aggregate_signature_distinct_messages
is failing, need to figure out whypairing
dependency was redirected to a fork, due to missing functionality. If no other solution is found, it should be merged to upstream and dependency to be redirected backbn254::testonly
: need to find a solution forrand::Rng (rand = "0.8.0")
trait object incompatibility withrand04::Rng (rand = "0.4.6")
trait bound