mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-18 13:28:33 +00:00
Fix proof-of-possession issues.
These were introduced in an earlier commit
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use super::Hash256;
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::*;
|
||||
use bls::{Keypair, PublicKey, Signature};
|
||||
use rand::RngCore;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
@@ -37,14 +37,30 @@ impl DepositInput {
|
||||
withdrawal_credentials: &Hash256,
|
||||
domain: u64,
|
||||
) -> Signature {
|
||||
let signable_deposite_input = DepositInput {
|
||||
let signable_deposit_input = DepositInput {
|
||||
pubkey: keypair.pk.clone(),
|
||||
withdrawal_credentials: withdrawal_credentials.clone(),
|
||||
proof_of_possession: Signature::empty_signature(),
|
||||
};
|
||||
let msg = signable_deposite_input.signed_root();
|
||||
let msg = signable_deposit_input.signed_root();
|
||||
|
||||
Signature::new(msg.as_slice(), domain, &keypair.sk)
|
||||
}
|
||||
|
||||
/// Verify that proof-of-possession is valid.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn validate_proof_of_possession(
|
||||
&self,
|
||||
epoch: Epoch,
|
||||
fork: &Fork,
|
||||
spec: &ChainSpec,
|
||||
) -> bool {
|
||||
let msg = self.signed_root();
|
||||
let domain = spec.get_domain(epoch, Domain::Deposit, fork);
|
||||
|
||||
self.proof_of_possession.verify(&msg, domain, &self.pubkey)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -153,12 +153,18 @@ impl TestingBeaconBlockBuilder {
|
||||
}
|
||||
|
||||
/// Insert a `Valid` deposit into the state.
|
||||
pub fn insert_deposit(&mut self, amount: u64, index: u64, domain: u64, spec: &ChainSpec) {
|
||||
pub fn insert_deposit(
|
||||
&mut self,
|
||||
amount: u64,
|
||||
index: u64,
|
||||
state: &BeaconState,
|
||||
spec: &ChainSpec,
|
||||
) {
|
||||
let keypair = Keypair::random();
|
||||
|
||||
let mut builder = TestingDepositBuilder::new(amount);
|
||||
builder.set_index(index);
|
||||
builder.sign(&keypair, domain, spec);
|
||||
builder.sign(&keypair, state, spec);
|
||||
|
||||
self.block.body.deposits.push(builder.build())
|
||||
}
|
||||
|
||||
@@ -30,10 +30,14 @@ impl TestingDepositBuilder {
|
||||
self.deposit.index = index;
|
||||
}
|
||||
|
||||
pub fn sign(&mut self, keypair: &Keypair, domain: u64, spec: &ChainSpec) {
|
||||
pub fn sign(&mut self, keypair: &Keypair, state: &BeaconState, spec: &ChainSpec) {
|
||||
let withdrawal_credentials = Hash256::from_slice(
|
||||
&get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..],
|
||||
);
|
||||
|
||||
let epoch = state.current_epoch(spec);
|
||||
let domain = spec.get_domain(epoch, Domain::Deposit, &state.fork);
|
||||
|
||||
self.deposit.deposit_data.deposit_input.pubkey = keypair.pk.clone();
|
||||
self.deposit
|
||||
.deposit_data
|
||||
|
||||
Reference in New Issue
Block a user