Skip to content

Commit 4963848

Browse files
committed
add shard info to public io
1 parent a0c7b91 commit 4963848

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

ceno_emul/src/shards.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ impl Shards {
1111
num_shards,
1212
}
1313
}
14+
15+
pub fn is_first_shard(&self) -> bool {
16+
self.shard_id == 0
17+
}
18+
19+
pub fn is_last_shard(&self) -> bool {
20+
self.shard_id == self.num_shards - 1
21+
}
1422
}

ceno_zkvm/src/chip_handler/general.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gkr_iop::{error::CircuitBuilderError, tables::LookupTable};
44
use crate::{
55
circuit_builder::CircuitBuilder,
66
instructions::riscv::constants::{
7-
END_CYCLE_IDX, END_PC_IDX, EXIT_CODE_IDX, INIT_CYCLE_IDX, INIT_PC_IDX,
7+
END_CYCLE_IDX, END_PC_IDX, END_SHARD_ID_IDX, EXIT_CODE_IDX, INIT_CYCLE_IDX, INIT_PC_IDX,
88
MEM_BUS_WITH_READ_IDX, MEM_BUS_WITH_WRITE_IDX, PUBLIC_IO_IDX, UINT_LIMBS,
99
},
1010
tables::InsnRecord,
@@ -22,7 +22,7 @@ pub trait PublicIOQuery {
2222
fn query_end_pc(&mut self) -> Result<Instance, CircuitBuilderError>;
2323
fn query_end_cycle(&mut self) -> Result<Instance, CircuitBuilderError>;
2424
fn query_public_io(&mut self) -> Result<[Instance; UINT_LIMBS], CircuitBuilderError>;
25-
25+
fn query_shard_id(&mut self) -> Result<Instance, CircuitBuilderError>;
2626
fn query_mem_bus_with_read(&mut self) -> Result<Instance, CircuitBuilderError>;
2727
fn query_mem_bus_with_write(&mut self) -> Result<Instance, CircuitBuilderError>;
2828
}
@@ -63,6 +63,10 @@ impl<'a, E: ExtensionField> PublicIOQuery for CircuitBuilder<'a, E> {
6363
self.cs.query_instance(|| "end_cycle", END_CYCLE_IDX)
6464
}
6565

66+
fn query_shard_id(&mut self) -> Result<Instance, CircuitBuilderError> {
67+
self.cs.query_instance(|| "shard_id", END_SHARD_ID_IDX)
68+
}
69+
6670
fn query_mem_bus_with_read(&mut self) -> Result<Instance, CircuitBuilderError> {
6771
self.cs
6872
.query_instance(|| "mem_bus_with_read", MEM_BUS_WITH_READ_IDX)

ceno_zkvm/src/e2e.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ pub fn emulate_program<'a>(
334334
Tracer::SUBCYCLES_PER_INSN,
335335
vm.get_pc().into(),
336336
end_cycle,
337+
shards.shard_id as u32,
338+
!shards.is_first_shard(), // first shard disable global read
339+
!shards.is_last_shard(), // last shard disable global write
337340
io_init.iter().map(|rec| rec.value).collect_vec(),
338341
);
339342

ceno_zkvm/src/instructions/riscv/constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ pub const INIT_PC_IDX: usize = 2;
99
pub const INIT_CYCLE_IDX: usize = 3;
1010
pub const END_PC_IDX: usize = 4;
1111
pub const END_CYCLE_IDX: usize = 5;
12-
pub const PUBLIC_IO_IDX: usize = 6;
12+
pub const END_SHARD_ID_IDX: usize = 6;
1313
pub const MEM_BUS_WITH_READ_IDX: usize = 7;
1414
pub const MEM_BUS_WITH_WRITE_IDX: usize = 8;
15+
pub const PUBLIC_IO_IDX: usize = 9;
1516

1617
pub const LIMB_BITS: usize = 16;
1718
pub const LIMB_MASK: u32 = 0xFFFF;

ceno_zkvm/src/scheme.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ pub struct PublicValues {
7272
init_cycle: u64,
7373
end_pc: u32,
7474
end_cycle: u64,
75+
shard_id: u32,
76+
mem_bus_with_read: bool,
77+
mem_bus_with_write: bool,
7578
public_io: Vec<u32>,
7679
}
7780

@@ -82,6 +85,9 @@ impl PublicValues {
8285
init_cycle: u64,
8386
end_pc: u32,
8487
end_cycle: u64,
88+
shard_id: u32,
89+
mem_bus_with_read: bool,
90+
mem_bus_with_write: bool,
8591
public_io: Vec<u32>,
8692
) -> Self {
8793
Self {
@@ -90,6 +96,9 @@ impl PublicValues {
9096
init_cycle,
9197
end_pc,
9298
end_cycle,
99+
shard_id,
100+
mem_bus_with_read,
101+
mem_bus_with_write,
93102
public_io,
94103
}
95104
}
@@ -103,6 +112,9 @@ impl PublicValues {
103112
vec![E::BaseField::from_canonical_u64(self.init_cycle)],
104113
vec![E::BaseField::from_canonical_u32(self.end_pc)],
105114
vec![E::BaseField::from_canonical_u64(self.end_cycle)],
115+
vec![E::BaseField::from_canonical_u32(self.shard_id)],
116+
vec![E::BaseField::from_bool(self.mem_bus_with_read)],
117+
vec![E::BaseField::from_bool(self.mem_bus_with_write)],
106118
]
107119
.into_iter()
108120
.chain(

0 commit comments

Comments
 (0)