Add support for compile time FIELD_ELEMENTS_PER_BLOB

This commit is contained in:
Pawan Dhananjay 2022-12-14 21:25:42 +05:30
parent 2e89a719b0
commit 52a06231c8
No known key found for this signature in database
GPG Key ID: 647E56278D7E9B4C
6 changed files with 17 additions and 11 deletions

View File

@ -20,6 +20,7 @@ withdrawals-processing = [
"execution_layer/withdrawals-processing",
"http_api/withdrawals-processing",
]
spec-minimal = ["beacon_chain/spec-minimal"]
[dependencies]
eth2_config = { path = "../common/eth2_config" }

View File

@ -17,6 +17,7 @@ withdrawals-processing = [
"execution_layer/withdrawals-processing",
"operation_pool/withdrawals-processing"
]
spec-minimal = ["kzg/minimal-spec"]
[dev-dependencies]
maplit = "1.0.2"

View File

@ -1,13 +1,12 @@
use kzg::{Error as KzgError, Kzg};
use kzg::{Error as KzgError, Kzg, BYTES_PER_BLOB};
use types::{Blob, BlobsSidecar, EthSpec, Hash256, KzgCommitment, KzgProof, Slot};
// TODO(pawan): make this generic over blob size
fn ssz_blob_to_crypto_blob<T: EthSpec>(blob: Blob<T>) -> Option<[u8; 131072]> {
if blob.len() != 131072 {
fn ssz_blob_to_crypto_blob<T: EthSpec>(blob: Blob<T>) -> Option<[u8; BYTES_PER_BLOB]> {
if blob.len() != BYTES_PER_BLOB {
return None;
}
let blob_vec: Vec<u8> = blob.into();
let mut arr = [0; 131072];
let mut arr = [0; BYTES_PER_BLOB];
arr.copy_from_slice(&blob_vec);
Some(arr)
}

View File

@ -18,5 +18,9 @@ eth2_serde_utils = "0.1.1"
hex = "0.4.2"
eth2_hashing = "0.3.0"
ethereum-types = "0.12.1"
c-kzg = {git = "https://github.com/pawanjay176/c-kzg-4844", rev = "669a13800a8a0d094c5387db58e06936ef194a25" }
c-kzg = {git = "https://github.com/pawanjay176/c-kzg-4844", rev = "48c048b12a7d29ae3e7bf09000e07870da4cb701" }
[features]
default = ["mainnet-spec"]
mainnet-spec = ["c-kzg/mainnet-spec"]
minimal-spec = ["c-kzg/minimal-spec"]

View File

@ -3,11 +3,12 @@ mod kzg_proof;
pub use crate::{kzg_commitment::KzgCommitment, kzg_proof::KzgProof};
pub use c_kzg::bytes_to_g1;
use c_kzg::{Error as CKzgError, KZGSettings, BYTES_PER_FIELD_ELEMENT, FIELD_ELEMENTS_PER_BLOB};
pub use c_kzg::{
Error as CKzgError, KZGSettings, BYTES_PER_BLOB, BYTES_PER_FIELD_ELEMENT,
FIELD_ELEMENTS_PER_BLOB,
};
use std::path::PathBuf;
const BYTES_PER_BLOB: usize = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT;
/// The consensus type `Blob` is generic over EthSpec, so it cannot be imported
/// in this crate without creating a cyclic dependency between the kzg and consensus/types crates.
/// So need to use a Vec here unless we think of a smarter way of doing this
@ -32,7 +33,7 @@ pub struct Kzg {
impl Kzg {
pub fn new_from_file(file_path: PathBuf) -> Result<Self, Error> {
Ok(Self {
trusted_setup: KZGSettings::load_trusted_setup(file_path)
trusted_setup: KZGSettings::load_trusted_setup_file(file_path)
.map_err(Error::InvalidTrustedSetup)?,
})
}

View File

@ -17,7 +17,7 @@ modern = ["bls/supranational-force-adx"]
# Uses the slower Milagro BLS library, which is written in native Rust.
milagro = ["bls/milagro"]
# Support minimal spec (used for testing only).
spec-minimal = []
spec-minimal = ["beacon_node/spec-minimal"]
# Support Gnosis spec and Gnosis Beacon Chain.
gnosis = []
# Support slasher MDBX backend.