1.1.5 merge spec tests (#2781)

* Fix arbitrary check kintsugi

* Add merge chain spec fields, and a function to determine which constant to use based on the state variant

* increment spec test version

* Remove `Transaction` enum wrapper

* Remove Transaction new-type

* Remove gas validations

* Add `--terminal-block-hash-epoch-override` flag

* Increment spec tests version to 1.1.5

* Remove extraneous gossip verification https://github.com/ethereum/consensus-specs/pull/2687

* - Remove unused Error variants
- Require both "terminal-block-hash-epoch-override" and "terminal-block-hash-override" when either flag is used

* - Remove a couple more unused Error variants

Co-authored-by: Paul Hauner <paul@paulhauner.com>
This commit is contained in:
realbigsean
2021-11-10 11:35:07 -05:00
committed by Paul Hauner
parent cdbe603adf
commit de49c7ddaa
20 changed files with 210 additions and 208 deletions

View File

@@ -31,14 +31,11 @@ pub fn slash_validator<T: EthSpec>(
.safe_add(validator_effective_balance)?,
)?;
let min_slashing_penalty_quotient = match state {
BeaconState::Base(_) => spec.min_slashing_penalty_quotient,
BeaconState::Altair(_) | BeaconState::Merge(_) => spec.min_slashing_penalty_quotient_altair,
};
decrease_balance(
state,
slashed_index,
validator_effective_balance.safe_div(min_slashing_penalty_quotient)?,
validator_effective_balance
.safe_div(spec.min_slashing_penalty_quotient_for_state(state))?,
)?;
// Apply proposer and whistleblower rewards

View File

@@ -295,50 +295,6 @@ pub fn get_new_eth1_data<T: EthSpec>(
}
}
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#is_valid_gas_limit
pub fn verify_is_valid_gas_limit<T: EthSpec>(
payload: &ExecutionPayload<T>,
parent: &ExecutionPayloadHeader<T>,
) -> Result<(), BlockProcessingError> {
// check if payload used too much gas
if payload.gas_used > payload.gas_limit {
return Err(BlockProcessingError::ExecutionInvalidGasLimit {
used: payload.gas_used,
limit: payload.gas_limit,
});
}
// check if payload changed the gas limit too much
if payload.gas_limit
>= parent
.gas_limit
.safe_add(parent.gas_limit.safe_div(T::gas_limit_denominator())?)?
{
return Err(BlockProcessingError::ExecutionInvalidGasLimitIncrease {
limit: payload.gas_limit,
parent_limit: parent.gas_limit,
});
}
if payload.gas_limit
<= parent
.gas_limit
.safe_sub(parent.gas_limit.safe_div(T::gas_limit_denominator())?)?
{
return Err(BlockProcessingError::ExecutionInvalidGasLimitDecrease {
limit: payload.gas_limit,
parent_limit: parent.gas_limit,
});
}
// check if the gas limit is at least the minimum gas limit
if payload.gas_limit < T::min_gas_limit() {
return Err(BlockProcessingError::ExecutionInvalidGasLimitTooSmall {
limit: payload.gas_limit,
min: T::min_gas_limit(),
});
}
Ok(())
}
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/merge/beacon-chain.md#process_execution_payload
pub fn process_execution_payload<T: EthSpec>(
state: &mut BeaconState<T>,
@@ -353,21 +309,6 @@ pub fn process_execution_payload<T: EthSpec>(
found: payload.parent_hash,
}
);
block_verify!(
payload.block_number
== state
.latest_execution_payload_header()?
.block_number
.safe_add(1)?,
BlockProcessingError::ExecutionBlockNumberIncontiguous {
expected: state
.latest_execution_payload_header()?
.block_number
.safe_add(1)?,
found: payload.block_number,
}
);
verify_is_valid_gas_limit(payload, state.latest_execution_payload_header()?)?;
}
block_verify!(
payload.random == *state.get_randao_mix(state.current_epoch())?,

View File

@@ -61,30 +61,10 @@ pub enum BlockProcessingError {
expected: Hash256,
found: Hash256,
},
ExecutionBlockNumberIncontiguous {
expected: u64,
found: u64,
},
ExecutionRandaoMismatch {
expected: Hash256,
found: Hash256,
},
ExecutionInvalidGasLimit {
used: u64,
limit: u64,
},
ExecutionInvalidGasLimitIncrease {
limit: u64,
parent_limit: u64,
},
ExecutionInvalidGasLimitDecrease {
limit: u64,
parent_limit: u64,
},
ExecutionInvalidGasLimitTooSmall {
limit: u64,
min: u64,
},
ExecutionInvalidTimestamp {
expected: u64,
found: u64,

View File

@@ -47,7 +47,6 @@ pub fn process_epoch<T: EthSpec>(
process_slashings(
state,
participation_cache.current_epoch_total_active_balance(),
spec.proportional_slashing_multiplier_altair,
spec,
)?;

View File

@@ -119,7 +119,7 @@ pub fn get_inactivity_penalty_deltas<T: EthSpec>(
.safe_mul(state.get_inactivity_score(index)?)?;
let penalty_denominator = spec
.inactivity_score_bias
.safe_mul(spec.inactivity_penalty_quotient_altair)?;
.safe_mul(spec.inactivity_penalty_quotient_for_state(state))?;
delta.penalize(penalty_numerator.safe_div(penalty_denominator)?)?;
}
deltas

View File

@@ -43,7 +43,6 @@ pub fn process_epoch<T: EthSpec>(
process_slashings(
state,
validator_statuses.total_balances.current_epoch(),
spec.proportional_slashing_multiplier,
spec,
)?;

View File

@@ -6,14 +6,15 @@ use types::{BeaconState, BeaconStateError, ChainSpec, EthSpec, Unsigned};
pub fn process_slashings<T: EthSpec>(
state: &mut BeaconState<T>,
total_balance: u64,
slashing_multiplier: u64,
spec: &ChainSpec,
) -> Result<(), Error> {
let epoch = state.current_epoch();
let sum_slashings = state.get_all_slashings().iter().copied().safe_sum()?;
let adjusted_total_slashing_balance =
std::cmp::min(sum_slashings.safe_mul(slashing_multiplier)?, total_balance);
let adjusted_total_slashing_balance = std::cmp::min(
sum_slashings.safe_mul(spec.proportional_slashing_multiplier_for_state(state))?,
total_balance,
);
let (validators, balances) = state.validators_and_balances_mut();
for (index, validator) in validators.iter().enumerate() {