From a8a36fef74534828db51b0d620a9a17b1df2b85a Mon Sep 17 00:00:00 2001 From: Stan Drozd Date: Mon, 17 Dec 2018 17:36:43 +0100 Subject: [PATCH 1/2] vec_shuffle: Add a keccak testsuite This refreshes the vec shuffle testsuite with a freshly generated keccak-based variety --- beacon_chain/utils/vec_shuffle/src/lib.rs | 36 +++++++-------- .../src/specs/shuffle_test_vectors.yaml | 44 +++++++++---------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/beacon_chain/utils/vec_shuffle/src/lib.rs b/beacon_chain/utils/vec_shuffle/src/lib.rs index b3d540174..f5c2b7ebd 100644 --- a/beacon_chain/utils/vec_shuffle/src/lib.rs +++ b/beacon_chain/utils/vec_shuffle/src/lib.rs @@ -42,40 +42,40 @@ mod tests { extern crate yaml_rust; use self::yaml_rust::yaml; - use super::hashing::canonical_hash; - use super::*; - use std::fs::File; - use std::io::prelude::*; - // TODO: update test vectors to use keccak instead of blake. - // https://github.com/sigp/lighthouse/issues/121 + use std::{fs::File, io::prelude::*, path::PathBuf}; + + use super::{hashing::canonical_hash, *}; + #[test] - #[should_panic] fn test_shuffling() { - let mut file = File::open("./src/specs/shuffle_test_vectors.yaml").unwrap(); + let mut file = { + let mut file_path_buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + file_path_buf.push("src/specs/shuffle_test_vectors.yaml"); + + File::open(file_path_buf).unwrap() + }; + let mut yaml_str = String::new(); file.read_to_string(&mut yaml_str).unwrap(); let docs = yaml::YamlLoader::load_from_str(&yaml_str).unwrap(); let doc = &docs[0]; - let test_cases = doc["test_cases"].as_vec(); + let test_cases = doc["test_cases"].as_vec().unwrap(); - for test_case in test_cases.unwrap() { + for test_case in test_cases { let input = test_case["input"].clone().into_vec().unwrap(); let output = test_case["output"].clone().into_vec().unwrap(); let seed_bytes = test_case["seed"].as_str().unwrap().as_bytes(); - let mut seed; - if seed_bytes.len() > 0 { - seed = canonical_hash(seed_bytes); + let seed = if seed_bytes.len() > 0 { + canonical_hash(seed_bytes) } else { - seed = vec![]; - } + vec![] + }; - let mut s = shuffle(&seed, input).unwrap(); - - assert_eq!(s, output); + assert_eq!(shuffle(&seed, input).unwrap(), output); } } } diff --git a/beacon_chain/utils/vec_shuffle/src/specs/shuffle_test_vectors.yaml b/beacon_chain/utils/vec_shuffle/src/specs/shuffle_test_vectors.yaml index c97d6d328..2571f0804 100644 --- a/beacon_chain/utils/vec_shuffle/src/specs/shuffle_test_vectors.yaml +++ b/beacon_chain/utils/vec_shuffle/src/specs/shuffle_test_vectors.yaml @@ -1,5 +1,3 @@ -# This file was generated with sigp/shuffling_sandbox -# python3 sandbox.py test_vectors title: Shuffling Algorithm Tests summary: Test vectors for shuffling a list based upon a seed. test_suite: Shuffling @@ -15,13 +13,13 @@ test_cases: output: [255] seed: '' - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [1, 6, 4, 1, 6, 6, 2, 2, 4, 5] + output: [2, 1, 1, 5, 6, 6, 6, 2, 4, 4] seed: '' - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [4, 7, 10, 13, 3, 1, 2, 9, 12, 6, 11, 8, 5] + output: [4, 9, 6, 8, 13, 3, 2, 11, 5, 1, 12, 7, 10] seed: '' - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [1, 6, 65, 1, 6, 6, 2, 2, 4, 5] + output: [2, 1, 1, 5, 6, 6, 6, 2, 4, 65] seed: '' - input: [] output: [] @@ -33,13 +31,13 @@ test_cases: output: [255] seed: 4kn4driuctg8 - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 4, 2, 5, 4, 2, 6, 6, 1, 1] + output: [2, 4, 4, 2, 1, 1, 6, 5, 6, 6] seed: 4kn4driuctg8 - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [13, 1, 9, 8, 3, 10, 6, 2, 5, 12, 11, 4, 7] + output: [7, 6, 3, 12, 11, 1, 8, 13, 10, 5, 9, 4, 2] seed: 4kn4driuctg8 - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 65, 2, 5, 4, 2, 6, 6, 1, 1] + output: [2, 4, 65, 2, 1, 1, 6, 5, 6, 6] seed: 4kn4driuctg8 - input: [] output: [] @@ -51,13 +49,13 @@ test_cases: output: [255] seed: ytre1p - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 2, 5, 1, 6, 4, 1, 2, 4, 6] + output: [6, 1, 1, 5, 6, 2, 6, 2, 4, 4] seed: ytre1p - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [3, 8, 10, 4, 7, 11, 6, 1, 2, 5, 13, 9, 12] + output: [6, 2, 3, 4, 8, 5, 12, 9, 7, 11, 10, 1, 13] seed: ytre1p - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 2, 5, 1, 6, 4, 1, 2, 65, 6] + output: [6, 1, 1, 5, 6, 2, 6, 2, 4, 65] seed: ytre1p - input: [] output: [] @@ -69,13 +67,13 @@ test_cases: output: [255] seed: mytobcffnkvj - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [5, 6, 2, 1, 6, 4, 6, 4, 1, 2] + output: [2, 4, 1, 1, 6, 4, 6, 5, 6, 2] seed: mytobcffnkvj - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [12, 4, 11, 6, 13, 10, 9, 2, 3, 7, 8, 1, 5] + output: [11, 5, 9, 7, 2, 4, 12, 10, 8, 1, 6, 3, 13] seed: mytobcffnkvj - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [5, 6, 2, 1, 6, 65, 6, 4, 1, 2] + output: [2, 65, 1, 1, 6, 4, 6, 5, 6, 2] seed: mytobcffnkvj - input: [] output: [] @@ -87,13 +85,13 @@ test_cases: output: [255] seed: myzu3g7evxp5nkvj - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 2, 6, 5, 4, 4, 1, 6, 2, 1] + output: [6, 2, 1, 4, 2, 6, 5, 6, 4, 1] seed: myzu3g7evxp5nkvj - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [10, 12, 13, 3, 7, 11, 2, 4, 9, 8, 6, 5, 1] + output: [2, 1, 11, 3, 9, 7, 8, 13, 4, 10, 5, 6, 12] seed: myzu3g7evxp5nkvj - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 2, 6, 5, 65, 4, 1, 6, 2, 1] + output: [6, 2, 1, 4, 2, 6, 5, 6, 65, 1] seed: myzu3g7evxp5nkvj - input: [] output: [] @@ -105,13 +103,13 @@ test_cases: output: [255] seed: xdpli1jsx5xb - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 2, 4, 1, 2, 6, 5, 1, 6, 4] + output: [2, 1, 2, 4, 6, 6, 5, 6, 1, 4] seed: xdpli1jsx5xb - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [11, 8, 12, 9, 2, 1, 10, 4, 13, 5, 7, 3, 6] + output: [5, 8, 12, 9, 11, 4, 7, 13, 1, 3, 2, 10, 6] seed: xdpli1jsx5xb - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [6, 2, 65, 1, 2, 6, 5, 1, 6, 4] + output: [2, 1, 2, 65, 6, 6, 5, 6, 1, 4] seed: xdpli1jsx5xb - input: [] output: [] @@ -123,11 +121,11 @@ test_cases: output: [255] seed: oab3mbb3xe8qsx5xb - input: [4, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [2, 5, 1, 6, 1, 2, 6, 6, 4, 4] + output: [6, 2, 1, 1, 6, 2, 4, 4, 6, 5] seed: oab3mbb3xe8qsx5xb - input: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - output: [5, 13, 9, 7, 11, 10, 12, 2, 6, 8, 3, 1, 4] + output: [1, 8, 5, 13, 2, 10, 7, 11, 12, 6, 3, 4, 9] seed: oab3mbb3xe8qsx5xb - input: [65, 6, 2, 6, 1, 4, 6, 2, 1, 5] - output: [2, 5, 1, 6, 1, 2, 6, 6, 65, 4] + output: [6, 2, 1, 1, 6, 2, 4, 65, 6, 5] seed: oab3mbb3xe8qsx5xb From ec20493f01f8df332acaae5b7f60f8e203a8e04a Mon Sep 17 00:00:00 2001 From: Stan Drozd Date: Fri, 28 Dec 2018 09:28:11 +0100 Subject: [PATCH 2/2] types: delete ChainConfig --- beacon_chain/types/src/chain_config.rs | 72 -------------------------- beacon_chain/types/src/lib.rs | 2 - 2 files changed, 74 deletions(-) delete mode 100644 beacon_chain/types/src/chain_config.rs diff --git a/beacon_chain/types/src/chain_config.rs b/beacon_chain/types/src/chain_config.rs deleted file mode 100644 index 8428945bb..000000000 --- a/beacon_chain/types/src/chain_config.rs +++ /dev/null @@ -1,72 +0,0 @@ -use super::ValidatorRegistration; - -#[derive(Debug, Clone, PartialEq)] -pub struct ChainConfig { - // Old, potentially outdated constants - pub cycle_length: u8, - pub deposit_size_gwei: u64, - pub shard_count: u16, - pub min_committee_size: u64, - pub max_validator_churn_quotient: u64, - pub genesis_time: u64, - pub slot_duration_millis: u64, - pub initial_validators: Vec, - - // New constants - pub epoch_length: u64, - pub min_attestation_inclusion_delay: u64, -} - -/* - * Presently this is just some arbitrary time in Sept 2018. - */ -const TEST_GENESIS_TIME: u64 = 1_537_488_655; - -impl ChainConfig { - pub fn standard() -> Self { - Self { - cycle_length: 64, - deposit_size_gwei: 32 * (10 ^ 9), - shard_count: 1024, - min_committee_size: 128, - max_validator_churn_quotient: 32, - genesis_time: TEST_GENESIS_TIME, - slot_duration_millis: 16 * 1000, - initial_validators: vec![], - - // New - epoch_length: 64, - min_attestation_inclusion_delay: 4, - } - } - - pub fn validate(&self) -> bool { - // criteria that ensure the config is valid - - // shard_count / cycle_length > 0 otherwise validator delegation - // will fail. - if self.shard_count / u16::from(self.cycle_length) == 0 { - return false; - } - - true - } - - #[cfg(test)] - pub fn super_fast_tests() -> Self { - Self { - cycle_length: 2, - deposit_size_gwei: 32 * (10 ^ 9), - shard_count: 2, - min_committee_size: 2, - max_validator_churn_quotient: 32, - genesis_time: TEST_GENESIS_TIME, // arbitrary - slot_duration_millis: 16 * 1000, - initial_validators: vec![], - - // New constants - epoch_length: 64, - min_attestation_inclusion_delay: 4, - } - } -} diff --git a/beacon_chain/types/src/lib.rs b/beacon_chain/types/src/lib.rs index 08b871c1c..b1bc03c31 100644 --- a/beacon_chain/types/src/lib.rs +++ b/beacon_chain/types/src/lib.rs @@ -13,7 +13,6 @@ pub mod beacon_block_body; pub mod beacon_state; pub mod candidate_pow_receipt_root_record; pub mod casper_slashing; -pub mod chain_config; pub mod crosslink_record; pub mod crystallized_state; pub mod deposit; @@ -41,7 +40,6 @@ pub use crate::beacon_block::BeaconBlock; pub use crate::beacon_block_body::BeaconBlockBody; pub use crate::beacon_state::BeaconState; pub use crate::casper_slashing::CasperSlashing; -pub use crate::chain_config::ChainConfig; pub use crate::crosslink_record::CrosslinkRecord; pub use crate::crystallized_state::CrystallizedState; pub use crate::deposit::Deposit;