Skip to content

Commit 58a36ff

Browse files
authored
public io size finalize in keygen time (#1065)
To close #1066 One of non-deterministic pk/vk came from PubIoTable fixed commitment length. Previously in key-setup time there is no public io, thus PubIoTable addr is hardcode as 16 byte -> 2 word In prove step once setup public io, then the PubIoTable addr will be dynamic extend to cover new public io, thus the fixed commitment are not identical, cause transcript challenge got different. To fixed the root cause, we pass public io size in key setup time, and then in "prove" phase we check public io data <= public io size.
1 parent aa5283d commit 58a36ff

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

ceno_cli/src/commands/common_args/ceno.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ pub struct CenoOptions {
5656
#[arg(long, value_parser, num_args = 1.., value_delimiter = ',')]
5757
public_io: Option<Vec<Word>>,
5858

59+
/// pub io size in byte
60+
#[arg(long, default_value = "1k", value_parser = parse_size)]
61+
public_io_size: u32,
62+
5963
/// The preset configuration to use.
6064
#[arg(short, long, value_enum, default_value_t = SecurityLevel::default())]
6165
security_level: SecurityLevel,
@@ -295,7 +299,7 @@ impl CenoOptions {
295299
self,
296300
compilation_options,
297301
elf_path,
298-
Checkpoint::PrepVerify, // FIXME: when whir and babybear is ready
302+
Checkpoint::Complete,
299303
)
300304
}
301305
(PcsKind::Whir, FieldType::Goldilocks) => {
@@ -337,26 +341,29 @@ fn run_elf_inner<
337341
let public_io = options
338342
.read_public_io()
339343
.context("failed to read public io")?;
340-
// estimate required pub io size, which is required in platform/key setup phase
341-
let pub_io_size: u32 = ((public_io.len() * WORD_SIZE) as u32)
342-
.next_power_of_two()
343-
.max(16);
344+
let public_io_size = options.public_io_size;
345+
assert!(
346+
public_io.len() <= public_io_size as usize / WORD_SIZE,
347+
"require pub io length {} < max public_io_size {}",
348+
public_io.len(),
349+
public_io_size as usize / WORD_SIZE
350+
);
344351

345352
let platform = if compilation_options.release {
346353
setup_platform(
347354
options.platform,
348355
&program,
349356
options.stack_size(),
350357
options.heap_size(),
351-
pub_io_size,
358+
public_io_size,
352359
)
353360
} else {
354361
setup_platform_debug(
355362
options.platform,
356363
&program,
357364
options.stack_size(),
358365
options.heap_size(),
359-
pub_io_size,
366+
public_io_size,
360367
)
361368
};
362369
tracing::info!("Running on platform {:?} {}", options.platform, platform);

ceno_zkvm/src/bin/e2e.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ struct Args {
101101
#[arg(long, value_parser, num_args = 1.., value_delimiter = ',')]
102102
public_io: Option<Vec<Word>>,
103103

104+
/// pub io size in byte
105+
#[arg(long, default_value = "1k", value_parser = parse_size)]
106+
public_io_size: u32,
107+
104108
/// The security level to use.
105109
#[arg(short, long, value_enum, default_value_t = SecurityLevel::default())]
106110
security_level: SecurityLevel,
@@ -168,11 +172,12 @@ fn main() {
168172
}
169173
})
170174
.unwrap_or_default();
171-
172-
// estimate required pub io size, which is required in platform/key setup phase
173-
let pub_io_size: u32 = ((public_io.len() * WORD_SIZE) as u32)
174-
.next_power_of_two()
175-
.max(16);
175+
assert!(
176+
public_io.len() <= args.public_io_size as usize / WORD_SIZE,
177+
"require pub io length {} < max public_io_size {}",
178+
public_io.len(),
179+
args.public_io_size as usize / WORD_SIZE
180+
);
176181

177182
tracing::info!("Loading ELF file: {}", args.elf.display());
178183
let elf_bytes = fs::read(&args.elf).expect("read elf file");
@@ -183,15 +188,15 @@ fn main() {
183188
&program,
184189
args.stack_size,
185190
args.heap_size,
186-
pub_io_size,
191+
args.public_io_size,
187192
)
188193
} else {
189194
setup_platform(
190195
args.platform,
191196
&program,
192197
args.stack_size,
193198
args.heap_size,
194-
pub_io_size,
199+
args.public_io_size,
195200
)
196201
};
197202
tracing::info!("Running on platform {:?} {}", args.platform, platform);

ceno_zkvm/src/e2e.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,17 @@ fn setup_platform_inner(
349349
heap.start..heap_end as u32
350350
};
351351

352+
assert!(
353+
pub_io_size.is_power_of_two(),
354+
"pub io size {pub_io_size} must be a power of two"
355+
);
352356
let platform = Platform {
353357
rom: program.base_address
354358
..program.base_address + (program.instructions.len() * WORD_SIZE) as u32,
355359
prog_data,
356360
stack,
357361
heap,
358-
public_io: preset.public_io.start..preset.public_io.start + pub_io_size.next_power_of_two(),
362+
public_io: preset.public_io.start..preset.public_io.start + pub_io_size,
359363
..preset
360364
};
361365
assert!(

0 commit comments

Comments
 (0)