Implement KZG EF Tests (#4274)

This commit is contained in:
ethDreamer
2023-05-08 14:58:23 -05:00
committed by GitHub
parent 9db6b39dc3
commit a22e4bf636
13 changed files with 583 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
use kzg::{Error as KzgError, Kzg, BYTES_PER_BLOB};
use types::{Blob, EthSpec, KzgCommitment, KzgProof};
use types::{Blob, EthSpec, Hash256, KzgCommitment, KzgProof};
/// Converts a blob ssz List object to an array to be used with the kzg
/// crypto library.
@@ -56,3 +56,25 @@ pub fn blob_to_kzg_commitment<T: EthSpec>(
) -> Result<KzgCommitment, KzgError> {
kzg.blob_to_kzg_commitment(ssz_blob_to_crypto_blob::<T>(blob))
}
/// Compute the kzg proof for a given blob and an evaluation point z.
pub fn compute_kzg_proof<T: EthSpec>(
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)
.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,
kzg_commitment: KzgCommitment,
kzg_proof: KzgProof,
z: Hash256,
y: Hash256,
) -> Result<bool, KzgError> {
kzg.verify_kzg_proof(kzg_commitment, z.0.into(), y.0.into(), kzg_proof)
}