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:
1 parent
074c4951fc
commit
6315a81260
36 files changed
+142
-467
No files matched your search
Generated
+2
-19
@@ -874,21 +874,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "c-kzg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/ethereum//c-kzg-4844?rev=f5f6f863d475847876a2bd5ee252058d37c3a15d#f5f6f863d475847876a2bd5ee252058d37c3a15d"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"blst",
|
||||
"cc",
|
||||
"glob",
|
||||
"hex",
|
||||
"libc",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "c-kzg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/ethereum/c-kzg-4844?rev=f5f6f863d475847876a2bd5ee252058d37c3a15d#f5f6f863d475847876a2bd5ee252058d37c3a15d"
|
||||
source = "git+https://github.com/ethereum/c-kzg-4844?rev=748283cced543c486145d5f3f38684becdfe3e1b#748283cced543c486145d5f3f38684becdfe3e1b"
|
||||
dependencies = [
|
||||
"bindgen 0.66.1",
|
||||
"blst",
|
||||
@@ -2203,7 +2189,6 @@ dependencies = [
|
||||
"discv5",
|
||||
"eth2_config",
|
||||
"ethereum_ssz",
|
||||
"kzg",
|
||||
"logging",
|
||||
"pretty_reqwest_error",
|
||||
"reqwest",
|
||||
@@ -3844,8 +3829,7 @@ name = "kzg"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"c-kzg 0.1.0 (git+https://github.com/ethereum//c-kzg-4844?rev=f5f6f863d475847876a2bd5ee252058d37c3a15d)",
|
||||
"c-kzg 0.1.0 (git+https://github.com/ethereum/c-kzg-4844?rev=f5f6f863d475847876a2bd5ee252058d37c3a15d)",
|
||||
"c-kzg",
|
||||
"derivative",
|
||||
"ethereum_hashing",
|
||||
"ethereum_serde_utils",
|
||||
@@ -3892,7 +3876,6 @@ dependencies = [
|
||||
"ethereum_ssz",
|
||||
"genesis",
|
||||
"int_to_bytes",
|
||||
"kzg",
|
||||
"lighthouse_network",
|
||||
"lighthouse_version",
|
||||
"log",
|
||||
|
||||
@@ -481,7 +481,7 @@ pub struct BeaconChain<T: BeaconChainTypes> {
|
||||
/// they are collected and combined.
|
||||
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
|
||||
/// The KZG trusted setup used by this chain.
|
||||
pub kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
|
||||
pub kzg: Option<Arc<Kzg>>,
|
||||
}
|
||||
|
||||
type BeaconBlockAndState<T, Payload> = (
|
||||
|
||||
@@ -499,7 +499,7 @@ impl<T: EthSpec> KzgVerifiedBlob<T> {
|
||||
/// Returns an error if the kzg verification check fails.
|
||||
pub fn verify_kzg_for_blob<T: EthSpec>(
|
||||
blob: Arc<BlobSidecar<T>>,
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
) -> Result<KzgVerifiedBlob<T>, AvailabilityCheckError> {
|
||||
let _timer = crate::metrics::start_timer(&crate::metrics::KZG_VERIFICATION_SINGLE_TIMES);
|
||||
if validate_blob::<T>(kzg, &blob.blob, blob.kzg_commitment, blob.kzg_proof)
|
||||
@@ -518,7 +518,7 @@ pub fn verify_kzg_for_blob<T: EthSpec>(
|
||||
/// in a loop since this function kzg verifies a list of blobs more efficiently.
|
||||
pub fn verify_kzg_for_blob_list<T: EthSpec>(
|
||||
blob_list: &BlobSidecarList<T>,
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
) -> Result<(), AvailabilityCheckError> {
|
||||
let _timer = crate::metrics::start_timer(&crate::metrics::KZG_VERIFICATION_BATCH_TIMES);
|
||||
let (blobs, (commitments, proofs)): (Vec<_>, (Vec<_>, Vec<_>)) = blob_list
|
||||
|
||||
@@ -50,7 +50,7 @@ pub struct DataAvailabilityChecker<T: BeaconChainTypes> {
|
||||
processing_cache: RwLock<ProcessingCache<T::EthSpec>>,
|
||||
availability_cache: Arc<OverflowLRUCache<T>>,
|
||||
slot_clock: T::SlotClock,
|
||||
kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
log: Logger,
|
||||
spec: ChainSpec,
|
||||
}
|
||||
@@ -79,7 +79,7 @@ impl<T: EthSpec> Debug for Availability<T> {
|
||||
impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
|
||||
pub fn new(
|
||||
slot_clock: T::SlotClock,
|
||||
kzg: Option<Arc<Kzg<<T::EthSpec as EthSpec>::Kzg>>>,
|
||||
kzg: Option<Arc<Kzg>>,
|
||||
store: BeaconStore<T>,
|
||||
log: &Logger,
|
||||
spec: ChainSpec,
|
||||
|
||||
@@ -970,6 +970,7 @@ mod test {
|
||||
) -> (
|
||||
BeaconChainHarness<DiskHarnessType<E>>,
|
||||
Arc<OverflowLRUCache<T>>,
|
||||
TempDir,
|
||||
)
|
||||
where
|
||||
E: EthSpec,
|
||||
@@ -984,7 +985,7 @@ mod test {
|
||||
OverflowLRUCache::<T>::new(capacity, test_store, spec.clone())
|
||||
.expect("should create cache"),
|
||||
);
|
||||
(harness, cache)
|
||||
(harness, cache, chain_db_path)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -992,7 +993,7 @@ mod test {
|
||||
type E = MinimalEthSpec;
|
||||
type T = DiskHarnessType<E>;
|
||||
let capacity = 4;
|
||||
let (harness, cache) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
let (harness, cache, _path) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
|
||||
let (pending_block, blobs) = availability_pending_block(&harness).await;
|
||||
let root = pending_block.import_data.block_root;
|
||||
@@ -1104,7 +1105,7 @@ mod test {
|
||||
type E = MinimalEthSpec;
|
||||
type T = DiskHarnessType<E>;
|
||||
let capacity = 4;
|
||||
let (harness, cache) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
let (harness, cache, _path) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
|
||||
let mut pending_blocks = VecDeque::new();
|
||||
let mut pending_blobs = VecDeque::new();
|
||||
@@ -1255,7 +1256,7 @@ mod test {
|
||||
type E = MinimalEthSpec;
|
||||
type T = DiskHarnessType<E>;
|
||||
let capacity = E::slots_per_epoch() as usize;
|
||||
let (harness, cache) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
let (harness, cache, _path) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
|
||||
let n_epochs = 4;
|
||||
let mut pending_blocks = VecDeque::new();
|
||||
@@ -1395,7 +1396,7 @@ mod test {
|
||||
type E = MinimalEthSpec;
|
||||
type T = DiskHarnessType<E>;
|
||||
let capacity = E::slots_per_epoch() as usize;
|
||||
let (harness, cache) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
let (harness, cache, _path) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
|
||||
let n_epochs = 4;
|
||||
let mut pending_blocks = VecDeque::new();
|
||||
@@ -1573,7 +1574,7 @@ mod test {
|
||||
type E = MinimalEthSpec;
|
||||
type T = DiskHarnessType<E>;
|
||||
let capacity = STATE_LRU_CAPACITY * 2;
|
||||
let (harness, cache) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
let (harness, cache, _path) = setup_harness_and_cache::<E, T>(capacity).await;
|
||||
|
||||
let mut pending_blocks = VecDeque::new();
|
||||
let mut states = Vec::new();
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
use kzg::{Error as KzgError, Kzg, KzgPreset};
|
||||
use kzg::{Blob as KzgBlob, Error as KzgError, Kzg};
|
||||
use types::{Blob, EthSpec, Hash256, KzgCommitment, KzgProof};
|
||||
|
||||
/// Converts a blob ssz List object to an array to be used with the kzg
|
||||
/// crypto library.
|
||||
fn ssz_blob_to_crypto_blob<T: EthSpec>(
|
||||
blob: &Blob<T>,
|
||||
) -> Result<<<T as EthSpec>::Kzg as KzgPreset>::Blob, KzgError> {
|
||||
T::blob_from_bytes(blob.as_ref())
|
||||
fn ssz_blob_to_crypto_blob<T: EthSpec>(blob: &Blob<T>) -> Result<KzgBlob, KzgError> {
|
||||
KzgBlob::from_bytes(blob.as_ref())
|
||||
}
|
||||
|
||||
/// Validate a single blob-commitment-proof triplet from a `BlobSidecar`.
|
||||
pub fn validate_blob<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
blob: &Blob<T>,
|
||||
kzg_commitment: KzgCommitment,
|
||||
kzg_proof: KzgProof,
|
||||
) -> Result<bool, KzgError> {
|
||||
kzg.verify_blob_kzg_proof(
|
||||
&ssz_blob_to_crypto_blob::<T>(blob)?,
|
||||
kzg_commitment,
|
||||
kzg_proof,
|
||||
)
|
||||
let kzg_blob = ssz_blob_to_crypto_blob::<T>(blob)?;
|
||||
kzg.verify_blob_kzg_proof(&kzg_blob, kzg_commitment, kzg_proof)
|
||||
}
|
||||
|
||||
/// Validate a batch of blob-commitment-proof triplets from multiple `BlobSidecars`.
|
||||
pub fn validate_blobs<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
expected_kzg_commitments: &[KzgCommitment],
|
||||
blobs: Vec<&Blob<T>>,
|
||||
kzg_proofs: &[KzgProof],
|
||||
@@ -40,36 +35,38 @@ pub fn validate_blobs<T: EthSpec>(
|
||||
|
||||
/// Compute the kzg proof given an ssz blob and its kzg commitment.
|
||||
pub fn compute_blob_kzg_proof<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
blob: &Blob<T>,
|
||||
kzg_commitment: KzgCommitment,
|
||||
) -> Result<KzgProof, KzgError> {
|
||||
// Avoid this blob clone
|
||||
kzg.compute_blob_kzg_proof(&ssz_blob_to_crypto_blob::<T>(blob)?, kzg_commitment)
|
||||
let kzg_blob = ssz_blob_to_crypto_blob::<T>(blob)?;
|
||||
kzg.compute_blob_kzg_proof(&kzg_blob, kzg_commitment)
|
||||
}
|
||||
|
||||
/// Compute the kzg commitment for a given blob.
|
||||
pub fn blob_to_kzg_commitment<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
blob: &Blob<T>,
|
||||
) -> Result<KzgCommitment, KzgError> {
|
||||
kzg.blob_to_kzg_commitment(&ssz_blob_to_crypto_blob::<T>(blob)?)
|
||||
let kzg_blob = ssz_blob_to_crypto_blob::<T>(blob)?;
|
||||
kzg.blob_to_kzg_commitment(&kzg_blob)
|
||||
}
|
||||
|
||||
/// Compute the kzg proof for a given blob and an evaluation point z.
|
||||
pub fn compute_kzg_proof<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
blob: &Blob<T>,
|
||||
z: Hash256,
|
||||
) -> Result<(KzgProof, Hash256), KzgError> {
|
||||
let z = z.0.into();
|
||||
kzg.compute_kzg_proof(&ssz_blob_to_crypto_blob::<T>(blob)?, &z)
|
||||
let kzg_blob = ssz_blob_to_crypto_blob::<T>(blob)?;
|
||||
kzg.compute_kzg_proof(&kzg_blob, &z)
|
||||
.map(|(proof, z)| (proof, Hash256::from_slice(&z.to_vec())))
|
||||
}
|
||||
|
||||
/// Verify a `kzg_proof` for a `kzg_commitment` that evaluating a polynomial at `z` results in `y`
|
||||
pub fn verify_kzg_proof<T: EthSpec>(
|
||||
kzg: &Kzg<T::Kzg>,
|
||||
kzg: &Kzg,
|
||||
kzg_commitment: KzgCommitment,
|
||||
kzg_proof: KzgProof,
|
||||
z: Hash256,
|
||||
|
||||
@@ -16,6 +16,7 @@ use crate::{
|
||||
};
|
||||
use bls::get_withdrawal_credentials;
|
||||
use eth2::types::SignedBlockContentsTuple;
|
||||
use eth2_network_config::TRUSTED_SETUP_BYTES;
|
||||
use execution_layer::test_utils::generate_genesis_header;
|
||||
use execution_layer::{
|
||||
auth::JwtKey,
|
||||
@@ -492,10 +493,9 @@ where
|
||||
.validator_keypairs
|
||||
.expect("cannot build without validator keypairs");
|
||||
let chain_config = self.chain_config.unwrap_or_default();
|
||||
let trusted_setup: TrustedSetup =
|
||||
serde_json::from_reader(eth2_network_config::get_trusted_setup::<E::Kzg>())
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
|
||||
.unwrap();
|
||||
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
|
||||
.unwrap();
|
||||
|
||||
let mut builder = BeaconChainBuilder::new(self.eth_spec_instance)
|
||||
.logger(log.clone())
|
||||
@@ -571,10 +571,9 @@ pub fn mock_execution_layer_from_parts<T: EthSpec>(
|
||||
HARNESS_GENESIS_TIME + spec.seconds_per_slot * T::slots_per_epoch() * epoch.as_u64()
|
||||
});
|
||||
|
||||
let trusted_setup: TrustedSetup =
|
||||
serde_json::from_reader(eth2_network_config::get_trusted_setup::<T::Kzg>())
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
|
||||
.expect("should have trusted setup");
|
||||
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {}", e))
|
||||
.expect("should have trusted setup");
|
||||
let kzg = Kzg::new_from_trusted_setup(trusted_setup).expect("should create kzg");
|
||||
|
||||
MockExecutionLayer::new(
|
||||
|
||||
@@ -14,7 +14,7 @@ use beacon_chain::{
|
||||
migrate::MigratorConfig, BeaconChain, BeaconChainError, BeaconChainTypes, BeaconSnapshot,
|
||||
BlockError, ChainConfig, NotifyExecutionLayer, ServerSentEventHandler, WhenSlotSkipped,
|
||||
};
|
||||
use eth2_network_config::get_trusted_setup;
|
||||
use eth2_network_config::TRUSTED_SETUP_BYTES;
|
||||
use kzg::TrustedSetup;
|
||||
use lazy_static::lazy_static;
|
||||
use logging::test_logger;
|
||||
@@ -2154,10 +2154,9 @@ async fn weak_subjectivity_sync_test(slots: Vec<Slot>, checkpoint_slot: Slot) {
|
||||
let store = get_store(&temp2);
|
||||
let spec = test_spec::<E>();
|
||||
let seconds_per_slot = spec.seconds_per_slot;
|
||||
let trusted_setup: TrustedSetup =
|
||||
serde_json::from_reader(get_trusted_setup::<<E as EthSpec>::Kzg>())
|
||||
.map_err(|e| println!("Unable to read trusted setup file: {}", e))
|
||||
.unwrap();
|
||||
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
|
||||
.map_err(|e| println!("Unable to read trusted setup file: {}", e))
|
||||
.unwrap();
|
||||
|
||||
let mock =
|
||||
mock_execution_layer_from_parts(&harness.spec, harness.runtime.task_executor.clone(), None);
|
||||
|
||||
@@ -14,22 +14,21 @@ use kzg::{Kzg, KzgCommitment, KzgProof};
|
||||
use parking_lot::Mutex;
|
||||
use rand::{rngs::StdRng, Rng, SeedableRng};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Decode;
|
||||
use ssz_types::VariableList;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tree_hash::TreeHash;
|
||||
use tree_hash_derive::TreeHash;
|
||||
use types::{
|
||||
Blob, ChainSpec, EthSpec, EthSpecId, ExecutionBlockHash, ExecutionPayload,
|
||||
ExecutionPayloadCapella, ExecutionPayloadDeneb, ExecutionPayloadHeader, ExecutionPayloadMerge,
|
||||
ForkName, Hash256, Transaction, Transactions, Uint256,
|
||||
Blob, ChainSpec, EthSpec, ExecutionBlockHash, ExecutionPayload, ExecutionPayloadCapella,
|
||||
ExecutionPayloadDeneb, ExecutionPayloadHeader, ExecutionPayloadMerge, ForkName, Hash256,
|
||||
Transaction, Transactions, Uint256,
|
||||
};
|
||||
|
||||
use super::DEFAULT_TERMINAL_BLOCK;
|
||||
use ssz::Decode;
|
||||
|
||||
const TEST_BLOB_BUNDLE_MAINNET: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle.ssz");
|
||||
const TEST_BLOB_BUNDLE_MINIMAL: &[u8] = include_bytes!("fixtures/minimal/test_blobs_bundle.ssz");
|
||||
const TEST_BLOB_BUNDLE: &[u8] = include_bytes!("fixtures/mainnet/test_blobs_bundle.ssz");
|
||||
|
||||
const GAS_LIMIT: u64 = 16384;
|
||||
const GAS_USED: u64 = GAS_LIMIT - 1;
|
||||
@@ -137,7 +136,7 @@ pub struct ExecutionBlockGenerator<T: EthSpec> {
|
||||
* deneb stuff
|
||||
*/
|
||||
pub blobs_bundles: HashMap<PayloadId, BlobsBundle<T>>,
|
||||
pub kzg: Option<Arc<Kzg<T::Kzg>>>,
|
||||
pub kzg: Option<Arc<Kzg>>,
|
||||
rng: Arc<Mutex<StdRng>>,
|
||||
}
|
||||
|
||||
@@ -154,7 +153,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
|
||||
terminal_block_hash: ExecutionBlockHash,
|
||||
shanghai_time: Option<u64>,
|
||||
cancun_time: Option<u64>,
|
||||
kzg: Option<Kzg<T::Kzg>>,
|
||||
kzg: Option<Kzg>,
|
||||
) -> Self {
|
||||
let mut gen = Self {
|
||||
head_block: <_>::default(),
|
||||
@@ -649,20 +648,12 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
|
||||
}
|
||||
|
||||
pub fn load_test_blobs_bundle<E: EthSpec>() -> Result<(KzgCommitment, KzgProof, Blob<E>), String> {
|
||||
let blob_bundle_bytes = match E::spec_name() {
|
||||
EthSpecId::Mainnet => TEST_BLOB_BUNDLE_MAINNET,
|
||||
EthSpecId::Minimal => TEST_BLOB_BUNDLE_MINIMAL,
|
||||
EthSpecId::Gnosis => {
|
||||
return Err("Test blobs bundle not available for Gnosis preset".to_string())
|
||||
}
|
||||
};
|
||||
|
||||
let BlobsBundle {
|
||||
let BlobsBundle::<E> {
|
||||
commitments,
|
||||
proofs,
|
||||
blobs,
|
||||
} = BlobsBundle::<E>::from_ssz_bytes(blob_bundle_bytes)
|
||||
.map_err(|e| format!("Unable to decode SSZ: {:?}", e))?;
|
||||
} = BlobsBundle::from_ssz_bytes(TEST_BLOB_BUNDLE)
|
||||
.map_err(|e| format!("Unable to decode ssz: {:?}", e))?;
|
||||
|
||||
Ok((
|
||||
commitments
|
||||
@@ -821,6 +812,7 @@ pub fn generate_pow_block(
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use eth2_network_config::TRUSTED_SETUP_BYTES;
|
||||
use kzg::TrustedSetup;
|
||||
use types::{MainnetEthSpec, MinimalEthSpec};
|
||||
|
||||
@@ -898,18 +890,17 @@ mod test {
|
||||
}
|
||||
|
||||
fn validate_blob<E: EthSpec>() -> Result<bool, String> {
|
||||
let kzg = load_kzg::<E>()?;
|
||||
let kzg = load_kzg()?;
|
||||
let (kzg_commitment, kzg_proof, blob) = load_test_blobs_bundle::<E>()?;
|
||||
let kzg_blob = E::blob_from_bytes(blob.as_ref())
|
||||
let kzg_blob = kzg::Blob::from_bytes(blob.as_ref())
|
||||
.map_err(|e| format!("Error converting blob to kzg blob: {e:?}"))?;
|
||||
kzg.verify_blob_kzg_proof(&kzg_blob, kzg_commitment, kzg_proof)
|
||||
.map_err(|e| format!("Invalid blobs bundle: {e:?}"))
|
||||
}
|
||||
|
||||
fn load_kzg<E: EthSpec>() -> Result<Kzg<E::Kzg>, String> {
|
||||
let trusted_setup: TrustedSetup =
|
||||
serde_json::from_reader(eth2_network_config::get_trusted_setup::<E::Kzg>())
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {e:?}"))?;
|
||||
fn load_kzg() -> Result<Kzg, String> {
|
||||
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {e:?}"))?;
|
||||
Kzg::new_from_trusted_setup(trusted_setup)
|
||||
.map_err(|e| format!("Failed to load trusted setup: {e:?}"))
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -46,7 +46,7 @@ impl<T: EthSpec> MockExecutionLayer<T> {
|
||||
builder_threshold: Option<u128>,
|
||||
jwt_key: Option<JwtKey>,
|
||||
spec: ChainSpec,
|
||||
kzg: Option<Kzg<T::Kzg>>,
|
||||
kzg: Option<Kzg>,
|
||||
) -> Self {
|
||||
let handle = executor.handle().unwrap();
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ impl<T: EthSpec> MockServer<T> {
|
||||
pub fn new_with_config(
|
||||
handle: &runtime::Handle,
|
||||
config: MockExecutionConfig,
|
||||
kzg: Option<Kzg<T::Kzg>>,
|
||||
kzg: Option<Kzg>,
|
||||
) -> Self {
|
||||
let MockExecutionConfig {
|
||||
jwt_key,
|
||||
@@ -188,7 +188,7 @@ impl<T: EthSpec> MockServer<T> {
|
||||
terminal_block_hash: ExecutionBlockHash,
|
||||
shanghai_time: Option<u64>,
|
||||
cancun_time: Option<u64>,
|
||||
kzg: Option<Kzg<T::Kzg>>,
|
||||
kzg: Option<Kzg>,
|
||||
) -> Self {
|
||||
Self::new_with_config(
|
||||
handle,
|
||||
|
||||
@@ -389,10 +389,12 @@ pub fn get_config<E: EthSpec>(
|
||||
client_config.trusted_setup = context
|
||||
.eth2_network_config
|
||||
.as_ref()
|
||||
.and_then(|config| config.kzg_trusted_setup.clone());
|
||||
.and_then(|config| config.kzg_trusted_setup.as_ref())
|
||||
.map(|trusted_setup_bytes| serde_json::from_slice(trusted_setup_bytes))
|
||||
.transpose()
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {}", e))?;
|
||||
|
||||
// Override default trusted setup file if required
|
||||
// TODO: consider removing this when we get closer to launch
|
||||
if let Some(trusted_setup_file_path) = cli_args.value_of("trusted-setup-file-override") {
|
||||
let file = std::fs::File::open(trusted_setup_file_path)
|
||||
.map_err(|e| format!("Failed to open trusted setup file: {}", e))?;
|
||||
|
||||
@@ -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 }
|
||||
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"setup_G1": ["0x97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", "0x854262641262cb9e056a8512808ea6864d903dbcad713fd6da8dddfa5ce40d85612c912063ace060ed8c4bf005bab839", "0x86f708eee5ae0cf40be36993e760d9cb3b2371f22db3209947c5d21ea68e55186b30871c50bf11ef29e5248bf42d5678", "0x94f9c0bafb23cbbf34a93a64243e3e0f934b57593651f3464de7dc174468123d9698f1b9dfa22bb5b6eb96eae002f29f"], "setup_G2": ["0x93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8", "0x99aca9fb2f7760cecb892bf7262c176b334824f5727f680bba701a33e322cb6667531410dfc7c8e4321a3f0ea8af48cb1436638a2093123f046f0f504cc2a864825542873edbbc5d7ed17af125a4f2cf6433c6f4f61b81173726981dd989761d", "0x88e2e982982bf8231e747e9dfcd14c05bd02623d1332734d2af26246c6869fb56ee6c994843f593178a040495ba61f4a083b0e18110b1d9f5224783d8f9a895e8ee744e87929430e9ba96bd29251cbf61240b256d1525600f3d562894d93d659", "0xa2d33775e3d9e6af0d1b27d389e6c021a578e617a3d6627686db6288d4b3dffd7a847a00f7ef01828b7f42885b660e4204923402aca18fbae74ccd4e9c50dd8c2281b38dc09c022342ed1ac695d53f7081cb21f05fdfc0a3508c04759196fcd3", "0xaf565445d2ad54c83a75c40e8895f5ad7219a8c728bce9d58d7a83716e095432993ebbd3f6911c66415a6f920d1a4d171478509b54a114308a020b33bf4487a7a8d0aa76ae4676a9b54e765a680f562d3a4fcb2e92c58b14b49b5b2917cc258f", "0x8aa99cfaf514cef4801599cadd780d222194ca1ad69a34779c2bcfda93e5dbeb931e13914421b5809a6c81f12cf7038b04a35257cc9e94c33761e68565b1274aa6a6f9d66477229747a66b308b138f92aa4326a3bf23df65a1fe33b3b289bfe1", "0x99ba36d8b4f56bde026099278548b1afc0a987cbd7c9baa51fc8e6cbb8237a17636f1a44a385cec69b05a5802059956a11fe793cabb939c38800f9c239ca2518e898ade1ec2513c9ee492071a35aabd78182392a09123d28dbc233313c9120c4", "0xa7dc40c36afccb30a2eaff250860b28b227c195cf05674704c567d77d6655c446ae835f8fc8667e71147ab02afcb2dad0babe60cbfa37d7c2cddc68d2dec54f28a4142f8353590a3902d5ddaa22066ab563dd1435dda83f276387b9767d69120", "0x939e6cc97a8b88572852a5b7f25e4838556307f60aeafb5d2b6961edbcafd4b48cb6ac980ffbacf4be963f324ba81e3d12de4f1459d8c746d0762c66ae1b166027f7fbe641d9c48f3c7d97b06d956b0be51dcc9aab65f3e99e1388e63bdd79f9", "0xb391e156541dfd4003d1697cdb7ec815b309807320574906b2e652ef0175828b356d215cd374b1b34d9f470b3fa0e643113e67b2273268f922f04f072cfb89008358185b25cd631f82911a3f20f90f75758ffb99bebb8076458ae1e9d1ae898c", "0xb9ac9c84934cc2a85c876eff65577e1dfce1935cd6392c877dd881a7d2f5c3e9344f28c04f90c62a6db4237ca00f9e0d00cb5f63e3f060fc7303916e19273b6fe455f331cabbe2fe5a22d584484f0d4176120fec9819fbb0a01e6d38695acfcd", "0x88209eb030c5d78734bf2c2a5c539653fd3c24b4c08e624f9ddc4a6550efbdc1054a56eb0c807595aad6de56fda326aa196d032a8b4b48d40140a2d77df3c7243eda6507936389a321a5811eb38e32ee433c788deeae1eb928b00940e2944bcc", "0xa8632ddc9cf7cbc1e8b74a05b7d4a89618c64afe30367ca0c9550ae7d320bf4e51c5a69e1501a1d8bee4240d13d7835501aa39fdc401a74f4d5734e268a7ce29a1fcfdb0a8bc64e0dd4a9e8578d6985bc2bc6a3764ce7a3703f6fb2e52557a2b", "0xa037ac67e8bb6f4193ac967e05d080a489f58ef8d3d30a89798246f3e4936121ee445b03e410a09e8ebc0db2e2477d110aad0ade99b0887f1eb016e750f42135866907f150bd6f4f99a8cb94281474166874808ebe03b118c5daab16dafdc38b", "0xa50d9143116bffa3b237da8e1805327e81e9cd25e658289bd727d5f9e0020172cc8690dcfe31a240e5cbc48353b88c4908baa1dd7320165556e0aa633f62fcbe7870222d345a3bbcdb7ab6c07f0fd86be559964afabf56f0a8cbc0b4b91d477e", "0xafa988ea6fa4f40c5ad07d2d580d29025ddf56d6ef1171a8b8de3464203f70b97d6f5ace72747345204b35150e06154d1477516a989ce8eea7871cc0d0de00a077c0fb23ad4837e409d0b885bf3f2dde11a30fa6273d662e68e09f461e52932f", "0x97fa1a943ed8b81574304a3d03f4f15907f6e6e0cd36a66bd2ad2c75afafc70a61d3ff69b77ebe4dae9ca0fcedef80081062705e60bbb6ea0f1f398c84d2f8e4a3ac142ac66426c21ad5e9994ebbcc406af474c4aec5e32fadcb21875af7c9f1", "0xb30a564614493886f14a5dd71c89457504f8c59a7ac01b665ed167e9a8f9ee5832198fd319ecd234196ee57031bdf3840bd5a923e203a1938bc795c704b5285389750e1fd10d7050061ba19db00a60a2c0384a7d661d7d48ebe6962272230859", "0x84c8dea942cfae71cb02e705ec496d967425793ce8812e7ee53c2f23713abeaff566a658cd1c73dfd18187d16253a6ee0a623e82cd18e31cd1a1875d19c078835dc9292e141686150a88065226ada264740143e87c03a0f6c4da8c187438ebf4", "0x8c3abae8aed60338f8c4ff80aab22f8a2ae56756a93566c906f490a97151d34a1c3318054e1c494c60cc53327ad86a2d02c6c76a406726ce4f88635bc32eff0db0b61762dc518b95fa8da82e87e4bf3de54f1d72180ef53ed7bc5413e6a9a510", "0xa328230c92a6b1cef6a444bcb64edb992f71e3d7b93f0b6b8b408ba7c908db746d92ddb2c7588bab438ef3bc61be1c2f0dfc86ba2ff514b42b35c80f89b2e780f813ea1dfb977fbded2cd9b553b747fa952e227ebd8f071163d421fc337f04c9", "0xb482cab423cd5f1c5df036070aade7aa016283d69619d664025c3feab866a0a5691d344b2ee2bedc5dedd1f9a73eae16003a3827c9e5bbe22ded32d848fba840ffad1141ad158f5c40bc8ae0d03781b9705d851a7f1391b096c576c0f4f2a6b0", "0x919ee1df27fabcb21237a1b7b98f53d41d849e1b6a8f9e28c3fae2841c6b5a250e4041c737e6725476e5cd715e34d3880f58d80f61efaabc261bdc703e8750f48a923e9bf8980931b9fd9e40014c66c54b3e7c98241d76d1aa47af43313a65a1", "0xac9483Line truncated
|
||||
@@ -1 +0,0 @@
|
||||
{"setup_G1": ["0x97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb", "0x854262641262cb9e056a8512808ea6864d903dbcad713fd6da8dddfa5ce40d85612c912063ace060ed8c4bf005bab839", "0x86f708eee5ae0cf40be36993e760d9cb3b2371f22db3209947c5d21ea68e55186b30871c50bf11ef29e5248bf42d5678", "0x94f9c0bafb23cbbf34a93a64243e3e0f934b57593651f3464de7dc174468123d9698f1b9dfa22bb5b6eb96eae002f29f", "0x82b8775b874067bdd4479ac237f8d56036a742c17901354caaf38bf8c70e696650fbec76f0cd941ed8c658f44ea359ff", "0xa7ce299c79c7d7e4f1adecd754c5aff8a720728ab27f5737b7b399f72724407ac54965088596375b8c876665ed8e4ff1", "0x81ca4c808a76a6f217f8b0540ff400199295da69b2587b7be6aeb56447fa4fac08d154a27c4aa6082bc40660078d36e9", "0xa70bad5311c97f1f3fea5d3375da1a11ba948aca41609ea28666dd343e07af766834e1256dc685ac1dcd915073250864", "0xa91c2911a658ba79f56abe30716a3398387630e785b351b07344022a04b2f5c90de5573bd6e8048fe8878dde19336c5b", "0xa8c560283fce9813bcbaddfb78cff93efcbc39b33025cfad94ebd40942a9fa605d2a947dc3a1f03c2e454075892e96bf", "0xaa14f07fbd2c1ce7bd995e335c69b5f675ea573517c1834e787b30ab4fa10aecc62ecc5e617ac8a539af1aff114dc9ec", "0x87f03429aff126b7c5a918423da278e17b5f48a4cdd6d34dba77a75f4f99e26a417e65d6a8579bcb2eaaf1d4d8c64dce", "0xb1ac81ba91ede78315f712d524e9d821a152203f04141ba77f4e481ad5881473dff14a71788ce941f0905b429e7ee5b2", "0x8f5c2af611ddfa3edf7e442d00e56a24d615bac848c05070c908c741ba18b67eb2e82e6651c9b3c70fb8edbf051810c4", "0xaa4115b19221e4d17cc335d4f9b0aad22df566231f2286d550e97ff2875cbc419edfa189c4ecb24001123b95c6aaa2da", "0xb363ba913969df0debd4e2712ae6e9177ce82e169ce7e0ff1d7616ef8e352aff3efb40fffbf7bff1b21cb8a33e19b455", "0xb1013d778727d20466778cea47e1bf56a77168a8ce1b33bb1265f66438ab2bf4a7df4f4142b8681f2993ea9baf798d17", "0x83b7250ee17d8529207db97b73c1c4a92ac076951a577ce2fe3a2cd633b461c1820c139ab36a895a5962e143c6198386", "0x86d180bd2f0a4919764e6f4e846ec0d5ebe44060ec1e529ed15101d7e531bf1b8f9412916ea5aeb93b37b2d7c6bfb408", "0x827451462c79d74b504c01bda199481b3c70416f66a95b2216686ca4d48da48932b0d323d0cd630a1e86e8033e832e5f", "0xb789d217cb12c334fedff0ae01f85b96e968fb98761755d1ba3ee17934e8fbd83172225df7c0c6cb99432a30a0ef8c24", "0xb730e5412dfbd646b0d2fe084a1a32eb5596c3fe8a5bc0f430151804f9e67f05f70b522e9aef08082b0afdc652a1d213", "0x9987653bacd9bc1659b17f6964aec06ea63b787813d4601bee0479706aed5595ac82c87ed4f96f0cd30c19e1d9510a91", "0x9506a9ba38f1d26c35a17c7e2554e28eb347a19cef523846a2559fb80fb40306b2f85bdc2c9fb98c2267df21c1ee3589", "0x98dda58de74c0cdaef97b2826b4a9d53c9e9ea592dc0a755ccf5b3fbc1264979578563f5979aaa246e679918053c5f83", "0xb00aaa16841ab53883af481e2f925050f5f7bf7d8088bc696f55f30593bdbbaf434f5d2b46095ed097b6cdb96c8fbc3b", "0xb463d656480f89335d3a840a7b9398877003985388871b148ba708c60f9857c7585ef17c8b2ae67fbb191c04ad61e692", "0x80af54f3d0584126e23635276d650292baf7e3e12bb06468708107bcd80937d36575721ee7472c5f085ffa71dbf438ad", "0x94ccb8ade84e834685110c96908b42e10d2184208f434d7f98d96cc158e0c0c95135979600e5e9f465d5846b0bb3c787", "0x8e13674b00c633d7cceb4f6ecd61e4f99420d6cccf9db5e81f8c90f6c661bc76e10939b83b56c225fce8565f525d4fa4", "0xa46a15b2e671c1a1df2490768dec1093caf537e1a21fbc11ff8ba8b21b9f2be8d50257027d9357df20d9fbb1307d7249", "0xb8ed532d48b0533a3084d7a5eea7b401255c5825e9a1b80ed81fd530cd69e347d152b1ad8a899acff7d68e0103bbfbde", "0xad6b7df980ebaa24177d830c4aa522d6179a9a489257f60ee6604cccc2cbe90fb1f72aa9d5bee0d3a88f73b179485f56", "0xa56855e9fcf62ceef3043991a93ec24f8f6b5667ef5fb7ad1771249ece68a73580ec3cf3e58a009ca4650c01241ad172", "0xab2f25517d4b0b33d317eb78d091d3c3f98dc352b8a3e4650f7005f9327129e23d95f38eaeda5e9b51c50a31d20a4c20", "0xa2d4071385b8a421da86f39739eaadcdea5685466feb6ac083cba0ea4c71dbbdf655032097276d703f9a77a4ca6fab03", "0xa8681d7c258984f01e92e92c95738692b7bbd59c3a802adf4dda8d34add69590b080391c09e98e3b75c085c9f191e5e5", "0x97685643da6c07b5e5fe91393122813ba11c8ef3dbd43a03b3a22a7a1603201fd516c1929418eafb14039270694c239a", "0xa7bb3b85d6101e4fb0bcf540f52041cdb3e819d517465e342b832f0e91346a9a18bdb38845ea4d2b71ab87ef3bf59f96", "0x8afc90b7d35336fdcf8f81cd024e921e244520ecfcb5a3994f2bbd595366b68bfa792a8dceb11e1e889b11432c9dad6b", "0x94d9db7bd04f962d8d6caa3b7aa0f19acbd58a09d35ae187158d77e537d2fc65215f51f1afd62d4ba378e7d176a680f9", "0xad62d7c01b14b6f97e6084ec9f9d084f106a7ff3d603032e6e34c027cdce4b0fe3c20ac7931f1209439a59c9fede4815", "0xa5b44a87bd0ada7498e011e495a2818a8694746c4e7dc9d24c0c1096f54be6439e08c1b11c10d7c4bf68fe392000e971", "0x828626c6609acc599f1bf216e9a4310fc3cb227e0d2e47bfe3360239427c8b0cc300cddf92456a5c36620596a6d37027", "0x8380f91baac6447dd39886455ec5d99b874ac114a3c6a6ded18fc4ef69c2208ec19732428d8329d200a69f31792b852e", "0x85a8389b522b0a686234450165514127006baaa3907f6eb29c976522591a542ffb681b3b88c4886814fd7ba3cc8110f7", "0xb8ae7949ddafad37c0bc4d48325a7cbcd3096fb92c04a027c650a03cc609c7eac250d6a7ba341616bc36f64f1b4c8be4", "0x8f9b9d2c2ab5c85abe946ed9986e0f304281b277d4d48c7760ea2331b55a9e9a1c4d53a6bdd83fa6294f421ca7431e29", "0x9464b906ea8bc994b31e03c5f2af2be0724a43293fd42cbd2263b2de75a2ec04832d1100ce62ac2c0708f0Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
{"g1_lagrange":["0xa0413c0dcafec6dbc9f47d66785cf1e8c981044f7d13cfe3e4fcbb71b5408dfde6312493cb3c1d30516cb3ca88c03654","0x8b997fb25730d661918371bb41f2a6e899cac23f04fc5365800b75433c0a953250e15e7a98fb5ca5cc56a8cd34c20c57","0x83302852db89424d5699f3f157e79e91dc1380f8d5895c5a772bb4ea3a5928e7c26c07db6775203ce33e62a114adaa99","0xa759c48b7e4a685e735c01e5aa6ef9c248705001f470f9ad856cd87806983e917a8742a3bd5ee27db8d76080269b7c83","0x967f8dc45ebc3be14c8705f43249a30ff48e96205fb02ae28daeab47b72eb3f45df0625928582aa1eb4368381c33e127","0xa418eb1e9fb84cb32b370610f56f3cb470706a40ac5a47c411c464299c45c91f25b63ae3fcd623172aa0f273c0526c13","0x8f44e3f0387293bc7931e978165abbaed08f53acd72a0a23ac85f6da0091196b886233bcee5b4a194db02f3d5a9b3f78","0x97173434b336be73c89412a6d70d416e170ea355bf1956c32d464090b107c090ef2d4e1a467a5632fbc332eeb679bf2d","0xa24052ad8d55ad04bc5d951f78e14213435681594110fd18173482609d5019105b8045182d53ffce4fc29fc8810516c1","0xb950768136b260277590b5bec3f56bbc2f7a8bc383d44ce8600e85bf8cf19f479898bcc999d96dfbd2001ede01d94949","0x92ab8077871037bd3b57b95cbb9fb10eb11efde9191690dcac655356986fd02841d8fdb25396faa0feadfe3f50baf56d","0xa79b096dff98038ac30f91112dd14b78f8ad428268af36d20c292e2b3b6d9ed4fb28480bb04e465071cc67d05786b6d1","0xb9ff71461328f370ce68bf591aa7fb13027044f42a575517f3319e2be4aa4843fa281e756d0aa5645428d6dfa857cef2","0x8d765808c00b3543ff182e2d159c38ae174b12d1314da88ea08e13bd9d1c37184cb515e6bf6420531b5d41767987d7ce","0xb8c9a837d20c3b53e6f578e4a257bb7ef8fc43178614ec2a154915b267ad2be135981d01ed2ee1b5fbd9d9bb27f0800a","0xa9773d92cf23f65f98ef68f6cf95c72b53d0683af2f9bf886bb9036e4a38184b1131b26fd24397910b494fbef856f3aa","0xb41ebe38962d112da4a01bf101cb248d808fbd50aaf749fc7c151cf332032eb3e3bdbd716db899724b734d392f26c412","0x90fbb030167fb47dcc13d604a726c0339418567c1d287d1d87423fa0cb92eec3455fbb46bcbe2e697144a2d3972142e4","0xb11d298bd167464b35fb923520d14832bd9ed50ed841bf6d7618424fd6f3699190af21759e351b89142d355952149da1","0x8bc36066f69dc89f7c4d1e58d67497675050c6aa002244cebd9fc957ec5e364c46bab4735ea3db02b73b3ca43c96e019","0xab7ab92c5d4d773068e485aa5831941ebd63db7118674ca38089635f3b4186833af2455a6fb9ed2b745df53b3ce96727","0xaf191ca3089892cb943cd97cf11a51f38e38bd9be50844a4e8da99f27e305e876f9ed4ab0628e8ae3939066b7d34a15f","0xa3204c1747feabc2c11339a542195e7cb6628fd3964f846e71e2e3f2d6bb379a5e51700682ea1844eba12756adb13216","0x903a29883846b7c50c15968b20e30c471aeac07b872c40a4d19eb1a42da18b649d5bbfde4b4cf6225d215a461b0deb6d","0x8e6e9c15ffbf1e16e5865a5fef7ed751dc81957a9757b535cb38b649e1098cda25d42381dc4f776778573cdf90c3e6e0","0xa8f6dd26100b512a8c96c52e00715c4b2cb9ac457f17aed8ffe1cf1ea524068fe5a1ddf218149845fc1417b789ecfc98","0xa5b0ffc819451ea639cfd1c18cbc9365cc79368d3b2e736c0ae54eba2f0801e6eb0ee14a5f373f4a70ca463bdb696c09","0x879f91ccd56a1b9736fbfd20d8747354da743fb121f0e308a0d298ff0d9344431890e41da66b5009af3f442c636b4f43","0x81bf3a2d9755e206b515a508ac4d1109bf933c282a46a4ae4a1b4cb4a94e1d23642fad6bd452428845afa155742ade7e","0x8de778d4742f945df40004964e165592f9c6b1946263adcdd5a88b00244bda46c7bb49098c8eb6b3d97a0dd46148a8ca","0xb7a57b21d13121907ee28c5c1f80ee2e3e83a3135a8101e933cf57171209a96173ff5037f5af606e9fd6d066de6ed693","0xb0877d1963fd9200414a38753dffd9f23a10eb3198912790d7eddbc9f6b477019d52ddd4ebdcb9f60818db076938a5a9","0x88da2d7a6611bc16adc55fc1c377480c828aba4496c645e3efe0e1a67f333c05a0307f7f1d2df8ac013602c655c6e209","0x95719eb02e8a9dede1a888c656a778b1c69b7716fbe3d1538fe8afd4a1bc972183c7d32aa7d6073376f7701df80116d8","0x8e8a1ca971f2444b35af3376e85dccda3abb8e8e11d095d0a4c37628dfe5d3e043a377c3de68289ef142e4308e9941a0","0xb720caaff02f6d798ac84c4f527203e823ff685869e3943c979e388e1c34c3f77f5c242c6daa7e3b30e511aab917b866","0x86040d55809afeec10e315d1ad950d269d37cfee8c144cd8dd4126459e3b15a53b3e68df5981df3c2346d23c7b4baaf4","0x82d8cabf13ab853db0377504f0aec00dba3a5cd3119787e8ad378ddf2c40b022ecfc67c642b7acc8c1e3dd03ab50993e","0xb8d873927936719d2484cd03a6687d65697e17dcf4f0d5aed6f5e4750f52ef2133d4645894e7ebfc4ef6ce6788d404c8","0xb1235594dbb15b674a419ff2b2deb644ad2a93791ca05af402823f87114483d6aa1689b7a9bea0f547ad12fe270e4344","0xa53fda86571b0651f5affb74312551a082fffc0385cfd24c1d779985b72a5b1cf7c78b42b4f7e51e77055f8e5e915b00","0xb579adcfd9c6ef916a5a999e77a0cb21d378c4ea67e13b7c58709d5da23a56c2e54218691fc4ac39a4a3d74f88cc31f7","0xab79e584011713e8a2f583e483a91a0c2a40771b77d91475825b5acbea82db4262132901cb3e4a108c46d7c9ee217a4e","0xa0fe58ea9eb982d7654c8aaf9366230578fc1362f6faae0594f8b9e659bcb405dff4aac0c7888bbe07f614ecf0d800a6","0x867e50e74281f28ecd4925560e2e7a6f8911b135557b688254623acce0dbc41e23ac3e706a184a45d54c586edc416eb0","0x89f81b61adda20ea9d0b387a36d0ab073dc7c7cbff518501962038be19867042f11fcc7ff78096e5d3b68c6d8dc04d9b","0xa58ee91bb556d43cf01f1398c5811f76dc0f11efdd569eed9ef178b3b0715e122060ec8f945b4dbf6eebfa2b90af6fa6","0xac460be540f4c840def2eef19fc754a9af34608d107cbadb53334cf194cc91138d53b9538fcd0ec970b5d4aa455b224a","0xb09b91f929de52c09d48ca0893be6eb44e2f5210a6c394689dc1f7729d4be4e11d0474b178e80cea8c2ac0d081f0e811","0x8d37a442a76b06a02a4e64c2504aea7Line truncated
|
||||
@@ -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,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Misc
|
||||
# ---------------------------------------------------------------
|
||||
# [customized]
|
||||
FIELD_ELEMENTS_PER_BLOB: 4
|
||||
FIELD_ELEMENTS_PER_BLOB: 4096
|
||||
# [customized]
|
||||
MAX_BLOB_COMMITMENTS_PER_BLOCK: 16
|
||||
# `uint64(6)`
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use crate::test_utils::TestRandom;
|
||||
use crate::{Blob, EthSpec, Hash256, SignedRoot, Slot};
|
||||
use derivative::Derivative;
|
||||
use kzg::{Kzg, KzgCommitment, KzgPreset, KzgProof, BYTES_PER_FIELD_ELEMENT};
|
||||
use kzg::{
|
||||
Blob as KzgBlob, Kzg, KzgCommitment, KzgProof, BYTES_PER_BLOB, BYTES_PER_FIELD_ELEMENT,
|
||||
FIELD_ELEMENTS_PER_BLOB,
|
||||
};
|
||||
use rand::Rng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz::Encode;
|
||||
@@ -142,12 +145,12 @@ impl<T: EthSpec> BlobSidecar<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn random_valid<R: Rng>(rng: &mut R, kzg: &Kzg<T::Kzg>) -> Result<Self, String> {
|
||||
let mut blob_bytes = vec![0u8; T::Kzg::BYTES_PER_BLOB];
|
||||
pub fn random_valid<R: Rng>(rng: &mut R, kzg: &Kzg) -> Result<Self, String> {
|
||||
let mut blob_bytes = vec![0u8; BYTES_PER_BLOB];
|
||||
rng.fill_bytes(&mut blob_bytes);
|
||||
// Ensure that the blob is canonical by ensuring that
|
||||
// each field element contained in the blob is < BLS_MODULUS
|
||||
for i in 0..T::Kzg::FIELD_ELEMENTS_PER_BLOB {
|
||||
for i in 0..FIELD_ELEMENTS_PER_BLOB {
|
||||
let Some(byte) = blob_bytes.get_mut(
|
||||
i.checked_mul(BYTES_PER_FIELD_ELEMENT)
|
||||
.ok_or("overflow".to_string())?,
|
||||
@@ -159,7 +162,7 @@ impl<T: EthSpec> BlobSidecar<T> {
|
||||
|
||||
let blob = Blob::<T>::new(blob_bytes)
|
||||
.map_err(|e| format!("error constructing random blob: {:?}", e))?;
|
||||
let kzg_blob = T::blob_from_bytes(&blob).unwrap();
|
||||
let kzg_blob = KzgBlob::from_bytes(&blob).unwrap();
|
||||
|
||||
let commitment = kzg
|
||||
.blob_to_kzg_commitment(&kzg_blob)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::*;
|
||||
|
||||
use kzg::{BlobTrait, KzgPreset, MainnetKzgPreset, MinimalKzgPreset};
|
||||
use safe_arith::SafeArith;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ssz_types::typenum::{
|
||||
@@ -52,8 +51,6 @@ impl fmt::Display for EthSpecId {
|
||||
pub trait EthSpec:
|
||||
'static + Default + Sync + Send + Clone + Debug + PartialEq + Eq + for<'a> arbitrary::Arbitrary<'a>
|
||||
{
|
||||
type Kzg: KzgPreset;
|
||||
|
||||
/*
|
||||
* Constants
|
||||
*/
|
||||
@@ -270,10 +267,6 @@ pub trait EthSpec:
|
||||
Self::FieldElementsPerBlob::to_usize()
|
||||
}
|
||||
|
||||
fn blob_from_bytes(bytes: &[u8]) -> Result<<Self::Kzg as KzgPreset>::Blob, kzg::Error> {
|
||||
<Self::Kzg as KzgPreset>::Blob::from_bytes(bytes)
|
||||
}
|
||||
|
||||
/// Returns the `BYTES_PER_BLOB` constant for this specification.
|
||||
fn bytes_per_blob() -> usize {
|
||||
Self::BytesPerBlob::to_usize()
|
||||
@@ -293,8 +286,6 @@ macro_rules! params_from_eth_spec {
|
||||
pub struct MainnetEthSpec;
|
||||
|
||||
impl EthSpec for MainnetEthSpec {
|
||||
type Kzg = MainnetKzgPreset;
|
||||
|
||||
type JustificationBitsLength = U4;
|
||||
type SubnetBitfieldLength = U64;
|
||||
type MaxValidatorsPerCommittee = U2048;
|
||||
@@ -344,8 +335,6 @@ impl EthSpec for MainnetEthSpec {
|
||||
pub struct MinimalEthSpec;
|
||||
|
||||
impl EthSpec for MinimalEthSpec {
|
||||
type Kzg = MinimalKzgPreset;
|
||||
|
||||
type SlotsPerEpoch = U8;
|
||||
type EpochsPerEth1VotingPeriod = U4;
|
||||
type SlotsPerHistoricalRoot = U64;
|
||||
@@ -356,8 +345,8 @@ impl EthSpec for MinimalEthSpec {
|
||||
type MaxPendingAttestations = U1024; // 128 max attestations * 8 slots per epoch
|
||||
type SlotsPerEth1VotingPeriod = U32; // 4 epochs * 8 slots per epoch
|
||||
type MaxWithdrawalsPerPayload = U4;
|
||||
type FieldElementsPerBlob = U4;
|
||||
type BytesPerBlob = U128;
|
||||
type FieldElementsPerBlob = U4096;
|
||||
type BytesPerBlob = U131072;
|
||||
type MaxBlobCommitmentsPerBlock = U16;
|
||||
|
||||
params_from_eth_spec!(MainnetEthSpec {
|
||||
@@ -398,8 +387,6 @@ impl EthSpec for MinimalEthSpec {
|
||||
pub struct GnosisEthSpec;
|
||||
|
||||
impl EthSpec for GnosisEthSpec {
|
||||
type Kzg = MainnetKzgPreset;
|
||||
|
||||
type JustificationBitsLength = U4;
|
||||
type SubnetBitfieldLength = U64;
|
||||
type MaxValidatorsPerCommittee = U2048;
|
||||
|
||||
@@ -16,10 +16,4 @@ serde = { workspace = true }
|
||||
ethereum_serde_utils = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
ethereum_hashing = { workspace = true }
|
||||
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", rev = "f5f6f863d475847876a2bd5ee252058d37c3a15d" , features = ["mainnet-spec", "serde"]}
|
||||
c_kzg_min = { package = "c-kzg", git = "https://github.com/ethereum//c-kzg-4844", rev = "f5f6f863d475847876a2bd5ee252058d37c3a15d", features = ["minimal-spec", "serde"], optional = true }
|
||||
|
||||
[features]
|
||||
# TODO(deneb): enabled by default for convenience, would need more cfg magic to disable
|
||||
default = ["c_kzg_min"]
|
||||
minimal-spec = ["c_kzg_min"]
|
||||
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", rev = "748283cced543c486145d5f3f38684becdfe3e1b"}
|
||||
@@ -34,12 +34,6 @@ impl From<KzgCommitment> for c_kzg::Bytes48 {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KzgCommitment> for c_kzg_min::Bytes48 {
|
||||
fn from(value: KzgCommitment) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for KzgCommitment {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", serde_utils::hex::encode(self.0))
|
||||
|
||||
@@ -17,12 +17,6 @@ impl From<KzgProof> for c_kzg::Bytes48 {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KzgProof> for c_kzg_min::Bytes48 {
|
||||
fn from(value: KzgProof) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl KzgProof {
|
||||
/// Creates a valid proof using `G1_POINT_AT_INFINITY`.
|
||||
pub fn empty() -> Self {
|
||||
|
||||
+36
-281
@@ -2,297 +2,54 @@ mod kzg_commitment;
|
||||
mod kzg_proof;
|
||||
mod trusted_setup;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Debug;
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub use crate::{kzg_commitment::KzgCommitment, kzg_proof::KzgProof, trusted_setup::TrustedSetup};
|
||||
pub use c_kzg::{Bytes32, Bytes48, BYTES_PER_COMMITMENT, BYTES_PER_FIELD_ELEMENT, BYTES_PER_PROOF};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
InvalidTrustedSetup(CryptoError),
|
||||
InvalidKzgProof(CryptoError),
|
||||
InvalidBytes(CryptoError),
|
||||
KzgProofComputationFailed(CryptoError),
|
||||
InvalidBlob(CryptoError),
|
||||
InvalidBytesForBlob(CryptoError),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CryptoError {
|
||||
CKzg(c_kzg::Error),
|
||||
CKzgMin(c_kzg_min::Error),
|
||||
/// Trusted setup is for the incorrect kzg preset.
|
||||
InconsistentTrustedSetup,
|
||||
}
|
||||
|
||||
impl From<c_kzg::Error> for CryptoError {
|
||||
fn from(e: c_kzg::Error) -> Self {
|
||||
Self::CKzg(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<c_kzg_min::Error> for CryptoError {
|
||||
fn from(e: c_kzg_min::Error) -> Self {
|
||||
Self::CKzgMin(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BlobTrait: Sized + Clone {
|
||||
fn from_bytes(bytes: &[u8]) -> Result<Self, Error>;
|
||||
}
|
||||
|
||||
pub enum KzgPresetId {
|
||||
Mainnet,
|
||||
Minimal,
|
||||
}
|
||||
|
||||
impl FromStr for KzgPresetId {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"mainnet" => Ok(KzgPresetId::Mainnet),
|
||||
"minimal" => Ok(KzgPresetId::Minimal),
|
||||
_ => Err(format!("Unknown eth spec: {}", s)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait KzgPreset:
|
||||
'static + Default + Sync + Send + Clone + Debug + PartialEq + Eq + for<'a> arbitrary::Arbitrary<'a>
|
||||
{
|
||||
type KzgSettings: Debug + Sync + Send;
|
||||
type Blob: BlobTrait;
|
||||
type Bytes32: From<[u8; 32]> + Deref<Target = [u8; 32]>;
|
||||
type Bytes48: From<KzgCommitment> + From<KzgProof>;
|
||||
type Error: Into<CryptoError>;
|
||||
|
||||
const BYTES_PER_BLOB: usize;
|
||||
const FIELD_ELEMENTS_PER_BLOB: usize;
|
||||
|
||||
fn spec_name() -> KzgPresetId;
|
||||
|
||||
fn bytes32_in(bytes: Bytes32) -> Self::Bytes32 {
|
||||
let bytes: [u8; 32] = *bytes;
|
||||
Self::Bytes32::from(bytes)
|
||||
}
|
||||
|
||||
fn bytes32_out(bytes: Self::Bytes32) -> Bytes32 {
|
||||
let bytes: [u8; 32] = *bytes;
|
||||
Bytes32::from(bytes)
|
||||
}
|
||||
|
||||
fn load_trusted_setup(trusted_setup: TrustedSetup) -> Result<Self::KzgSettings, CryptoError>;
|
||||
|
||||
fn compute_blob_kzg_proof(
|
||||
blob: &Self::Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<KzgProof, CryptoError>;
|
||||
|
||||
fn verify_blob_kzg_proof(
|
||||
blob: &Self::Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
kzg_proof: KzgProof,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<bool, CryptoError>;
|
||||
|
||||
fn verify_blob_kzg_proof_batch(
|
||||
blobs: &[Self::Blob],
|
||||
commitments_bytes: &[Self::Bytes48],
|
||||
proofs_bytes: &[Self::Bytes48],
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<bool, CryptoError>;
|
||||
|
||||
fn blob_to_kzg_commitment(
|
||||
blob: &Self::Blob,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<KzgCommitment, CryptoError>;
|
||||
|
||||
fn compute_kzg_proof(
|
||||
blob: &Self::Blob,
|
||||
z: &Self::Bytes32,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<(KzgProof, Self::Bytes32), CryptoError>;
|
||||
|
||||
fn verify_kzg_proof(
|
||||
kzg_commitment: KzgCommitment,
|
||||
z: &Self::Bytes32,
|
||||
y: &Self::Bytes32,
|
||||
kzg_proof: KzgProof,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<bool, CryptoError>;
|
||||
}
|
||||
|
||||
macro_rules! implement_kzg_preset {
|
||||
($preset_type:ident, $module_name:ident, $preset_id:ident) => {
|
||||
impl KzgPreset for $preset_type {
|
||||
type KzgSettings = $module_name::KzgSettings;
|
||||
type Blob = $module_name::Blob;
|
||||
type Bytes32 = $module_name::Bytes32;
|
||||
type Bytes48 = $module_name::Bytes48;
|
||||
type Error = $module_name::Error;
|
||||
|
||||
const BYTES_PER_BLOB: usize = $module_name::BYTES_PER_BLOB;
|
||||
const FIELD_ELEMENTS_PER_BLOB: usize = $module_name::FIELD_ELEMENTS_PER_BLOB;
|
||||
|
||||
fn spec_name() -> KzgPresetId {
|
||||
KzgPresetId::$preset_id
|
||||
}
|
||||
|
||||
fn load_trusted_setup(
|
||||
trusted_setup: TrustedSetup,
|
||||
) -> Result<Self::KzgSettings, CryptoError> {
|
||||
if trusted_setup.g1_len() != Self::FIELD_ELEMENTS_PER_BLOB {
|
||||
return Err(CryptoError::InconsistentTrustedSetup);
|
||||
}
|
||||
$module_name::KzgSettings::load_trusted_setup(
|
||||
&trusted_setup.g1_points(),
|
||||
&trusted_setup.g2_points(),
|
||||
)
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
|
||||
fn compute_blob_kzg_proof(
|
||||
blob: &Self::Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<KzgProof, CryptoError> {
|
||||
$module_name::KzgProof::compute_blob_kzg_proof(
|
||||
blob,
|
||||
&kzg_commitment.into(),
|
||||
trusted_setup,
|
||||
)
|
||||
.map(|proof| KzgProof(proof.to_bytes().into_inner()))
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
|
||||
fn verify_blob_kzg_proof(
|
||||
blob: &Self::Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
kzg_proof: KzgProof,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<bool, CryptoError> {
|
||||
$module_name::KzgProof::verify_blob_kzg_proof(
|
||||
blob,
|
||||
&kzg_commitment.into(),
|
||||
&kzg_proof.into(),
|
||||
trusted_setup,
|
||||
)
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
|
||||
fn verify_blob_kzg_proof_batch(
|
||||
blobs: &[Self::Blob],
|
||||
commitments_bytes: &[Self::Bytes48],
|
||||
proofs_bytes: &[Self::Bytes48],
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<bool, CryptoError> {
|
||||
$module_name::KzgProof::verify_blob_kzg_proof_batch(
|
||||
blobs,
|
||||
commitments_bytes,
|
||||
proofs_bytes,
|
||||
trusted_setup,
|
||||
)
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
|
||||
fn blob_to_kzg_commitment(
|
||||
blob: &Self::Blob,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<KzgCommitment, CryptoError> {
|
||||
$module_name::KzgCommitment::blob_to_kzg_commitment(blob, trusted_setup)
|
||||
.map(|com| KzgCommitment(com.to_bytes().into_inner()))
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
|
||||
fn compute_kzg_proof(
|
||||
blob: &Self::Blob,
|
||||
z: &Self::Bytes32,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<(KzgProof, Self::Bytes32), CryptoError> {
|
||||
$module_name::KzgProof::compute_kzg_proof(blob, z, trusted_setup)
|
||||
.map(|(proof, y)| (KzgProof(proof.to_bytes().into_inner()), y))
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
|
||||
fn verify_kzg_proof(
|
||||
kzg_commitment: KzgCommitment,
|
||||
z: &Self::Bytes32,
|
||||
y: &Self::Bytes32,
|
||||
kzg_proof: KzgProof,
|
||||
trusted_setup: &Self::KzgSettings,
|
||||
) -> Result<bool, CryptoError> {
|
||||
$module_name::KzgProof::verify_kzg_proof(
|
||||
&kzg_commitment.into(),
|
||||
z,
|
||||
y,
|
||||
&kzg_proof.into(),
|
||||
trusted_setup,
|
||||
)
|
||||
.map_err(CryptoError::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl BlobTrait for $module_name::Blob {
|
||||
fn from_bytes(bytes: &[u8]) -> Result<Self, Error> {
|
||||
Self::from_bytes(bytes)
|
||||
.map_err(CryptoError::from)
|
||||
.map_err(Error::InvalidBlob)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, arbitrary::Arbitrary)]
|
||||
pub struct MainnetKzgPreset;
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, arbitrary::Arbitrary)]
|
||||
pub struct MinimalKzgPreset;
|
||||
|
||||
implement_kzg_preset!(MainnetKzgPreset, c_kzg, Mainnet);
|
||||
implement_kzg_preset!(MinimalKzgPreset, c_kzg_min, Minimal);
|
||||
pub use c_kzg::{
|
||||
Blob, Bytes32, Bytes48, Error, KzgSettings, BYTES_PER_BLOB, BYTES_PER_COMMITMENT,
|
||||
BYTES_PER_FIELD_ELEMENT, BYTES_PER_PROOF, FIELD_ELEMENTS_PER_BLOB,
|
||||
};
|
||||
|
||||
/// A wrapper over a kzg library that holds the trusted setup parameters.
|
||||
#[derive(Debug)]
|
||||
pub struct Kzg<P: KzgPreset> {
|
||||
trusted_setup: P::KzgSettings,
|
||||
pub struct Kzg {
|
||||
trusted_setup: KzgSettings,
|
||||
}
|
||||
|
||||
impl<P: KzgPreset> Kzg<P> {
|
||||
impl Kzg {
|
||||
/// Load the kzg trusted setup parameters from a vec of G1 and G2 points.
|
||||
///
|
||||
/// The number of G1 points should be equal to FIELD_ELEMENTS_PER_BLOB
|
||||
/// Note: this number changes based on the preset values.
|
||||
/// The number of G2 points should be equal to 65.
|
||||
pub fn new_from_trusted_setup(trusted_setup: TrustedSetup) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
trusted_setup: P::load_trusted_setup(trusted_setup)
|
||||
.map_err(Error::InvalidTrustedSetup)?,
|
||||
trusted_setup: KzgSettings::load_trusted_setup(
|
||||
&trusted_setup.g1_points(),
|
||||
&trusted_setup.g2_points(),
|
||||
)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Compute the kzg proof given a blob and its kzg commitment.
|
||||
pub fn compute_blob_kzg_proof(
|
||||
&self,
|
||||
blob: &P::Blob,
|
||||
blob: &Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
) -> Result<KzgProof, Error> {
|
||||
P::compute_blob_kzg_proof(blob, kzg_commitment, &self.trusted_setup)
|
||||
.map_err(Error::KzgProofComputationFailed)
|
||||
c_kzg::KzgProof::compute_blob_kzg_proof(blob, &kzg_commitment.into(), &self.trusted_setup)
|
||||
.map(|proof| KzgProof(proof.to_bytes().into_inner()))
|
||||
}
|
||||
|
||||
/// Verify a kzg proof given the blob, kzg commitment and kzg proof.
|
||||
pub fn verify_blob_kzg_proof(
|
||||
&self,
|
||||
blob: &P::Blob,
|
||||
blob: &Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
kzg_proof: KzgProof,
|
||||
) -> Result<bool, Error> {
|
||||
P::verify_blob_kzg_proof(blob, kzg_commitment, kzg_proof, &self.trusted_setup)
|
||||
.map_err(Error::InvalidKzgProof)
|
||||
c_kzg::KzgProof::verify_blob_kzg_proof(
|
||||
blob,
|
||||
&kzg_commitment.into(),
|
||||
&kzg_proof.into(),
|
||||
&self.trusted_setup,
|
||||
)
|
||||
}
|
||||
|
||||
/// Verify a batch of blob commitment proof triplets.
|
||||
@@ -301,43 +58,42 @@ impl<P: KzgPreset> Kzg<P> {
|
||||
/// TODO(pawan): test performance against a parallelized rayon impl.
|
||||
pub fn verify_blob_kzg_proof_batch(
|
||||
&self,
|
||||
blobs: &[P::Blob],
|
||||
blobs: &[Blob],
|
||||
kzg_commitments: &[KzgCommitment],
|
||||
kzg_proofs: &[KzgProof],
|
||||
) -> Result<bool, Error> {
|
||||
let commitments_bytes = kzg_commitments
|
||||
.iter()
|
||||
.map(|comm| P::Bytes48::from(*comm))
|
||||
.map(|comm| Bytes48::from(*comm))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let proofs_bytes = kzg_proofs
|
||||
.iter()
|
||||
.map(|proof| P::Bytes48::from(*proof))
|
||||
.map(|proof| Bytes48::from(*proof))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
P::verify_blob_kzg_proof_batch(
|
||||
c_kzg::KzgProof::verify_blob_kzg_proof_batch(
|
||||
blobs,
|
||||
&commitments_bytes,
|
||||
&proofs_bytes,
|
||||
&self.trusted_setup,
|
||||
)
|
||||
.map_err(Error::InvalidKzgProof)
|
||||
}
|
||||
|
||||
/// Converts a blob to a kzg commitment.
|
||||
pub fn blob_to_kzg_commitment(&self, blob: &P::Blob) -> Result<KzgCommitment, Error> {
|
||||
P::blob_to_kzg_commitment(blob, &self.trusted_setup).map_err(Error::InvalidBlob)
|
||||
pub fn blob_to_kzg_commitment(&self, blob: &Blob) -> Result<KzgCommitment, Error> {
|
||||
c_kzg::KzgCommitment::blob_to_kzg_commitment(blob, &self.trusted_setup)
|
||||
.map(|commitment| KzgCommitment(commitment.to_bytes().into_inner()))
|
||||
}
|
||||
|
||||
/// Computes the kzg proof for a given `blob` and an evaluation point `z`
|
||||
pub fn compute_kzg_proof(
|
||||
&self,
|
||||
blob: &P::Blob,
|
||||
blob: &Blob,
|
||||
z: &Bytes32,
|
||||
) -> Result<(KzgProof, Bytes32), Error> {
|
||||
P::compute_kzg_proof(blob, &P::bytes32_in(*z), &self.trusted_setup)
|
||||
.map_err(Error::KzgProofComputationFailed)
|
||||
.map(|(proof, y)| (proof, P::bytes32_out(y)))
|
||||
c_kzg::KzgProof::compute_kzg_proof(blob, z, &self.trusted_setup)
|
||||
.map(|(proof, y)| (KzgProof(proof.to_bytes().into_inner()), y))
|
||||
}
|
||||
|
||||
/// Verifies a `kzg_proof` for a `kzg_commitment` that evaluating a polynomial at `z` results in `y`
|
||||
@@ -348,13 +104,12 @@ impl<P: KzgPreset> Kzg<P> {
|
||||
y: &Bytes32,
|
||||
kzg_proof: KzgProof,
|
||||
) -> Result<bool, Error> {
|
||||
P::verify_kzg_proof(
|
||||
kzg_commitment,
|
||||
&P::bytes32_in(*z),
|
||||
&P::bytes32_in(*y),
|
||||
kzg_proof,
|
||||
c_kzg::KzgProof::verify_kzg_proof(
|
||||
&kzg_commitment.into(),
|
||||
z,
|
||||
y,
|
||||
&kzg_proof.into(),
|
||||
&self.trusted_setup,
|
||||
)
|
||||
.map_err(Error::InvalidKzgProof)
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,12 @@ struct G2Point([u8; BYTES_PER_G2_POINT]);
|
||||
/// The serialize/deserialize implementations are written according to
|
||||
/// the format specified in the the ethereum consensus specs trusted setup files.
|
||||
///
|
||||
/// See https://github.com/ethereum/consensus-specs/blob/dev/presets/mainnet/trusted_setups/testing_trusted_setups.json
|
||||
/// 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 = "setup_G1_lagrange")]
|
||||
#[serde(rename = "g1_lagrange")]
|
||||
g1_points: Vec<G1Point>,
|
||||
#[serde(rename = "setup_G2")]
|
||||
#[serde(rename = "g2_monomial")]
|
||||
g2_points: Vec<G2Point>,
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ jemalloc = ["malloc_utils/jemalloc"]
|
||||
|
||||
[dependencies]
|
||||
bls = { workspace = true }
|
||||
kzg = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
log = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use account_utils::eth2_keystore::keypair_from_secret;
|
||||
use clap::ArgMatches;
|
||||
use clap_utils::{parse_optional, parse_required, parse_ssz_optional};
|
||||
use eth2_network_config::{get_trusted_setup, Eth2NetworkConfig, GenesisStateSource};
|
||||
use eth2_network_config::{Eth2NetworkConfig, GenesisStateSource, TRUSTED_SETUP_BYTES};
|
||||
use eth2_wallet::bip39::Seed;
|
||||
use eth2_wallet::bip39::{Language, Mnemonic};
|
||||
use eth2_wallet::{recover_validator_secret_from_mnemonic, KeyType};
|
||||
use ethereum_hashing::hash;
|
||||
use kzg::TrustedSetup;
|
||||
use ssz::Decode;
|
||||
use ssz::Encode;
|
||||
use state_processing::process_activations;
|
||||
@@ -199,10 +198,7 @@ pub fn run<T: EthSpec>(testnet_dir_path: PathBuf, matches: &ArgMatches) -> Resul
|
||||
let kzg_trusted_setup = if let Some(epoch) = spec.deneb_fork_epoch {
|
||||
// Only load the trusted setup if the deneb fork epoch is set
|
||||
if epoch != Epoch::max_value() {
|
||||
let trusted_setup: TrustedSetup =
|
||||
serde_json::from_reader(get_trusted_setup::<T::Kzg>())
|
||||
.map_err(|e| format!("Unable to read trusted setup file: {}", e))?;
|
||||
Some(trusted_setup)
|
||||
Some(TRUSTED_SETUP_BYTES.to_vec())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
TESTS_TAG := v1.4.0-beta.2-hotfix
|
||||
TESTS_TAG := v1.4.0-beta.3
|
||||
TESTS = general minimal mainnet
|
||||
TARBALLS = $(patsubst %,%-$(TESTS_TAG).tar.gz,$(TESTS))
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ impl<E: EthSpec> Case for KZGBlobToKZGCommitment<E> {
|
||||
}
|
||||
|
||||
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let kzg = get_kzg()?;
|
||||
|
||||
let commitment = parse_blob::<E>(&self.input.blob).and_then(|blob| {
|
||||
blob_to_kzg_commitment::<E>(&kzg, &blob).map_err(|e| {
|
||||
|
||||
@@ -39,7 +39,7 @@ impl<E: EthSpec> Case for KZGComputeBlobKZGProof<E> {
|
||||
Ok((blob, commitment))
|
||||
};
|
||||
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let kzg = get_kzg()?;
|
||||
let proof = parse_input(&self.input).and_then(|(blob, commitment)| {
|
||||
compute_blob_kzg_proof::<E>(&kzg, &blob, commitment)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to compute kzg proof: {:?}", e)))
|
||||
|
||||
@@ -46,7 +46,7 @@ impl<E: EthSpec> Case for KZGComputeKZGProof<E> {
|
||||
Ok((blob, z))
|
||||
};
|
||||
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let kzg = get_kzg()?;
|
||||
let proof = parse_input(&self.input).and_then(|(blob, z)| {
|
||||
compute_kzg_proof::<E>(&kzg, &blob, z)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to compute kzg proof: {:?}", e)))
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use super::*;
|
||||
use crate::case_result::compare_result;
|
||||
use beacon_chain::kzg_utils::validate_blob;
|
||||
use eth2_network_config::get_trusted_setup;
|
||||
use kzg::{Kzg, KzgCommitment, KzgPreset, KzgProof, TrustedSetup};
|
||||
use eth2_network_config::TRUSTED_SETUP_BYTES;
|
||||
use kzg::{Kzg, KzgCommitment, KzgProof, TrustedSetup};
|
||||
use serde::Deserialize;
|
||||
use std::convert::TryInto;
|
||||
use std::marker::PhantomData;
|
||||
use types::Blob;
|
||||
|
||||
pub fn get_kzg<P: KzgPreset>() -> Result<Kzg<P>, Error> {
|
||||
let trusted_setup: TrustedSetup = serde_json::from_reader(get_trusted_setup::<P>())
|
||||
pub fn get_kzg() -> Result<Kzg, Error> {
|
||||
let trusted_setup: TrustedSetup = serde_json::from_reader(TRUSTED_SETUP_BYTES)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to initialize kzg: {:?}", e)))?;
|
||||
Kzg::new_from_trusted_setup(trusted_setup)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to initialize kzg: {:?}", e)))
|
||||
@@ -89,7 +89,7 @@ impl<E: EthSpec> Case for KZGVerifyBlobKZGProof<E> {
|
||||
Ok((blob, commitment, proof))
|
||||
};
|
||||
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let kzg = get_kzg()?;
|
||||
let result = parse_input(&self.input).and_then(|(blob, commitment, proof)| {
|
||||
validate_blob::<E>(&kzg, &blob, commitment, proof)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to validate blob: {:?}", e)))
|
||||
|
||||
@@ -52,7 +52,7 @@ impl<E: EthSpec> Case for KZGVerifyBlobKZGProofBatch<E> {
|
||||
Ok((commitments, blobs, proofs))
|
||||
};
|
||||
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let kzg = get_kzg()?;
|
||||
let result = parse_input(&self.input).and_then(|(commitments, blobs, proofs)| {
|
||||
validate_blobs::<E>(&kzg, &commitments, blobs.iter().collect(), &proofs)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to validate blobs: {:?}", e)))
|
||||
|
||||
@@ -42,7 +42,7 @@ impl<E: EthSpec> Case for KZGVerifyKZGProof<E> {
|
||||
Ok((commitment, z, y, proof))
|
||||
};
|
||||
|
||||
let kzg = get_kzg::<E::Kzg>()?;
|
||||
let kzg = get_kzg()?;
|
||||
let result = parse_input(&self.input).and_then(|(commitment, z, y, proof)| {
|
||||
verify_kzg_proof::<E>(&kzg, commitment, proof, z, y)
|
||||
.map_err(|e| Error::InternalError(format!("Failed to validate proof: {:?}", e)))
|
||||
|
||||
Reference in new issue
Block a user