mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
## 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.
64 lines
2.0 KiB
Rust
64 lines
2.0 KiB
Rust
use super::*;
|
|
use crate::case_result::compare_result;
|
|
use crate::impl_bls_load_case;
|
|
use bls::{AggregateSignature, PublicKeyBytes};
|
|
use serde_derive::Deserialize;
|
|
use types::Hash256;
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct BlsAggregateVerifyInput {
|
|
pub pubkeys: Vec<PublicKeyBytes>,
|
|
pub messages: Vec<String>,
|
|
pub signature: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct BlsAggregateVerify {
|
|
pub input: BlsAggregateVerifyInput,
|
|
pub output: bool,
|
|
}
|
|
|
|
impl_bls_load_case!(BlsAggregateVerify);
|
|
|
|
impl Case for BlsAggregateVerify {
|
|
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
|
|
let messages = self
|
|
.input
|
|
.messages
|
|
.iter()
|
|
.map(|message| {
|
|
let bytes = hex::decode(&message[2..])
|
|
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
|
Ok(Hash256::from_slice(&bytes))
|
|
})
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
let pubkeys_result = self
|
|
.input
|
|
.pubkeys
|
|
.iter()
|
|
.map(|pkb| pkb.decompress())
|
|
.collect::<Result<Vec<_>, _>>();
|
|
|
|
let pubkeys = match pubkeys_result {
|
|
Ok(pubkeys) => pubkeys,
|
|
Err(bls::Error::InvalidInfinityPublicKey) if !self.output => {
|
|
return Ok(());
|
|
}
|
|
Err(e) => return Err(Error::FailedToParseTest(format!("{:?}", e))),
|
|
};
|
|
|
|
let pubkey_refs = pubkeys.iter().collect::<Vec<_>>();
|
|
|
|
let signature_bytes = hex::decode(&self.input.signature[2..])
|
|
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
|
|
|
let signature_valid = AggregateSignature::deserialize(&signature_bytes)
|
|
.ok()
|
|
.map(|signature| signature.aggregate_verify(&messages, &pubkey_refs[..]))
|
|
.unwrap_or(false);
|
|
|
|
compare_result::<bool, ()>(&Ok(signature_valid), &Some(self.output))
|
|
}
|
|
}
|