From 88790e6abeb5bc1b0fc7ce2a4ea97d3fdd672dd9 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 12 Jun 2019 15:44:23 +1000 Subject: [PATCH] bls: debugging utils and fake sig fix There was a discrepancy between the is_empty fields of fake signatures during testing, so I've added a small hack to set the is_empty field of a fake signature based on the byte content. Alternatively, we could just make it so that any fake signature is defined to be equal to any other. --- eth2/utils/bls/src/fake_aggregate_public_key.rs | 1 - eth2/utils/bls/src/fake_public_key.rs | 1 - eth2/utils/bls/src/fake_signature.rs | 3 ++- eth2/utils/bls/src/signature.rs | 6 ++++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/eth2/utils/bls/src/fake_aggregate_public_key.rs b/eth2/utils/bls/src/fake_aggregate_public_key.rs index 9ac607311..65774b7c6 100644 --- a/eth2/utils/bls/src/fake_aggregate_public_key.rs +++ b/eth2/utils/bls/src/fake_aggregate_public_key.rs @@ -1,5 +1,4 @@ use super::{PublicKey, BLS_PUBLIC_KEY_BYTE_SIZE}; -use milagro_bls::AggregatePublicKey as RawAggregatePublicKey; /// A BLS aggregate public key. /// diff --git a/eth2/utils/bls/src/fake_public_key.rs b/eth2/utils/bls/src/fake_public_key.rs index d8a1b1be5..617363d12 100644 --- a/eth2/utils/bls/src/fake_public_key.rs +++ b/eth2/utils/bls/src/fake_public_key.rs @@ -1,6 +1,5 @@ use super::{SecretKey, BLS_PUBLIC_KEY_BYTE_SIZE}; use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector; -use milagro_bls::PublicKey as RawPublicKey; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::{encode as hex_encode, HexVisitor}; diff --git a/eth2/utils/bls/src/fake_signature.rs b/eth2/utils/bls/src/fake_signature.rs index de16a05f3..ebe4e997e 100644 --- a/eth2/utils/bls/src/fake_signature.rs +++ b/eth2/utils/bls/src/fake_signature.rs @@ -59,9 +59,10 @@ impl FakeSignature { expected: BLS_SIG_BYTE_SIZE, }) } else { + let is_empty = bytes.iter().all(|x| *x == 0); Ok(Self { bytes: bytes.to_vec(), - is_empty: false, + is_empty, }) } } diff --git a/eth2/utils/bls/src/signature.rs b/eth2/utils/bls/src/signature.rs index 5009d060c..257254eba 100644 --- a/eth2/utils/bls/src/signature.rs +++ b/eth2/utils/bls/src/signature.rs @@ -101,6 +101,12 @@ impl Signature { pub fn is_empty(&self) -> bool { self.is_empty } + + /// Display a signature as a hex string of its bytes. + #[cfg(test)] + pub fn as_hex_string(&self) -> String { + hex_encode(self.as_bytes()) + } } impl_ssz!(Signature, BLS_SIG_BYTE_SIZE, "Signature");