Skip to content
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
1,037 changes: 574 additions & 463 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ edition = "2021"

[workspace.dependencies]
account_utils = { path = "common/account_utils" }
alloy-consensus = "0.3.0"
alloy-primitives = { version = "0.8", features = ["rlp", "getrandom"] }
alloy-consensus = { version = "0.14.0", default-features = false }
alloy-primitives = { version = "1.0", features = ["rlp", "getrandom"] }
alloy-rlp = "0.3.4"
anyhow = "1"
arbitrary = { version = "1", features = ["derive"] }
Expand All @@ -116,7 +116,7 @@ byteorder = "1"
bytes = "1"
# Turn off c-kzg's default features which include `blst/portable`. We can turn on blst's portable
# feature ourselves when desired.
c-kzg = { version = "1", default-features = false }
c-kzg = { version = "2.1.0", default-features = false }
cargo_metadata = "0.19"
clap = { version = "4.5.4", features = ["derive", "cargo", "wrap_help"] }
clap_utils = { path = "common/clap_utils" }
Expand All @@ -143,9 +143,9 @@ eth2_keystore = { path = "crypto/eth2_keystore" }
eth2_network_config = { path = "common/eth2_network_config" }
eth2_wallet = { path = "crypto/eth2_wallet" }
ethereum_hashing = "0.7.0"
ethereum_serde_utils = "0.7"
ethereum_ssz = "0.8.2"
ethereum_ssz_derive = "0.8.2"
ethereum_serde_utils = "0.8.0"
ethereum_ssz = "0.9.0"
ethereum_ssz_derive = "0.9.0"
ethers-core = "1"
ethers-middleware = { version = "1", default-features = false }
ethers-providers = { version = "1", default-features = false }
Expand Down Expand Up @@ -184,7 +184,7 @@ malloc_utils = { path = "common/malloc_utils" }
maplit = "1"
merkle_proof = { path = "consensus/merkle_proof" }
metrics = { path = "common/metrics" }
milhouse = "0.5"
milhouse = "0.6"
mockall = "0.13"
mockall_double = "0.3"
mockito = "1.5.0"
Expand Down Expand Up @@ -230,7 +230,7 @@ slashing_protection = { path = "validator_client/slashing_protection" }
slot_clock = { path = "common/slot_clock" }
smallvec = { version = "1.11.2", features = ["arbitrary"] }
snap = "1"
ssz_types = "0.10"
ssz_types = "0.11.0"
state_processing = { path = "consensus/state_processing" }
store = { path = "beacon_node/store" }
strum = { version = "0.24", features = ["derive"] }
Expand All @@ -254,8 +254,8 @@ tracing-appender = "0.2"
tracing-core = "0.1"
tracing-log = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
tree_hash = "0.9"
tree_hash_derive = "0.9"
tree_hash = "0.10.0"
tree_hash_derive = "0.10.0"
types = { path = "consensus/types" }
unused_port = { path = "common/unused_port" }
url = "2"
Expand Down
10 changes: 5 additions & 5 deletions consensus/types/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,12 @@ mod tests {
let attestation_data = size_of::<AttestationData>();
let signature = size_of::<AggregateSignature>();

assert_eq!(aggregation_bits, 152);
assert_eq!(aggregation_bits, 144);
assert_eq!(attestation_data, 128);
assert_eq!(signature, 288 + 16);

let attestation_expected = aggregation_bits + attestation_data + signature;
assert_eq!(attestation_expected, 584);
assert_eq!(attestation_expected, 576);
assert_eq!(
size_of::<AttestationBase<MainnetEthSpec>>(),
attestation_expected
Expand All @@ -684,13 +684,13 @@ mod tests {
size_of::<BitList<<MainnetEthSpec as EthSpec>::MaxCommitteesPerSlot>>();
let signature = size_of::<AggregateSignature>();

assert_eq!(aggregation_bits, 152);
assert_eq!(committee_bits, 152);
assert_eq!(aggregation_bits, 144);
assert_eq!(committee_bits, 144);
assert_eq!(attestation_data, 128);
assert_eq!(signature, 288 + 16);

let attestation_expected = aggregation_bits + committee_bits + attestation_data + signature;
assert_eq!(attestation_expected, 736);
assert_eq!(attestation_expected, 720);
assert_eq!(
size_of::<AttestationElectra<MainnetEthSpec>>(),
attestation_expected
Expand Down
11 changes: 8 additions & 3 deletions crypto/kzg/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use c_kzg::KzgSettings;
use criterion::{criterion_group, criterion_main, Criterion};
use kzg::{trusted_setup::get_trusted_setup, TrustedSetup};
use kzg::{trusted_setup::get_trusted_setup, TrustedSetup, NO_PRECOMPUTE};
use rust_eth_kzg::{DASContext, TrustedSetup as PeerDASTrustedSetup};

pub fn bench_init_context(c: &mut Criterion) {
Expand All @@ -25,8 +25,13 @@ pub fn bench_init_context(c: &mut Criterion) {
serde_json::from_reader(get_trusted_setup().as_slice())
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
.expect("should have trusted setup");
KzgSettings::load_trusted_setup(&trusted_setup.g1_points(), &trusted_setup.g2_points())
.unwrap()
KzgSettings::load_trusted_setup(
&trusted_setup.g1_monomial(),
&trusted_setup.g1_lagrange(),
&trusted_setup.g2_monomial(),
NO_PRECOMPUTE,
)
.unwrap()
})
});
}
Expand Down
51 changes: 30 additions & 21 deletions crypto/kzg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub use rust_eth_kzg::{
Cell, CellIndex as CellID, CellRef, TrustedSetup as PeerDASTrustedSetup,
};

/// Disables the fixed-base multi-scalar multiplication optimization for computing
/// cell KZG proofs, because `rust-eth-kzg` already handles the precomputation.
///
/// Details about `precompute` parameter can be found here:
/// <https://github.com/ethereum/c-kzg-4844/pull/545/files>
pub const NO_PRECOMPUTE: u64 = 0;

// Note: `spec.number_of_columns` is a config and should match `CELLS_PER_EXT_BLOB` - however this
// is a constant in the KZG library - be aware that overriding `number_of_columns` will break KZG
// operations.
Expand Down Expand Up @@ -65,8 +72,10 @@ impl Kzg {

Ok(Self {
trusted_setup: KzgSettings::load_trusted_setup(
&trusted_setup.g1_points(),
&trusted_setup.g2_points(),
&trusted_setup.g1_monomial(),
&trusted_setup.g1_lagrange(),
&trusted_setup.g2_monomial(),
NO_PRECOMPUTE,
)?,
context,
})
Expand All @@ -85,8 +94,10 @@ impl Kzg {

Ok(Self {
trusted_setup: KzgSettings::load_trusted_setup(
&trusted_setup.g1_points(),
&trusted_setup.g2_points(),
&trusted_setup.g1_monomial(),
&trusted_setup.g1_lagrange(),
&trusted_setup.g2_monomial(),
NO_PRECOMPUTE,
)?,
context,
})
Expand All @@ -111,8 +122,10 @@ impl Kzg {

Ok(Self {
trusted_setup: KzgSettings::load_trusted_setup(
&trusted_setup.g1_points(),
&trusted_setup.g2_points(),
&trusted_setup.g1_monomial(),
&trusted_setup.g1_lagrange(),
&trusted_setup.g2_monomial(),
NO_PRECOMPUTE,
)?,
context,
})
Expand All @@ -128,7 +141,8 @@ impl Kzg {
blob: &Blob,
kzg_commitment: KzgCommitment,
) -> Result<KzgProof, Error> {
c_kzg::KzgProof::compute_blob_kzg_proof(blob, &kzg_commitment.into(), &self.trusted_setup)
self.trusted_setup
.compute_blob_kzg_proof(blob, &kzg_commitment.into())
.map(|proof| KzgProof(proof.to_bytes().into_inner()))
.map_err(Into::into)
}
Expand All @@ -140,11 +154,10 @@ impl Kzg {
kzg_commitment: KzgCommitment,
kzg_proof: KzgProof,
) -> Result<(), Error> {
if !c_kzg::KzgProof::verify_blob_kzg_proof(
if !self.trusted_setup.verify_blob_kzg_proof(
blob,
&kzg_commitment.into(),
&kzg_proof.into(),
&self.trusted_setup,
)? {
Err(Error::KzgVerificationFailed)
} else {
Expand Down Expand Up @@ -172,11 +185,10 @@ impl Kzg {
.map(|proof| Bytes48::from(*proof))
.collect::<Vec<_>>();

if !c_kzg::KzgProof::verify_blob_kzg_proof_batch(
if !self.trusted_setup.verify_blob_kzg_proof_batch(
blobs,
&commitments_bytes,
&proofs_bytes,
&self.trusted_setup,
)? {
Err(Error::KzgVerificationFailed)
} else {
Expand All @@ -186,7 +198,8 @@ impl Kzg {

/// Converts a blob to a kzg commitment.
pub fn blob_to_kzg_commitment(&self, blob: &Blob) -> Result<KzgCommitment, Error> {
c_kzg::KzgCommitment::blob_to_kzg_commitment(blob, &self.trusted_setup)
self.trusted_setup
.blob_to_kzg_commitment(blob)
.map(|commitment| KzgCommitment(commitment.to_bytes().into_inner()))
.map_err(Into::into)
}
Expand All @@ -197,7 +210,8 @@ impl Kzg {
blob: &Blob,
z: &Bytes32,
) -> Result<(KzgProof, Bytes32), Error> {
c_kzg::KzgProof::compute_kzg_proof(blob, z, &self.trusted_setup)
self.trusted_setup
.compute_kzg_proof(blob, z)
.map(|(proof, y)| (KzgProof(proof.to_bytes().into_inner()), y))
.map_err(Into::into)
}
Expand All @@ -210,14 +224,9 @@ impl Kzg {
y: &Bytes32,
kzg_proof: KzgProof,
) -> Result<bool, Error> {
c_kzg::KzgProof::verify_kzg_proof(
&kzg_commitment.into(),
z,
y,
&kzg_proof.into(),
&self.trusted_setup,
)
.map_err(Into::into)
self.trusted_setup
.verify_kzg_proof(&kzg_commitment.into(), z, y, &kzg_proof.into())
.map_err(Into::into)
}

/// Computes the cells and associated proofs for a given `blob`.
Expand Down
37 changes: 21 additions & 16 deletions crypto/kzg/src/trusted_setup.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::PeerDASTrustedSetup;
use c_kzg::{BYTES_PER_G1_POINT, BYTES_PER_G2_POINT};
use serde::{
de::{self, Deserializer, Visitor},
Deserialize, Serialize,
};

// Number of bytes per G1 point.
const BYTES_PER_G1_POINT: usize = 48;
// Number of bytes per G2 point.
const BYTES_PER_G2_POINT: usize = 96;

pub const TRUSTED_SETUP_BYTES: &[u8] = include_bytes!("../trusted_setup.json");

pub fn get_trusted_setup() -> Vec<u8> {
Expand All @@ -23,48 +27,49 @@ struct G2Point([u8; BYTES_PER_G2_POINT]);
/// `c_kzg::KzgSettings` object.
///
/// The serialize/deserialize implementations are written according to
/// the format specified in the the ethereum consensus specs trusted setup files.
/// the format specified in the ethereum consensus specs trusted setup files.
///
/// See https://github.com/ethereum/consensus-specs/blob/dev/presets/mainnet/trusted_setups/trusted_setup_4096.json
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TrustedSetup {
#[serde(rename = "g1_monomial")]
g1_monomial_points: Vec<G1Point>,
#[serde(rename = "g1_lagrange")]
g1_points: Vec<G1Point>,
#[serde(rename = "g2_monomial")]
g2_points: Vec<G2Point>,
g1_monomial: Vec<G1Point>,
g1_lagrange: Vec<G1Point>,
g2_monomial: Vec<G2Point>,
}

impl TrustedSetup {
pub fn g1_points(&self) -> Vec<[u8; BYTES_PER_G1_POINT]> {
self.g1_points.iter().map(|p| p.0).collect()
pub fn g1_monomial(&self) -> Vec<u8> {
self.g1_monomial.iter().flat_map(|p| p.0).collect()
}

pub fn g1_lagrange(&self) -> Vec<u8> {
self.g1_lagrange.iter().flat_map(|p| p.0).collect()
}

pub fn g2_points(&self) -> Vec<[u8; BYTES_PER_G2_POINT]> {
self.g2_points.iter().map(|p| p.0).collect()
pub fn g2_monomial(&self) -> Vec<u8> {
self.g2_monomial.iter().flat_map(|p| p.0).collect()
}

pub fn g1_len(&self) -> usize {
self.g1_points.len()
self.g1_lagrange.len()
}
}

impl From<&TrustedSetup> for PeerDASTrustedSetup {
fn from(trusted_setup: &TrustedSetup) -> Self {
Self {
g1_monomial: trusted_setup
.g1_monomial_points
.g1_monomial
.iter()
.map(|g1_point| format!("0x{}", hex::encode(g1_point.0)))
.collect::<Vec<_>>(),
g1_lagrange: trusted_setup
.g1_points
.g1_lagrange
.iter()
.map(|g1_point| format!("0x{}", hex::encode(g1_point.0)))
.collect::<Vec<_>>(),
g2_monomial: trusted_setup
.g2_points
.g2_monomial
.iter()
.map(|g2_point| format!("0x{}", hex::encode(g2_point.0)))
.collect::<Vec<_>>(),
Expand Down
2 changes: 1 addition & 1 deletion testing/simulator/src/basic_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use tracing::Level;
use types::{Epoch, EthSpec, MinimalEthSpec};

const END_EPOCH: u64 = 16;
const GENESIS_DELAY: u64 = 32;
const GENESIS_DELAY: u64 = 38;
const ALTAIR_FORK_EPOCH: u64 = 0;
const BELLATRIX_FORK_EPOCH: u64 = 0;
const CAPELLA_FORK_EPOCH: u64 = 0;
Expand Down
2 changes: 1 addition & 1 deletion testing/simulator/src/fallback_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tracing_subscriber::prelude::*;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
use types::{Epoch, EthSpec, MinimalEthSpec};
const END_EPOCH: u64 = 16;
const GENESIS_DELAY: u64 = 32;
const GENESIS_DELAY: u64 = 38;
const ALTAIR_FORK_EPOCH: u64 = 0;
const BELLATRIX_FORK_EPOCH: u64 = 0;
const CAPELLA_FORK_EPOCH: u64 = 1;
Expand Down