Add domain to all signature funcitons, modify validate_proof_of_possession()

This commit is contained in:
Kirk Baird
2019-02-15 13:58:14 +11:00
parent 88c42bf3fb
commit 977f3edfb6
19 changed files with 98 additions and 65 deletions

View File

@@ -25,11 +25,10 @@ impl Attestation {
&self,
group_public_key: &AggregatePublicKey,
custody_bit: bool,
// TODO: use domain.
_domain: u64,
domain: u64,
) -> bool {
self.aggregate_signature
.verify(&self.signable_message(custody_bit), group_public_key)
.verify(&self.signable_message(custody_bit), domain, group_public_key)
}
}

View File

@@ -1,10 +1,9 @@
use crate::test_utils::TestRandom;
use crate::{
validator::StatusFlags, validator_registry::get_active_validator_indices, AttestationData,
Bitfield, ChainSpec, Crosslink, Deposit, Epoch, Eth1Data, Eth1DataVote, Fork, Hash256,
Bitfield, ChainSpec, Crosslink, Deposit, DepositInput, Epoch, Eth1Data, Eth1DataVote, Fork, Hash256,
PendingAttestation, PublicKey, Signature, Slot, Validator,
};
use bls::verify_proof_of_possession;
use honey_badger_split::SplitExt;
use rand::RngCore;
use serde_derive::Serialize;
@@ -587,6 +586,32 @@ impl BeaconState {
self.validator_registry_update_epoch = current_epoch;
}
/// Confirm validator owns PublicKey
pub fn validate_proof_of_possession(
&self,
pubkey: PublicKey,
proof_of_possession: Signature,
withdrawal_credentials: Hash256,
spec: &ChainSpec
) -> bool {
let proof_of_possession_data = DepositInput {
pubkey: pubkey.clone(),
withdrawal_credentials,
proof_of_possession: proof_of_possession.clone(),
};
proof_of_possession.verify(
&proof_of_possession_data.hash_tree_root(),
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
@@ -598,8 +623,7 @@ impl BeaconState {
withdrawal_credentials: Hash256,
spec: &ChainSpec,
) -> Result<usize, ()> {
// TODO: ensure verify proof-of-possession represents the spec accurately.
if !verify_proof_of_possession(&proof_of_possession, &pubkey) {
if !self.validate_proof_of_possession(pubkey.clone(), proof_of_possession, withdrawal_credentials, &spec) {
return Err(());
}

View File

@@ -10,6 +10,22 @@ pub struct Fork {
pub epoch: Epoch,
}
impl Fork {
/// Return the fork version of the given ``epoch``.
pub fn get_fork_version(&self, epoch: Epoch) -> u64 {
if epoch < self.epoch {
return self.previous_version;
}
self.current_version
}
/// 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
}
}
impl Encodable for Fork {
fn ssz_append(&self, s: &mut SszStream) {
s.append(&self.previous_version);

View File

@@ -8,6 +8,6 @@ impl<T: RngCore> TestRandom<T> for Signature {
let mut message = vec![0; 32];
rng.fill_bytes(&mut message);
Signature::new(&message, &secret_key)
Signature::new(&message, 0, &secret_key)
}
}