Skip to content

Commit

Permalink
once more for great good
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Jan 14, 2025
1 parent cb2fe2b commit fa0e981
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
4 changes: 1 addition & 3 deletions o1vm/src/interpreters/mips/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,10 @@ impl<Fp: Field, PreImageOracle: PreImageOracleT> InterpreterEnv for Env<Fp, PreI
preimage_key[4 * i + j] = bytes[j]
}
}
let preimage: Vec<u8> = panic!(
panic!(
"Attempted to get preimage key {}",
hex::encode(preimage_key)
);
self.preimage = Some(preimage.clone());
self.preimage_key = Some(preimage_key);
}

const LENGTH_SIZE: usize = 8;
Expand Down
64 changes: 33 additions & 31 deletions o1vm/src/preimage_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::cannon::{
PREIMAGE_CLIENT_READ_FD, PREIMAGE_CLIENT_WRITE_FD,
};
use command_fds::{CommandFdExt, FdMapping};
use log::debug;
//use log::debug;
use os_pipe::{PipeReader, PipeWriter};
use std::{
io::{Read, Write},
Expand All @@ -20,7 +20,9 @@ pub struct PreImageOracle {
}

pub trait PreImageOracleT {
fn get_preimage(&mut self, key: [u8; 32]) -> Preimage;
fn get_preimage(&mut self, key: [u8; 32]) -> Preimage {
panic!("This function is never being used {}", hex::encode(key));
}

fn hint(&mut self, hint: Hint);
}
Expand Down Expand Up @@ -178,35 +180,35 @@ impl PreImageOracleT for PreImageOracle {
// b. the preimage data, with a size of <length> bits
#[allow(unreachable_code)]
fn get_preimage(&mut self, key: [u8; 32]) -> Preimage {
panic!("Attempted to get preimage for key {}", hex::encode(&key));
let RW(ReadWrite { reader, writer }) = &mut self.oracle_client;

let r = writer.write_all(&key);
assert!(r.is_ok());
let r = writer.flush();
assert!(r.is_ok());

debug!("Reading response");
let mut buf = [0_u8; 8];
let resp = reader.read_exact(&mut buf);
assert!(resp.is_ok());

debug!("Extracting contents");
let length = u64::from_be_bytes(buf);
let mut preimage = vec![0_u8; length as usize];
let resp = reader.read_exact(&mut preimage);

assert!(resp.is_ok());

debug!(
"Got preimage of length {}\n {}",
preimage.len(),
hex::encode(&preimage)
);
// We should have read exactly <length> bytes
assert_eq!(preimage.len(), length as usize);

Preimage::create(preimage)
panic!("Attempted to get preimage for key {}", hex::encode(key));
//let RW(ReadWrite { reader, writer }) = &mut self.oracle_client;

//let r = writer.write_all(&key);
//assert!(r.is_ok());
//let r = writer.flush();
//assert!(r.is_ok());

//debug!("Reading response");
//let mut buf = [0_u8; 8];
//let resp = reader.read_exact(&mut buf);
//assert!(resp.is_ok());

//debug!("Extracting contents");
//let length = u64::from_be_bytes(buf);
//let mut preimage = vec![0_u8; length as usize];
//let resp = reader.read_exact(&mut preimage);

//assert!(resp.is_ok());

//debug!(
// "Got preimage of length {}\n {}",
// preimage.len(),
// hex::encode(&preimage)
//);
//// We should have read exactly <length> bytes
//assert_eq!(preimage.len(), length as usize);

//Preimage::create(preimage)
}

// The hint protocol goes as follows:
Expand Down

0 comments on commit fa0e981

Please sign in to comment.