Rust's `write_volatile` and `read_volatile` trigger index out of bounds
### Description
When trying to perform byte-wise (`u8`) read and writes using rust's `write_volatile` and `read_volatile`, I receive many index out of bounds errors. I experience the same behavior when replacing the read and writes with inline assembly `lbu` and `sb`.
### Source
**guest**
```rust
#![cfg_attr(feature = "guest", no_std)]
#[jolt::provable(guest_only, memory_size = 10240, max_trace_length = 65536)]
fn volatile_test() -> u64 {
let mut memory: [u8; 64] = [0; 64];
let memory_ptr: *mut u8 = memory.as_mut_ptr();
let output: u8;
unsafe {
core::ptr::write_volatile(memory_ptr, 0x01_u8);
output = core::ptr::read_volatile(memory_ptr);
}
output as u64
}
```
**host**
```rust
pub fn main() {
let target_dir = "/tmp/jolt-guest-targets";
let mut program = guest::compile_volatile_test(target_dir);
let prover_preprocessing = guest::preprocess_prover_volatile_test(&mut program);
let verifier_preprocessing = guest::verifier_preprocessing_from_prover_volatile_test(&prover_preprocessing);
let prove_volatile_test = guest::build_prover_volatile_test(program, prover_preprocessing);
let verify_volatile_test = guest::build_verifier_volatile_test(verifier_preprocessing);
let (output, proof, program_io) = prove_volatile_test();
if !verify_volatile_test(output, program_io.panic, proof) {
panic!("verifier failed!");
}
println!("success");
}
```
### Error
```bash
$> cargo run --release
...
thread '<unnamed>' panicked at /root/jolt/tracer/src/emulator/memory.rs:68:22:
index out of bounds: the len is 1808 but the index is 2391
thread '<unnamed>' panicked at /root/jolt/tracer/src/emulator/memory.rs:68:22:
index out of bounds: the len is 1808 but the index is 3873
thread '<unnamed>' panicked at /root/jolt/tracer/src/emulator/memory.rs:68:22:
index out of bounds: the len is 1808 but the index is 3738
...
```
---
commit: ec0b7b807a1b2faa834cbab304e55b23098efad7
0 条评论