Add support for compile time FIELD_ELEMENTS_PER_BLOB
This commit is contained in:
parent
2e89a719b0
commit
52a06231c8
@ -20,6 +20,7 @@ withdrawals-processing = [
|
|||||||
"execution_layer/withdrawals-processing",
|
"execution_layer/withdrawals-processing",
|
||||||
"http_api/withdrawals-processing",
|
"http_api/withdrawals-processing",
|
||||||
]
|
]
|
||||||
|
spec-minimal = ["beacon_chain/spec-minimal"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eth2_config = { path = "../common/eth2_config" }
|
eth2_config = { path = "../common/eth2_config" }
|
||||||
|
@ -17,6 +17,7 @@ withdrawals-processing = [
|
|||||||
"execution_layer/withdrawals-processing",
|
"execution_layer/withdrawals-processing",
|
||||||
"operation_pool/withdrawals-processing"
|
"operation_pool/withdrawals-processing"
|
||||||
]
|
]
|
||||||
|
spec-minimal = ["kzg/minimal-spec"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
|
@ -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};
|
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; BYTES_PER_BLOB]> {
|
||||||
fn ssz_blob_to_crypto_blob<T: EthSpec>(blob: Blob<T>) -> Option<[u8; 131072]> {
|
if blob.len() != BYTES_PER_BLOB {
|
||||||
if blob.len() != 131072 {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let blob_vec: Vec<u8> = blob.into();
|
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);
|
arr.copy_from_slice(&blob_vec);
|
||||||
Some(arr)
|
Some(arr)
|
||||||
}
|
}
|
||||||
|
@ -18,5 +18,9 @@ eth2_serde_utils = "0.1.1"
|
|||||||
hex = "0.4.2"
|
hex = "0.4.2"
|
||||||
eth2_hashing = "0.3.0"
|
eth2_hashing = "0.3.0"
|
||||||
ethereum-types = "0.12.1"
|
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"]
|
@ -3,11 +3,12 @@ mod kzg_proof;
|
|||||||
|
|
||||||
pub use crate::{kzg_commitment::KzgCommitment, kzg_proof::KzgProof};
|
pub use crate::{kzg_commitment::KzgCommitment, kzg_proof::KzgProof};
|
||||||
pub use c_kzg::bytes_to_g1;
|
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;
|
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
|
/// 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.
|
/// 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
|
/// 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 {
|
impl Kzg {
|
||||||
pub fn new_from_file(file_path: PathBuf) -> Result<Self, Error> {
|
pub fn new_from_file(file_path: PathBuf) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
trusted_setup: KZGSettings::load_trusted_setup(file_path)
|
trusted_setup: KZGSettings::load_trusted_setup_file(file_path)
|
||||||
.map_err(Error::InvalidTrustedSetup)?,
|
.map_err(Error::InvalidTrustedSetup)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ modern = ["bls/supranational-force-adx"]
|
|||||||
# Uses the slower Milagro BLS library, which is written in native Rust.
|
# Uses the slower Milagro BLS library, which is written in native Rust.
|
||||||
milagro = ["bls/milagro"]
|
milagro = ["bls/milagro"]
|
||||||
# Support minimal spec (used for testing only).
|
# Support minimal spec (used for testing only).
|
||||||
spec-minimal = []
|
spec-minimal = ["beacon_node/spec-minimal"]
|
||||||
# Support Gnosis spec and Gnosis Beacon Chain.
|
# Support Gnosis spec and Gnosis Beacon Chain.
|
||||||
gnosis = []
|
gnosis = []
|
||||||
# Support slasher MDBX backend.
|
# Support slasher MDBX backend.
|
||||||
|
Loading…
Reference in New Issue
Block a user