Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest ssz-rs #371

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
cache-on-failure: true

- name: Build
run: cargo build --all-targets --all-features --verbose
run: cargo build --all-targets --all-features --workspace --verbose

- name: Run tests
run: cargo test --all-features --all-targets --workspace --exclude spec-tests --verbose
Expand All @@ -56,4 +56,4 @@ jobs:
run: cargo +nightly fmt --all --check

- name: Check clippy
run: cargo +nightly clippy --all-targets --all-features --verbose -- -D warnings
run: cargo +nightly clippy --all-targets --all-features --workspace --verbose -- -D warnings
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ serde_yaml = "0.8"
itertools = "0.10.3"
thiserror = "1.0.30"
hex = "0.4.3"
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "9a238ce6385b6fe7745a7c7ff0c42a9315628da1" }
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "8b2eb8ea06fd14227e5a16c85e79fccbed151a3b" }
blst = "0.3.11"
rand = "0.8.4"
sha2 = "0.10.8"
Expand Down
7 changes: 3 additions & 4 deletions ethereum-consensus/examples/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
let previous_epoch = phase0::get_previous_epoch(&state, &context);
dbg!(previous_epoch);

let _ = phase0::state_transition(&mut state, &mut signed_block, Validation::Enabled, &context);
let _ = phase0::state_transition(&mut state, &signed_block, Validation::Enabled, &context);
dbg!(state.fork);

// altair transition
Expand All @@ -28,7 +28,7 @@ fn main() {
let current_epoch = altair::get_current_epoch(&state, &context);
dbg!(current_epoch);

let _ = altair::state_transition(&mut state, &mut signed_block, Validation::Enabled, &context);
let _ = altair::state_transition(&mut state, &signed_block, Validation::Enabled, &context);
dbg!(state.fork);

// bellatrix transition
Expand All @@ -40,7 +40,6 @@ fn main() {
let current_epoch = bellatrix::get_current_epoch(&state, &context);
dbg!(current_epoch);

let _ =
bellatrix::state_transition(&mut state, &mut signed_block, Validation::Enabled, &context);
let _ = bellatrix::state_transition(&mut state, &signed_block, Validation::Enabled, &context);
dbg!(state.fork);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ fn main() -> std::result::Result<(), Box<dyn Error>> {

let mut block = SignedBeaconBlock::Phase0(Default::default());
*block.message_mut().slot_mut() = 1;
executor.apply_block(&mut block)?;
executor.apply_block(&block)?;

let mut block = SignedBeaconBlock::Altair(Default::default());
*block.message_mut().slot_mut() =
executor.context.altair_fork_epoch * executor.context.slots_per_epoch;
executor.apply_block(&mut block)?;
executor.apply_block(&block)?;

let mut block = SignedBeaconBlock::Bellatrix(Default::default());
*block.message_mut().slot_mut() =
executor.context.bellatrix_fork_epoch * executor.context.slots_per_epoch;
executor.apply_block(&mut block)?;
executor.apply_block(&block)?;

let state = executor.state.bellatrix_mut().unwrap();
let state = executor.state.bellatrix().unwrap();
let state_root = state.hash_tree_root()?;
dbg!(state_root);
Ok(())
Expand Down
10 changes: 5 additions & 5 deletions ethereum-consensus/src/altair/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn process_attestation<
// Verify signature
is_valid_indexed_attestation(
state,
&mut get_indexed_attestation(state, attestation, context)?,
&get_indexed_attestation(state, attestation, context)?,
context,
)?;

Expand Down Expand Up @@ -225,8 +225,8 @@ pub fn process_sync_aggregate<
Some(compute_epoch_at_slot(previous_slot, context)),
context,
)?;
let mut root_at_slot = *get_block_root_at_slot(state, previous_slot)?;
let signing_root = compute_signing_root(&mut root_at_slot, domain)?;
let root_at_slot = *get_block_root_at_slot(state, previous_slot)?;
let signing_root = compute_signing_root(&root_at_slot, domain)?;
if eth_fast_aggregate_verify(
participant_public_keys.as_slice(),
signing_root.as_ref(),
Expand Down Expand Up @@ -304,7 +304,7 @@ pub fn process_block<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
block: &mut BeaconBlock<
block: &BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -318,7 +318,7 @@ pub fn process_block<
process_block_header(state, block, context)?;
process_randao(state, &block.body, context)?;
process_eth1_data(state, &block.body, context);
process_operations(state, &mut block.body, context)?;
process_operations(state, &block.body, context)?;
process_sync_aggregate(state, &block.body.sync_aggregate, context)?;
Ok(())
}
6 changes: 3 additions & 3 deletions ethereum-consensus/src/altair/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn initialize_beacon_state_from_eth1<
>(
eth1_block_hash: Hash32,
eth1_timestamp: u64,
deposits: &mut [Deposit],
deposits: &[Deposit],
context: &Context,
) -> Result<
BeaconState<
Expand All @@ -50,7 +50,7 @@ pub fn initialize_beacon_state_from_eth1<
deposit_count: deposits.len() as u64,
..Default::default()
};
let mut latest_block_body = BeaconBlockBody::<
let latest_block_body = BeaconBlockBody::<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -77,7 +77,7 @@ pub fn initialize_beacon_state_from_eth1<
};

let mut leaves = List::<DepositData, DEPOSIT_DATA_LIST_BOUND>::default();
for deposit in deposits.iter_mut() {
for deposit in deposits.iter() {
leaves.push(deposit.data.clone());
state.eth1_data.deposit_root = leaves.hash_tree_root()?;
process_deposit(&mut state, deposit, context)?;
Expand Down
60 changes: 28 additions & 32 deletions ethereum-consensus/src/altair/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub fn process_proposer_slashing<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
proposer_slashing: &mut ProposerSlashing,
proposer_slashing: &ProposerSlashing,
context: &Context,
) -> Result<()> {
let header_1 = &proposer_slashing.signed_header_1.message;
Expand Down Expand Up @@ -126,10 +126,8 @@ pub fn process_proposer_slashing<
}
let epoch = compute_epoch_at_slot(header_1.slot, context);
let domain = get_domain(state, DomainType::BeaconProposer, Some(epoch), context)?;
for signed_header in
[&mut proposer_slashing.signed_header_1, &mut proposer_slashing.signed_header_2]
{
let signing_root = compute_signing_root(&mut signed_header.message, domain)?;
for signed_header in [&proposer_slashing.signed_header_1, &proposer_slashing.signed_header_2] {
let signing_root = compute_signing_root(&signed_header.message, domain)?;
let public_key = &proposer.public_key;
if verify_signature(public_key, signing_root.as_ref(), &signed_header.signature).is_err() {
return Err(invalid_operation_error(InvalidOperation::ProposerSlashing(
Expand Down Expand Up @@ -159,11 +157,11 @@ pub fn process_attester_slashing<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
attester_slashing: &mut AttesterSlashing<MAX_VALIDATORS_PER_COMMITTEE>,
attester_slashing: &AttesterSlashing<MAX_VALIDATORS_PER_COMMITTEE>,
context: &Context,
) -> Result<()> {
let attestation_1 = &mut attester_slashing.attestation_1;
let attestation_2 = &mut attester_slashing.attestation_2;
let attestation_1 = &attester_slashing.attestation_1;
let attestation_2 = &attester_slashing.attestation_2;
if !is_slashable_attestation_data(&attestation_1.data, &attestation_2.data) {
return Err(invalid_operation_error(InvalidOperation::AttesterSlashing(
InvalidAttesterSlashing::NotSlashable(
Expand Down Expand Up @@ -226,13 +224,13 @@ pub fn apply_deposit<
increase_balance(state, index, amount);
return Ok(());
}
let mut deposit_message = DepositMessage {
let deposit_message = DepositMessage {
public_key: public_key.clone(),
withdrawal_credentials: withdrawal_credentials.clone(),
amount,
};
let domain = compute_domain(DomainType::Deposit, None, None, context)?;
let signing_root = compute_signing_root(&mut deposit_message, domain)?;
let signing_root = compute_signing_root(&deposit_message, domain)?;
if verify_signature(public_key, signing_root.as_ref(), signature).is_err() {
return Ok(());
}
Expand Down Expand Up @@ -265,7 +263,7 @@ pub fn process_deposit<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
deposit: &mut Deposit,
deposit: &Deposit,
context: &Context,
) -> Result<()> {
let leaf = deposit.data.hash_tree_root()?;
Expand Down Expand Up @@ -305,10 +303,10 @@ pub fn process_voluntary_exit<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
signed_voluntary_exit: &mut SignedVoluntaryExit,
signed_voluntary_exit: &SignedVoluntaryExit,
context: &Context,
) -> Result<()> {
let voluntary_exit = &mut signed_voluntary_exit.message;
let voluntary_exit = &signed_voluntary_exit.message;
let validator = state.validators.get(voluntary_exit.validator_index).ok_or_else(|| {
invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidIndex(voluntary_exit.validator_index),
Expand Down Expand Up @@ -378,7 +376,7 @@ pub fn process_block_header<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
block: &mut BeaconBlock<
block: &BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand Down Expand Up @@ -464,11 +462,11 @@ pub fn process_randao<
>,
context: &Context,
) -> Result<()> {
let mut epoch = get_current_epoch(state, context);
let epoch = get_current_epoch(state, context);
let proposer_index = get_beacon_proposer_index(state, context)?;
let proposer = &state.validators[proposer_index];
let domain = get_domain(state, DomainType::Randao, Some(epoch), context)?;
let signing_root = compute_signing_root(&mut epoch, domain)?;
let signing_root = compute_signing_root(&epoch, domain)?;
if verify_signature(&proposer.public_key, signing_root.as_ref(), &body.randao_reveal).is_err() {
return Err(invalid_operation_error(InvalidOperation::Randao(body.randao_reveal.clone())));
}
Expand Down Expand Up @@ -545,7 +543,7 @@ pub fn process_operations<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
body: &mut BeaconBlockBody<
body: &BeaconBlockBody<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -569,16 +567,14 @@ pub fn process_operations<
)));
}
body.proposer_slashings
.iter_mut()
.iter()
.try_for_each(|op| process_proposer_slashing(state, op, context))?;
body.attester_slashings
.iter_mut()
.iter()
.try_for_each(|op| process_attester_slashing(state, op, context))?;
body.attestations.iter().try_for_each(|op| process_attestation(state, op, context))?;
body.deposits.iter_mut().try_for_each(|op| process_deposit(state, op, context))?;
body.voluntary_exits
.iter_mut()
.try_for_each(|op| process_voluntary_exit(state, op, context))?;
body.deposits.iter().try_for_each(|op| process_deposit(state, op, context))?;
body.voluntary_exits.iter().try_for_each(|op| process_voluntary_exit(state, op, context))?;
Ok(())
}
pub fn process_registry_updates<
Expand Down Expand Up @@ -783,7 +779,7 @@ pub fn process_historical_roots_update<
let next_epoch = get_current_epoch(state, context) + 1;
let epochs_per_historical_root = context.slots_per_historical_root / context.slots_per_epoch;
if next_epoch % epochs_per_historical_root == 0 {
let mut historical_batch = HistoricalSummary {
let historical_batch = HistoricalSummary {
block_summary_root: state.block_roots.hash_tree_root()?,
state_summary_root: state.state_roots.hash_tree_root()?,
};
Expand Down Expand Up @@ -968,7 +964,7 @@ pub fn get_genesis_block<
const MAX_DEPOSITS: usize,
const MAX_VOLUNTARY_EXITS: usize,
>(
genesis_state: &mut BeaconState<
genesis_state: &BeaconState<
SLOTS_PER_HISTORICAL_ROOT,
HISTORICAL_ROOTS_LIMIT,
ETH1_DATA_VOTES_BOUND,
Expand Down Expand Up @@ -1036,7 +1032,7 @@ pub fn is_valid_indexed_attestation<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
indexed_attestation: &mut IndexedAttestation<MAX_VALIDATORS_PER_COMMITTEE>,
indexed_attestation: &IndexedAttestation<MAX_VALIDATORS_PER_COMMITTEE>,
context: &Context,
) -> Result<()> {
let attesting_indices = &indexed_attestation.attesting_indices;
Expand Down Expand Up @@ -1078,7 +1074,7 @@ pub fn is_valid_indexed_attestation<
Some(indexed_attestation.data.target.epoch),
context,
)?;
let signing_root = compute_signing_root(&mut indexed_attestation.data, domain)?;
let signing_root = compute_signing_root(&indexed_attestation.data, domain)?;
fast_aggregate_verify(&public_keys, signing_root.as_ref(), &indexed_attestation.signature)
.map_err(Into::into)
}
Expand Down Expand Up @@ -1107,7 +1103,7 @@ pub fn verify_block_signature<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
signed_block: &mut SignedBeaconBlock<
signed_block: &SignedBeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -1124,7 +1120,7 @@ pub fn verify_block_signature<
.get(proposer_index)
.ok_or(Error::OutOfBounds { requested: proposer_index, bound: state.validators.len() })?;
let domain = get_domain(state, DomainType::BeaconProposer, None, context)?;
let signing_root = compute_signing_root(&mut signed_block.message, domain)?;
let signing_root = compute_signing_root(&signed_block.message, domain)?;
let public_key = &proposer.public_key;
verify_signature(public_key, signing_root.as_ref(), &signed_block.signature).map_err(Into::into)
}
Expand Down Expand Up @@ -1927,7 +1923,7 @@ pub fn state_transition_block_in_slot<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
signed_block: &mut SignedBeaconBlock<
signed_block: &SignedBeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -1946,7 +1942,7 @@ pub fn state_transition_block_in_slot<
if validate_result {
verify_block_signature(state, signed_block, context)?;
}
let block = &mut signed_block.message;
let block = &signed_block.message;
process_block(state, block, context)?;
if validate_result && block.state_root != state.hash_tree_root()? {
Err(Error::InvalidStateRoot)
Expand Down Expand Up @@ -1979,7 +1975,7 @@ pub fn state_transition<
MAX_VALIDATORS_PER_COMMITTEE,
SYNC_COMMITTEE_SIZE,
>,
signed_block: &mut SignedBeaconBlock<
signed_block: &SignedBeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand Down
10 changes: 5 additions & 5 deletions ethereum-consensus/src/bellatrix/block_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn process_execution_payload<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
>,
block: &mut BeaconBlockBody<
block: &BeaconBlockBody<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -57,7 +57,7 @@ pub fn process_execution_payload<
>,
context: &Context,
) -> Result<()> {
let payload = &mut block.execution_payload;
let payload = &block.execution_payload;

let parent_hash_invalid =
payload.parent_hash != state.latest_execution_payload_header.block_hash;
Expand Down Expand Up @@ -148,7 +148,7 @@ pub fn process_block<
BYTES_PER_LOGS_BLOOM,
MAX_EXTRA_DATA_BYTES,
>,
block: &mut BeaconBlock<
block: &BeaconBlock<
MAX_PROPOSER_SLASHINGS,
MAX_VALIDATORS_PER_COMMITTEE,
MAX_ATTESTER_SLASHINGS,
Expand All @@ -165,11 +165,11 @@ 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, context)?;
process_execution_payload(state, &block.body, context)?;
}
process_randao(state, &block.body, context)?;
process_eth1_data(state, &block.body, context);
process_operations(state, &mut block.body, context)?;
process_operations(state, &block.body, context)?;
process_sync_aggregate(state, &block.body.sync_aggregate, context)?;
Ok(())
}
Loading
Loading