Devnet6 (#4404)
* some blob reprocessing work * remove ForceBlockLookup * reorder enum match arms in sync manager * a lot more reprocessing work * impl logic for triggerng blob lookups along with block lookups * deal with rpc blobs in groups per block in the da checker. don't cache missing blob ids in the da checker. * make single block lookup generic * more work * add delayed processing logic and combine some requests * start fixing some compile errors * fix compilation in main block lookup mod * much work * get things compiling * parent blob lookups * fix compile * revert red/stevie changes * fix up sync manager delay message logic * add peer usefulness enum * should remove lookup refactor * consolidate retry error handling * improve peer scoring during certain failures in parent lookups * improve retry code * drop parent lookup if either req has a peer disconnect during download * refactor single block processed method * processing peer refactor * smol bugfix * fix some todos * fix lints * fix lints * fix compile in lookup tests * fix lints * fix lints * fix existing block lookup tests * renamings * fix after merge * cargo fmt * compilation fix in beacon chain tests * fix * refactor lookup tests to work with multiple forks and response types * make tests into macros * wrap availability check error * fix compile after merge * add random blobs * start fixing up lookup verify error handling * some bug fixes and the start of deneb only tests * make tests work for all forks * track information about peer source * error refactoring * improve peer scoring * fix test compilation * make sure blobs are sent for processing after stream termination, delete copied tests * add some tests and fix a bug * smol bugfixes and moar tests * add tests and fix some things * compile after merge * lots of refactoring * retry on invalid block/blob * merge unknown parent messages before current slot lookup * get tests compiling * penalize blob peer on invalid blobs * Check disk on in-memory cache miss * Update beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs * Update beacon_node/network/src/sync/network_context.rs Co-authored-by: Divma <26765164+divagant-martian@users.noreply.github.com> * fix bug in matching blocks and blobs in range sync * pr feedback * fix conflicts * upgrade logs from warn to crit when we receive incorrect response in range * synced_and_connected_within_tolerance -> should_search_for_block * remove todo * add data gas used and update excess data gas to u64 * Fix Broken Overflow Tests * payload verification with commitments * fix merge conflicts * restore payload file * Restore payload file * remove todo * add max blob commitments per block * c-kzg lib update * Fix ef tests * Abstract over minimal/mainnet spec in kzg crate * Start integrating new KZG * checkpoint sync without alignment * checkpoint sync without alignment * add import * add import * query for checkpoint state by slot rather than state root (teku doesn't serve by state root) * query for checkpoint state by slot rather than state root (teku doesn't serve by state root) * loosen check * get state first and query by most recent block root * Revert "loosen check" This reverts commit 069d13dd63aa794a3505db9f17bd1a6b73f0be81. * get state first and query by most recent block root * merge max blobs change * simplify delay logic * rename unknown parent sync message variants * rename parameter, block_slot -> slot * add some docs to the lookup module * use interval instead of sleep * drop request if blocks and blobs requests both return `None` for `Id` * clean up `find_single_lookup` logic * add lookup source enum * clean up `find_single_lookup` logic * add docs to find_single_lookup_request * move LookupSource our of param where unnecessary * remove unnecessary todo * query for block by `state.latest_block_header.slot` * fix lint * fix merge transition ef tests * fix test * fix test * fix observed blob sidecars test * Add some metrics (#33) * fix protocol limits for blobs by root * Update Engine API for 1:1 Structure Method * make beacon chain tests to fix devnet 6 changes * get ckzg working and fix some tests * fix remaining tests * fix lints * Fix KZG linking issues * remove unused dep * lockfile * test fixes * remove dbgs * remove unwrap * cleanup tx generator * small fixes * fixing fixes * more self reivew * more self review * refactor genesis header initialization * refactor mock el instantiations * fix compile * fix network test, make sure they run for each fork * pr feedback * fix last test (hopefully) --------- Co-authored-by: Pawan Dhananjay <pawandhananjay@gmail.com> Co-authored-by: Mark Mackey <mark@sigmaprime.io> Co-authored-by: Divma <26765164+divagant-martian@users.noreply.github.com> Co-authored-by: Michael Sproul <michael@sigmaprime.io>
This commit is contained in:
co-authored by
Divma
Pawan Dhananjay
Mark Mackey
Michael Sproul
parent
4c9fcf1e83
commit
adbb62f7f3
@@ -16,10 +16,11 @@ serde_derive = "1.0.116"
|
||||
ethereum_serde_utils = "0.5.0"
|
||||
hex = "0.4.2"
|
||||
ethereum_hashing = "1.0.0-beta.2"
|
||||
c-kzg = {git = "https://github.com/ethereum/c-kzg-4844", rev = "fd24cf8e1e2f09a96b4e62a595b4e49f046ce6cf" }
|
||||
c-kzg = { git = "https://github.com/ethereum/c-kzg-4844", rev = "13cec820c08f45318f82ed4e0da0300042758b92" , features = ["mainnet-spec"]}
|
||||
c_kzg_min = { package = "c-kzg", git = "https://github.com/ethereum//c-kzg-4844", rev = "13cec820c08f45318f82ed4e0da0300042758b92", features = ["minimal-spec"], optional = true }
|
||||
arbitrary = { version = "1.0", features = ["derive"], optional = true }
|
||||
|
||||
[features]
|
||||
default = ["mainnet-spec"]
|
||||
mainnet-spec = ["c-kzg/mainnet-spec"]
|
||||
minimal-spec = ["c-kzg/minimal-spec"]
|
||||
# TODO(deneb): enabled by default for convenience, would need more cfg magic to disable
|
||||
default = ["c_kzg_min"]
|
||||
minimal-spec = ["c_kzg_min"]
|
||||
@@ -1,4 +1,4 @@
|
||||
use c_kzg::{Bytes48, BYTES_PER_COMMITMENT};
|
||||
use c_kzg::BYTES_PER_COMMITMENT;
|
||||
use derivative::Derivative;
|
||||
use ethereum_hashing::hash_fixed;
|
||||
use serde::de::{Deserialize, Deserializer};
|
||||
@@ -14,7 +14,7 @@ pub const BLOB_COMMITMENT_VERSION_KZG: u8 = 0x01;
|
||||
#[derive(Derivative, Clone, Copy, Encode, Decode)]
|
||||
#[derivative(PartialEq, Eq, Hash)]
|
||||
#[ssz(struct_behaviour = "transparent")]
|
||||
pub struct KzgCommitment(pub [u8; BYTES_PER_COMMITMENT]);
|
||||
pub struct KzgCommitment(pub [u8; c_kzg::BYTES_PER_COMMITMENT]);
|
||||
|
||||
impl KzgCommitment {
|
||||
pub fn calculate_versioned_hash(&self) -> Hash256 {
|
||||
@@ -24,7 +24,13 @@ impl KzgCommitment {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KzgCommitment> for Bytes48 {
|
||||
impl From<KzgCommitment> for c_kzg::Bytes48 {
|
||||
fn from(value: KzgCommitment) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KzgCommitment> for c_kzg_min::Bytes48 {
|
||||
fn from(value: KzgCommitment) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use c_kzg::{Bytes48, BYTES_PER_PROOF};
|
||||
use c_kzg::BYTES_PER_PROOF;
|
||||
use serde::de::{Deserialize, Deserializer};
|
||||
use serde::ser::{Serialize, Serializer};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
@@ -11,7 +11,13 @@ use tree_hash::{PackedEncoding, TreeHash};
|
||||
#[ssz(struct_behaviour = "transparent")]
|
||||
pub struct KzgProof(pub [u8; BYTES_PER_PROOF]);
|
||||
|
||||
impl From<KzgProof> for Bytes48 {
|
||||
impl From<KzgProof> for c_kzg::Bytes48 {
|
||||
fn from(value: KzgProof) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KzgProof> for c_kzg_min::Bytes48 {
|
||||
fn from(value: KzgProof) -> Self {
|
||||
value.0.into()
|
||||
}
|
||||
|
||||
+274
-61
@@ -2,30 +2,263 @@ mod kzg_commitment;
|
||||
mod kzg_proof;
|
||||
mod trusted_setup;
|
||||
|
||||
use serde_derive::{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::{
|
||||
Blob, Error as CKzgError, KzgSettings, BYTES_PER_BLOB, BYTES_PER_FIELD_ELEMENT,
|
||||
FIELD_ELEMENTS_PER_BLOB,
|
||||
};
|
||||
use c_kzg::{Bytes32, Bytes48};
|
||||
use std::path::PathBuf;
|
||||
pub use c_kzg::{Bytes32, Bytes48};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
InvalidTrustedSetup(CKzgError),
|
||||
InvalidKzgProof(CKzgError),
|
||||
InvalidBytes(CKzgError),
|
||||
KzgProofComputationFailed(CKzgError),
|
||||
InvalidBlob(CKzgError),
|
||||
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),
|
||||
}
|
||||
|
||||
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 BYTES_PER_FIELD_ELEMENT: 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 BYTES_PER_FIELD_ELEMENT: usize = $module_name::BYTES_PER_FIELD_ELEMENT;
|
||||
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> {
|
||||
$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);
|
||||
|
||||
/// A wrapper over a kzg library that holds the trusted setup parameters.
|
||||
#[derive(Debug)]
|
||||
pub struct Kzg {
|
||||
trusted_setup: KzgSettings,
|
||||
pub struct Kzg<P: KzgPreset> {
|
||||
trusted_setup: P::KzgSettings,
|
||||
}
|
||||
|
||||
impl Kzg {
|
||||
impl<P: KzgPreset> Kzg<P> {
|
||||
/// 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
|
||||
@@ -33,22 +266,7 @@ impl Kzg {
|
||||
/// 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: KzgSettings::load_trusted_setup(
|
||||
trusted_setup.g1_points(),
|
||||
trusted_setup.g2_points(),
|
||||
)
|
||||
.map_err(Error::InvalidTrustedSetup)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Loads a trusted setup given the path to the file containing the trusted setup values.
|
||||
/// The format is specified in `c_kzg::KzgSettings::load_trusted_setup_file`.
|
||||
///
|
||||
/// Note: This function will likely be deprecated. Use `Kzg::new_from_trusted_setup` instead.
|
||||
#[deprecated]
|
||||
pub fn new_from_file(file_path: PathBuf) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
trusted_setup: KzgSettings::load_trusted_setup_file(file_path)
|
||||
trusted_setup: P::load_trusted_setup(trusted_setup)
|
||||
.map_err(Error::InvalidTrustedSetup)?,
|
||||
})
|
||||
}
|
||||
@@ -56,28 +274,22 @@ impl Kzg {
|
||||
/// Compute the kzg proof given a blob and its kzg commitment.
|
||||
pub fn compute_blob_kzg_proof(
|
||||
&self,
|
||||
blob: Blob,
|
||||
blob: P::Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
) -> Result<KzgProof, Error> {
|
||||
c_kzg::KzgProof::compute_blob_kzg_proof(blob, kzg_commitment.into(), &self.trusted_setup)
|
||||
P::compute_blob_kzg_proof(blob, kzg_commitment, &self.trusted_setup)
|
||||
.map_err(Error::KzgProofComputationFailed)
|
||||
.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: Blob,
|
||||
blob: P::Blob,
|
||||
kzg_commitment: KzgCommitment,
|
||||
kzg_proof: KzgProof,
|
||||
) -> Result<bool, Error> {
|
||||
c_kzg::KzgProof::verify_blob_kzg_proof(
|
||||
blob,
|
||||
kzg_commitment.into(),
|
||||
kzg_proof.into(),
|
||||
&self.trusted_setup,
|
||||
)
|
||||
.map_err(Error::InvalidKzgProof)
|
||||
P::verify_blob_kzg_proof(blob, kzg_commitment, kzg_proof, &self.trusted_setup)
|
||||
.map_err(Error::InvalidKzgProof)
|
||||
}
|
||||
|
||||
/// Verify a batch of blob commitment proof triplets.
|
||||
@@ -86,22 +298,21 @@ impl Kzg {
|
||||
/// TODO(pawan): test performance against a parallelized rayon impl.
|
||||
pub fn verify_blob_kzg_proof_batch(
|
||||
&self,
|
||||
blobs: &[Blob],
|
||||
blobs: &[P::Blob],
|
||||
kzg_commitments: &[KzgCommitment],
|
||||
kzg_proofs: &[KzgProof],
|
||||
) -> Result<bool, Error> {
|
||||
let commitments_bytes = kzg_commitments
|
||||
.iter()
|
||||
.map(|comm| Bytes48::from_bytes(&comm.0))
|
||||
.collect::<Result<Vec<Bytes48>, _>>()
|
||||
.map_err(Error::InvalidBytes)?;
|
||||
.map(|comm| P::Bytes48::from(*comm))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let proofs_bytes = kzg_proofs
|
||||
.iter()
|
||||
.map(|proof| Bytes48::from_bytes(&proof.0))
|
||||
.collect::<Result<Vec<Bytes48>, _>>()
|
||||
.map_err(Error::InvalidBytes)?;
|
||||
c_kzg::KzgProof::verify_blob_kzg_proof_batch(
|
||||
.map(|proof| P::Bytes48::from(*proof))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
P::verify_blob_kzg_proof_batch(
|
||||
blobs,
|
||||
&commitments_bytes,
|
||||
&proofs_bytes,
|
||||
@@ -111,17 +322,19 @@ impl Kzg {
|
||||
}
|
||||
|
||||
/// Converts a blob to a kzg commitment.
|
||||
pub fn blob_to_kzg_commitment(&self, blob: Blob) -> Result<KzgCommitment, Error> {
|
||||
c_kzg::KzgCommitment::blob_to_kzg_commitment(blob, &self.trusted_setup)
|
||||
.map_err(Error::InvalidBlob)
|
||||
.map(|com| KzgCommitment(com.to_bytes().into_inner()))
|
||||
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)
|
||||
}
|
||||
|
||||
/// Computes the kzg proof for a given `blob` and an evaluation point `z`
|
||||
pub fn compute_kzg_proof(&self, blob: Blob, z: Bytes32) -> Result<(KzgProof, Bytes32), Error> {
|
||||
c_kzg::KzgProof::compute_kzg_proof(blob, z, &self.trusted_setup)
|
||||
pub fn compute_kzg_proof(
|
||||
&self,
|
||||
blob: P::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)| (KzgProof(proof.to_bytes().into_inner()), y))
|
||||
.map(|(proof, y)| (proof, P::bytes32_out(y)))
|
||||
}
|
||||
|
||||
/// Verifies a `kzg_proof` for a `kzg_commitment` that evaluating a polynomial at `z` results in `y`
|
||||
@@ -132,11 +345,11 @@ impl Kzg {
|
||||
y: Bytes32,
|
||||
kzg_proof: KzgProof,
|
||||
) -> Result<bool, Error> {
|
||||
c_kzg::KzgProof::verify_kzg_proof(
|
||||
kzg_commitment.into(),
|
||||
z,
|
||||
y,
|
||||
kzg_proof.into(),
|
||||
P::verify_kzg_proof(
|
||||
kzg_commitment,
|
||||
P::bytes32_in(z),
|
||||
P::bytes32_in(y),
|
||||
kzg_proof,
|
||||
&self.trusted_setup,
|
||||
)
|
||||
.map_err(Error::InvalidKzgProof)
|
||||
|
||||
@@ -21,7 +21,7 @@ struct G2Point([u8; BYTES_PER_G2_POINT]);
|
||||
/// See https://github.com/ethereum/consensus-specs/blob/dev/presets/mainnet/trusted_setups/testing_trusted_setups.json
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct TrustedSetup {
|
||||
#[serde(rename = "setup_G1")]
|
||||
#[serde(rename = "setup_G1_lagrange")]
|
||||
#[serde(deserialize_with = "deserialize_g1_points")]
|
||||
g1_points: Vec<G1Point>,
|
||||
#[serde(rename = "setup_G2")]
|
||||
|
||||
Reference in New Issue
Block a user