Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/core/cli/comm_data.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use p3_field::Field;
use anyhow::Result;
use p3_field::{Field, PrimeField32};
use serde::{Deserialize, Serialize};
use std::hash::Hash;

use crate::{
core::zstore::{ZPtr, ZStore, DIGEST_SIZE, HASH3_SIZE},
core::{
big_num::field_elts_to_biguint,
zstore::{ZPtr, ZStore, DIGEST_SIZE, HASH3_SIZE},
},
lair::chipset::Chipset,
};

use super::zdag::ZDag;
use super::{paths::commits_dir, zdag::ZDag};

#[derive(Serialize, Deserialize)]
pub(crate) struct CommData<F: Hash + Eq> {
Expand All @@ -25,7 +29,7 @@ impl<F: Field> CommData<F> {
let mut preimg = [F::default(); HASH3_SIZE];
preimg[..DIGEST_SIZE].copy_from_slice(secret);
preimg[DIGEST_SIZE..].copy_from_slice(&payload.flatten());
zstore.hash3(preimg)
zstore.commit(preimg)
}
}

Expand Down Expand Up @@ -59,16 +63,6 @@ impl<F: Hash + Eq + Default + Copy> CommData<F> {
{
ZPtr::comm(self.compute_digest(zstore))
}

#[inline]
pub(crate) fn populate_zstore<C: Chipset<F>>(self, zstore: &mut ZStore<F, C>)
where
F: Field,
{
let digest = self.compute_digest(zstore);
zstore.intern_comm(digest);
self.zdag.populate_zstore(zstore);
}
}

impl<F: Field> CommData<F> {
Expand All @@ -77,3 +71,13 @@ impl<F: Field> CommData<F> {
self.zdag.is_flawed(&self.payload, zstore)
}
}

impl<F: PrimeField32> CommData<F> {
#[inline]
pub(crate) fn dump<C: Chipset<F>>(&self, zstore: &mut ZStore<F, C>) -> Result<ZPtr<F>> {
let comm = self.commit(zstore);
let hash = format!("{:x}", field_elts_to_biguint(&comm.digest));
std::fs::write(commits_dir()?.join(hash), bincode::serialize(self)?)?;
Ok(comm)
}
}
Loading