Merge branch 'master' into validator-record-update

This commit is contained in:
Grant Wuerker 2018-12-23 12:21:49 -06:00
commit 1b3de3a507
32 changed files with 100 additions and 59 deletions

View File

@ -2,6 +2,7 @@
name = "lighthouse" name = "lighthouse"
version = "0.0.1" version = "0.0.1"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
blake2-rfc = "0.2.18" blake2-rfc = "0.2.18"

View File

@ -264,3 +264,9 @@ proof-of-concept implementation in Python is available at
Presently, the specification focuses almost exclusively on the beacon chain, Presently, the specification focuses almost exclusively on the beacon chain,
as it is the focus of current development efforts. Progress on shard chain as it is the focus of current development efforts. Progress on shard chain
specification will soon follow. specification will soon follow.
# Donations
If you support the cause, we could certainly use donations to help fund development:
`0x25c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b`

View File

@ -2,6 +2,7 @@
name = "attestation_validation" name = "attestation_validation"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls = { path = "../utils/bls" } bls = { path = "../utils/bls" }

View File

@ -15,9 +15,9 @@ mod justified_slot;
mod shard_block; mod shard_block;
mod signature; mod signature;
pub use enums::{Invalid, Outcome, Error}; pub use crate::enums::{Invalid, Outcome, Error};
pub use block_inclusion::validate_attestation_for_block; pub use crate::block_inclusion::validate_attestation_for_block;
pub use justified_slot::validate_attestation_justified_slot; pub use crate::justified_slot::validate_attestation_justified_slot;
pub use justified_block::validate_attestation_justified_block_hash; pub use crate::justified_block::validate_attestation_justified_block_hash;
pub use signature::validate_attestation_signature; pub use crate::signature::validate_attestation_signature;
pub use shard_block::validate_attestation_data_shard_block_hash; pub use crate::shard_block::validate_attestation_data_shard_block_hash;

View File

@ -2,6 +2,7 @@
name = "chain" name = "chain"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls = { path = "../utils/bls" } bls = { path = "../utils/bls" }

View File

@ -14,11 +14,11 @@ mod stores;
mod transition; mod transition;
use db::ClientDB; use db::ClientDB;
use genesis::{genesis_states, Error as GenesisError}; use crate::genesis::{genesis_states, Error as GenesisError};
use maps::{generate_attester_and_proposer_maps, AttesterAndProposerMapError}; use crate::maps::{generate_attester_and_proposer_maps, AttesterAndProposerMapError};
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use stores::BeaconChainStore; use crate::stores::BeaconChainStore;
use types::{ActiveState, AttesterMap, ChainConfig, CrystallizedState, Hash256, ProposerMap}; use types::{ActiveState, AttesterMap, ChainConfig, CrystallizedState, Hash256, ProposerMap};
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]

View File

@ -2,6 +2,7 @@
name = "naive_fork_choice" name = "naive_fork_choice"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
db = { path = "../../lighthouse/db" } db = { path = "../../lighthouse/db" }

View File

@ -2,6 +2,7 @@
name = "spec" name = "spec"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
types = { path = "../types" } types = { path = "../types" }

View File

@ -2,6 +2,7 @@
name = "state-transition" name = "state-transition"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
types = { path = "../types" } types = { path = "../types" }

View File

@ -2,6 +2,7 @@
name = "types" name = "types"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls = { path = "../utils/bls" } bls = { path = "../utils/bls" }

View File

@ -25,22 +25,22 @@ pub mod validator_record;
use self::ethereum_types::{H160, H256, U256}; use self::ethereum_types::{H160, H256, U256};
use std::collections::HashMap; use std::collections::HashMap;
pub use active_state::ActiveState; pub use crate::active_state::ActiveState;
pub use attestation_data::AttestationData; pub use crate::attestation_data::AttestationData;
pub use attestation::Attestation; pub use crate::attestation::Attestation;
pub use beacon_block::BeaconBlock; pub use crate::beacon_block::BeaconBlock;
pub use beacon_state::BeaconState; pub use crate::beacon_state::BeaconState;
pub use chain_config::ChainConfig; pub use crate::chain_config::ChainConfig;
pub use crosslink_record::CrosslinkRecord; pub use crate::crosslink_record::CrosslinkRecord;
pub use crystallized_state::CrystallizedState; pub use crate::crystallized_state::CrystallizedState;
pub use deposit::Deposit; pub use crate::deposit::Deposit;
pub use deposit_data::DepositData; pub use crate::deposit_data::DepositData;
pub use deposit_input::DepositInput; pub use crate::deposit_input::DepositInput;
pub use fork_data::ForkData; pub use crate::fork_data::ForkData;
pub use pending_attestation_record::PendingAttestationRecord; pub use crate::pending_attestation_record::PendingAttestationRecord;
pub use shard_and_committee::ShardAndCommittee; pub use crate::shard_and_committee::ShardAndCommittee;
pub use special_record::{SpecialRecord, SpecialRecordKind}; pub use crate::special_record::{SpecialRecord, SpecialRecordKind};
pub use validator_record::{ValidatorRecord, ValidatorStatus}; pub use crate::validator_record::{ValidatorRecord, ValidatorStatus};
pub type Hash256 = H256; pub type Hash256 = H256;
pub type Address = H160; pub type Address = H160;

View File

@ -2,6 +2,7 @@
name = "bls" name = "bls"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls-aggregates = { git = "https://github.com/sigp/signature-schemes" } bls-aggregates = { git = "https://github.com/sigp/signature-schemes" }

View File

@ -10,16 +10,24 @@ pub use self::bls_aggregates::Signature;
pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97; pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97;
use hashing::proof_of_possession_hash; use hashing::canonical_hash;
use std::default::Default;
fn extend_if_needed(hash: &mut Vec<u8>) {
// NOTE: bls_aggregates crate demands 48 bytes, this may be removed as we get closer to production
hash.resize(48, Default::default())
}
/// For some signature and public key, ensure that the signature message was the public key and it /// 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. /// was signed by the secret key that corresponds to that public key.
pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) -> bool { pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) -> bool {
let hash = proof_of_possession_hash(&pubkey.as_bytes()); let mut hash = canonical_hash(&pubkey.as_bytes());
extend_if_needed(&mut hash);
sig.verify_hashed(&hash, &pubkey) sig.verify_hashed(&hash, &pubkey)
} }
pub fn create_proof_of_possession(keypair: &Keypair) -> Signature { pub fn create_proof_of_possession(keypair: &Keypair) -> Signature {
let hash = proof_of_possession_hash(&keypair.pk.as_bytes()); let mut hash = canonical_hash(&keypair.pk.as_bytes());
extend_if_needed(&mut hash);
Signature::new_hashed(&hash, &keypair.sk) Signature::new_hashed(&hash, &keypair.sk)
} }

View File

@ -2,6 +2,7 @@
name = "boolean-bitfield" name = "boolean-bitfield"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
ssz = { path = "../ssz" } ssz = { path = "../ssz" }

View File

@ -2,6 +2,7 @@
name = "hashing" name = "hashing"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
blake2-rfc = "0.2.18" tiny-keccak = "1.4.2"

View File

@ -1,17 +1,30 @@
extern crate blake2_rfc; extern crate tiny_keccak;
use self::blake2_rfc::blake2b::blake2b; use tiny_keccak::Keccak;
pub fn canonical_hash(input: &[u8]) -> Vec<u8> { pub fn canonical_hash(input: &[u8]) -> Vec<u8> {
let result = blake2b(64, &[], input); let mut keccak = Keccak::new_keccak256();
result.as_bytes()[0..32].to_vec() keccak.update(input);
let mut result = vec![0; 32];
keccak.finalize(result.as_mut_slice());
result
} }
pub fn proof_of_possession_hash(input: &[u8]) -> Vec<u8> { #[cfg(test)]
let result = blake2b(64, &[], input); mod tests {
let mut hash = result.as_bytes()[32..64].to_vec(); use super::*;
// TODO: this padding is not part of the spec, it is required otherwise Milagro will panic. use std::convert::From;
// We should either drop the padding or ensure the padding is in the spec.
hash.append(&mut vec![0; 18]); #[test]
hash fn test_hashing() {
let input: Vec<u8> = From::from("hello");
let output = canonical_hash(input.as_ref());
let expected = &[
0x1c, 0x8a, 0xff, 0x95, 0x06, 0x85, 0xc2, 0xed, 0x4b, 0xc3, 0x17, 0x4f, 0x34, 0x72,
0x28, 0x7b, 0x56, 0xd9, 0x51, 0x7b, 0x9c, 0x94, 0x81, 0x27, 0x31, 0x9a, 0x09, 0xa7,
0xa3, 0x6d, 0xea, 0xc8,
];
assert_eq!(expected, output.as_slice());
}
} }

View File

@ -2,5 +2,6 @@
name = "honey-badger-split" name = "honey-badger-split"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]

View File

@ -2,5 +2,6 @@
name = "slot-clock" name = "slot-clock"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]

View File

@ -2,6 +2,7 @@
name = "ssz" name = "ssz"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bytes = "0.4.9" bytes = "0.4.9"

View File

@ -16,8 +16,8 @@ pub mod encode;
mod impl_decode; mod impl_decode;
mod impl_encode; mod impl_encode;
pub use decode::{decode_ssz, decode_ssz_list, Decodable, DecodeError}; pub use crate::decode::{decode_ssz, decode_ssz_list, Decodable, DecodeError};
pub use encode::{Encodable, SszStream}; pub use crate::encode::{Encodable, SszStream};
pub const LENGTH_BYTES: usize = 4; pub const LENGTH_BYTES: usize = 4;
pub const MAX_LIST_SIZE: usize = 1 << (4 * 8); pub const MAX_LIST_SIZE: usize = 1 << (4 * 8);

View File

@ -2,6 +2,7 @@
name = "ssz_helpers" name = "ssz_helpers"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls = { path = "../bls" } bls = { path = "../bls" }

View File

@ -220,6 +220,8 @@ mod tests {
use super::super::types::{Attestation, BeaconBlock, SpecialRecord}; use super::super::types::{Attestation, BeaconBlock, SpecialRecord};
use super::*; use super::*;
use super::canonical_hash;
fn get_block_ssz(b: &BeaconBlock) -> Vec<u8> { fn get_block_ssz(b: &BeaconBlock) -> Vec<u8> {
let mut ssz_stream = SszStream::new(); let mut ssz_stream = SszStream::new();
ssz_stream.append(b); ssz_stream.append(b);
@ -292,9 +294,10 @@ mod tests {
// it was simply printed then copied into the code. This test // it was simply printed then copied into the code. This test
// will tell us if the hash changes, not that it matches some // will tell us if the hash changes, not that it matches some
// canonical reference. // canonical reference.
// TODO: make sure this test conforms to canonical test vectors; it is not clear that it currently does so
let expected_hash = [ let expected_hash = [
254, 192, 124, 164, 240, 137, 162, 126, 50, 255, 118, 88, 189, 151, 221, 4, 40, 121, 132, 43, 230, 49, 234, 240, 253, 146, 85, 121, 104, 79, 35, 0, 126, 162, 132, 99, 145,
198, 33, 248, 221, 104, 255, 46, 234, 146, 161, 202, 140, 109, 175, 13, 30, 57, 118, 5, 175, 136, 174, 7, 52, 161, 87, 196,
]; ];
assert_eq!(hash, expected_hash); assert_eq!(hash, expected_hash);

View File

@ -2,6 +2,7 @@
name = "vec_shuffle" name = "vec_shuffle"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
hashing = { path = "../hashing" } hashing = { path = "../hashing" }

View File

@ -47,7 +47,10 @@ mod tests {
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
// TODO: update test vectors to use keccak instead of blake.
// https://github.com/sigp/lighthouse/issues/121
#[test] #[test]
#[should_panic]
fn test_shuffling() { fn test_shuffling() {
let mut file = File::open("./src/specs/shuffle_test_vectors.yaml").unwrap(); let mut file = File::open("./src/specs/shuffle_test_vectors.yaml").unwrap();
let mut yaml_str = String::new(); let mut yaml_str = String::new();

View File

@ -87,15 +87,4 @@ mod tests {
x = int_from_byte_slice(&[0x8f, 0xbb, 0xc7], 0); x = int_from_byte_slice(&[0x8f, 0xbb, 0xc7], 0);
assert_eq!(x, 9419719); assert_eq!(x, 9419719);
} }
#[test]
fn test_shuffling_hash_fn() {
let digest = canonical_hash(&canonical_hash(&"4kn4driuctg8".as_bytes())); // double-hash is intentional
let expected = [
103, 21, 99, 143, 60, 75, 116, 81, 248, 175, 190, 114, 54, 65, 23, 8, 3, 116, 160, 178,
7, 75, 63, 47, 180, 239, 191, 247, 57, 194, 144, 88,
];
assert_eq!(digest.len(), expected.len());
assert_eq!(digest, expected)
}
} }

View File

@ -2,6 +2,7 @@
name = "validator_change" name = "validator_change"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bytes = "0.4.10" bytes = "0.4.10"

View File

@ -2,6 +2,7 @@
name = "validator_induction" name = "validator_induction"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
bls = { path = "../utils/bls" } bls = { path = "../utils/bls" }

View File

@ -5,4 +5,4 @@ extern crate spec;
mod inductor; mod inductor;
pub use inductor::{ValidatorInductionError}; pub use crate::inductor::{ValidatorInductionError};

View File

@ -2,6 +2,7 @@
name = "validator_shuffling" name = "validator_shuffling"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
honey-badger-split = { path = "../utils/honey-badger-split" } honey-badger-split = { path = "../utils/honey-badger-split" }

View File

@ -4,4 +4,4 @@ extern crate vec_shuffle;
mod shuffle; mod shuffle;
pub use shuffle::{shard_and_committees_for_cycle, ValidatorAssignmentError}; pub use crate::shuffle::{shard_and_committees_for_cycle, ValidatorAssignmentError};

View File

@ -2,6 +2,7 @@
name = "db" name = "db"
version = "0.1.0" version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018"
[dependencies] [dependencies]
blake2-rfc = "0.2.18" blake2-rfc = "0.2.18"

View File

@ -13,7 +13,7 @@ mod config;
use std::path::PathBuf; use std::path::PathBuf;
use clap::{App, Arg}; use clap::{App, Arg};
use config::LighthouseConfig; use crate::config::LighthouseConfig;
use slog::Drain; use slog::Drain;
fn main() { fn main() {