Upgrade to v1.4.0-beta.3 (#4862)

## Issue Addressed

Makes lighthouse compliant with new kzg changes in https://github.com/ethereum/consensus-specs/releases/tag/v1.4.0-beta.3

## Proposed Changes

1. Adds new official trusted setup
2. Refactors kzg to match upstream changes in https://github.com/ethereum/c-kzg-4844/pull/377
3. Updates pre-generated `BlobBundle` to work with official trusted setup. ~~Using json here instead of ssz to account for different value of `MaxBlobCommitmentsPerBlock` in minimal and mainnet. By using json, we can just use one pre generated bundle for both minimal and mainnet. Size of 2 separate ssz bundles is approximately equal to one json bundle cc @jimmygchen~~ 
Dunno what I was doing, ssz works without any issues  
4. Stores trusted_setup as just bytes in eth2_network_config so that we don't have kzg dependency in that lib and in lcli. 


Co-authored-by: realbigsean <seananderson33@gmail.com>
Co-authored-by: realbigsean <seananderson33@GMAIL.com>
This commit is contained in:
Pawan Dhananjay
2023-10-21 13:49:27 +00:00
parent 074c4951fc
commit 6315a81260
36 changed files with 142 additions and 467 deletions

View File

@@ -18,7 +18,6 @@ tokio = { workspace = true }
serde_yaml = { workspace = true }
serde_json = { workspace = true }
types = { workspace = true }
kzg = { workspace = true }
ethereum_ssz = { workspace = true }
eth2_config = { workspace = true }
discv5 = { workspace = true }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -14,7 +14,6 @@
use bytes::Bytes;
use discv5::enr::{CombinedKey, Enr};
use eth2_config::{instantiate_hardcoded_nets, HardcodedNet};
use kzg::{KzgPreset, KzgPresetId, TrustedSetup};
use pretty_reqwest_error::PrettyReqwestError;
use reqwest::{Client, Error};
use sensitive_url::SensitiveUrl;
@@ -49,35 +48,19 @@ pub const DEFAULT_HARDCODED_NETWORK: &str = "mainnet";
///
/// This is done to ensure that testnets also inherit the high security and
/// randomness of the mainnet kzg trusted setup ceremony.
const TRUSTED_SETUP: &[u8] =
include_bytes!("../built_in_network_configs/testing_trusted_setups.json");
///
/// Note: The trusted setup for both mainnet and minimal presets are the same.
pub const TRUSTED_SETUP_BYTES: &[u8] =
include_bytes!("../built_in_network_configs/trusted_setup.json");
const TRUSTED_SETUP_MINIMAL: &[u8] =
include_bytes!("../built_in_network_configs/minimal_testing_trusted_setups.json");
pub fn get_trusted_setup<P: KzgPreset>() -> &'static [u8] {
get_trusted_setup_from_id(P::spec_name())
}
pub fn get_trusted_setup_from_id(id: KzgPresetId) -> &'static [u8] {
match id {
KzgPresetId::Mainnet => TRUSTED_SETUP,
KzgPresetId::Minimal => TRUSTED_SETUP_MINIMAL,
}
}
fn get_trusted_setup_from_config(config: &Config) -> Result<Option<TrustedSetup>, String> {
/// Returns `Some(TrustedSetup)` if the deneb fork epoch is set and `None` otherwise.
///
/// Returns an error if the trusted setup parsing failed.
fn get_trusted_setup_from_config(config: &Config) -> Option<Vec<u8>> {
config
.deneb_fork_epoch
.filter(|epoch| epoch.value != Epoch::max_value())
.map(|_| {
let id = KzgPresetId::from_str(&config.preset_base)
.map_err(|e| format!("Unable to parse preset_base as KZG preset: {:?}", e))?;
let trusted_setup_bytes = get_trusted_setup_from_id(id);
serde_json::from_reader(trusted_setup_bytes)
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
})
.transpose()
.map(|_| TRUSTED_SETUP_BYTES.to_vec())
}
/// A simple slice-or-vec enum to avoid cloning the beacon state bytes in the
@@ -121,7 +104,7 @@ pub struct Eth2NetworkConfig {
pub genesis_state_source: GenesisStateSource,
pub genesis_state_bytes: Option<GenesisStateBytes>,
pub config: Config,
pub kzg_trusted_setup: Option<TrustedSetup>,
pub kzg_trusted_setup: Option<Vec<u8>>,
}
impl Eth2NetworkConfig {
@@ -139,7 +122,7 @@ impl Eth2NetworkConfig {
fn from_hardcoded_net(net: &HardcodedNet) -> Result<Self, String> {
let config: Config = serde_yaml::from_reader(net.config)
.map_err(|e| format!("Unable to parse yaml config: {:?}", e))?;
let kzg_trusted_setup = get_trusted_setup_from_config(&config)?;
let kzg_trusted_setup = get_trusted_setup_from_config(&config);
Ok(Self {
deposit_contract_deploy_block: serde_yaml::from_reader(net.deploy_block)
.map_err(|e| format!("Unable to parse deploy block: {:?}", e))?,
@@ -376,7 +359,7 @@ impl Eth2NetworkConfig {
(None, GenesisStateSource::Unknown)
};
let kzg_trusted_setup = get_trusted_setup_from_config(&config)?;
let kzg_trusted_setup = get_trusted_setup_from_config(&config);
Ok(Self {
deposit_contract_deploy_block,