Skip to content

Commit bcc4f9d

Browse files
authored
Merge branch 'unstable' into remove/blinded_blocks
2 parents 00f985e + 734ad90 commit bcc4f9d

File tree

9 files changed

+651
-521
lines changed

9 files changed

+651
-521
lines changed

Cargo.lock

Lines changed: 574 additions & 463 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ edition = "2021"
9898

9999
[workspace.dependencies]
100100
account_utils = { path = "common/account_utils" }
101-
alloy-consensus = "0.3.0"
102-
alloy-primitives = { version = "0.8", features = ["rlp", "getrandom"] }
101+
alloy-consensus = { version = "0.14.0", default-features = false }
102+
alloy-primitives = { version = "1.0", features = ["rlp", "getrandom"] }
103103
alloy-rlp = "0.3.4"
104104
anyhow = "1"
105105
arbitrary = { version = "1", features = ["derive"] }
@@ -116,7 +116,7 @@ byteorder = "1"
116116
bytes = "1"
117117
# Turn off c-kzg's default features which include `blst/portable`. We can turn on blst's portable
118118
# feature ourselves when desired.
119-
c-kzg = { version = "1", default-features = false }
119+
c-kzg = { version = "2.1.0", default-features = false }
120120
cargo_metadata = "0.19"
121121
clap = { version = "4.5.4", features = ["derive", "cargo", "wrap_help"] }
122122
clap_utils = { path = "common/clap_utils" }
@@ -143,9 +143,9 @@ eth2_keystore = { path = "crypto/eth2_keystore" }
143143
eth2_network_config = { path = "common/eth2_network_config" }
144144
eth2_wallet = { path = "crypto/eth2_wallet" }
145145
ethereum_hashing = "0.7.0"
146-
ethereum_serde_utils = "0.7"
147-
ethereum_ssz = "0.8.2"
148-
ethereum_ssz_derive = "0.8.2"
146+
ethereum_serde_utils = "0.8.0"
147+
ethereum_ssz = "0.9.0"
148+
ethereum_ssz_derive = "0.9.0"
149149
ethers-core = "1"
150150
ethers-middleware = { version = "1", default-features = false }
151151
ethers-providers = { version = "1", default-features = false }
@@ -184,7 +184,7 @@ malloc_utils = { path = "common/malloc_utils" }
184184
maplit = "1"
185185
merkle_proof = { path = "consensus/merkle_proof" }
186186
metrics = { path = "common/metrics" }
187-
milhouse = "0.5"
187+
milhouse = "0.6"
188188
mockall = "0.13"
189189
mockall_double = "0.3"
190190
mockito = "1.5.0"
@@ -230,7 +230,7 @@ slashing_protection = { path = "validator_client/slashing_protection" }
230230
slot_clock = { path = "common/slot_clock" }
231231
smallvec = { version = "1.11.2", features = ["arbitrary"] }
232232
snap = "1"
233-
ssz_types = "0.10"
233+
ssz_types = "0.11.0"
234234
state_processing = { path = "consensus/state_processing" }
235235
store = { path = "beacon_node/store" }
236236
strum = { version = "0.24", features = ["derive"] }
@@ -254,8 +254,8 @@ tracing-appender = "0.2"
254254
tracing-core = "0.1"
255255
tracing-log = "0.2"
256256
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
257-
tree_hash = "0.9"
258-
tree_hash_derive = "0.9"
257+
tree_hash = "0.10.0"
258+
tree_hash_derive = "0.10.0"
259259
types = { path = "consensus/types" }
260260
unused_port = { path = "common/unused_port" }
261261
url = "2"

beacon_node/store/src/metrics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub static DISK_DB_WRITE_COUNT: LazyLock<Result<IntCounterVec>> = LazyLock::new(
6868
pub static DISK_DB_READ_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {
6969
try_create_histogram(
7070
"store_disk_db_read_seconds",
71-
"Time taken to write bytes to store.",
71+
"Time taken to read bytes from store.",
7272
)
7373
});
7474
pub static DISK_DB_WRITE_TIMES: LazyLock<Result<Histogram>> = LazyLock::new(|| {

consensus/types/src/attestation.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,12 @@ mod tests {
661661
let attestation_data = size_of::<AttestationData>();
662662
let signature = size_of::<AggregateSignature>();
663663

664-
assert_eq!(aggregation_bits, 152);
664+
assert_eq!(aggregation_bits, 144);
665665
assert_eq!(attestation_data, 128);
666666
assert_eq!(signature, 288 + 16);
667667

668668
let attestation_expected = aggregation_bits + attestation_data + signature;
669-
assert_eq!(attestation_expected, 584);
669+
assert_eq!(attestation_expected, 576);
670670
assert_eq!(
671671
size_of::<AttestationBase<MainnetEthSpec>>(),
672672
attestation_expected
@@ -684,13 +684,13 @@ mod tests {
684684
size_of::<BitList<<MainnetEthSpec as EthSpec>::MaxCommitteesPerSlot>>();
685685
let signature = size_of::<AggregateSignature>();
686686

687-
assert_eq!(aggregation_bits, 152);
688-
assert_eq!(committee_bits, 152);
687+
assert_eq!(aggregation_bits, 144);
688+
assert_eq!(committee_bits, 144);
689689
assert_eq!(attestation_data, 128);
690690
assert_eq!(signature, 288 + 16);
691691

692692
let attestation_expected = aggregation_bits + committee_bits + attestation_data + signature;
693-
assert_eq!(attestation_expected, 736);
693+
assert_eq!(attestation_expected, 720);
694694
assert_eq!(
695695
size_of::<AttestationElectra<MainnetEthSpec>>(),
696696
attestation_expected

crypto/kzg/benches/benchmark.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use c_kzg::KzgSettings;
22
use criterion::{criterion_group, criterion_main, Criterion};
3-
use kzg::{trusted_setup::get_trusted_setup, TrustedSetup};
3+
use kzg::{trusted_setup::get_trusted_setup, TrustedSetup, NO_PRECOMPUTE};
44
use rust_eth_kzg::{DASContext, TrustedSetup as PeerDASTrustedSetup};
55

66
pub fn bench_init_context(c: &mut Criterion) {
@@ -25,8 +25,13 @@ pub fn bench_init_context(c: &mut Criterion) {
2525
serde_json::from_reader(get_trusted_setup().as_slice())
2626
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
2727
.expect("should have trusted setup");
28-
KzgSettings::load_trusted_setup(&trusted_setup.g1_points(), &trusted_setup.g2_points())
29-
.unwrap()
28+
KzgSettings::load_trusted_setup(
29+
&trusted_setup.g1_monomial(),
30+
&trusted_setup.g1_lagrange(),
31+
&trusted_setup.g2_monomial(),
32+
NO_PRECOMPUTE,
33+
)
34+
.unwrap()
3035
})
3136
});
3237
}

crypto/kzg/src/lib.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ pub use rust_eth_kzg::{
2121
Cell, CellIndex as CellID, CellRef, TrustedSetup as PeerDASTrustedSetup,
2222
};
2323

24+
/// Disables the fixed-base multi-scalar multiplication optimization for computing
25+
/// cell KZG proofs, because `rust-eth-kzg` already handles the precomputation.
26+
///
27+
/// Details about `precompute` parameter can be found here:
28+
/// <https://github.com/ethereum/c-kzg-4844/pull/545/files>
29+
pub const NO_PRECOMPUTE: u64 = 0;
30+
2431
// Note: `spec.number_of_columns` is a config and should match `CELLS_PER_EXT_BLOB` - however this
2532
// is a constant in the KZG library - be aware that overriding `number_of_columns` will break KZG
2633
// operations.
@@ -65,8 +72,10 @@ impl Kzg {
6572

6673
Ok(Self {
6774
trusted_setup: KzgSettings::load_trusted_setup(
68-
&trusted_setup.g1_points(),
69-
&trusted_setup.g2_points(),
75+
&trusted_setup.g1_monomial(),
76+
&trusted_setup.g1_lagrange(),
77+
&trusted_setup.g2_monomial(),
78+
NO_PRECOMPUTE,
7079
)?,
7180
context,
7281
})
@@ -85,8 +94,10 @@ impl Kzg {
8594

8695
Ok(Self {
8796
trusted_setup: KzgSettings::load_trusted_setup(
88-
&trusted_setup.g1_points(),
89-
&trusted_setup.g2_points(),
97+
&trusted_setup.g1_monomial(),
98+
&trusted_setup.g1_lagrange(),
99+
&trusted_setup.g2_monomial(),
100+
NO_PRECOMPUTE,
90101
)?,
91102
context,
92103
})
@@ -111,8 +122,10 @@ impl Kzg {
111122

112123
Ok(Self {
113124
trusted_setup: KzgSettings::load_trusted_setup(
114-
&trusted_setup.g1_points(),
115-
&trusted_setup.g2_points(),
125+
&trusted_setup.g1_monomial(),
126+
&trusted_setup.g1_lagrange(),
127+
&trusted_setup.g2_monomial(),
128+
NO_PRECOMPUTE,
116129
)?,
117130
context,
118131
})
@@ -128,7 +141,8 @@ impl Kzg {
128141
blob: &Blob,
129142
kzg_commitment: KzgCommitment,
130143
) -> Result<KzgProof, Error> {
131-
c_kzg::KzgProof::compute_blob_kzg_proof(blob, &kzg_commitment.into(), &self.trusted_setup)
144+
self.trusted_setup
145+
.compute_blob_kzg_proof(blob, &kzg_commitment.into())
132146
.map(|proof| KzgProof(proof.to_bytes().into_inner()))
133147
.map_err(Into::into)
134148
}
@@ -140,11 +154,10 @@ impl Kzg {
140154
kzg_commitment: KzgCommitment,
141155
kzg_proof: KzgProof,
142156
) -> Result<(), Error> {
143-
if !c_kzg::KzgProof::verify_blob_kzg_proof(
157+
if !self.trusted_setup.verify_blob_kzg_proof(
144158
blob,
145159
&kzg_commitment.into(),
146160
&kzg_proof.into(),
147-
&self.trusted_setup,
148161
)? {
149162
Err(Error::KzgVerificationFailed)
150163
} else {
@@ -172,11 +185,10 @@ impl Kzg {
172185
.map(|proof| Bytes48::from(*proof))
173186
.collect::<Vec<_>>();
174187

175-
if !c_kzg::KzgProof::verify_blob_kzg_proof_batch(
188+
if !self.trusted_setup.verify_blob_kzg_proof_batch(
176189
blobs,
177190
&commitments_bytes,
178191
&proofs_bytes,
179-
&self.trusted_setup,
180192
)? {
181193
Err(Error::KzgVerificationFailed)
182194
} else {
@@ -186,7 +198,8 @@ impl Kzg {
186198

187199
/// Converts a blob to a kzg commitment.
188200
pub fn blob_to_kzg_commitment(&self, blob: &Blob) -> Result<KzgCommitment, Error> {
189-
c_kzg::KzgCommitment::blob_to_kzg_commitment(blob, &self.trusted_setup)
201+
self.trusted_setup
202+
.blob_to_kzg_commitment(blob)
190203
.map(|commitment| KzgCommitment(commitment.to_bytes().into_inner()))
191204
.map_err(Into::into)
192205
}
@@ -197,7 +210,8 @@ impl Kzg {
197210
blob: &Blob,
198211
z: &Bytes32,
199212
) -> Result<(KzgProof, Bytes32), Error> {
200-
c_kzg::KzgProof::compute_kzg_proof(blob, z, &self.trusted_setup)
213+
self.trusted_setup
214+
.compute_kzg_proof(blob, z)
201215
.map(|(proof, y)| (KzgProof(proof.to_bytes().into_inner()), y))
202216
.map_err(Into::into)
203217
}
@@ -210,14 +224,9 @@ impl Kzg {
210224
y: &Bytes32,
211225
kzg_proof: KzgProof,
212226
) -> Result<bool, Error> {
213-
c_kzg::KzgProof::verify_kzg_proof(
214-
&kzg_commitment.into(),
215-
z,
216-
y,
217-
&kzg_proof.into(),
218-
&self.trusted_setup,
219-
)
220-
.map_err(Into::into)
227+
self.trusted_setup
228+
.verify_kzg_proof(&kzg_commitment.into(), z, y, &kzg_proof.into())
229+
.map_err(Into::into)
221230
}
222231

223232
/// Computes the cells and associated proofs for a given `blob`.

crypto/kzg/src/trusted_setup.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use crate::PeerDASTrustedSetup;
2-
use c_kzg::{BYTES_PER_G1_POINT, BYTES_PER_G2_POINT};
32
use serde::{
43
de::{self, Deserializer, Visitor},
54
Deserialize, Serialize,
65
};
76

7+
// Number of bytes per G1 point.
8+
const BYTES_PER_G1_POINT: usize = 48;
9+
// Number of bytes per G2 point.
10+
const BYTES_PER_G2_POINT: usize = 96;
11+
812
pub const TRUSTED_SETUP_BYTES: &[u8] = include_bytes!("../trusted_setup.json");
913

1014
pub fn get_trusted_setup() -> Vec<u8> {
@@ -23,48 +27,49 @@ struct G2Point([u8; BYTES_PER_G2_POINT]);
2327
/// `c_kzg::KzgSettings` object.
2428
///
2529
/// The serialize/deserialize implementations are written according to
26-
/// the format specified in the the ethereum consensus specs trusted setup files.
30+
/// the format specified in the ethereum consensus specs trusted setup files.
2731
///
2832
/// See https://github.com/ethereum/consensus-specs/blob/dev/presets/mainnet/trusted_setups/trusted_setup_4096.json
2933
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
3034
pub struct TrustedSetup {
31-
#[serde(rename = "g1_monomial")]
32-
g1_monomial_points: Vec<G1Point>,
33-
#[serde(rename = "g1_lagrange")]
34-
g1_points: Vec<G1Point>,
35-
#[serde(rename = "g2_monomial")]
36-
g2_points: Vec<G2Point>,
35+
g1_monomial: Vec<G1Point>,
36+
g1_lagrange: Vec<G1Point>,
37+
g2_monomial: Vec<G2Point>,
3738
}
3839

3940
impl TrustedSetup {
40-
pub fn g1_points(&self) -> Vec<[u8; BYTES_PER_G1_POINT]> {
41-
self.g1_points.iter().map(|p| p.0).collect()
41+
pub fn g1_monomial(&self) -> Vec<u8> {
42+
self.g1_monomial.iter().flat_map(|p| p.0).collect()
43+
}
44+
45+
pub fn g1_lagrange(&self) -> Vec<u8> {
46+
self.g1_lagrange.iter().flat_map(|p| p.0).collect()
4247
}
4348

44-
pub fn g2_points(&self) -> Vec<[u8; BYTES_PER_G2_POINT]> {
45-
self.g2_points.iter().map(|p| p.0).collect()
49+
pub fn g2_monomial(&self) -> Vec<u8> {
50+
self.g2_monomial.iter().flat_map(|p| p.0).collect()
4651
}
4752

4853
pub fn g1_len(&self) -> usize {
49-
self.g1_points.len()
54+
self.g1_lagrange.len()
5055
}
5156
}
5257

5358
impl From<&TrustedSetup> for PeerDASTrustedSetup {
5459
fn from(trusted_setup: &TrustedSetup) -> Self {
5560
Self {
5661
g1_monomial: trusted_setup
57-
.g1_monomial_points
62+
.g1_monomial
5863
.iter()
5964
.map(|g1_point| format!("0x{}", hex::encode(g1_point.0)))
6065
.collect::<Vec<_>>(),
6166
g1_lagrange: trusted_setup
62-
.g1_points
67+
.g1_lagrange
6368
.iter()
6469
.map(|g1_point| format!("0x{}", hex::encode(g1_point.0)))
6570
.collect::<Vec<_>>(),
6671
g2_monomial: trusted_setup
67-
.g2_points
72+
.g2_monomial
6873
.iter()
6974
.map(|g2_point| format!("0x{}", hex::encode(g2_point.0)))
7075
.collect::<Vec<_>>(),

testing/simulator/src/basic_sim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tracing::Level;
2525
use types::{Epoch, EthSpec, MinimalEthSpec};
2626

2727
const END_EPOCH: u64 = 16;
28-
const GENESIS_DELAY: u64 = 32;
28+
const GENESIS_DELAY: u64 = 38;
2929
const ALTAIR_FORK_EPOCH: u64 = 0;
3030
const BELLATRIX_FORK_EPOCH: u64 = 0;
3131
const CAPELLA_FORK_EPOCH: u64 = 0;

testing/simulator/src/fallback_sim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tracing_subscriber::prelude::*;
2121
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
2222
use types::{Epoch, EthSpec, MinimalEthSpec};
2323
const END_EPOCH: u64 = 16;
24-
const GENESIS_DELAY: u64 = 32;
24+
const GENESIS_DELAY: u64 = 38;
2525
const ALTAIR_FORK_EPOCH: u64 = 0;
2626
const BELLATRIX_FORK_EPOCH: u64 = 0;
2727
const CAPELLA_FORK_EPOCH: u64 = 1;

0 commit comments

Comments
 (0)