mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +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.
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
use super::*;
|
|
use crate::case_result::compare_result;
|
|
use crate::impl_bls_load_case;
|
|
use bls::{PublicKeyBytes, Signature, SignatureBytes};
|
|
use serde_derive::Deserialize;
|
|
use std::convert::TryInto;
|
|
use types::Hash256;
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct BlsVerifyInput {
|
|
pub pubkey: PublicKeyBytes,
|
|
pub message: String,
|
|
pub signature: SignatureBytes,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct BlsVerify {
|
|
pub input: BlsVerifyInput,
|
|
pub output: bool,
|
|
}
|
|
|
|
impl_bls_load_case!(BlsVerify);
|
|
|
|
impl Case for BlsVerify {
|
|
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
|
|
let message = hex::decode(&self.input.message[2..])
|
|
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?;
|
|
|
|
let signature_ok = (&self.input.signature)
|
|
.try_into()
|
|
.and_then(|signature: Signature| {
|
|
let pk = self.input.pubkey.decompress()?;
|
|
Ok(signature.verify(&pk, Hash256::from_slice(&message)))
|
|
})
|
|
.unwrap_or(false);
|
|
|
|
compare_result::<bool, ()>(&Ok(signature_ok), &Some(self.output))
|
|
}
|
|
}
|