Skip to content

Commit

Permalink
Merge pull request #2092 from OffchainLabs/4844-inbox-reader
Browse files Browse the repository at this point in the history
4844 inbox reader
  • Loading branch information
PlasmaPower authored Jan 28, 2024
2 parents 91f67ba + 1ba8e07 commit 26eb57d
Show file tree
Hide file tree
Showing 49 changed files with 1,107 additions and 208 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/arbitrator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ jobs:
make -j
make install
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Cache cbrotli
uses: actions/cache@v3
id: cache-cbrotli
Expand Down Expand Up @@ -158,4 +161,5 @@ jobs:
cd contracts
yarn install
yarn build
yarn build:forge:yul
yarn hardhat --network localhost test test/prover/*.ts
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
with:
targets: 'wasm32-unknown-unknown, wasm32-wasi'

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Cache Build Products
uses: actions/cache@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ jobs:
- name: Install rust stable
uses: dtolnay/rust-toolchain@stable

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Cache Rust Build Products
uses: actions/cache@v3
with:
Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ COPY --from=brotli-library-builder /workspace/install/ /

FROM node:16-bookworm-slim as contracts-builder
RUN apt-get update && \
apt-get install -y git python3 make g++
apt-get install -y git python3 make g++ curl
RUN curl -L https://foundry.paradigm.xyz | bash && . ~/.bashrc && ~/.foundry/bin/foundryup
WORKDIR /workspace
COPY contracts/package.json contracts/yarn.lock contracts/
RUN cd contracts && yarn install
COPY contracts contracts/
COPY Makefile .
RUN NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-solidity
RUN . ~/.bashrc && NITRO_BUILD_IGNORE_TIMESTAMPS=1 make build-solidity

FROM debian:bookworm-20231218 as wasm-base
WORKDIR /workspace
Expand Down Expand Up @@ -181,6 +182,7 @@ COPY fastcache/go.mod fastcache/go.sum fastcache/
RUN go mod download
COPY . ./
COPY --from=contracts-builder workspace/contracts/build/ contracts/build/
COPY --from=contracts-builder workspace/contracts/out/ contracts/out/
COPY --from=contracts-builder workspace/contracts/node_modules/@offchainlabs/upgrade-executor/build/contracts/src/UpgradeExecutor.sol/UpgradeExecutor.json contracts/node_modules/@offchainlabs/upgrade-executor/build/contracts/src/UpgradeExecutor.sol/
COPY --from=contracts-builder workspace/.make/ .make/
COPY --from=prover-header-export / target/
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ contracts/test/prover/proofs/%.json: $(arbitrator_cases)/%.wasm $(arbitrator_pro

.make/solidity: $(DEP_PREDICATE) contracts/src/*/*.sol .make/yarndeps $(ORDER_ONLY_PREDICATE) .make
yarn --cwd contracts build
yarn --cwd contracts build:forge:yul
@touch $@

.make/yarndeps: $(DEP_PREDICATE) contracts/package.json contracts/yarn.lock $(ORDER_ONLY_PREDICATE) .make
Expand Down
4 changes: 2 additions & 2 deletions arbitrator/jit/src/wavmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ pub fn resolve_preimage_impl(
};

let offset = match u32::try_from(offset) {
Ok(offset) => offset as usize,
Err(_) => error!("bad offset {offset} in {name}"),
Ok(offset) if offset % 32 == 0 => offset as usize,
_ => error!("bad offset {offset} in {name}"),
};

let len = std::cmp::min(32, preimage.len().saturating_sub(offset));
Expand Down
18 changes: 11 additions & 7 deletions arbitrator/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::machine::{argument_data_to_inbox, Machine};
use arbutil::PreimageType;
use eyre::Result;
use machine::{get_empty_preimage_resolver, GlobalState, MachineStatus, PreimageResolver};
use sha3::{Digest, Keccak256};
use static_assertions::const_assert_eq;
use std::{
ffi::CStr,
Expand Down Expand Up @@ -303,13 +302,18 @@ pub unsafe extern "C" fn arbitrator_set_preimage_resolver(
return None;
}
let data = CBytes::from_raw_parts(res.ptr, res.len as usize);
let have_hash = Keccak256::digest(&data);
if have_hash.as_slice() != *hash {
panic!(
"Resolved incorrect data for hash {}: got {}",
#[cfg(debug_assertions)]
match crate::utils::hash_preimage(&data, ty) {
Ok(have_hash) if have_hash.as_slice() == *hash => {}
Ok(got_hash) => panic!(
"Resolved incorrect data for hash {} (rehashed to {})",
hash,
hex::encode(data),
);
Bytes32(got_hash),
),
Err(err) => panic!(
"Failed to hash preimage from resolver (expecting hash {}): {}",
hash, err,
),
}
Some(data)
},
Expand Down
Binary file modified arbitrator/prover/test-cases/rust/data/msg0.bin
Binary file not shown.
Binary file modified arbitrator/prover/test-cases/rust/data/msg1.bin
Binary file not shown.
19 changes: 12 additions & 7 deletions arbitrator/prover/test-cases/rust/src/bin/host-io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@ fn main() {
let mut bytebuffer = Bytes32([0x0; 32]);
// in delayed inbox - we're skipping the "kind" byte
println!("delayed inbox message 0");
let mut expected_buffer = bytebuffer.0;
let len = wavm_read_delayed_inbox_message(0, bytebuffer.0.as_mut_ptr(), DELAYED_HEADER_LEN);
assert_eq!(len, 2);
assert_eq!(bytebuffer.0[1], 0xaa);
assert_eq!(len, 3);
expected_buffer[2] = 0xaa;
assert_eq!(bytebuffer.0, expected_buffer);
println!("delayed inbox message 1");
let len = wavm_read_delayed_inbox_message(1, bytebuffer.0.as_mut_ptr(), DELAYED_HEADER_LEN);
assert_eq!(len, 32);
for j in 1..31 {
assert_eq!(bytebuffer.0[j], (j as u8));
for j in 1..32 {
assert_eq!(bytebuffer.0[j], (j as u8) - 1);
}
println!("inbox message 0");
expected_buffer = bytebuffer.0;
let len = wavm_read_inbox_message(0, bytebuffer.0.as_mut_ptr(), INBOX_HEADER_LEN);
assert_eq!(len, 1);
assert_eq!(bytebuffer.0[0], 0xaa);
expected_buffer[0] = 0;
expected_buffer[1] = 0xaa;
assert_eq!(len, 2);
assert_eq!(bytebuffer.0, expected_buffer);
println!("inbox message 1");
let len = wavm_read_inbox_message(1, bytebuffer.0.as_mut_ptr(), INBOX_HEADER_LEN);
assert_eq!(len, 32);
for j in 0..32 {
assert_eq!(bytebuffer.0[j], (j as u8) + 1);
assert_eq!(bytebuffer.0[j], (j as u8));
}

let keccak_hash = hex!("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad");
Expand Down
Loading

0 comments on commit 26eb57d

Please sign in to comment.