Skip to content

Commit 2ccb630

Browse files
committed
review comments
1 parent 88bce4b commit 2ccb630

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

docs/specs/ISA.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ with user input-output.
418418

419419
| Name | Operands | Description |
420420
| ---------------- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
421-
| HINT_STOREW_RV32 | `_,b,_,1,2` | `[r32{0}(b):4]_2 = next 4 bytes from hint stream`. Only valid if next 4 values in hint stream are bytes. |
421+
| HINT_STOREW_RV32 | `_,b,_,1,2` | `[r32{0}(b):4]_2 = next 4 bytes from hint stream`. Only valid if next 4 values in hint stream are bytes. The pointer address `r32{0}(b)` must be divisible by 4. |
422422
| HINT_BUFFER_RV32 | `a,b,_,1,2` | `[r32{0}(b):4 * l]_2 = next 4 * l bytes from hint stream` where `l = r32{0}(a)`. Only valid if next `4 * l` values in hint stream are bytes. Very important: `l` should not be 0. The pointer address `r32{0}(b)` must be divisible by 4. |
423423
| REVEAL_RV32 | `a,b,c,1,3,_,g` | Pseudo-instruction for `STOREW_RV32 a,b,c,1,3,_,g` writing to the user IO address space `3`. Only valid when continuations are enabled. |
424424

docs/specs/RISCV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ as part of its state:
6262

6363
| RISC-V Inst | FMT | opcode[6:0] | funct3 | imm[0:11] | RISC-V description and notes |
6464
| ----------- | --- | ----------- | ------ | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
65-
| hintstorew | I | 0001011 | 001 | 0x0 | Stores next 4-byte word from hint stream in user memory at `[rd]_2`. Only valid if next 4 values in hint stream are bytes. |
65+
| hintstorew | I | 0001011 | 001 | 0x0 | Stores next 4-byte word from hint stream in user memory at `[rd]_2`. Only valid if next 4 values in hint stream are bytes. The address `rd` must be aligned to a 4-byte boundary. |
6666
| hintbuffer | I | 0001011 | 001 | 0x1 | Stores next `4 * rs1` bytes from hint stream in user memory at `[rd..rd + 4 * rs1]_2`. Only valid if next `4 * rs1` values in hint stream are bytes and `rs1` is non-zero. The address `rd` must be aligned to a 4-byte boundary. |
6767
| reveal | I | 0001011 | 010 | | Stores the 4-byte word `rs1` at address `rd + imm` in user IO space. The address `rd + imm` must be aligned to a 4-byte boundary. |
6868
| hintinput | I | 0001011 | 011 | 0x0 | Pop next vector from input stream and reset hint stream to the vector. |

extensions/rv32im/circuit/src/hintstore/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use openvm_stark_backend::{
3636
p3_air::{Air, AirBuilder, BaseAir},
3737
p3_field::{Field, FieldAlgebra, PrimeField32},
3838
p3_matrix::{dense::RowMajorMatrix, Matrix},
39+
p3_util::log2_strict_usize,
3940
prover::types::AirProofInput,
4041
rap::{AnyRap, BaseAirWithPublicValues, PartitionedBaseAir},
4142
Chip, ChipUsageGetter,
@@ -232,10 +233,12 @@ impl<AB: InteractionBuilder> Air<AB> for Rv32HintStoreAir {
232233
self.memory_bridge
233234
.range_bus()
234235
.range_check::<AB::Expr>(
235-
local_cols.mem_ptr_limbs[0] * AB::F::from_canonical_u32(4).inverse(),
236-
RV32_CELL_BITS - 2,
236+
local_cols.mem_ptr_limbs[0]
237+
* AB::F::from_canonical_usize(RV32_REGISTER_NUM_LIMBS).inverse(),
238+
RV32_CELL_BITS - log2_strict_usize(RV32_REGISTER_NUM_LIMBS),
237239
)
238240
.eval(builder, is_start.clone());
241+
// We only check this on `is_start` since it is implied on non-start rows by the next_mem_ptr = mem_ptr + 4 constraint below
239242

240243
// Checking that hint is bytes
241244
for i in 0..RV32_REGISTER_NUM_LIMBS / 2 {
@@ -366,7 +369,7 @@ impl<F: PrimeField32> InstructionExecutor<F> for Rv32HintStoreChip<F> {
366369

367370
debug_assert!(mem_ptr <= (1 << self.air.pointer_max_bits));
368371
assert!(
369-
mem_ptr % 4 == 0,
372+
(mem_ptr as usize) % RV32_REGISTER_NUM_LIMBS == 0,
370373
"Memory pointer {mem_ptr} is not 4-byte aligned"
371374
);
372375

@@ -478,9 +481,10 @@ impl<F: PrimeField32> Rv32HintStoreChip<F> {
478481
mem_ptr_msl << (RV32_REGISTER_NUM_LIMBS * RV32_CELL_BITS - pointer_max_bits),
479482
rem_words_msl << (RV32_REGISTER_NUM_LIMBS * RV32_CELL_BITS - pointer_max_bits),
480483
);
481-
memory
482-
.range_checker()
483-
.add_count((mem_ptr & 0xff) >> 2, RV32_CELL_BITS - 2);
484+
memory.range_checker().add_count(
485+
(mem_ptr & ((1 << RV32_CELL_BITS) - 1)) >> 2,
486+
RV32_CELL_BITS - 2,
487+
);
484488
for (i, &(data, write)) in record.hints.iter().enumerate() {
485489
for half in 0..(RV32_REGISTER_NUM_LIMBS / 2) {
486490
bitwise_lookup_chip.request_range(

0 commit comments

Comments
 (0)