Skip to content

Commit 2348cd9

Browse files
authored
Hints (#22)
hints
1 parent 803e7bb commit 2348cd9

File tree

7 files changed

+170
-206
lines changed

7 files changed

+170
-206
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ num-integer = { version = "0.1.46", default-features = false }
3737
serde = { version = "1.0.201", default-features = false, features = ["derive"] }
3838
serde-big-array = "0.5.1"
3939
struct-reflection = { git = "https://github.com/gzanitti/struct-reflection-rs.git" }
40+
rustc-hash = "2.0.0"
4041

4142
rrs-lib = "0.1.0"
4243
tracing = "0.1.40"

extensions/circuit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ derive_more = { workspace = true, features = ["from"] }
2020
rand.workspace = true
2121
eyre.workspace = true
2222
thiserror.workspace = true
23+
rustc-hash.workspace = true
2324
# for div_rem:
2425
num-bigint.workspace = true
2526
num-integer.workspace = true

extensions/circuit/src/extension.rs

Lines changed: 31 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ pub struct WomirIConfig {
3838
pub system: SystemConfig,
3939
#[extension]
4040
pub base: WomirI,
41-
#[extension]
42-
pub io: WomirIo,
4341
}
4442

4543
// Default implementation uses no init file
@@ -63,7 +61,6 @@ impl Default for WomirIConfig {
6361
Self {
6462
system,
6563
base: Default::default(),
66-
io: Default::default(),
6764
}
6865
}
6966
}
@@ -76,7 +73,6 @@ impl WomirIConfig {
7673
Self {
7774
system,
7875
base: Default::default(),
79-
io: Default::default(),
8076
}
8177
}
8278

@@ -88,7 +84,6 @@ impl WomirIConfig {
8884
Self {
8985
system,
9086
base: Default::default(),
91-
io: Default::default(),
9287
}
9388
}
9489
}
@@ -115,10 +110,6 @@ impl WomirImConfig {
115110
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
116111
pub struct WomirI;
117112

118-
/// Extension similar to RISC-V for handling IO (not to be confused with I base extension)
119-
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
120-
pub struct WomirIo;
121-
122113
/// Extension similar to RISC-V 32-bit Multiplication Extension (RV32M)
123114
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
124115
pub struct WomirM {
@@ -149,6 +140,7 @@ pub enum WomirIExecutor<F: PrimeField32> {
149140
CopyIntoFrame(CopyIntoFrameChipWom<F>),
150141
Const32(ConstsChipWom<F>),
151142
LessThan(LessThanChipWom<F>),
143+
HintStore(HintStoreChip<F>),
152144
// Shift(Rv32ShiftChip<F>),
153145
// LoadStore(Rv32LoadStoreChip<F>),
154146
// LoadSignExtend(Rv32LoadSignExtendChip<F>),
@@ -166,12 +158,6 @@ pub enum WomirMExecutor<F: PrimeField32> {
166158
DivRem(Rv32DivRemChip<F>),
167159
}
168160

169-
/// RISC-V 32-bit Io Instruction Executors
170-
#[derive(ChipUsageGetter, Chip, InstructionExecutor, From, AnyEnum)]
171-
pub enum WomirIoExecutor<F: PrimeField32> {
172-
HintStore(Rv32HintStoreChip<F>),
173-
}
174-
175161
#[derive(From, ChipUsageGetter, Chip, AnyEnum)]
176162
pub enum WomirIPeriphery<F: PrimeField32> {
177163
BitwiseOperationLookup(SharedBitwiseOperationLookupChip<8>),
@@ -188,13 +174,6 @@ pub enum WomirMPeriphery<F: PrimeField32> {
188174
Phantom(PhantomChip<F>),
189175
}
190176

191-
#[derive(From, ChipUsageGetter, Chip, AnyEnum)]
192-
pub enum WomirIoPeriphery<F: PrimeField32> {
193-
BitwiseOperationLookup(SharedBitwiseOperationLookupChip<8>),
194-
// We put this only to get the <F> generic to work
195-
Phantom(PhantomChip<F>),
196-
}
197-
198177
// ============ VmExtension Implementations ============
199178

200179
impl<F: PrimeField32> VmExtension<F> for WomirI {
@@ -308,7 +287,25 @@ impl<F: PrimeField32> VmExtension<F> for WomirI {
308287
shared_fp.clone(),
309288
);
310289
inventory.add_executor(lt_chip, LessThanOpcode::iter().map(|x| x.global_opcode()))?;
311-
//
290+
291+
let mut hintstore_chip = HintStoreChip::new(
292+
execution_bus,
293+
frame_bus,
294+
program_bus,
295+
bitwise_lu_chip.clone(),
296+
memory_bridge,
297+
offline_memory.clone(),
298+
shared_fp.clone(),
299+
builder.system_config().memory_config.pointer_max_bits,
300+
HintStoreOpcode::CLASS_OFFSET,
301+
);
302+
hintstore_chip.set_streams(builder.streams().clone());
303+
304+
inventory.add_executor(
305+
hintstore_chip,
306+
HintStoreOpcode::iter().map(|x| x.global_opcode()),
307+
)?;
308+
312309
// let shift_chip = Rv32ShiftChip::new(
313310
// Rv32WomBaseAluAdapterChip::new(
314311
// execution_bus,
@@ -507,54 +504,6 @@ impl<F: PrimeField32> VmExtension<F> for WomirM {
507504
}
508505
}
509506

510-
impl<F: PrimeField32> VmExtension<F> for WomirIo {
511-
type Executor = WomirIoExecutor<F>;
512-
type Periphery = WomirIoPeriphery<F>;
513-
514-
fn build(
515-
&self,
516-
builder: &mut VmInventoryBuilder<F>,
517-
) -> Result<VmInventory<Self::Executor, Self::Periphery>, VmInventoryError> {
518-
let mut inventory = VmInventory::new();
519-
let SystemPort {
520-
execution_bus,
521-
program_bus,
522-
memory_bridge,
523-
} = builder.system_port();
524-
let offline_memory = builder.system_base().offline_memory();
525-
526-
let bitwise_lu_chip = if let Some(&chip) = builder
527-
.find_chip::<SharedBitwiseOperationLookupChip<8>>()
528-
.first()
529-
{
530-
chip.clone()
531-
} else {
532-
let bitwise_lu_bus = BitwiseOperationLookupBus::new(builder.new_bus_idx());
533-
let chip = SharedBitwiseOperationLookupChip::new(bitwise_lu_bus);
534-
inventory.add_periphery_chip(chip.clone());
535-
chip
536-
};
537-
538-
let mut hintstore_chip = Rv32HintStoreChip::new(
539-
execution_bus,
540-
program_bus,
541-
bitwise_lu_chip.clone(),
542-
memory_bridge,
543-
offline_memory.clone(),
544-
builder.system_config().memory_config.pointer_max_bits,
545-
HintStoreOpcode::CLASS_OFFSET,
546-
);
547-
hintstore_chip.set_streams(builder.streams().clone());
548-
549-
inventory.add_executor(
550-
hintstore_chip,
551-
HintStoreOpcode::iter().map(|x| x.global_opcode()),
552-
)?;
553-
554-
Ok(inventory)
555-
}
556-
}
557-
558507
/// Phantom sub-executors
559508
mod phantom {
560509
use eyre::bail;
@@ -590,22 +539,23 @@ mod phantom {
590539
_: F,
591540
_: u16,
592541
) -> eyre::Result<()> {
593-
let mut hint = match streams.input_stream.pop_front() {
542+
let hint = match streams.input_stream.pop_front() {
594543
Some(hint) => hint,
595544
None => {
596545
bail!("EndOfInputStream");
597546
}
598547
};
599548
streams.hint_stream.clear();
600-
streams.hint_stream.extend(
601-
(hint.len() as u32)
602-
.to_le_bytes()
603-
.iter()
604-
.map(|b| F::from_canonical_u8(*b)),
605-
);
606-
// Extend by 0 for 4 byte alignment
607-
let capacity = hint.len().div_ceil(4) * 4;
608-
hint.resize(capacity, F::ZERO);
549+
// TODO add this back when we support generic read over serialized data.
550+
// streams.hint_stream.extend(
551+
// (hint.len() as u32)
552+
// .to_le_bytes()
553+
// .iter()
554+
// .map(|b| F::from_canonical_u8(*b)),
555+
// );
556+
// // Extend by 0 for 4 byte alignment
557+
// let capacity = hint.len().div_ceil(4) * 4;
558+
// hint.resize(capacity, F::ZERO);
609559
streams.hint_stream.extend(hint);
610560
Ok(())
611561
}

0 commit comments

Comments
 (0)