From d3161e5a7a36facca04ada325134ee7a802a78c9 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Mon, 15 Apr 2024 15:06:55 +0200 Subject: [PATCH] Fix lib and types exposures --- nomos-da/kzgrs-backend/Cargo.toml | 2 ++ nomos-da/kzgrs-backend/src/common.rs | 25 +++++++++++++++++++++++++ nomos-da/kzgrs/src/common.rs | 1 + nomos-da/kzgrs/src/kzg.rs | 2 +- nomos-da/kzgrs/src/lib.rs | 2 +- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/nomos-da/kzgrs-backend/Cargo.toml b/nomos-da/kzgrs-backend/Cargo.toml index 82dffc88..67b59815 100644 --- a/nomos-da/kzgrs-backend/Cargo.toml +++ b/nomos-da/kzgrs-backend/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +blake2 = "0.10" +ark-serialize = "0.4.2" ark-poly = "0.4.2" kzgrs = { path = "../kzgrs" } rand = "0.8.5" diff --git a/nomos-da/kzgrs-backend/src/common.rs b/nomos-da/kzgrs-backend/src/common.rs index 5732ea04..422c2ab2 100644 --- a/nomos-da/kzgrs-backend/src/common.rs +++ b/nomos-da/kzgrs-backend/src/common.rs @@ -1,3 +1,8 @@ +use ark_serialize::CanonicalSerialize; +use blake2::digest::{Update, VariableOutput}; +use kzgrs::Commitment; +use std::io::Cursor; + #[derive(Clone)] pub struct Chunk(Vec); pub struct Row(Vec); @@ -68,3 +73,23 @@ impl FromIterator for ChunksMatrix { Self(iter.into_iter().collect()) } } + +pub fn hash_column_and_commitment( + column: &Column, + commitment: &Commitment, +) -> [u8; HASH_SIZE] { + use ark_serialize::CanonicalSerialize; + let mut hasher = blake2::Blake2bVar::new(HASH_SIZE) + .unwrap_or_else(|e| panic!("Blake2b should work for size {HASH_SIZE}, {e}")); + hasher.update(column.as_bytes().as_ref()); + let mut buff = Cursor::new(vec![]); + commitment + .serialize_uncompressed(&mut buff) + .expect("Serialization of commitment should work"); + hasher.update(buff.into_inner().as_ref()); + hasher + .finalize_boxed() + .to_vec() + .try_into() + .unwrap_or_else(|_| panic!("Size is guaranteed by constant {HASH_SIZE:?}")) +} diff --git a/nomos-da/kzgrs/src/common.rs b/nomos-da/kzgrs/src/common.rs index 9f6636d9..1dcb968b 100644 --- a/nomos-da/kzgrs/src/common.rs +++ b/nomos-da/kzgrs/src/common.rs @@ -1,5 +1,6 @@ // std // crates +use crate::Commitment; use ark_bls12_381::fr::Fr; use ark_ff::{BigInteger256, PrimeField, Zero}; use ark_poly::domain::general::GeneralEvaluationDomain; diff --git a/nomos-da/kzgrs/src/kzg.rs b/nomos-da/kzgrs/src/kzg.rs index d64ddfdc..6c94b29d 100644 --- a/nomos-da/kzgrs/src/kzg.rs +++ b/nomos-da/kzgrs/src/kzg.rs @@ -28,7 +28,7 @@ pub fn generate_element_proof( element_index: usize, polynomial: &DensePolynomial, global_parameters: &UniversalParams, - domain: &GeneralEvaluationDomain, + domain: GeneralEvaluationDomain, ) -> Result, KzgRsError> { let u = domain.element(element_index); let v = polynomial.evaluate(&u); diff --git a/nomos-da/kzgrs/src/lib.rs b/nomos-da/kzgrs/src/lib.rs index 03e4c224..188bee30 100644 --- a/nomos-da/kzgrs/src/lib.rs +++ b/nomos-da/kzgrs/src/lib.rs @@ -1,5 +1,5 @@ pub mod common; -mod global_parameters; +pub mod global_parameters; pub mod kzg; pub mod rs;