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

feat(rust): integrate new blst based bls-signatures #159

Merged
merged 2 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 15 additions & 123 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ publish = false
crate-type = ["rlib", "staticlib"]

[dependencies]
bls-signatures = "0.6.0"
bls-signatures = { version = "0.7.0", default-features = false, features = ["blst"] }
blstrs = { version = "0.1.2" }
byteorder = "1.2"
drop_struct_macro_derive = "0.4.0"
ff = { version = "0.2.1", package = "fff" }
ffi-toolkit = "0.4.0"
groupy = "0.3.0"
libc = "0.2.58"
log = "0.4.7"
fil_logger = "0.1.0"
Expand All @@ -47,4 +49,5 @@ tempfile = "3.0.8"
[features]
default = ["pairing"]
pairing = ["filecoin-proofs-api/pairing", "bellperson/pairing"]
blst = ["filecoin-proofs-api/blst", "bellperson/blst"]
blst = ["filecoin-proofs-api/blst", "bellperson/blst"]

23 changes: 9 additions & 14 deletions rust/src/bls/api.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::slice::from_raw_parts;

use bls_signatures::{
aggregate as aggregate_sig,
groupy::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError},
hash as hash_sig,
paired::bls12_381::{G2Affine, G2Compressed},
verify as verify_sig, PrivateKey, PublicKey, Serialize, Signature,
aggregate as aggregate_sig, hash as hash_sig, verify as verify_sig,
verify_messages as verify_messages_sig, PrivateKey, PublicKey, Serialize, Signature,
};
use blstrs::{G2Affine, G2Compressed};
use groupy::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError};

use rand::rngs::OsRng;
use rand::SeedableRng;
use rand_chacha::ChaChaRng;
Expand Down Expand Up @@ -177,7 +177,7 @@ pub unsafe extern "C" fn fil_verify(
verify_sig(&signature, digests.as_slice(), public_keys.as_slice()) as libc::c_int
}

/// Verify that a signature is the aggregated signature of the hhashed messages
/// Verify that a signature is the aggregated signature of the hashed messages
///
/// # Arguments
///
Expand Down Expand Up @@ -219,11 +219,6 @@ pub unsafe extern "C" fn fil_hash_verify(
return 0;
}

let digests: Vec<_> = messages
.into_par_iter()
.map(|message: &[u8]| hash_sig(message))
.collect::<Vec<_>>();

let public_keys: Vec<_> = try_ffi!(
raw_public_keys
.par_chunks(PUBLIC_KEY_BYTES)
Expand All @@ -232,7 +227,7 @@ pub unsafe extern "C" fn fil_hash_verify(
0
);

verify_sig(&signature, &digests, &public_keys) as libc::c_int
verify_messages_sig(&signature, &messages, &public_keys) as libc::c_int
}

/// Generate a new private key
Expand Down Expand Up @@ -427,8 +422,8 @@ mod tests {
.inner;
assert_eq!(
[
115, 245, 77, 209, 4, 57, 40, 107, 10, 153, 141, 16, 153, 172, 85, 197, 125,
163, 35, 217, 108, 241, 64, 235, 231, 220, 131, 1, 77, 253, 176, 19
56, 13, 181, 159, 37, 1, 12, 96, 45, 77, 254, 118, 103, 235, 218, 176, 220,
241, 142, 119, 206, 233, 83, 35, 26, 15, 118, 198, 192, 120, 179, 52
],
private_key,
);
Expand Down