From f06caa813e36141abcc5bef1acb8dacbc035df48 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Mon, 1 Jul 2024 17:55:03 +0200 Subject: [PATCH 1/2] bindings/rust/src/lib.rs: rectify the API omissions in no_std. --- bindings/rust/src/lib.rs | 143 +++++++++++++++++++++++++++------------ 1 file changed, 101 insertions(+), 42 deletions(-) diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs index 49dac393..0123a67c 100644 --- a/bindings/rust/src/lib.rs +++ b/bindings/rust/src/lib.rs @@ -1035,44 +1035,6 @@ macro_rules! sig_variant_impl { Ok(sig) } - #[cfg(not(feature = "std"))] - pub fn verify( - &self, - sig_groupcheck: bool, - msg: &[u8], - dst: &[u8], - aug: &[u8], - pk: &PublicKey, - pk_validate: bool, - ) -> BLST_ERROR { - if sig_groupcheck { - match self.validate(false) { - Err(err) => return err, - _ => (), - } - } - if pk_validate { - match pk.validate() { - Err(err) => return err, - _ => (), - } - } - unsafe { - $verify( - &pk.point, - &self.point, - $hash_or_encode, - msg.as_ptr(), - msg.len(), - dst.as_ptr(), - dst.len(), - aug.as_ptr(), - aug.len(), - ) - } - } - - #[cfg(feature = "std")] pub fn verify( &self, sig_groupcheck: bool, @@ -1092,6 +1054,57 @@ macro_rules! sig_variant_impl { ) } + #[cfg(not(feature = "std"))] + pub fn aggregate_verify( + &self, + sig_groupcheck: bool, + msgs: &[&[u8]], + dst: &[u8], + pks: &[&PublicKey], + pks_validate: bool, + ) -> BLST_ERROR { + let n_elems = pks.len(); + if n_elems == 0 || msgs.len() != n_elems { + return BLST_ERROR::BLST_VERIFY_FAIL; + } + + let mut pairing = Pairing::new($hash_or_encode, dst); + + let err = pairing.aggregate( + &pks[0].point, + pks_validate, + &self.point, + sig_groupcheck, + &msgs[0], + &[], + ); + if err != BLST_ERROR::BLST_SUCCESS { + return err; + } + + for i in 1..n_elems { + let err = pairing.aggregate( + &pks[i].point, + pks_validate, + &unsafe { ptr::null::<$sig_aff>().as_ref() }, + false, + &msgs[i], + &[], + ); + if err != BLST_ERROR::BLST_SUCCESS { + return err; + } + } + + pairing.commit(); + + if pairing.finalverify(None) { + BLST_ERROR::BLST_SUCCESS + } else { + BLST_ERROR::BLST_VERIFY_FAIL + } + } + #[cfg(feature = "std")] pub fn aggregate_verify( &self, @@ -1175,7 +1188,6 @@ macro_rules! sig_variant_impl { // pks are assumed to be verified for proof of possession, // which implies that they are already group-checked - #[cfg(feature = "std")] pub fn fast_aggregate_verify( &self, sig_groupcheck: bool, @@ -1197,7 +1209,6 @@ macro_rules! sig_variant_impl { ) } - #[cfg(feature = "std")] pub fn fast_aggregate_verify_pre_aggregated( &self, sig_groupcheck: bool, @@ -1288,6 +1299,56 @@ macro_rules! sig_variant_impl { } } + #[cfg(not(feature = "std"))] + #[allow(clippy::too_many_arguments)] + pub fn verify_multiple_aggregate_signatures( + msgs: &[&[u8]], + dst: &[u8], + pks: &[&PublicKey], + pks_validate: bool, + sigs: &[&Signature], + sigs_groupcheck: bool, + rands: &[blst_scalar], + rand_bits: usize, + ) -> BLST_ERROR { + let n_elems = pks.len(); + if n_elems == 0 + || msgs.len() != n_elems + || sigs.len() != n_elems + || rands.len() != n_elems + { + return BLST_ERROR::BLST_VERIFY_FAIL; + } + + // TODO - check msg uniqueness? + + let mut pairing = Pairing::new($hash_or_encode, dst); + + for i in 0..n_elems { + let err = pairing.mul_n_aggregate( + &pks[i].point, + pks_validate, + &sigs[i].point, + sigs_groupcheck, + &rands[i].b, + rand_bits, + msgs[i], + &[], + ); + if err != BLST_ERROR::BLST_SUCCESS { + return err; + } + } + + pairing.commit(); + + if pairing.finalverify(None) { + BLST_ERROR::BLST_SUCCESS + } else { + BLST_ERROR::BLST_VERIFY_FAIL + } + } + pub fn from_aggregate(agg_sig: &AggregateSignature) -> Self { let mut sig_aff = <$sig_aff>::default(); unsafe { @@ -1556,7 +1617,6 @@ macro_rules! sig_variant_impl { } #[test] - #[cfg(feature = "std")] fn test_aggregate() { let num_msgs = 10; let dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_"; @@ -1629,7 +1689,6 @@ macro_rules! sig_variant_impl { } #[test] - #[cfg(feature = "std")] fn test_multiple_agg_sigs() { let dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_"; let num_pks_per_sig = 10; From 17388c08c0ae1dbbe3af46461074e115d948d2c4 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Mon, 1 Jul 2024 18:08:47 +0200 Subject: [PATCH 2/2] .github/workflows/ci.yml: fix build failures. - pin SWIG version; - appease git in Emscripten docker image; --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 327a9839..5c0b0072 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -218,7 +218,7 @@ jobs: node_js=bindings/node.js if [ -x $node_js/run.me ]; then if [ ! -x ~/swig/bin/swig ]; then - ( git clone https://github.com/swig/swig; + ( git clone --branch v4.2.1 https://github.com/swig/swig; cd swig; ./autogen.sh; ./configure --prefix=$HOME/swig; @@ -264,7 +264,7 @@ jobs: registry: https://index.docker.io/v1/ image: emscripten/emsdk options: --volume ${{ github.workspace }}:/blst --network=none - run: git clone -q /blst /tmp/blst && /tmp/blst/bindings/emscripten/run.me -O2 + run: git config --global safe.directory \* && git clone -q /blst /tmp/blst && /tmp/blst/bindings/emscripten/run.me -O2 - name: C# run: |