Consensus updates for v0.12 (#1228)

* Update state processing for v0.12

* Fix EF test runners for v0.12

* Fix some tests

* Fix broken attestation verification test

* More test fixes

* Fix typo found in review
This commit is contained in:
Michael Sproul
2020-06-03 13:34:01 +10:00
parent 197adeff0b
commit fe03ff0f21
29 changed files with 359 additions and 323 deletions

View File

@@ -1,5 +1,5 @@
# Bump the test tag here and in .gitlab-ci.yml and CI will take care of updating the cached tarballs
TESTS_TAG := v0.11.1
TESTS_TAG := v0.12.0
TESTS = general minimal mainnet
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))

View File

@@ -25,12 +25,17 @@ impl Case for BlsAggregateSigs {
aggregate_signature.add(&sig);
}
let output_bytes = Some(
// Check for YAML null value, indicating invalid input. This is a bit of a hack,
// as our mutating `aggregate_signature.add` API doesn't play nicely with aggregating 0
// inputs.
let output_bytes = if self.output == "~" {
AggregateSignature::new().as_bytes().to_vec()
} else {
hex::decode(&self.output[2..])
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?,
);
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))?
};
let aggregate_signature = Ok(aggregate_signature.as_bytes().to_vec());
compare_result::<Vec<u8>, Vec<u8>>(&aggregate_signature, &output_bytes)
compare_result::<Vec<u8>, Vec<u8>>(&aggregate_signature, &Some(output_bytes))
}
}

View File

@@ -4,15 +4,10 @@ use crate::cases::common::BlsCase;
use bls::{AggregateSignature, PublicKey};
use serde_derive::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct BlsAggregatePair {
pub pubkey: PublicKey,
pub message: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct BlsAggregateVerifyInput {
pub pairs: Vec<BlsAggregatePair>,
pub pubkeys: Vec<PublicKey>,
pub messages: Vec<String>,
pub signature: String,
}
@@ -28,11 +23,10 @@ impl Case for BlsAggregateVerify {
fn result(&self, _case_index: usize) -> Result<(), Error> {
let messages = self
.input
.pairs
.messages
.iter()
.map(|pair| {
hex::decode(&pair.message[2..])
.map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))
.map(|message| {
hex::decode(&message[2..]).map_err(|e| Error::FailedToParseTest(format!("{:?}", e)))
})
.collect::<Result<Vec<Vec<_>>, _>>()?;
@@ -41,12 +35,7 @@ impl Case for BlsAggregateVerify {
.map(|x| x.as_slice())
.collect::<Vec<&[u8]>>();
let pubkey_refs = self
.input
.pairs
.iter()
.map(|p| &p.pubkey)
.collect::<Vec<_>>();
let pubkey_refs = self.input.pubkeys.iter().collect::<Vec<_>>();
let signature_ok = hex::decode(&self.input.signature[2..])
.ok()

View File

@@ -27,7 +27,7 @@ struct Metadata {
pub struct Operations<E: EthSpec, O: Operation<E>> {
metadata: Metadata,
pub pre: BeaconState<E>,
pub operation: O,
pub operation: Option<O>,
pub post: Option<BeaconState<E>>,
}
@@ -135,8 +135,16 @@ impl<E: EthSpec, O: Operation<E>> LoadCase for Operations<E, O> {
} else {
Metadata::default()
};
let pre = ssz_decode_file(&path.join("pre.ssz"))?;
let operation = ssz_decode_file(&path.join(O::filename()))?;
// Check BLS setting here before SSZ deserialization, as most types require signatures
// to be valid.
let operation = if metadata.bls_setting.unwrap_or_default().check().is_ok() {
Some(ssz_decode_file(&path.join(O::filename()))?)
} else {
None
};
let post_filename = path.join("post.ssz");
let post = if post_filename.is_file() {
Some(ssz_decode_file(&post_filename)?)
@@ -162,8 +170,6 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
}
fn result(&self, _case_index: usize) -> Result<(), Error> {
self.metadata.bls_setting.unwrap_or_default().check()?;
let spec = &E::default_spec();
let mut state = self.pre.clone();
let mut expected = self.post.clone();
@@ -173,7 +179,12 @@ impl<E: EthSpec, O: Operation<E>> Case for Operations<E, O> {
.build_all_committee_caches(spec)
.expect("committee caches OK");
let mut result = self.operation.apply_to(&mut state, spec).map(|()| state);
let mut result = self
.operation
.as_ref()
.ok_or(Error::SkippedBls)?
.apply_to(&mut state, spec)
.map(|()| state);
compare_beacon_state_results_without_caches(&mut result, &mut expected)
}

View File

@@ -28,6 +28,25 @@ fn minimal_config_ok() {
config_test::<MinimalEthSpec>();
}
// Check that the hand-computed multiplications on EthSpec are correctly computed.
// This test lives here because one is most likely to muck these up during a spec update.
fn check_typenum_values<E: EthSpec>() {
assert_eq!(
E::MaxPendingAttestations::to_u64(),
E::MaxAttestations::to_u64() * E::SlotsPerEpoch::to_u64()
);
assert_eq!(
E::SlotsPerEth1VotingPeriod::to_u64(),
E::EpochsPerEth1VotingPeriod::to_u64() * E::SlotsPerEpoch::to_u64()
);
}
#[test]
fn derived_typenum_values() {
check_typenum_values::<MinimalEthSpec>();
check_typenum_values::<MainnetEthSpec>();
}
#[test]
fn shuffling() {
ShufflingHandler::<MinimalEthSpec>::run();

View File

@@ -7,8 +7,8 @@ use types::{BeaconBlock, BeaconState, Epoch, EthSpec, SignedBeaconBlock};
// Default validator index to exit.
pub const VALIDATOR_INDEX: u64 = 0;
// Epoch that the state will be transitioned to by default, equal to PERSISTENT_COMMITTEE_PERIOD.
pub const STATE_EPOCH: Epoch = Epoch::new(2048);
// Epoch that the state will be transitioned to by default, equal to SHARD_COMMITTEE_PERIOD.
pub const STATE_EPOCH: Epoch = Epoch::new(256);
struct ExitTest {
validator_index: u64,
@@ -62,7 +62,7 @@ impl ExitTest {
fn run(self) -> BeaconState<E> {
let spec = &E::default_spec();
let expected = self.expected.clone();
assert_eq!(STATE_EPOCH, spec.persistent_committee_period);
assert_eq!(STATE_EPOCH, spec.shard_committee_period);
let (block, mut state) = self.block_and_pre_state();