Files
lighthouse/testing/ef_tests/src/cases/bls_batch_verify.rs
will 9f242137b0 Add a new bls test (#3235)
## Issue Addressed

Which issue # does this PR address?
#2629 

## Proposed Changes

Please list or describe the changes introduced by this PR.

1. ci would dowload the bls test cases from https://github.com/ethereum/bls12-381-tests/
2. all the bls test cases(except eth ones) would use cases in the archive from step one
3. The bls test cases from https://github.com/ethereum/consensus-spec-tests would stay there and no use . For the future , these bls test cases would be remove suggested from https://github.com/ethereum/consensus-spec-tests/issues/25 . So it would do no harm and compatible for future cases.

## Additional Info

Please provide any additional information. For example, future considerations
or information useful for reviewers.


Question: 

I am not sure if I should implement tests about `deserialization_G1`, `deserialization_G2` and `hash_to_G2` for the issue.
2022-10-12 23:40:42 +00:00

68 lines
2.0 KiB
Rust

use super::*;
use crate::case_result::compare_result;
use crate::impl_bls_load_case;
use bls::{verify_signature_sets, BlsWrappedSignature, PublicKeyBytes, Signature, SignatureSet};
use serde_derive::Deserialize;
use std::borrow::Cow;
use std::str::FromStr;
use types::Hash256;
#[derive(Debug, Clone, Deserialize)]
pub struct BlsBatchVerifyInput {
pubkeys: Vec<PublicKeyBytes>,
messages: Vec<String>,
signatures: Vec<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct BlsBatchVerify {
pub input: BlsBatchVerifyInput,
pub output: bool,
}
impl_bls_load_case!(BlsBatchVerify);
impl Case for BlsBatchVerify {
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
let messages = self
.input
.messages
.iter()
.map(|s| Hash256::from_str(s).map_err(|e| Error::FailedToParseTest(format!("{:?}", e))))
.collect::<Result<Vec<_>, _>>()?;
let pubkeys = self
.input
.pubkeys
.iter()
.map(|pkb| {
pkb.decompress()
.map_err(|_| Error::FailedToParseTest("pubkeys parse error".to_string()))
})
.collect::<Result<Vec<_>, _>>()?;
let signatures = self
.input
.signatures
.iter()
.map(|s| {
Signature::from_str(s).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))
})
.collect::<Result<Vec<_>, _>>()?;
let signature_set = messages
.iter()
.zip(pubkeys.iter())
.zip(signatures.iter())
.map(|((&message, pubkey), signature)| {
let wraped_signature = BlsWrappedSignature::from(signature);
SignatureSet::single_pubkey(wraped_signature, Cow::Borrowed(pubkey), message)
})
.collect::<Vec<_>>();
let signature_valid = verify_signature_sets(signature_set.iter());
compare_result::<bool, ()>(&Ok(signature_valid), &Some(self.output))
}
}