Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/program-size4: fix padding in edge cases #637

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion ceno_zkvm/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub trait Instruction<E: ExtensionField> {
})
.collect::<Result<(), ZKVMError>>()?;

let num_padding_instances = raw_witin.num_padding_instances();
let num_padding_instances = raw_witin.num_padding_instances(None);
if num_padding_instances > 0 {
// Fill the padding based on strategy

Expand Down
3 changes: 1 addition & 2 deletions ceno_zkvm/src/tables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub fn padding_zero<F: SmallField>(
num_cols: usize,
num_instances: Option<usize>,
) {
// Fill the padding with zeros, if any.
let num_padding_instances = table.num_padding_instances();
let num_padding_instances = table.num_padding_instances(num_instances);
if num_padding_instances > 0 {
let nthreads =
std::env::var("RAYON_NUM_THREADS").map_or(8, |s| s.parse::<usize>().unwrap_or(8));
Expand Down
4 changes: 2 additions & 2 deletions ceno_zkvm/src/tables/ram/ram_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<NVRAM: NonVolatileTable + Send + Sync + Clone> NonVolatileTableConfig<NVRAM
);

let mut init_table = RowMajorMatrix::<F>::new(NVRAM::len(&self.params), num_fixed);
assert_eq!(init_table.num_padding_instances(), 0);
assert_eq!(init_table.num_padding_instances(None), 0);

init_table
.par_iter_mut()
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<NVRAM: NonVolatileTable + Send + Sync + Clone> PubIOTableConfig<NVRAM> {
assert!(NVRAM::len(&self.params).is_power_of_two());

let mut init_table = RowMajorMatrix::<F>::new(NVRAM::len(&self.params), num_fixed);
assert_eq!(init_table.num_padding_instances(), 0);
assert_eq!(init_table.num_padding_instances(None), 0);

init_table
.par_iter_mut()
Expand Down
5 changes: 4 additions & 1 deletion ceno_zkvm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ impl<T: Sized + Sync + Clone + Send + Copy> RowMajorMatrix<T> {
self.values.len() / self.num_col - self.num_padding_rows
}

pub fn num_padding_instances(&self) -> usize {
pub fn num_padding_instances(&self, num_instances: Option<usize>) -> usize {
self.num_padding_rows
+ num_instances
.map(|ni| self.num_instances() - ni)
.unwrap_or(0)
}

pub fn iter_rows(&self) -> Chunks<MaybeUninit<T>> {
Expand Down