Skip to content

Commit

Permalink
preimage: add some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonichon committed Nov 23, 2023
1 parent 6b0252e commit 64b2a3a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions optimism/src/preimage_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ impl PreImageOracle {
.expect("Could not spawn pre-image oracle process")
}

// The preimage protocol goes as follows
// 1. Ask for data through a key
// 2. Get the answers as a
// a. a 64-bit integer indicating the length of the actual data
// b. the preimage data, with a size of <length> bits
pub fn get_preimage(&mut self, key: [u8; 32]) -> Preimage {
let RW(ReadWrite { reader, writer }) = &mut self.oracle_client;

Expand All @@ -97,13 +102,14 @@ impl PreImageOracle {
let mut buf = [0_u8; 8];
let _ = reader.read_exact(&mut buf);

let length: u64 = u64::from_be_bytes(buf);

let length = u64::from_be_bytes(buf);
let mut handle = reader.take(length);

let mut v = vec![0_u8; length as usize];

let _ = handle.read(&mut v);

// We should have read exactly <length> bytes
assert_eq!(v.len(), length as usize);

Preimage::create(v)
}

Expand Down

0 comments on commit 64b2a3a

Please sign in to comment.