Update to signature-scheme 0.5.2

This commit is contained in:
Kirk Baird 2019-02-18 10:50:40 +11:00
parent 977f3edfb6
commit 9c4a1f1d1f
No known key found for this signature in database
GPG Key ID: BF864B7ED0BEA33F
12 changed files with 67 additions and 38 deletions

View File

@ -110,10 +110,11 @@ impl AttestationAggregator {
Message::BadValidatorIndex
);
if !free_attestation
.signature
.verify(&signable_message, spec.domain_attestation, &validator_record.pubkey)
{
if !free_attestation.signature.verify(
&signable_message,
spec.domain_attestation,
&validator_record.pubkey,
) {
return Ok(Outcome {
valid: false,
message: Message::BadSignature,

View File

@ -137,8 +137,10 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> Attester<T, U, V,
fn sign_attestation_data(&mut self, attestation_data: &AttestationData) -> Option<Signature> {
self.store_produce(attestation_data);
self.signer
.sign_attestation_message(&attestation_data.signable_message(PHASE_0_CUSTODY_BIT)[..], DOMAIN_ATTESTATION)
self.signer.sign_attestation_message(
&attestation_data.signable_message(PHASE_0_CUSTODY_BIT)[..],
DOMAIN_ATTESTATION,
)
}
/// Returns `true` if signing some attestation_data is safe (non-slashable).

View File

@ -134,7 +134,10 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> BlockProducer<T, U
// TODO: add domain, etc to this message. Also ensure result matches `into_to_bytes32`.
let message = ssz_encode(&slot.epoch(self.spec.epoch_length));
match self.signer.sign_randao_reveal(&message, self.spec.domain_randao) {
match self
.signer
.sign_randao_reveal(&message, self.spec.domain_randao)
{
None => return Ok(PollOutcome::SignerRejection(slot)),
Some(signature) => signature,
}
@ -166,10 +169,10 @@ impl<T: SlotClock, U: BeaconNode, V: DutiesReader, W: Signer> BlockProducer<T, U
fn sign_block(&mut self, mut block: BeaconBlock) -> Option<BeaconBlock> {
self.store_produce(&block);
match self
.signer
.sign_block_proposal(&block.proposal_root(&self.spec)[..], self.spec.domain_proposal)
{
match self.signer.sign_block_proposal(
&block.proposal_root(&self.spec)[..],
self.spec.domain_proposal,
) {
None => None,
Some(signature) => {
block.signature = signature;

View File

@ -30,11 +30,8 @@ use fast_math::log2_raw;
use std::collections::HashMap;
use std::sync::Arc;
use types::{
readers::BeaconBlockReader,
slot_epoch::Slot,
slot_height::SlotHeight,
validator_registry::get_active_validator_indices,
BeaconBlock, Hash256,
readers::BeaconBlockReader, slot_epoch::Slot, slot_height::SlotHeight,
validator_registry::get_active_validator_indices, BeaconBlock, Hash256,
};
//TODO: Pruning - Children

View File

@ -27,8 +27,11 @@ impl Attestation {
custody_bit: bool,
domain: u64,
) -> bool {
self.aggregate_signature
.verify(&self.signable_message(custody_bit), domain, group_public_key)
self.aggregate_signature.verify(
&self.signable_message(custody_bit),
domain,
group_public_key,
)
}
}

View File

@ -1,8 +1,8 @@
use crate::test_utils::TestRandom;
use crate::{
validator::StatusFlags, validator_registry::get_active_validator_indices, AttestationData,
Bitfield, ChainSpec, Crosslink, Deposit, DepositInput, Epoch, Eth1Data, Eth1DataVote, Fork, Hash256,
PendingAttestation, PublicKey, Signature, Slot, Validator,
Bitfield, ChainSpec, Crosslink, Deposit, DepositInput, Epoch, Eth1Data, Eth1DataVote, Fork,
Hash256, PendingAttestation, PublicKey, Signature, Slot, Validator,
};
use honey_badger_split::SplitExt;
use rand::RngCore;
@ -593,7 +593,7 @@ impl BeaconState {
pubkey: PublicKey,
proof_of_possession: Signature,
withdrawal_credentials: Hash256,
spec: &ChainSpec
spec: &ChainSpec,
) -> bool {
let proof_of_possession_data = DepositInput {
pubkey: pubkey.clone(),
@ -603,15 +603,12 @@ impl BeaconState {
proof_of_possession.verify(
&proof_of_possession_data.hash_tree_root(),
self.fork.get_domain(
self.slot.epoch(spec.epoch_length),
spec.domain_deposit,
),
self.fork
.get_domain(self.slot.epoch(spec.epoch_length), spec.domain_deposit),
&pubkey,
)
}
/// Process a validator deposit, returning the validator index if the deposit is valid.
///
/// Spec v0.2.0
@ -623,7 +620,12 @@ impl BeaconState {
withdrawal_credentials: Hash256,
spec: &ChainSpec,
) -> Result<usize, ()> {
if !self.validate_proof_of_possession(pubkey.clone(), proof_of_possession, withdrawal_credentials, &spec) {
if !self.validate_proof_of_possession(
pubkey.clone(),
proof_of_possession,
withdrawal_credentials,
&spec,
) {
return Err(());
}

View File

@ -22,7 +22,7 @@ impl Fork {
/// Get the domain number that represents the fork meta and signature domain.
pub fn get_domain(&self, epoch: Epoch, domain_type: u64) -> u64 {
let fork_version = self.get_fork_version(epoch);
fork_version * u64::pow(2,32) + domain_type
fork_version * u64::pow(2, 32) + domain_type
}
}

View File

@ -5,7 +5,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies]
bls-aggregates = { git = "https://github.com/sigp/signature-schemes", tag = "0.4.1" }
bls-aggregates = { git = "https://github.com/sigp/signature-schemes", tag = "0.5.2" }
hashing = { path = "../hashing" }
hex = "0.3"
serde = "1.0"

View File

@ -27,7 +27,12 @@ impl AggregateSignature {
///
/// Only returns `true` if the set of keys in the `AggregatePublicKey` match the set of keys
/// that signed the `AggregateSignature`.
pub fn verify(&self, msg: &[u8], domain: u64, aggregate_public_key: &AggregatePublicKey) -> bool {
pub fn verify(
&self,
msg: &[u8],
domain: u64,
aggregate_public_key: &AggregatePublicKey,
) -> bool {
self.0.verify(msg, domain, aggregate_public_key)
}
}

View File

@ -30,7 +30,6 @@ fn extend_if_needed(hash: &mut Vec<u8>) {
/// For some signature and public key, ensure that the signature message was the public key and it
/// was signed by the secret key that corresponds to that public key.
pub fn create_proof_of_possession(keypair: &Keypair) -> Signature {
Signature::new(&ssz_encode(&keypair.pk), 0, &keypair.sk)
}

View File

@ -21,7 +21,11 @@ impl Signature {
/// Instantiate a new Signature from a message and a SecretKey, where the message has already
/// been hashed.
pub fn new_hashed(x_real_hashed: &[u8], x_imaginary_hashed: &[u8], sk: &SecretKey) -> Self {
Signature(RawSignature::new_hashed(x_real_hashed, x_imaginary_hashed, sk.as_raw()))
Signature(RawSignature::new_hashed(
x_real_hashed,
x_imaginary_hashed,
sk.as_raw(),
))
}
/// Verify the Signature against a PublicKey.
@ -30,8 +34,14 @@ impl Signature {
}
/// Verify the Signature against a PublicKey, where the message has already been hashed.
pub fn verify_hashed(&self, x_real_hashed: &[u8], x_imaginary_hashed: &[u8], pk: &PublicKey) -> bool {
self.0.verify_hashed(x_real_hashed, x_imaginary_hashed, pk.as_raw())
pub fn verify_hashed(
&self,
x_real_hashed: &[u8],
x_imaginary_hashed: &[u8],
pk: &PublicKey,
) -> bool {
self.0
.verify_hashed(x_real_hashed, x_imaginary_hashed, pk.as_raw())
}
/// Returns the underlying signature.
@ -41,7 +51,9 @@ impl Signature {
/// Returns a new empty signature.
pub fn empty_signature() -> Self {
let empty: Vec<u8> = vec![0; 96];
let mut empty: Vec<u8> = vec![0; 96];
// TODO: Modify the way flags are used (b_flag should not be used for empty_signature in the future)
empty[0] += u8::pow(2, 6);
Signature(RawSignature::from_bytes(&empty).unwrap())
}
}
@ -99,9 +111,13 @@ mod tests {
let sig_as_bytes: Vec<u8> = sig.as_raw().as_bytes();
assert_eq!(sig_as_bytes.len(), 97);
for one_byte in sig_as_bytes.iter() {
assert_eq!(*one_byte, 0);
assert_eq!(sig_as_bytes.len(), 96);
for (i, one_byte) in sig_as_bytes.iter().enumerate() {
if i == 0 {
assert_eq!(*one_byte, u8::pow(2, 6));
} else {
assert_eq!(*one_byte, 0);
}
}
}
}