Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
WitnessVec is abstract over Allocator and GoodAllocator is 'static
Browse files Browse the repository at this point in the history
  • Loading branch information
saitima committed Dec 12, 2023
1 parent 1588de7 commit b618e67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/cs/implementations/convenience.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::verifier::VerificationKey;
use super::witness::WitnessVec;
use crate::cs::cs_builder_verifier::CsVerifierBuilder;
use crate::cs::oracle::merkle_tree::MerkleTreeWithCap;
use crate::cs::traits::GoodAllocator;

use super::transcript::Transcript;
use crate::cs::traits::circuit::Circuit;
Expand Down Expand Up @@ -160,9 +161,10 @@ impl<
TR: Transcript<F>,

Check warning on line 161 in src/cs/implementations/convenience.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/era-boojum/era-boojum/src/cs/implementations/convenience.rs
H: TreeHasher<F, Output = TR::CompatibleCap>,
POW: PoWRunner,
A: GoodAllocator
>(
&self,
witness_vector: &WitnessVec<F>,
witness_vector: &WitnessVec<F, A>,
proof_config: ProofConfig,
setup_base: &SetupBaseStorage<F, P>,
setup: &SetupStorage<F, P>,
Expand Down
25 changes: 15 additions & 10 deletions src/cs/implementations/witness.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cs::implementations::fast_serialization::MemcopySerializable;
use crate::cs::traits::GoodAllocator;
use crate::dag::WitnessSource;
use std::alloc::Global;
use std::sync::atomic::AtomicU32;
Expand Down Expand Up @@ -29,13 +30,17 @@ pub struct WitnessSet<F: SmallField> {
#[derive(Derivative, serde::Serialize, serde::Deserialize)]
#[derivative(Clone, Debug)]
#[serde(bound = "F: serde::Serialize + serde::de::DeserializeOwned")]
pub struct WitnessVec<F: SmallField> {
pub struct WitnessVec<F: SmallField, A: GoodAllocator> {
pub public_inputs_locations: Vec<(usize, usize)>,
pub all_values: Vec<F>,
pub multiplicities: Vec<u32>,
#[serde(serialize_with = "crate::utils::serialize_vec_with_allocator")]
#[serde(deserialize_with = "crate::utils::deserialize_vec_with_allocator")]
pub all_values: Vec<F, A>,
#[serde(serialize_with = "crate::utils::serialize_vec_with_allocator")]
#[serde(deserialize_with = "crate::utils::deserialize_vec_with_allocator")]
pub multiplicities: Vec<u32, A>,
}

impl<F: SmallField> MemcopySerializable for WitnessVec<F> {
impl<F: SmallField, A: GoodAllocator> MemcopySerializable for WitnessVec<F, A> {
fn read_from_buffer<R: std::io::Read>(mut src: R) -> Result<Self, Box<dyn std::error::Error>> {
let public_inputs_locations = read_vec_from_buffer(&mut src)?;
let all_values = MemcopySerializable::read_from_buffer(&mut src)?;
Expand Down Expand Up @@ -428,7 +433,7 @@ impl<
result
}

pub fn materialize_witness_vec(&mut self) -> WitnessVec<F> {
pub fn materialize_witness_vec<A: GoodAllocator>(&mut self) -> WitnessVec<F, A> {
assert!(
CFG::WitnessConfig::EVALUATE_WITNESS,
"CS is not configured to have witness available"
Expand All @@ -454,7 +459,7 @@ impl<
assert!(max_idx > 0);

// we should do memcopy instead later on
let mut all_values = Vec::with_capacity(max_idx);
let mut all_values = Vec::with_capacity_in(max_idx, A::default());
let storage_ref = &self.variables_storage.read().unwrap();
for idx in 0..max_idx {
let place = Place(idx as u64);
Expand All @@ -463,9 +468,9 @@ impl<
}

let multiplicities = if self.lookup_parameters.lookup_is_allowed() == false {

Check warning on line 470 in src/cs/implementations/witness.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/era-boojum/era-boojum/src/cs/implementations/witness.rs
Vec::new()
Vec::new_in(A::default())
} else {
let mut multiplicities = Vec::with_capacity(self.lookups_tables_total_len());
let mut multiplicities = Vec::with_capacity_in(self.lookups_tables_total_len(), A::default());
for subtable in self.lookup_multiplicities.iter() {
multiplicities.extend(
subtable
Expand All @@ -484,9 +489,9 @@ impl<
}
}

pub fn witness_set_from_witness_vec(
pub fn witness_set_from_witness_vec<A: GoodAllocator>(
&self,
witness_set: &WitnessVec<F>,
witness_set: &WitnessVec<F, A>,
vars_hint: &DenseVariablesCopyHint,
wits_hint: &DenseWitnessCopyHint,
worker: &Worker,
Expand Down
2 changes: 1 addition & 1 deletion src/cs/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pub mod evaluator;
pub mod gate;

Check warning on line 10 in src/cs/traits/mod.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/era-boojum/era-boojum/src/cs/traits/mod.rs
pub mod trace_source;

pub trait GoodAllocator: Allocator + Clone + Default + Send + Sync + std::fmt::Debug {}
pub trait GoodAllocator: Allocator + Clone + Default + Send + Sync + std::fmt::Debug + 'static {}

impl GoodAllocator for std::alloc::Global {}

0 comments on commit b618e67

Please sign in to comment.