From dce50b0de0f0d53d5ac25ad029f6d1444b6d9f16 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Wed, 10 Jul 2024 22:33:43 +0530 Subject: [PATCH 1/5] Validate wasmModuleRoot while building docker --- Dockerfile | 3 +++ arbitrator/prover/src/main.rs | 15 +++++++++++++++ scripts/validate-wasm-module-root.sh | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100755 scripts/validate-wasm-module-root.sh diff --git a/Dockerfile b/Dockerfile index 37c1020a42..d7b4a5415b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -249,7 +249,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 && \ diff --git a/arbitrator/prover/src/main.rs b/arbitrator/prover/src/main.rs index 9ddd5020c8..006458b597 100644 --- a/arbitrator/prover/src/main.rs +++ b/arbitrator/prover/src/main.rs @@ -41,6 +41,9 @@ struct Opts { #[structopt(long)] /// print modules to the console print_modules: bool, + #[structopt(long)] + /// print modules to the console + print_wasmmoduleroot: bool, /// profile output instead of generting proofs #[structopt(short = "p", long)] profile_run: bool, @@ -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.into()); + } + } + } let mut inbox_contents = HashMap::default(); let mut inbox_position = opts.inbox_position; let mut delayed_position = opts.delayed_inbox_position; diff --git a/scripts/validate-wasm-module-root.sh b/scripts/validate-wasm-module-root.sh new file mode 100755 index 0000000000..4de0278da8 --- /dev/null +++ b/scripts/validate-wasm-module-root.sh @@ -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=$(basename "$machine") + 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 \ No newline at end of file From 867a1b13228da29fabe399a045e7ed4e09e02d02 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Wed, 10 Jul 2024 22:46:16 +0530 Subject: [PATCH 2/5] fix --- scripts/validate-wasm-module-root.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate-wasm-module-root.sh b/scripts/validate-wasm-module-root.sh index 4de0278da8..5a7dd32abb 100755 --- a/scripts/validate-wasm-module-root.sh +++ b/scripts/validate-wasm-module-root.sh @@ -6,7 +6,7 @@ PROVER=$2 for machine in "$MACHINES_DIR"/*/ ; do if [ -d "$machine" ]; then - expectedWasmModuleRoot=$(basename "$machine") + 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" From c8602b39cb5b5f45a0a09741ec553edabe0bd53a Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 11 Jul 2024 11:04:17 +0530 Subject: [PATCH 3/5] fix --- arbitrator/prover/src/main.rs | 2 +- scripts/validate-wasm-module-root.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arbitrator/prover/src/main.rs b/arbitrator/prover/src/main.rs index 006458b597..2d09d30cea 100644 --- a/arbitrator/prover/src/main.rs +++ b/arbitrator/prover/src/main.rs @@ -42,7 +42,7 @@ struct Opts { /// print modules to the console print_modules: bool, #[structopt(long)] - /// print modules to the console + /// print wasm module root to the console print_wasmmoduleroot: bool, /// profile output instead of generting proofs #[structopt(short = "p", long)] diff --git a/scripts/validate-wasm-module-root.sh b/scripts/validate-wasm-module-root.sh index 5a7dd32abb..f62a46a8d7 100755 --- a/scripts/validate-wasm-module-root.sh +++ b/scripts/validate-wasm-module-root.sh @@ -13,4 +13,4 @@ for machine in "$MACHINES_DIR"/*/ ; do exit 1 fi fi -done \ No newline at end of file +done From 3692cce6585f31df46e474d145054e18dfd985d1 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 11 Jul 2024 11:19:33 +0530 Subject: [PATCH 4/5] fix --- arbitrator/prover/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/prover/src/main.rs b/arbitrator/prover/src/main.rs index 2d09d30cea..0f4d19bbaf 100644 --- a/arbitrator/prover/src/main.rs +++ b/arbitrator/prover/src/main.rs @@ -133,7 +133,7 @@ fn main() -> Result<()> { }, Err(err) => { eprintln!("Error loading binary: {err}"); - return Err(err.into()); + return Err(err); } } } From dfe1fa78337ad447aa8891675dc41f9570b8dd66 Mon Sep 17 00:00:00 2001 From: Aman Sanghi Date: Thu, 11 Jul 2024 12:07:18 +0530 Subject: [PATCH 5/5] fix --- arbitrator/prover/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arbitrator/prover/src/main.rs b/arbitrator/prover/src/main.rs index 0f4d19bbaf..e10a415389 100644 --- a/arbitrator/prover/src/main.rs +++ b/arbitrator/prover/src/main.rs @@ -130,7 +130,7 @@ fn main() -> Result<()> { Ok(mach) => { println!("0x{}", mach.get_modules_root()); return Ok(()); - }, + } Err(err) => { eprintln!("Error loading binary: {err}"); return Err(err);