Skip to content

Commit

Permalink
impl deneb spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Sep 19, 2023
1 parent dc10cdf commit e88c731
Show file tree
Hide file tree
Showing 28 changed files with 4,491 additions and 498 deletions.
2 changes: 1 addition & 1 deletion ethereum-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async = ["tokio", "tokio-stream", "async-stream"]
spec-tests = ["serde", "serde_yaml"]

[dependencies]
ssz_rs = "0.9.0"
ssz_rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "51f3932d1578a62f856c19175482056912de5f3e" }
blst = "0.3.11"
rand = "0.8.4"
thiserror = "1.0.30"
Expand Down
16 changes: 7 additions & 9 deletions ethereum-consensus/src/altair/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub use crate::{
},
primitives::*,
signing::*,
state_transition::*,
state_transition::{error::*, Context, Result, Validation},
};
use crate::{
crypto::{fast_aggregate_verify, hash, verify_signature},
Expand Down Expand Up @@ -264,15 +264,13 @@ pub fn process_voluntary_exit<
)))
}
let domain = get_domain(state, DomainType::VoluntaryExit, Some(voluntary_exit.epoch), context)?;
let signing_root = compute_signing_root(voluntary_exit, domain)?;
let public_key = &validator.public_key;
if verify_signature(public_key, signing_root.as_ref(), &signed_voluntary_exit.signature)
.is_err()
{
return Err(invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidSignature(signed_voluntary_exit.signature.clone()),
)))
}
verify_signed_data(voluntary_exit, &signed_voluntary_exit.signature, public_key, domain)
.map_err(|_| {
invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidSignature(signed_voluntary_exit.signature.clone()),
))
})?;
initiate_validator_exit(state, voluntary_exit.validator_index, context);
Ok(())
}
Expand Down
16 changes: 7 additions & 9 deletions ethereum-consensus/src/bellatrix/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use crate::{
},
primitives::*,
signing::*,
state_transition::*,
state_transition::{error::*, Context, Result, Validation},
};
use crate::{
crypto::{
Expand Down Expand Up @@ -555,15 +555,13 @@ pub fn process_voluntary_exit<
)))
}
let domain = get_domain(state, DomainType::VoluntaryExit, Some(voluntary_exit.epoch), context)?;
let signing_root = compute_signing_root(voluntary_exit, domain)?;
let public_key = &validator.public_key;
if verify_signature(public_key, signing_root.as_ref(), &signed_voluntary_exit.signature)
.is_err()
{
return Err(invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidSignature(signed_voluntary_exit.signature.clone()),
)))
}
verify_signed_data(voluntary_exit, &signed_voluntary_exit.signature, public_key, domain)
.map_err(|_| {
invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidSignature(signed_voluntary_exit.signature.clone()),
))
})?;
initiate_validator_exit(state, voluntary_exit.validator_index, context);
Ok(())
}
Expand Down
16 changes: 7 additions & 9 deletions ethereum-consensus/src/capella/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub use crate::{
},
primitives::*,
signing::*,
state_transition::*,
state_transition::{error::*, Context, Result, Validation},
};
use crate::{
crypto::{
Expand Down Expand Up @@ -558,15 +558,13 @@ pub fn process_voluntary_exit<
)))
}
let domain = get_domain(state, DomainType::VoluntaryExit, Some(voluntary_exit.epoch), context)?;
let signing_root = compute_signing_root(voluntary_exit, domain)?;
let public_key = &validator.public_key;
if verify_signature(public_key, signing_root.as_ref(), &signed_voluntary_exit.signature)
.is_err()
{
return Err(invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidSignature(signed_voluntary_exit.signature.clone()),
)))
}
verify_signed_data(voluntary_exit, &signed_voluntary_exit.signature, public_key, domain)
.map_err(|_| {
invalid_operation_error(InvalidOperation::VoluntaryExit(
InvalidVoluntaryExit::InvalidSignature(signed_voluntary_exit.signature.clone()),
))
})?;
initiate_validator_exit(state, voluntary_exit.validator_index, context);
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions ethereum-consensus/src/deneb/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub struct BeaconBlock<
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
const MAX_BLOBS_PER_BLOCK: usize,
const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize,
> {
#[serde(with = "crate::serde::as_string")]
pub slot: Slot,
Expand All @@ -87,7 +87,7 @@ pub struct BeaconBlock<
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
MAX_BLOBS_PER_BLOCK,
MAX_BLOB_COMMITMENTS_PER_BLOCK,
>,
}

Expand All @@ -107,7 +107,7 @@ pub struct SignedBeaconBlock<
const MAX_TRANSACTIONS_PER_PAYLOAD: usize,
const MAX_WITHDRAWALS_PER_PAYLOAD: usize,
const MAX_BLS_TO_EXECUTION_CHANGES: usize,
const MAX_BLOBS_PER_BLOCK: usize,
const MAX_BLOB_COMMITMENTS_PER_BLOCK: usize,
> {
pub message: BeaconBlock<
MAX_PROPOSER_SLASHINGS,
Expand All @@ -123,7 +123,7 @@ pub struct SignedBeaconBlock<
MAX_TRANSACTIONS_PER_PAYLOAD,
MAX_WITHDRAWALS_PER_PAYLOAD,
MAX_BLS_TO_EXECUTION_CHANGES,
MAX_BLOBS_PER_BLOCK,
MAX_BLOB_COMMITMENTS_PER_BLOCK,
>,
pub signature: BlsSignature,
}
2 changes: 0 additions & 2 deletions ethereum-consensus/src/deneb/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ pub struct BeaconState<
const SYNC_COMMITTEE_SIZE: 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,
> {
#[serde(with = "crate::serde::as_string")]
pub genesis_time: u64,
Expand Down
6 changes: 3 additions & 3 deletions ethereum-consensus/src/deneb/blinded_blob_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ssz_rs::prelude::*;

#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BlindedBlobSidecar<const BYTES_PER_BLOB: usize> {
pub struct BlindedBlobSidecar {
pub block_root: Root,
#[serde(with = "crate::serde::as_string")]
pub index: BlobIndex,
Expand All @@ -22,7 +22,7 @@ pub struct BlindedBlobSidecar<const BYTES_PER_BLOB: usize> {

#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignedBlindedBlobSidecar<const MAX_BLOBS_PER_BLOCK: usize, const BYTES_PER_BLOB: usize> {
pub message: BlindedBlobSidecar<BYTES_PER_BLOB>,
pub struct SignedBlindedBlobSidecar {
pub message: BlindedBlobSidecar,
pub signature: BlsSignature,
}
2 changes: 1 addition & 1 deletion ethereum-consensus/src/deneb/blob_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct BlobSidecar<const BYTES_PER_BLOB: usize> {

#[derive(Default, Debug, Clone, SimpleSerialize, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SignedBlobSidecar<const MAX_BLOBS_PER_BLOCK: usize, const BYTES_PER_BLOB: usize> {
pub struct SignedBlobSidecar<const BYTES_PER_BLOB: usize> {
pub message: BlobSidecar<BYTES_PER_BLOB>,
pub signature: BlsSignature,
}
Expand Down
Loading

0 comments on commit e88c731

Please sign in to comment.