Skip to content

Commit

Permalink
Merge pull request #2479 from OffchainLabs/compute_wasm
Browse files Browse the repository at this point in the history
[NIT-2609] Compute and validate wasmModuleRoot while building docker
  • Loading branch information
joshuacolvin0 authored Jul 15, 2024
2 parents b50b745 + 3f8f213 commit 1acbed1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ COPY --from=node-builder /workspace/target/bin/nitro /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/relay /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/nitro-val /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/seq-coordinator-manager /usr/local/bin/
COPY --from=node-builder /workspace/target/bin/prover /usr/local/bin/
COPY --from=machine-versions /workspace/machines /home/user/target/machines
COPY ./scripts/validate-wasm-module-root.sh .
RUN ./validate-wasm-module-root.sh /home/user/target/machines /usr/local/bin/prover
USER root
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
Expand Down
15 changes: 15 additions & 0 deletions arbitrator/prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct Opts {
#[structopt(long)]
/// print modules to the console
print_modules: bool,
#[structopt(long)]
/// print wasm module root to the console
print_wasmmoduleroot: bool,
/// profile output instead of generting proofs
#[structopt(short = "p", long)]
profile_run: bool,
Expand Down Expand Up @@ -122,6 +125,18 @@ const DELAYED_HEADER_LEN: usize = 112; // also in test-case's host-io.rs & contr
fn main() -> Result<()> {
let opts = Opts::from_args();

if opts.print_wasmmoduleroot {
match Machine::new_from_wavm(&opts.binary) {
Ok(mach) => {
println!("0x{}", mach.get_modules_root());
return Ok(());
}
Err(err) => {
eprintln!("Error loading binary: {err}");
return Err(err);
}
}
}
let mut inbox_contents = HashMap::default();
let mut inbox_position = opts.inbox_position;
let mut delayed_position = opts.delayed_inbox_position;
Expand Down
16 changes: 16 additions & 0 deletions scripts/validate-wasm-module-root.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e

MACHINES_DIR=$1
PROVER=$2

for machine in "$MACHINES_DIR"/*/ ; do
if [ -d "$machine" ]; then
expectedWasmModuleRoot=$(cat "$machine/module-root.txt")
actualWasmModuleRoot=$(cd "$machine" && "$PROVER" machine.wavm.br --print-wasmmoduleroot)
if [ "$expectedWasmModuleRoot" != "$actualWasmModuleRoot" ]; then
echo "Error: Expected module root $expectedWasmModuleRoot but found $actualWasmModuleRoot in $machine"
exit 1
fi
fi
done

0 comments on commit 1acbed1

Please sign in to comment.