Run cargo fmt
This commit is contained in:
parent
2b991854ab
commit
25b08f0096
@ -118,12 +118,16 @@ impl BeaconChainHarness {
|
||||
let deposits = generate_deposits_from_keypairs(
|
||||
&keypairs,
|
||||
genesis_time,
|
||||
spec.get_domain(spec.genesis_epoch, Domain::Deposit, &Fork{
|
||||
previous_version: spec.genesis_fork_version,
|
||||
current_version: spec.genesis_fork_version,
|
||||
epoch: spec.genesis_epoch,
|
||||
}),
|
||||
&spec
|
||||
spec.get_domain(
|
||||
spec.genesis_epoch,
|
||||
Domain::Deposit,
|
||||
&Fork {
|
||||
previous_version: spec.genesis_fork_version,
|
||||
current_version: spec.genesis_fork_version,
|
||||
epoch: spec.genesis_epoch,
|
||||
},
|
||||
),
|
||||
&spec,
|
||||
);
|
||||
state_builder.process_initial_deposits(&deposits, &spec);
|
||||
};
|
||||
|
@ -42,28 +42,32 @@ pub fn generate_deposits_from_keypairs(
|
||||
keypairs.len()
|
||||
);
|
||||
|
||||
let initial_validator_deposits =
|
||||
keypairs
|
||||
.par_iter()
|
||||
.map(|keypair| {
|
||||
let withdrawal_credentials = Hash256::from_slice(
|
||||
&get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..]);
|
||||
Deposit {
|
||||
branch: vec![], // branch verification is not specified.
|
||||
index: 0, // index verification is not specified.
|
||||
deposit_data: DepositData {
|
||||
amount: 32_000_000_000, // 32 ETH (in Gwei)
|
||||
timestamp: genesis_time - 1,
|
||||
deposit_input: DepositInput {
|
||||
pubkey: keypair.pk.clone(),
|
||||
// Validator can withdraw using their main keypair.
|
||||
withdrawal_credentials: withdrawal_credentials.clone(),
|
||||
proof_of_possession: DepositInput::create_proof_of_possession(&keypair, &withdrawal_credentials, domain),
|
||||
},
|
||||
let initial_validator_deposits = keypairs
|
||||
.par_iter()
|
||||
.map(|keypair| {
|
||||
let withdrawal_credentials = Hash256::from_slice(
|
||||
&get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..],
|
||||
);
|
||||
Deposit {
|
||||
branch: vec![], // branch verification is not specified.
|
||||
index: 0, // index verification is not specified.
|
||||
deposit_data: DepositData {
|
||||
amount: 32_000_000_000, // 32 ETH (in Gwei)
|
||||
timestamp: genesis_time - 1,
|
||||
deposit_input: DepositInput {
|
||||
pubkey: keypair.pk.clone(),
|
||||
// Validator can withdraw using their main keypair.
|
||||
withdrawal_credentials: withdrawal_credentials.clone(),
|
||||
proof_of_possession: DepositInput::create_proof_of_possession(
|
||||
&keypair,
|
||||
&withdrawal_credentials,
|
||||
domain,
|
||||
),
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
initial_validator_deposits
|
||||
}
|
||||
|
@ -265,10 +265,14 @@ fn build_deposit(
|
||||
&keypair,
|
||||
&withdrawal_credentials,
|
||||
harness.spec.get_domain(
|
||||
harness.beacon_chain.state.read().current_epoch(&harness.spec),
|
||||
harness
|
||||
.beacon_chain
|
||||
.state
|
||||
.read()
|
||||
.current_epoch(&harness.spec),
|
||||
Domain::Deposit,
|
||||
&harness.beacon_chain.state.read().fork,
|
||||
)
|
||||
),
|
||||
);
|
||||
let index = harness.beacon_chain.state.read().deposit_index + index_offset;
|
||||
|
||||
|
@ -19,8 +19,8 @@ use slot_clock::SystemTimeSlotClock;
|
||||
use ssz::TreeHash;
|
||||
use std::sync::Arc;
|
||||
use types::{
|
||||
beacon_state::BeaconStateBuilder, BeaconBlock, ChainSpec, Domain, Deposit, DepositData, DepositInput,
|
||||
Eth1Data, Fork, Hash256, Keypair,
|
||||
beacon_state::BeaconStateBuilder, BeaconBlock, ChainSpec, Deposit, DepositData, DepositInput,
|
||||
Domain, Eth1Data, Fork, Hash256, Keypair,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
@ -123,7 +123,7 @@ fn main() {
|
||||
previous_version: spec.genesis_fork_version,
|
||||
current_version: spec.genesis_fork_version,
|
||||
epoch: spec.genesis_epoch,
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
},
|
||||
|
@ -618,19 +618,14 @@ impl BeaconState {
|
||||
pubkey_map: Option<&HashMap<PublicKey, usize>>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<usize, ()> {
|
||||
|
||||
let proof_is_valid = deposit_input.proof_of_possession.verify(
|
||||
&deposit_input.signed_root(),
|
||||
spec.get_domain(
|
||||
self.current_epoch(&spec),
|
||||
Domain::Deposit,
|
||||
&self.fork,
|
||||
),
|
||||
spec.get_domain(self.current_epoch(&spec), Domain::Deposit, &self.fork),
|
||||
&deposit_input.pubkey,
|
||||
);
|
||||
|
||||
if !proof_is_valid {
|
||||
return Err(())
|
||||
return Err(());
|
||||
}
|
||||
|
||||
let pubkey = deposit_input.pubkey.clone();
|
||||
|
@ -3,14 +3,25 @@ use crate::test_utils::TestRandom;
|
||||
use bls::{Keypair, PublicKey, Signature};
|
||||
use rand::RngCore;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use ssz_derive::{Decode, Encode, SignedRoot, TreeHash};
|
||||
use ssz::{SignedRoot, TreeHash};
|
||||
use ssz_derive::{Decode, Encode, SignedRoot, TreeHash};
|
||||
use test_random_derive::TestRandom;
|
||||
|
||||
/// The data supplied by the user to the deposit contract.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Encode, Decode, SignedRoot, TreeHash, TestRandom)]
|
||||
#[derive(
|
||||
Debug,
|
||||
PartialEq,
|
||||
Clone,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Encode,
|
||||
Decode,
|
||||
SignedRoot,
|
||||
TreeHash,
|
||||
TestRandom,
|
||||
)]
|
||||
pub struct DepositInput {
|
||||
pub pubkey: PublicKey,
|
||||
pub withdrawal_credentials: Hash256,
|
||||
@ -21,7 +32,11 @@ impl DepositInput {
|
||||
/// Generate the 'proof_of_posession' signature for a given DepositInput details.
|
||||
///
|
||||
/// Spec v0.4.0
|
||||
pub fn create_proof_of_possession(keypair: &Keypair, withdrawal_credentials: &Hash256, domain: u64) -> Signature {
|
||||
pub fn create_proof_of_possession(
|
||||
keypair: &Keypair,
|
||||
withdrawal_credentials: &Hash256,
|
||||
domain: u64,
|
||||
) -> Signature {
|
||||
let signable_deposite_input = DepositInput {
|
||||
pubkey: keypair.pk.clone(),
|
||||
withdrawal_credentials: withdrawal_credentials.clone(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::*;
|
||||
use bls::{get_withdrawal_credentials};
|
||||
use bls::get_withdrawal_credentials;
|
||||
|
||||
pub struct TestingDepositBuilder {
|
||||
deposit: Deposit,
|
||||
@ -31,15 +31,16 @@ impl TestingDepositBuilder {
|
||||
}
|
||||
|
||||
pub fn sign(&mut self, keypair: &Keypair, domain: u64, spec: &ChainSpec) {
|
||||
let withdrawal_credentials = Hash256::from_slice(&get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..]);
|
||||
let withdrawal_credentials = Hash256::from_slice(
|
||||
&get_withdrawal_credentials(&keypair.pk, spec.bls_withdrawal_prefix_byte)[..],
|
||||
);
|
||||
self.deposit.deposit_data.deposit_input.pubkey = keypair.pk.clone();
|
||||
self.deposit.deposit_data.deposit_input.withdrawal_credentials = withdrawal_credentials.clone();
|
||||
self.deposit
|
||||
.deposit_data
|
||||
.deposit_input
|
||||
.withdrawal_credentials = withdrawal_credentials.clone();
|
||||
self.deposit.deposit_data.deposit_input.proof_of_possession =
|
||||
DepositInput::create_proof_of_possession(
|
||||
&keypair,
|
||||
&withdrawal_credentials,
|
||||
domain,
|
||||
);
|
||||
DepositInput::create_proof_of_possession(&keypair, &withdrawal_credentials, domain);
|
||||
}
|
||||
|
||||
pub fn build(self) -> Deposit {
|
||||
|
@ -29,7 +29,6 @@ pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) -> bool {
|
||||
sig.verify(&ssz_encode(pubkey), 0, &pubkey)
|
||||
}
|
||||
|
||||
|
||||
/// Returns the withdrawal credentials for a given public key.
|
||||
pub fn get_withdrawal_credentials(pubkey: &PublicKey, prefix_byte: u8) -> Vec<u8> {
|
||||
let hashed = hash(&ssz_encode(pubkey));
|
||||
|
Loading…
Reference in New Issue
Block a user