Fix domains in verifier, decoder and dispersal

This commit is contained in:
danielsanchezq 2024-06-24 15:50:06 +02:00
parent befc472768
commit 442cec3c89
3 changed files with 12 additions and 15 deletions

View File

@ -221,10 +221,8 @@ impl AsRef<[u8]> for Index {
#[cfg(test)]
mod tests {
use ark_poly::EvaluationDomain;
use bitvec::prelude::*;
use blst::min_sig::{PublicKey, SecretKey};
use kzgrs::PolynomialEvaluationDomain;
use rand::{rngs::OsRng, thread_rng, Rng, RngCore};
use crate::{
@ -252,8 +250,7 @@ mod tests {
verifiers: &[DaVerifier],
) -> Vec<Attestation> {
let mut attestations = Vec::new();
let domain =
PolynomialEvaluationDomain::new(encoded_data.extended_data.0[0].len()).unwrap();
let domain_size = encoded_data.extended_data.0[0].len();
for (i, column) in encoded_data.extended_data.columns().enumerate() {
let verifier = &verifiers[i];
let da_blob = DaBlob {
@ -268,7 +265,7 @@ mod tests {
.map(|proofs| proofs.get(i).cloned().unwrap())
.collect(),
};
attestations.push(verifier.verify(da_blob, domain).unwrap());
attestations.push(verifier.verify(da_blob, domain_size).unwrap());
}
attestations
}

View File

@ -134,11 +134,9 @@ impl DaVerifier {
}
}
pub fn verify(
&self,
blob: DaBlob,
rows_domain: PolynomialEvaluationDomain,
) -> Option<Attestation> {
pub fn verify(&self, blob: DaBlob, rows_domain_size: usize) -> Option<Attestation> {
let rows_domain = PolynomialEvaluationDomain::new(rows_domain_size)
.expect("Domain should be able to build");
let is_column_verified = DaVerifier::verify_column(
&blob.column,
&blob.column_commitment,
@ -176,8 +174,7 @@ mod test {
use ark_poly::{EvaluationDomain, GeneralEvaluationDomain};
use blst::min_sig::SecretKey;
use kzgrs::{
bytes_to_polynomial, commit_polynomial, generate_element_proof, PolynomialEvaluationDomain,
BYTES_PER_FIELD_ELEMENT,
bytes_to_polynomial, commit_polynomial, generate_element_proof, BYTES_PER_FIELD_ELEMENT,
};
use rand::{thread_rng, RngCore};
@ -224,7 +221,7 @@ mod test {
fn test_verify() {
let encoder = &ENCODER;
let data = rand_data(32);
let domain = PolynomialEvaluationDomain::new(16).unwrap();
let domain_size = 16usize;
let mut rng = thread_rng();
let sks: Vec<SecretKey> = (0..16)
.map(|_| {
@ -254,7 +251,7 @@ mod test {
.map(|proofs| proofs.get(i).cloned().unwrap())
.collect(),
};
assert!(verifier.verify(da_blob, domain).is_some());
assert!(verifier.verify(da_blob, domain_size).is_some());
}
}
}

View File

@ -45,7 +45,10 @@ impl DaVerifier for KzgrsDaVerifier {
fn verify(&self, blob: &Self::DaBlob) -> Result<Self::Attestation, Self::Error> {
let blob = blob.clone();
match self.verifier.verify(blob) {
// TODO: Prepare the domain depending the size, if fixed, so fixed domain, if not it needs
// to come with some metadata.
let domain_size = 4096usize;
match self.verifier.verify(blob, domain_size) {
Some(attestation) => Ok(attestation),
None => Err(KzgrsDaVerifierError::VerificationError),
}