Skip to content

Commit

Permalink
Merge pull request #344 from ralexstokes/spec-tests-1.4.0
Browse files Browse the repository at this point in the history
Spec tests 1.4.0
  • Loading branch information
ralexstokes authored Mar 27, 2024
2 parents dbf2f2f + e533133 commit 176ab58
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 69 deletions.
20 changes: 17 additions & 3 deletions ethereum-consensus/src/bellatrix/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
bellatrix::{
compute_timestamp_at_slot, get_current_epoch, get_randao_mix, is_execution_enabled,
is_merge_transition_complete, process_block_header, process_eth1_data, process_operations,
process_randao, process_sync_aggregate, BeaconBlock, BeaconState, ExecutionPayload,
process_randao, process_sync_aggregate, BeaconBlock, BeaconBlockBody, BeaconState,
ExecutionPayloadHeader,
},
error::{invalid_operation_error, InvalidExecutionPayload},
Expand All @@ -20,6 +20,11 @@ pub fn process_execution_payload<
const EPOCHS_PER_SLASHINGS_VECTOR: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const SYNC_COMMITTEE_SIZE: usize,
const MAX_PROPOSER_SLASHINGS: usize,
const MAX_ATTESTER_SLASHINGS: usize,
const MAX_ATTESTATIONS: usize,
const MAX_DEPOSITS: usize,
const MAX_VOLUNTARY_EXITS: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
Expand All @@ -37,14 +42,23 @@ pub fn process_execution_payload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
>,
payload: &mut ExecutionPayload<
block: &mut BeaconBlockBody<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
>,
context: &Context,
) -> Result<()> {
let payload = &mut block.execution_payload;

let parent_hash_invalid =
payload.parent_hash != state.latest_execution_payload_header.block_hash;
if is_merge_transition_complete(state) && parent_hash_invalid {
Expand Down Expand Up @@ -151,7 +165,7 @@ pub fn process_block<
) -> Result<()> {
process_block_header(state, block, context)?;
if is_execution_enabled(state, &block.body) {
process_execution_payload(state, &mut block.body.execution_payload, context)?;
process_execution_payload(state, &mut block.body, context)?;
}
process_randao(state, &block.body, context)?;
process_eth1_data(state, &block.body, context);
Expand Down
20 changes: 18 additions & 2 deletions ethereum-consensus/src/capella/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,17 @@ pub fn process_execution_payload<
const EPOCHS_PER_SLASHINGS_VECTOR: usize,
const MAX_VALIDATORS_PER_COMMITTEE: usize,
const SYNC_COMMITTEE_SIZE: usize,
const MAX_PROPOSER_SLASHINGS: usize,
const MAX_ATTESTER_SLASHINGS: usize,
const MAX_ATTESTATIONS: usize,
const MAX_DEPOSITS: usize,
const MAX_VOLUNTARY_EXITS: usize,
const BYTES_PER_LOGS_BLOOM: usize,
const MAX_EXTRA_DATA_BYTES: usize,
const MAX_BYTES_PER_TRANSACTION: usize,
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
>(
state: &mut BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
Expand All @@ -194,15 +200,25 @@ pub fn process_execution_payload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
>,
payload: &mut ExecutionPayload<
block: &mut BeaconBlockBody<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
MAX_ATTESTATIONS,
MAX_DEPOSITS,
MAX_VOLUNTARY_EXITS,
SYNC_COMMITTEE_SIZE,
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
MAX_BYTES_PER_TRANSACTION,
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
>,
context: &Context,
) -> Result<()> {
let payload = &mut block.execution_payload;

let parent_hash_invalid =
payload.parent_hash != state.latest_execution_payload_header.block_hash;
if parent_hash_invalid {
Expand Down Expand Up @@ -450,7 +466,7 @@ pub fn process_block<
) -> Result<()> {
process_block_header(state, block, context)?;
process_withdrawals(state, &block.body.execution_payload, context)?;
process_execution_payload(state, &mut block.body.execution_payload, context)?;
process_execution_payload(state, &mut block.body, context)?;
process_randao(state, &block.body, context)?;
process_eth1_data(state, &block.body, context);
process_operations(state, &mut block.body, context)?;
Expand Down
2 changes: 1 addition & 1 deletion ethereum-consensus/src/configs/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const ETH1_FOLLOW_DISTANCE: u64 = 16;
pub const INACTIVITY_SCORE_BIAS: u64 = 4;
pub const INACTIVITY_SCORE_RECOVERY_RATE: u64 = 16;
pub const EJECTION_BALANCE: Gwei = 16 * 10u64.pow(9);
pub const MIN_PER_EPOCH_CHURN_LIMIT: u64 = 4;
pub const MIN_PER_EPOCH_CHURN_LIMIT: u64 = 2;
pub const MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT: u64 = 4;
pub const CHURN_LIMIT_QUOTIENT: u64 = 32;
pub const PROPOSER_SCORE_BOOST: u64 = 40;
Expand Down
65 changes: 8 additions & 57 deletions spec-tests/runners/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn load_execution_payload_test<S: ssz_rs::Deserialize, O: ssz_rs::Deserialize>(
let path = test_case_path.to_string() + "/post.ssz_snappy";
let post: Option<S> = load_snappy_ssz(&path);

let path = test_case_path.to_string() + "/execution_payload.ssz_snappy";
let path = test_case_path.to_string() + "/body.ssz_snappy";
let operation: O = load_snappy_ssz(&path).unwrap();

let path = test_case_path.to_string() + "/execution.yaml";
Expand Down Expand Up @@ -188,62 +188,13 @@ pub fn dispatch(test: &TestCase) -> Result<(), Error> {
"execution_payload" => {
gen_match_for! {
test,
(mainnet, bellatrix) => {
gen_exec! {
test,
load_execution_payload_test,
|(pre, post, operation, execution_valid): (spec::BeaconState, Option<spec::BeaconState>, spec::ExecutionPayload, bool), context: &Context| {
let mut context = context.clone();
context.execution_engine = execution_valid;
run_test(pre, post, operation, &context, spec::process_execution_payload)
}
}
}
(mainnet, capella) => {
gen_exec! {
test,
load_execution_payload_test,
|(pre, post, operation, execution_valid): (spec::BeaconState, Option<spec::BeaconState>, spec::ExecutionPayload, bool), context: &Context| {
let mut context = context.clone();
context.execution_engine = execution_valid;
run_test(pre, post, operation, &context, spec::process_execution_payload)
}
}
}
(mainnet, deneb) => {
gen_exec! {
test,
load_execution_payload_test,
|(pre, post, operation, execution_valid): (spec::BeaconState, Option<spec::BeaconState>, spec::BeaconBlockBody, bool), context: &Context| {
let mut context = context.clone();
context.execution_engine = execution_valid;
run_test(pre, post, operation, &context, spec::process_execution_payload)
}
}
}
(minimal, bellatrix) => {
gen_exec! {
test,
load_execution_payload_test,
|(pre, post, operation, execution_valid): (spec::BeaconState, Option<spec::BeaconState>, spec::ExecutionPayload, bool), context: &Context| {
let mut context = context.clone();
context.execution_engine = execution_valid;
run_test(pre, post, operation, &context, spec::process_execution_payload)
}
}
}
(minimal, capella) => {
gen_exec! {
test,
load_execution_payload_test,
|(pre, post, operation, execution_valid): (spec::BeaconState, Option<spec::BeaconState>, spec::ExecutionPayload, bool), context: &Context| {
let mut context = context.clone();
context.execution_engine = execution_valid;
run_test(pre, post, operation, &context, spec::process_execution_payload)
}
}
}
(minimal, deneb) => {
(mainnet, bellatrix),
(mainnet, capella),
(mainnet, deneb),
(minimal, bellatrix),
(minimal, capella),
(minimal, deneb)
{
gen_exec! {
test,
load_execution_payload_test,
Expand Down
31 changes: 31 additions & 0 deletions spec-tests/runners/ssz_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ fn run_test<T: ssz_rs::SimpleSerialize>(
Ok(())
}

macro_rules! gen_deneb_and_later {
($test_case:expr, $($handler:ident),*) => {
let result = match $test_case.meta.handler.0.as_str() {
$(
stringify!($handler) => gen_match_for! {
$test_case,
(mainnet, deneb),
(minimal, deneb)
{
gen_exec! {
$test_case, load_test, run_test::<spec::$handler>
}
}
},
)*
_ => Err(Error::InternalContinue),
};
match result {
Ok(()) => return Ok(()),
Err(Error::InternalContinue) => {},
Err(err) => return Err(err)
}
};
}

macro_rules! gen_capella_and_later {
($test_case:expr, $($handler:ident),*) => {
let result = match $test_case.meta.handler.0.as_str() {
Expand Down Expand Up @@ -140,6 +165,12 @@ macro_rules! gen_match {
}

pub fn dispatch(test: &TestCase) -> Result<(), Error> {
gen_deneb_and_later! {
test,
BlobSidecar,
BlobIdentifier
}

gen_capella_and_later! {
test,
Withdrawal,
Expand Down
64 changes: 64 additions & 0 deletions spec-tests/runners/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ fn set_fork_epochs(meta: &mut Meta, context: &mut Context) {
context.bellatrix_fork_epoch = 0;
context.capella_fork_epoch = meta.fork_epoch;
}
"deneb" => {
context.altair_fork_epoch = 0;
context.bellatrix_fork_epoch = 0;
context.capella_fork_epoch = 0;
context.deneb_fork_epoch = meta.fork_epoch;
}
_ => todo!(),
}
}
Expand Down Expand Up @@ -172,6 +178,35 @@ pub fn dispatch(test: &TestCase) -> Result<(), Error> {
}
}
}
Fork::Deneb => {
use ethereum_consensus::{
capella::mainnet as pre_spec, deneb::mainnet as spec,
};
gen_exec! {
test,
load_test,
| (pre, expected, pre_blocks, post_blocks, mut meta): (pre_spec::BeaconState, spec::BeaconState, Vec<pre_spec::SignedBeaconBlock>, Vec<spec::SignedBeaconBlock>, Meta), context: &Context| {
assert_eq!(meta.post_fork, "deneb");
let mut context = context.clone();
set_fork_epochs(&mut meta, &mut context);
let mut executor = state_transition::mainnet::Executor::new(BeaconState::Capella(pre), context);
for block in pre_blocks.into_iter() {
let mut block = SignedBeaconBlock::Capella(block);
executor.apply_block(&mut block)?;
}
for block in post_blocks.into_iter() {
let mut block = SignedBeaconBlock::Deneb(block);
executor.apply_block(&mut block)?;
}
let post = executor.state.deneb().unwrap();
if post != &expected {
Err(Error::InvalidState)
} else {
Ok(())
}
}
}
}
_ => todo!(),
},
Config::Minimal => match test.meta.fork {
Expand Down Expand Up @@ -262,6 +297,35 @@ pub fn dispatch(test: &TestCase) -> Result<(), Error> {
}
}
}
Fork::Deneb => {
use ethereum_consensus::{
capella::minimal as pre_spec, deneb::minimal as spec,
};
gen_exec! {
test,
load_test,
| (pre, expected, pre_blocks, post_blocks, mut meta): (pre_spec::BeaconState, spec::BeaconState, Vec<pre_spec::SignedBeaconBlock>, Vec<spec::SignedBeaconBlock>, Meta), context: &Context| {
assert_eq!(meta.post_fork, "deneb");
let mut context = context.clone();
set_fork_epochs(&mut meta, &mut context);
let mut executor = state_transition::minimal::Executor::new(BeaconState::Capella(pre), context);
for block in pre_blocks.into_iter() {
let mut block = SignedBeaconBlock::Capella(block);
executor.apply_block(&mut block)?;
}
for block in post_blocks.into_iter() {
let mut block = SignedBeaconBlock::Deneb(block);
executor.apply_block(&mut block)?;
}
let post = executor.state.deneb().unwrap();
if post != &expected {
Err(Error::InvalidState)
} else {
Ok(())
}
}
}
}
_ => todo!(),
},
config => unreachable!("no tests for {config:?}"),
Expand Down
2 changes: 1 addition & 1 deletion spec-tests/spec-test-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.3.0
v1.4.0
15 changes: 10 additions & 5 deletions spec-tests/test_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum Fork {
Bellatrix,
Capella,
Deneb,
Eip6110,
Whisk,
}

impl From<&str> for Fork {
Expand All @@ -43,7 +45,9 @@ impl From<&str> for Fork {
"bellatrix" => Self::Bellatrix,
"capella" => Self::Capella,
"deneb" => Self::Deneb,
_ => panic!("unsupported fork"),
"eip6110" => Self::Eip6110,
"whisk" => Self::Whisk,
fork => panic!("unsupported fork: {fork:?}"),
}
}
}
Expand Down Expand Up @@ -102,7 +106,7 @@ impl From<&str> for Runner {
"genesis" => Self::Genesis,
"kzg" => Self::Kzg,
"light_client" => Self::LightClient,
"merkle" => Self::MerkleProof,
"merkle_proof" => Self::MerkleProof,
"operations" => Self::Operations,
"random" => Self::Random,
"rewards" => Self::Rewards,
Expand Down Expand Up @@ -203,11 +207,12 @@ impl TestMeta {
let ignored_runner = self.runner.should_ignore();
let ignored_handler =
matches!(self.runner, Runner::SszStatic) && self.handler.0.contains("LightClient");
let ignored_fork = matches!(self.fork, Fork::Deneb);
ignored_runner | ignored_handler | ignored_fork
ignored_runner | ignored_handler
}

pub fn should_skip(&self) -> bool {
self.runner.should_skip()
let skipped_runner = self.runner.should_skip();
let skipped_forks = matches!(self.fork, Fork::Eip6110 | Fork::Whisk);
skipped_runner | skipped_forks
}
}

0 comments on commit 176ab58

Please sign in to comment.