diff --git a/Makefile b/Makefile index 0a71d64f12..b736b04906 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ replay_wasm=$(output_latest)/replay.wasm arb_brotli_files = $(wildcard arbitrator/brotli/src/*.* arbitrator/brotli/src/*/*.* arbitrator/brotli/*.toml arbitrator/brotli/*.rs) .make/cbrotli-lib .make/cbrotli-wasm arbitrator_generated_header=$(output_root)/include/arbitrator.h -arbitrator_wasm_libs=$(patsubst %, $(output_root)/machines/latest/%.wasm, forward wasi_stub host_io soft-float arbcompress user_host program_exec) +arbitrator_wasm_libs=$(patsubst %, $(output_root)/machines/latest/%.wasm, wasi_stub host_io soft-float arbcompress user_host program_exec) arbitrator_stylus_lib=$(output_root)/lib/libstylus.a prover_bin=$(output_root)/bin/prover arbitrator_jit=$(output_root)/bin/jit @@ -75,16 +75,12 @@ arbitrator_test_wasms=$(patsubst %.wat,%.wasm, $(arbitrator_tests_wat)) $(patsub arbitrator_tests_link_info = $(shell cat $(arbitrator_cases)/link.txt | xargs) arbitrator_tests_link_deps = $(patsubst %,$(arbitrator_cases)/%.wasm, $(arbitrator_tests_link_info)) -arbitrator_tests_forward_wats = $(wildcard $(arbitrator_cases)/forward/*.wat) -arbitrator_tests_forward_deps = $(arbitrator_tests_forward_wats:wat=wasm) - WASI_SYSROOT?=/opt/wasi-sdk/wasi-sysroot arbitrator_wasm_lib_flags=$(patsubst %, -l %, $(arbitrator_wasm_libs)) rust_arbutil_files = $(wildcard arbitrator/arbutil/src/*.* arbitrator/arbutil/src/*/*.* arbitrator/arbutil/*.toml arbitrator/caller-env/src/*.* arbitrator/caller-env/src/*/*.* arbitrator/caller-env/*.toml) .make/cbrotli-lib -prover_direct_includes = $(patsubst %,$(output_latest)/%.wasm, forward forward_stub) prover_dir = arbitrator/prover/ rust_prover_files = $(wildcard $(prover_dir)/src/*.* $(prover_dir)/src/*/*.* $(prover_dir)/*.toml $(prover_dir)/*.rs) $(rust_arbutil_files) $(prover_direct_includes) $(arb_brotli_files) @@ -92,12 +88,9 @@ wasm_lib = arbitrator/wasm-libraries wasm_lib_cargo = $(wasm_lib)/.cargo/config.toml wasm_lib_deps = $(wildcard $(wasm_lib)/$(1)/*.toml $(wasm_lib)/$(1)/src/*.rs $(wasm_lib)/$(1)/*.rs) $(wasm_lib_cargo) $(rust_arbutil_files) $(arb_brotli_files) .make/machines wasm_lib_go_abi = $(call wasm_lib_deps,go-abi) -wasm_lib_forward = $(call wasm_lib_deps,forward) wasm_lib_user_host_trait = $(call wasm_lib_deps,user-host-trait) wasm_lib_user_host = $(call wasm_lib_deps,user-host) $(wasm_lib_user_host_trait) -forward_dir = $(wasm_lib)/forward - stylus_files = $(wildcard $(stylus_dir)/*.toml $(stylus_dir)/src/*.rs) $(wasm_lib_user_host_trait) $(rust_prover_files) jit_dir = arbitrator/jit @@ -281,7 +274,6 @@ clean: rm -f arbitrator/wasm-libraries/soft-float/*.o rm -f arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/*.o rm -f arbitrator/wasm-libraries/soft-float/SoftFloat/build/Wasm-Clang/*.a - rm -f arbitrator/wasm-libraries/forward/*.wat rm -rf arbitrator/stylus/tests/*/target/ arbitrator/stylus/tests/*/*.wasm @rm -rf contracts/build contracts/cache solgen/go/ @rm -f .make/* @@ -399,7 +391,7 @@ $(output_latest)/host_io.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,host-io) $( cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package host-io install arbitrator/wasm-libraries/$(wasm32_wasi)/host_io.wasm $@ -$(output_latest)/user_host.wasm: $(DEP_PREDICATE) $(wasm_lib_user_host) $(rust_prover_files) $(output_latest)/forward_stub.wasm .make/machines +$(output_latest)/user_host.wasm: $(DEP_PREDICATE) $(wasm_lib_user_host) $(rust_prover_files) .make/machines cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package user-host install arbitrator/wasm-libraries/$(wasm32_wasi)/user_host.wasm $@ @@ -415,17 +407,9 @@ $(output_latest)/arbcompress.wasm: $(DEP_PREDICATE) $(call wasm_lib_deps,brotli) cargo build --manifest-path arbitrator/wasm-libraries/Cargo.toml --release --target wasm32-wasi --config $(wasm_lib_cargo) --package arbcompress install arbitrator/wasm-libraries/$(wasm32_wasi)/arbcompress.wasm $@ -$(output_latest)/forward.wasm: $(DEP_PREDICATE) $(wasm_lib_forward) .make/machines - cargo run --manifest-path $(forward_dir)/Cargo.toml -- --path $(forward_dir)/forward.wat - wat2wasm $(wasm_lib)/forward/forward.wat -o $@ - -$(output_latest)/forward_stub.wasm: $(DEP_PREDICATE) $(wasm_lib_forward) .make/machines - cargo run --manifest-path $(forward_dir)/Cargo.toml -- --path $(forward_dir)/forward_stub.wat --stub - wat2wasm $(wasm_lib)/forward/forward_stub.wat -o $@ - $(output_latest)/machine.wavm.br: $(DEP_PREDICATE) $(prover_bin) $(arbitrator_wasm_libs) $(replay_wasm) - $(prover_bin) $(replay_wasm) --generate-binaries $(output_latest) \ - $(patsubst %,-l $(output_latest)/%.wasm, forward soft-float wasi_stub host_io user_host arbcompress program_exec) + $(prover_bin) $(replay_wasm) --generate-binaries $(output_latest) --with-forwarder \ + $(patsubst %,-l $(output_latest)/%.wasm, soft-float wasi_stub host_io user_host arbcompress program_exec) $(arbitrator_cases)/%.wasm: $(arbitrator_cases)/%.wat wat2wasm $< -o $@ @@ -492,10 +476,10 @@ target/testdata/preimages.bin: python3 scripts/create-test-preimages.py $@ contracts/test/prover/proofs/rust-%.json: $(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm $(prover_bin) $(arbitrator_wasm_libs) target/testdata/preimages.bin - $(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -b --allow-hostapi --require-success --inbox-add-stub-headers --inbox $(arbitrator_cases)/rust/data/msg0.bin --inbox $(arbitrator_cases)/rust/data/msg1.bin --delayed-inbox $(arbitrator_cases)/rust/data/msg0.bin --delayed-inbox $(arbitrator_cases)/rust/data/msg1.bin --preimages target/testdata/preimages.bin + $(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -b --allow-hostapi --require-success --inbox-add-stub-headers --inbox $(arbitrator_cases)/rust/data/msg0.bin --inbox $(arbitrator_cases)/rust/data/msg1.bin --delayed-inbox $(arbitrator_cases)/rust/data/msg0.bin --delayed-inbox $(arbitrator_cases)/rust/data/msg1.bin --preimages target/testdata/preimages.bin --with-forwarder contracts/test/prover/proofs/go.json: $(arbitrator_cases)/go/testcase.wasm $(prover_bin) $(arbitrator_wasm_libs) target/testdata/preimages.bin $(arbitrator_tests_link_deps) $(arbitrator_cases)/user.wasm - $(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -b --require-success --preimages target/testdata/preimages.bin --stylus-modules $(arbitrator_cases)/user.wasm + $(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -b --require-success --preimages target/testdata/preimages.bin --stylus-modules $(arbitrator_cases)/user.wasm --with-forwarder # avoid testing user.wasm in onestepproofs. It can only run as stylus program. contracts/test/prover/proofs/user.json: @@ -508,9 +492,6 @@ contracts/test/prover/proofs/read-inboxmsg-10.json: contracts/test/prover/proofs/global-state.json: echo "[]" > $@ -contracts/test/prover/proofs/forward-test.json: $(arbitrator_cases)/forward-test.wasm $(arbitrator_tests_forward_deps) $(prover_bin) - $(prover_bin) $< -o $@ --allow-hostapi $(patsubst %,-l %, $(arbitrator_tests_forward_deps)) - contracts/test/prover/proofs/link.json: $(arbitrator_cases)/link.wasm $(arbitrator_tests_link_deps) $(prover_bin) $(prover_bin) $< -o $@ --allow-hostapi --stylus-modules $(arbitrator_tests_link_deps) --require-success diff --git a/arbitrator/arbutil/src/hostios.rs b/arbitrator/arbutil/src/hostios.rs new file mode 100644 index 0000000000..05bcb94f73 --- /dev/null +++ b/arbitrator/arbutil/src/hostios.rs @@ -0,0 +1,64 @@ +use std::fmt::Display; + +pub enum ParamType { + I32, + I64, +} + +impl Display for ParamType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use ParamType::*; + match self { + I32 => write!(f, "i32"), + I64 => write!(f, "i64"), + } + } +} + +use ParamType::*; + +/// order matters! +pub const HOSTIOS: [(&str, &[ParamType], &[ParamType]); 42] = [ + ("read_args", &[I32], &[]), + ("write_result", &[I32, I32], &[]), + ("exit_early", &[I32], &[]), + ("storage_load_bytes32", &[I32, I32], &[]), + ("storage_cache_bytes32", &[I32, I32], &[]), + ("storage_flush_cache", &[I32], &[]), + ("transient_load_bytes32", &[I32, I32], &[]), + ("transient_store_bytes32", &[I32, I32], &[]), + ("call_contract", &[I32, I32, I32, I32, I64, I32], &[I32]), + ("delegate_call_contract", &[I32, I32, I32, I64, I32], &[I32]), + ("static_call_contract", &[I32, I32, I32, I64, I32], &[I32]), + ("create1", &[I32, I32, I32, I32, I32], &[]), + ("create2", &[I32, I32, I32, I32, I32, I32], &[]), + ("read_return_data", &[I32, I32, I32], &[I32]), + ("return_data_size", &[], &[I32]), + ("emit_log", &[I32, I32, I32], &[]), + ("account_balance", &[I32, I32], &[]), + ("account_code", &[I32, I32, I32, I32], &[I32]), + ("account_code_size", &[I32], &[I32]), + ("account_codehash", &[I32, I32], &[]), + ("evm_gas_left", &[], &[I64]), + ("evm_ink_left", &[], &[I64]), + ("block_basefee", &[I32], &[]), + ("chainid", &[], &[I64]), + ("block_coinbase", &[I32], &[]), + ("block_gas_limit", &[], &[I64]), + ("block_number", &[], &[I64]), + ("block_timestamp", &[], &[I64]), + ("contract_address", &[I32], &[]), + ("math_div", &[I32, I32], &[]), + ("math_mod", &[I32, I32], &[]), + ("math_pow", &[I32, I32], &[]), + ("math_add_mod", &[I32, I32, I32], &[]), + ("math_mul_mod", &[I32, I32, I32], &[]), + ("msg_reentrant", &[], &[I32]), + ("msg_sender", &[I32], &[]), + ("msg_value", &[I32], &[]), + ("native_keccak256", &[I32, I32, I32], &[]), + ("tx_gas_price", &[I32], &[]), + ("tx_ink_price", &[], &[I32]), + ("tx_origin", &[I32], &[]), + ("pay_for_memory_grow", &[I32], &[]), +]; diff --git a/arbitrator/arbutil/src/lib.rs b/arbitrator/arbutil/src/lib.rs index 9c48a9fefc..8d8c1d0fca 100644 --- a/arbitrator/arbutil/src/lib.rs +++ b/arbitrator/arbutil/src/lib.rs @@ -6,6 +6,7 @@ pub mod color; pub mod crypto; pub mod evm; pub mod format; +pub mod hostios; pub mod math; pub mod operator; pub mod pricing; diff --git a/arbitrator/prover/Cargo.toml b/arbitrator/prover/Cargo.toml index 5475647765..a634dba19e 100644 --- a/arbitrator/prover/Cargo.toml +++ b/arbitrator/prover/Cargo.toml @@ -47,6 +47,10 @@ enum-iterator = "2.0.1" criterion = { version = "0.5.0", features = ["html_reports"] } rand = "0.8.4" +[build-dependencies] +wasmer = { path = "../tools/wasmer/lib/api" } +arbutil = { path = "../arbutil/" } + [[bench]] name = "merkle_bench" harness = false diff --git a/arbitrator/prover/build.rs b/arbitrator/prover/build.rs new file mode 100644 index 0000000000..db0560b2c5 --- /dev/null +++ b/arbitrator/prover/build.rs @@ -0,0 +1,89 @@ +use arbutil::hostios::HOSTIOS; +use std::{env, fmt::Write, fs, path::Path}; + +pub fn gen_forwarder(out_path: &Path) { + let mut wat = String::new(); + macro_rules! wln { + ($($text:tt)*) => { + writeln!(wat, $($text)*).unwrap(); + }; + } + let s = " "; + + wln!("(module"); + + macro_rules! group { + ($list:expr, $kind:expr) => { + (!$list.is_empty()) + .then(|| { + format!( + " ({} {})", + $kind, + $list + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(" ") + ) + }) + .unwrap_or_default() + }; + } + + wln!("{s};; symbols to re-export"); + for (name, ins, outs) in HOSTIOS { + let params = group!(ins, "param"); + let result = group!(outs, "result"); + wln!(r#"{s}(import "user_host" "{name}" (func $_{name}{params}{result}))"#); + } + wln!(); + + wln!("{s};; reserved offsets for future user_host imports"); + for i in HOSTIOS.len()..512 { + wln!("{s}(func $reserved_{i} unreachable)"); + } + wln!(); + + wln!( + "{s};; allows user_host to request a trap\n\ + {s}(global $trap (mut i32) (i32.const 0))\n\ + {s}(func $check\n\ + {s}{s}global.get $trap ;; see if set\n\ + {s}{s}(global.set $trap (i32.const 0)) ;; reset the flag\n\ + {s}{s}(if (then (unreachable)))\n\ + {s})\n\ + {s}(func (export \"forward__set_trap\")\n\ + {s}{s}(global.set $trap (i32.const 1))\n\ + {s})\n" + ); + + wln!("{s};; user linkage"); + for (name, ins, outs) in HOSTIOS { + let params = group!(ins, "param"); + let result = group!(outs, "result"); + wln!("{s}(func (export \"vm_hooks__{name}\"){params}{result}"); + + for i in 0..ins.len() { + wln!("{s}{s}local.get {i}"); + } + + wln!( + "{s}{s}call $_{name}\n\ + {s}{s}call $check\n\ + {s})" + ); + } + + wln!(")"); + eprintln!("{}", &wat); + + let wasm = wasmer::wat2wasm(wat.as_bytes()).unwrap(); + + fs::write(out_path, wasm.as_ref()).unwrap(); +} + +fn main() { + let out_dir = env::var("OUT_DIR").unwrap(); + let forwarder_path = Path::new(&out_dir).join("forwarder.wasm"); + gen_forwarder(&forwarder_path); +} diff --git a/arbitrator/prover/src/binary.rs b/arbitrator/prover/src/binary.rs index aa5537476c..b1d819deb2 100644 --- a/arbitrator/prover/src/binary.rs +++ b/arbitrator/prover/src/binary.rs @@ -471,10 +471,14 @@ pub fn parse<'a>(input: &'a [u8], path: &'_ Path) -> Result> { let export = export.rsplit("__").take(1); exports.extend(export); } - for import in &binary.imports { - let name = import.name; - if exports.contains(name) { - bail!("binary exports an import with the same name {}", name.red()); + // forwarder is allowed to re-export the same name + // TODO: is there a real problem if import_name == export_name but module names don't? + if path != Path::new("forwarder") { + for import in &binary.imports { + let name = import.name; + if exports.contains(name) { + bail!("binary exports an import with the same name {}", name.red()); + } } } diff --git a/arbitrator/prover/src/host.rs b/arbitrator/prover/src/host.rs index 1d0fe658ec..dc0f0b74b2 100644 --- a/arbitrator/prover/src/host.rs +++ b/arbitrator/prover/src/host.rs @@ -405,7 +405,7 @@ impl Hostio { } } -pub fn get_impl(module: &str, name: &str) -> Result<(Function, bool)> { +pub fn get_impl(module: &str, name: &str) -> Result { let hostio: Hostio = format!("{module}__{name}").parse()?; let append = |code: &mut Vec| { @@ -414,8 +414,11 @@ pub fn get_impl(module: &str, name: &str) -> Result<(Function, bool)> { Ok(()) }; - let debug = module == "console" || module == "debug"; - Function::new(&[], append, hostio.ty(), &[]).map(|x| (x, debug)) + Function::new(&[], append, hostio.ty(), &[]) +} + +pub fn hostio_module_is_debug(module: &str) -> bool { + module == "console" || module == "debug" } /// Adds internal functions to a module. diff --git a/arbitrator/prover/src/lib.rs b/arbitrator/prover/src/lib.rs index 0f537478eb..e45d12c492 100644 --- a/arbitrator/prover/src/lib.rs +++ b/arbitrator/prover/src/lib.rs @@ -70,10 +70,16 @@ pub unsafe extern "C" fn arbitrator_load_machine( library_paths: *const *const c_char, library_paths_size: isize, debug_chain: usize, + with_forwarder: bool, ) -> *mut Machine { let debug_chain = debug_chain != 0; - match arbitrator_load_machine_impl(binary_path, library_paths, library_paths_size, debug_chain) - { + match arbitrator_load_machine_impl( + binary_path, + library_paths, + library_paths_size, + debug_chain, + with_forwarder, + ) { Ok(mach) => mach, Err(err) => { eprintln!("Error loading binary: {:?}", err); @@ -87,6 +93,7 @@ unsafe fn arbitrator_load_machine_impl( library_paths: *const *const c_char, library_paths_size: isize, debug_chain: bool, + with_forwarder: bool, ) -> Result<*mut Machine> { let binary_path = cstr_to_string(binary_path); let binary_path = Path::new(&binary_path); @@ -107,6 +114,7 @@ unsafe fn arbitrator_load_machine_impl( Default::default(), Default::default(), get_empty_preimage_resolver(), + with_forwarder, )?; Ok(Box::into_raw(Box::new(mach))) } diff --git a/arbitrator/prover/src/machine.rs b/arbitrator/prover/src/machine.rs index 358876bd25..2418d3cc2e 100644 --- a/arbitrator/prover/src/machine.rs +++ b/arbitrator/prover/src/machine.rs @@ -19,7 +19,7 @@ use crate::{ IBinOpType, IRelOpType, IUnOpType, Instruction, Opcode, }, }; -use arbutil::{crypto, math, Bytes32, Color, DebugColor, PreimageType}; +use arbutil::{crypto, hostios::HOSTIOS, math, Bytes32, Color, DebugColor, PreimageType}; use brotli::Dictionary; #[cfg(feature = "native")] use c_kzg::BYTES_PER_BLOB; @@ -330,36 +330,115 @@ pub struct Module { pub(crate) extra_hash: Arc, } +#[cfg(feature = "native")] +static FORWARDER_WASM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/forwarder.wasm")); + lazy_static! { static ref USER_IMPORTS: HashMap = { let mut imports = HashMap::default(); - let forward = include_bytes!("../../../target/machines/latest/forward_stub.wasm"); - let forward = binary::parse(forward, Path::new("forward")).unwrap(); - - for (name, &(export, kind)) in &forward.exports { - if kind == ExportKind::Func { - let ty = match forward.get_function(FunctionIndex::from_u32(export)) { - Ok(ty) => ty, - Err(error) => panic!("failed to read export {name}: {error:?}"), - }; - let import = AvailableImport::new(ty, 1, export); - imports.insert(name.to_owned(), import); - } + // 0-513 are internal + for (index, (name, ins, outs)) in HOSTIOS.iter().enumerate() { + let import = AvailableImport::new(FunctionType::new(ins.iter().map(|x|x.into()).collect::>(), outs.iter().map(|x|x.into()).collect::>()), 1, (index + 514).try_into().unwrap()); + imports.insert(format!("vm_hooks__{name}"), import); } imports }; } +trait ImportResolver: for<'a, 'b> Fn(&'a str, &'b str) -> Result + Sized { + fn compose(self, other: impl ImportResolver) -> impl ImportResolver { + move |module, name| { + self(module, name).or_else(|original_err| { + let mut result = other(module, name); + if result.is_err() { + for err_layer in original_err.chain().rev() { + result = result.wrap_err(format!("{err_layer}")); + } + } + result + }) + } + } + + fn condition(self, condition: bool) -> impl ImportResolver { + move |module, name| { + if condition { + self(module, name) + } else { + bail!("resolver disabled") + } + } + } +} + +impl Fn(&'a str, &'b str) -> Result> ImportResolver for F {} + impl Module { - const FORWARDING_PREFIX: &'static str = "arbitrator_forward__"; + fn make_imports_resolver( + import_map: &HashMap, + ) -> impl ImportResolver + '_ { + move |module, name| { + let qualified_name = format!("{module}__{name}"); + + let Some(import) = import_map.get(&qualified_name) else { + bail!("func not found {module} {name}") + }; + let wavm = vec![ + Instruction::simple(Opcode::InitFrame), + Instruction::with_data( + Opcode::CrossModuleCall, + pack_cross_module_call(import.module, import.func), + ), + Instruction::simple(Opcode::Return), + ]; + Ok(Function::new_from_wavm(wavm, import.ty.clone(), vec![])) + } + } + + fn make_forward_resolver( + import_map: &HashMap, + ) -> impl ImportResolver + '_ { + move |module, name| { + let qualified_name = format!("{module}__{name}"); + + let Some(import) = import_map.get(&qualified_name) else { + bail!("func not found {module} {name}") + }; + let wavm = vec![ + Instruction::simple(Opcode::InitFrame), + Instruction::with_data( + Opcode::CrossModuleForward, + pack_cross_module_call(import.module, import.func), + ), + Instruction::simple(Opcode::Return), + ]; + Ok(Function::new_from_wavm(wavm, import.ty.clone(), vec![])) + } + } + + fn hostio_resolver(module: &str, name: &str) -> Result { + if host::hostio_module_is_debug(module) { + return Self::notfound_resolver(module, name); + } + host::get_impl(module, name) + } + + fn debug_resolver(module: &str, name: &str) -> Result { + if !host::hostio_module_is_debug(module) { + return Self::notfound_resolver(module, name); + } + host::get_impl(module, name) + } + + fn notfound_resolver(module: &str, name: &str) -> Result { + bail!("import not found {module} {name}") + } - fn from_binary( + fn from_binary( bin: &WasmBinary, - available_imports: &HashMap, + import_resolver: R, floating_point_impls: &FloatingPointImpls, - allow_hostapi: bool, - debug_funcs: bool, stylus_data: Option, ) -> Result { let mut code = Vec::new(); @@ -371,53 +450,18 @@ impl Module { for import in &bin.imports { let module = import.module; let have_ty = &bin.types[import.offset as usize]; - let (forward, import_name) = match import.name.strip_prefix(Module::FORWARDING_PREFIX) { - Some(name) => (true, name), - None => (false, import.name), - }; - let mut qualified_name = format!("{module}__{import_name}"); - qualified_name = qualified_name.replace(&['/', '.', '-'] as &[char], "_"); + let func = import_resolver(import.module, import.name)?; - let func = if let Some(import) = available_imports.get(&qualified_name) { - let call = match forward { - true => Opcode::CrossModuleForward, - false => Opcode::CrossModuleCall, - }; - let wavm = vec![ - Instruction::simple(Opcode::InitFrame), - Instruction::with_data( - call, - pack_cross_module_call(import.module, import.func), - ), - Instruction::simple(Opcode::Return), - ]; - Function::new_from_wavm(wavm, import.ty.clone(), vec![]) - } else if let Ok((hostio, debug)) = host::get_impl(import.module, import_name) { - ensure!( - (debug && debug_funcs) || (!debug && allow_hostapi), - "Host func {} in {} not enabled debug_funcs={debug_funcs} hostapi={allow_hostapi} debug={debug}", - import_name.red(), - import.module.red(), - ); - hostio - } else { - bail!( - "No such import {} in {} for {}", - import_name.red(), - import.module.red(), - bin_name.red() - ) - }; ensure!( &func.ty == have_ty, "Import {} for {} has different function signature than export.\nexpected {} in {}\nbut have {}", - import_name.red(), bin_name.red(), func.ty.red(), module.red(), have_ty.red(), + import.name.red(), bin_name.red(), func.ty.red(), module.red(), have_ty.red(), ); func_type_idxs.push(import.offset); code.push(func); - host_call_hooks.push(Some((import.module.into(), import_name.into()))); + host_call_hooks.push(Some((import.module.into(), import.name.into()))); } func_type_idxs.extend(bin.functions.iter()); @@ -613,10 +657,9 @@ impl Module { ) -> Result { Self::from_binary( bin, - &USER_IMPORTS, + Module::make_imports_resolver(&USER_IMPORTS) + .compose(Module::debug_resolver.condition(debug_funcs)), &HashMap::default(), - false, - debug_funcs, stylus_data, ) } @@ -1227,6 +1270,7 @@ impl Machine { global_state: GlobalState, inbox_contents: HashMap<(InboxIdentifier, u64), Vec>, preimage_resolver: PreimageResolver, + with_forwarder: bool, ) -> Result { let bin_source = file_bytes(binary_path)?; let bin = parse(&bin_source, binary_path) @@ -1252,6 +1296,7 @@ impl Machine { inbox_contents, preimage_resolver, None, + with_forwarder, ) } @@ -1281,6 +1326,7 @@ impl Machine { HashMap::default(), Arc::new(|_, _, _| panic!("tried to read preimage")), Some(stylus_data), + false, )?; let footprint: u32 = stylus_data.footprint.into(); @@ -1328,6 +1374,7 @@ impl Machine { inbox_contents: HashMap<(InboxIdentifier, u64), Vec>, preimage_resolver: PreimageResolver, stylus_data: Option, + with_forwarder: bool, ) -> Result { use ArbValueType::*; @@ -1335,25 +1382,19 @@ impl Machine { let mut modules = vec![Module::default()]; let mut available_imports = HashMap::default(); let mut floating_point_impls = HashMap::default(); - let main_module_index = u32::try_from(modules.len() + libraries.len())?; - - // make the main module's exports available to libraries - for (name, &(export, kind)) in &bin.exports { - if kind == ExportKind::Func { - let index: usize = export.try_into()?; - if let Some(index) = index.checked_sub(bin.imports.len()) { - let ty: usize = bin.functions[index].try_into()?; - let ty = bin.types[ty].clone(); - available_imports.insert( - format!("env__wavm_guest_call__{name}"), - AvailableImport::new(ty, main_module_index, export), - ); - } - } - } + + let forwarder = if with_forwarder { + #[cfg(not(feature = "native"))] + bail!("forwarder not supported without native"); + + #[cfg(feature = "native")] + Some(parse(FORWARDER_WASM, Path::new("forwarder"))?) + } else { + None + }; // collect all the library exports in advance so they can use each other's - for (index, lib) in libraries.iter().enumerate() { + for (index, lib) in forwarder.iter().chain(libraries.iter()).enumerate() { let module = 1 + index as u32; // off by one due to the entry point for (name, &(export, kind)) in &lib.exports { if kind == ExportKind::Func { @@ -1361,54 +1402,57 @@ impl Machine { Ok(ty) => ty, Err(error) => bail!("failed to read export {name}: {error}"), }; - let import = AvailableImport::new(ty, module, export); + let import = AvailableImport::new(ty.clone(), module, export); available_imports.insert(name.to_owned(), import); + if let Ok(op) = name.parse::() { + let mut sig = op.signature(); + // wavm codegen takes care of effecting this type change at callsites + for ty in sig.inputs.iter_mut().chain(sig.outputs.iter_mut()) { + if *ty == F32 { + *ty = I32; + } else if *ty == F64 { + *ty = I64; + } + } + ensure!( + ty == sig, + "Wrong type for floating point impl {} expecting {} but got {}", + name.red(), + sig.red(), + ty.red() + ); + floating_point_impls.insert(op, (module, export)); + } } } } - for lib in libraries { - let module = Module::from_binary( + if let Some(lib) = forwarder { + modules.push(Module::from_binary( + &lib, + Module::make_forward_resolver(&available_imports), + &floating_point_impls, + None, + )?); + } + + for lib in libraries.iter() { + modules.push(Module::from_binary( lib, - &available_imports, + Module::hostio_resolver + .compose(Module::debug_resolver.condition(debug_funcs)) + .compose(Module::make_imports_resolver(&available_imports)), &floating_point_impls, - true, - debug_funcs, None, - )?; - for (name, &func) in &*module.func_exports { - let ty = module.func_types[func as usize].clone(); - if let Ok(op) = name.parse::() { - let mut sig = op.signature(); - // wavm codegen takes care of effecting this type change at callsites - for ty in sig.inputs.iter_mut().chain(sig.outputs.iter_mut()) { - if *ty == F32 { - *ty = I32; - } else if *ty == F64 { - *ty = I64; - } - } - ensure!( - ty == sig, - "Wrong type for floating point impl {} expecting {} but got {}", - name.red(), - sig.red(), - ty.red() - ); - floating_point_impls.insert(op, (modules.len() as u32, func)); - } - } - modules.push(module); + )?); } - // Shouldn't be necessary, but to be safe, don't allow the main binary to import its own guest calls - available_imports.retain(|_, i| i.module as usize != modules.len()); modules.push(Module::from_binary( &bin, - &available_imports, + Module::make_imports_resolver(&available_imports) + .compose(Module::hostio_resolver.condition(allow_hostapi_from_main)) + .compose(Module::debug_resolver.condition(debug_funcs)), &floating_point_impls, - allow_hostapi_from_main, - debug_funcs, stylus_data, )?); diff --git a/arbitrator/prover/src/main.rs b/arbitrator/prover/src/main.rs index dba32e0e72..442b35992d 100644 --- a/arbitrator/prover/src/main.rs +++ b/arbitrator/prover/src/main.rs @@ -86,6 +86,8 @@ struct Opts { skip_until_host_io: bool, #[structopt(long)] max_steps: Option, + #[structopt(short, long)] + with_forwarder: bool, } fn file_with_stub_header(path: &Path, headerlength: usize) -> Result> { @@ -211,6 +213,7 @@ fn main() -> Result<()> { global_state, inbox_contents, preimage_resolver, + opts.with_forwarder, )?; for path in &opts.stylus_modules { diff --git a/arbitrator/prover/src/test.rs b/arbitrator/prover/src/test.rs index 97170441ff..2f32aff012 100644 --- a/arbitrator/prover/src/test.rs +++ b/arbitrator/prover/src/test.rs @@ -57,7 +57,7 @@ pub fn reject_ambiguous_imports() { #[test] pub fn test_compress() -> Result<()> { - let data = include_bytes!("../../../target/machines/latest/forward_stub.wasm"); + let data = include_bytes!(concat!(env!("OUT_DIR"), "/forwarder.wasm")); let mut last = vec![]; for dict in [Dictionary::Empty, Dictionary::StylusProgram] { diff --git a/arbitrator/prover/src/value.rs b/arbitrator/prover/src/value.rs index 6afffdf7a0..f2f54404f0 100644 --- a/arbitrator/prover/src/value.rs +++ b/arbitrator/prover/src/value.rs @@ -2,7 +2,7 @@ // For license information, see https://github.com/nitro/blob/master/LICENSE use crate::binary::FloatType; -use arbutil::{Bytes32, Color}; +use arbutil::{hostios::ParamType, Bytes32, Color}; use digest::Digest; use eyre::{bail, ErrReport, Result}; use serde::{Deserialize, Serialize}; @@ -77,6 +77,16 @@ impl From for ValType { } } +impl From<&ParamType> for ArbValueType { + fn from(ty: &ParamType) -> Self { + use ParamType as V; + match ty { + V::I32 => Self::I32, + V::I64 => Self::I64, + } + } +} + #[cfg(feature = "native")] pub fn parser_type(ty: &wasmer::Type) -> wasmer::wasmparser::ValType { match ty { diff --git a/arbitrator/prover/test-cases/forward-test.wat b/arbitrator/prover/test-cases/forward-test.wat deleted file mode 100644 index b9beff0d82..0000000000 --- a/arbitrator/prover/test-cases/forward-test.wat +++ /dev/null @@ -1,32 +0,0 @@ - -(module - (import "forward" "add" (func $add (param i32 i32) (result i32))) - (import "forward" "sub" (func $sub (param i32 i32) (result i32))) - (import "forward" "mul" (func $mul (param i32 i32) (result i32))) - (func $start - ;; this address will update each time a forwarded call is made - i32.const 0xa4b - i32.const 805 - i32.store - - i32.const 11 - i32.const 5 - call $sub - - i32.const 3 - i32.const -2 - call $mul - - call $add - (if - (then (unreachable))) - - ;; check that the address has changed - i32.const 0xa4b - i32.load - i32.const 808 - i32.ne - (if - (then (unreachable)))) - (start $start) - (memory 1)) diff --git a/arbitrator/prover/test-cases/forward/forward.wat b/arbitrator/prover/test-cases/forward/forward.wat deleted file mode 100644 index ff55953e62..0000000000 --- a/arbitrator/prover/test-cases/forward/forward.wat +++ /dev/null @@ -1,8 +0,0 @@ - -(module - (import "target" "arbitrator_forward__add" (func $add (param i32 i32) (result i32))) - (import "target" "arbitrator_forward__sub" (func $sub (param i32 i32) (result i32))) - (import "target" "arbitrator_forward__mul" (func $mul (param i32 i32) (result i32))) - (export "forward__add" (func $add)) - (export "forward__sub" (func $sub)) - (export "forward__mul" (func $mul))) diff --git a/arbitrator/prover/test-cases/forward/target.wat b/arbitrator/prover/test-cases/forward/target.wat deleted file mode 100644 index 0779eb753d..0000000000 --- a/arbitrator/prover/test-cases/forward/target.wat +++ /dev/null @@ -1,27 +0,0 @@ - -(module - (import "env" "wavm_caller_load8" (func $load (param i32) (result i32))) - (import "env" "wavm_caller_store8" (func $store (param i32 i32))) - (func (export "target__add") (param i32 i32) (result i32) - call $write_caller - local.get 0 - local.get 1 - i32.add) - (func (export "target__sub") (param i32 i32) (result i32) - call $write_caller - local.get 0 - local.get 1 - i32.sub) - (func (export "target__mul") (param i32 i32) (result i32) - call $write_caller - local.get 0 - local.get 1 - i32.mul) - (func $write_caller (export "write_caller") - ;; increment the value at address 0xa4b in the caller - i32.const 0xa4b - i32.const 0xa4b - call $load - i32.const 1 - i32.add - call $store)) diff --git a/arbitrator/stylus/src/test/mod.rs b/arbitrator/stylus/src/test/mod.rs index 00c9c62ae4..42c9446564 100644 --- a/arbitrator/stylus/src/test/mod.rs +++ b/arbitrator/stylus/src/test/mod.rs @@ -164,6 +164,7 @@ fn new_test_machine(path: &str, compile: &CompileConfig) -> Result { HashMap::default(), Arc::new(|_, _, _| panic!("tried to read preimage")), Some(stylus_data), + false, )?; mach.set_ink(u64::MAX); mach.set_stack(u32::MAX); diff --git a/arbitrator/tools/module_roots/src/main.rs b/arbitrator/tools/module_roots/src/main.rs index 32e4764847..fc22bed5fa 100644 --- a/arbitrator/tools/module_roots/src/main.rs +++ b/arbitrator/tools/module_roots/src/main.rs @@ -39,6 +39,7 @@ fn main() -> Result<()> { GlobalState::default(), HashMap::default(), Arc::new(|_, _, _| panic!("tried to read preimage")), + false, )?; let mut stylus = vec![]; diff --git a/arbitrator/wasm-libraries/Cargo.lock b/arbitrator/wasm-libraries/Cargo.lock index 7620ff538b..b234424f69 100644 --- a/arbitrator/wasm-libraries/Cargo.lock +++ b/arbitrator/wasm-libraries/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli 0.29.0", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.7.8" @@ -91,6 +106,21 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "bincode" version = "1.3.3" @@ -187,6 +217,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.7.0" @@ -203,6 +239,15 @@ dependencies = [ "rand_pcg", ] +[[package]] +name = "cc" +version = "1.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +dependencies = [ + "shlex", +] + [[package]] name = "cfg-if" version = "0.1.10" @@ -236,6 +281,19 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "corosensei" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80128832c58ea9cbd041d2a759ec449224487b2c1e400453d99d244eead87a8e" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "libc", + "scopeguard", + "windows-sys 0.33.0", +] + [[package]] name = "cpufeatures" version = "0.2.12" @@ -245,6 +303,123 @@ dependencies = [ "libc", ] +[[package]] +name = "cranelift-bforest" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2ab4512dfd3a6f4be184403a195f76e81a8a9f9e6c898e19d2dc3ce20e0115" +dependencies = [ + "cranelift-entity", +] + +[[package]] +name = "cranelift-codegen" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b022ed2a5913a38839dfbafe6cf135342661293b08049843362df4301261dc" +dependencies = [ + "arrayvec", + "bumpalo", + "cranelift-bforest", + "cranelift-codegen-meta", + "cranelift-codegen-shared", + "cranelift-egraph", + "cranelift-entity", + "cranelift-isle", + "gimli 0.26.2", + "log", + "regalloc2", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-codegen-meta" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "639307b45434ad112a98f8300c0f0ab085cbefcd767efcdef9ef19d4c0756e74" +dependencies = [ + "cranelift-codegen-shared", +] + +[[package]] +name = "cranelift-codegen-shared" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "278e52e29c53fcf32431ef08406c295699a70306d05a0715c5b1bf50e33a9ab7" + +[[package]] +name = "cranelift-egraph" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624b54323b06e675293939311943ba82d323bb340468ce1889be5da7932c8d73" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown 0.12.3", + "indexmap 1.9.3", + "log", + "smallvec", +] + +[[package]] +name = "cranelift-entity" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a59bcbca89c3f1b70b93ab3cbba5e5e0cbf3e63dadb23c7525cb142e21a9d4c" + +[[package]] +name = "cranelift-frontend" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d70abacb8cfef3dc8ff7e8836e9c1d70f7967dfdac824a4cd5e30223415aca6" +dependencies = [ + "cranelift-codegen", + "log", + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cranelift-isle" +version = "0.91.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "393bc73c451830ff8dbb3a07f61843d6cb41a084f9996319917c0b291ed785bb" + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crunchy" version = "0.2.2" @@ -330,6 +505,19 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if 1.0.0", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "derivative" version = "2.2.0" @@ -456,26 +644,33 @@ dependencies = [ "once_cell", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "forward" -version = "0.1.0" -dependencies = [ - "eyre", - "structopt", -] - [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -497,6 +692,23 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +dependencies = [ + "fallible-iterator", + "indexmap 1.9.3", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + [[package]] name = "hashbrown" version = "0.12.3" @@ -595,6 +807,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "keccak" version = "0.1.5" @@ -632,6 +853,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "lru" version = "0.12.4" @@ -641,12 +868,57 @@ dependencies = [ "hashbrown 0.14.5", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "mach2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "memmap2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d28bba84adfe6646737845bc5ebbfa2c08424eb1c37e94a1fd2a82adb56a872" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + [[package]] name = "memory_units" version = "0.4.0" @@ -659,6 +931,15 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + [[package]] name = "more-asserts" version = "0.2.2" @@ -791,6 +1072,15 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -832,6 +1122,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -912,6 +1208,7 @@ dependencies = [ "smallvec", "static_assertions", "structopt", + "wasmer", "wasmer-types", "wasmparser", "wat", @@ -976,6 +1273,26 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.3" @@ -985,6 +1302,30 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "regalloc2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" +dependencies = [ + "fxhash", + "log", + "slice-group-by", + "smallvec", +] + +[[package]] +name = "region" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b6ebd13bc009aef9cd476c1310d49ac354d36e240cf1bd753290f3dc7199a7" +dependencies = [ + "bitflags 1.3.2", + "libc", + "mach2", + "windows-sys 0.52.0", +] + [[package]] name = "rend" version = "0.4.2" @@ -1075,6 +1416,12 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" +[[package]] +name = "self_cell" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" + [[package]] name = "semver" version = "1.0.23" @@ -1090,6 +1437,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_derive" version = "1.0.204" @@ -1181,6 +1539,22 @@ dependencies = [ "keccak", ] +[[package]] +name = "shared-buffer" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6c99835bad52957e7aa241d3975ed17c1e5f8c92026377d117a606f36b84b16" +dependencies = [ + "bytes", + "memmap2 0.6.2", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "simdutf8" version = "0.1.4" @@ -1193,6 +1567,12 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "smallvec" version = "1.13.2" @@ -1202,6 +1582,12 @@ dependencies = [ "serde", ] +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" @@ -1348,6 +1734,37 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + [[package]] name = "typenum" version = "1.17.0" @@ -1445,13 +1862,147 @@ dependencies = [ "wee_alloc", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.72", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + [[package]] name = "wasm-encoder" -version = "0.215.0" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb56df3e06b8e6b77e37d2969a50ba51281029a9aeb3855e76b7f49b6418847" +checksum = "1ba64e81215916eaeb48fee292f29401d69235d62d8b8fd92a7b2844ec5ae5f7" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasmer" +version = "4.2.8" dependencies = [ + "bytes", + "cfg-if 1.0.0", + "derivative", + "indexmap 1.9.3", + "js-sys", + "more-asserts", + "rustc-demangle", + "serde", + "serde-wasm-bindgen", + "shared-buffer", + "target-lexicon", + "thiserror", + "tracing", + "wasm-bindgen", + "wasmer-compiler", + "wasmer-compiler-cranelift", + "wasmer-derive", + "wasmer-types", + "wasmer-vm", + "wat", + "winapi", +] + +[[package]] +name = "wasmer-compiler" +version = "4.2.8" +dependencies = [ + "backtrace", + "bytes", + "cfg-if 1.0.0", + "enum-iterator 0.7.0", + "enumset", + "lazy_static", "leb128", + "memmap2 0.5.10", + "more-asserts", + "region", + "rkyv", + "self_cell", + "shared-buffer", + "smallvec", + "thiserror", + "wasmer-types", + "wasmer-vm", + "wasmparser", + "winapi", +] + +[[package]] +name = "wasmer-compiler-cranelift" +version = "4.2.8" +dependencies = [ + "cranelift-codegen", + "cranelift-entity", + "cranelift-frontend", + "gimli 0.26.2", + "more-asserts", + "rayon", + "smallvec", + "target-lexicon", + "tracing", + "wasmer-compiler", + "wasmer-types", +] + +[[package]] +name = "wasmer-derive" +version = "4.2.8" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -1468,6 +2019,32 @@ dependencies = [ "thiserror", ] +[[package]] +name = "wasmer-vm" +version = "4.2.8" +dependencies = [ + "backtrace", + "cc", + "cfg-if 1.0.0", + "corosensei", + "crossbeam-queue", + "dashmap", + "derivative", + "enum-iterator 0.7.0", + "fnv", + "indexmap 1.9.3", + "lazy_static", + "libc", + "mach", + "memoffset", + "more-asserts", + "region", + "scopeguard", + "thiserror", + "wasmer-types", + "winapi", +] + [[package]] name = "wasmparser" version = "0.121.2" @@ -1481,11 +2058,10 @@ dependencies = [ [[package]] name = "wast" -version = "215.0.0" +version = "64.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ff1d00d893593249e60720be04a7c1f42f1c4dc3806a2869f4e66ab61eb54cb" +checksum = "a259b226fd6910225aa7baeba82f9d9933b6d00f2ce1b49b80fa4214328237cc" dependencies = [ - "bumpalo", "leb128", "memchr", "unicode-width", @@ -1494,9 +2070,9 @@ dependencies = [ [[package]] name = "wat" -version = "1.215.0" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670bf4d9c8cf76ae242d70ded47c546525b6dafaa6871f9bcb065344bf2b4e3d" +checksum = "53253d920ab413fca1c7dc2161d601c79b4fdf631d0ba51dd4343bf9b556c3f6" dependencies = [ "wast", ] @@ -1535,6 +2111,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43dbb096663629518eb1dfa72d80243ca5a6aca764cae62a2df70af760a9be75" +dependencies = [ + "windows_aarch64_msvc 0.33.0", + "windows_i686_gnu 0.33.0", + "windows_i686_msvc 0.33.0", + "windows_x86_64_gnu 0.33.0", + "windows_x86_64_msvc 0.33.0", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -1542,13 +2140,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -1557,12 +2155,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd761fd3eb9ab8cc1ed81e56e567f02dd82c4c837e48ac3b2181b9ffc5060807" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_i686_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab0cf703a96bab2dc0c02c0fa748491294bf9b7feb27e1f4f96340f208ada0e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1575,12 +2185,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfdbe89cc9ad7ce618ba34abc34bbb6c36d99e96cae2245b7943cd75ee773d0" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_x86_64_gnu" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4dd9b0c0e9ece7bb22e84d70d01b71c6d6248b81a3c60d11869451b4cb24784" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" @@ -1593,6 +2215,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_msvc" +version = "0.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1e4aa646495048ec7f3ffddc411e1d829c026a2ec62b39da15c1055e406eaa" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/arbitrator/wasm-libraries/Cargo.toml b/arbitrator/wasm-libraries/Cargo.toml index 837df8f4da..2fd585ee7d 100644 --- a/arbitrator/wasm-libraries/Cargo.toml +++ b/arbitrator/wasm-libraries/Cargo.toml @@ -7,6 +7,5 @@ members = [ "user-host-trait", "user-test", "program-exec", - "forward", ] resolver = "2" diff --git a/arbitrator/wasm-libraries/forward/.gitignore b/arbitrator/wasm-libraries/forward/.gitignore deleted file mode 100644 index 40da2042b7..0000000000 --- a/arbitrator/wasm-libraries/forward/.gitignore +++ /dev/null @@ -1 +0,0 @@ -**.wat diff --git a/arbitrator/wasm-libraries/forward/Cargo.toml b/arbitrator/wasm-libraries/forward/Cargo.toml deleted file mode 100644 index 73ed9d8827..0000000000 --- a/arbitrator/wasm-libraries/forward/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "forward" -version = "0.1.0" -edition = "2021" - -[dependencies] -eyre = "0.6.5" -structopt = "0.3.26" diff --git a/arbitrator/wasm-libraries/forward/src/main.rs b/arbitrator/wasm-libraries/forward/src/main.rs deleted file mode 100644 index 05a949e8aa..0000000000 --- a/arbitrator/wasm-libraries/forward/src/main.rs +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright 2022-2024, Offchain Labs, Inc. -// For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE - -use eyre::Result; -use std::{fs::File, io::Write, path::PathBuf}; -use structopt::StructOpt; - -/// order matters! -const HOSTIOS: [[&str; 3]; 42] = [ - ["read_args", "i32", ""], - ["write_result", "i32 i32", ""], - ["exit_early", "i32", ""], - ["storage_load_bytes32", "i32 i32", ""], - ["storage_cache_bytes32", "i32 i32", ""], - ["storage_flush_cache", "i32", ""], - ["transient_load_bytes32", "i32 i32", ""], - ["transient_store_bytes32", "i32 i32", ""], - ["call_contract", "i32 i32 i32 i32 i64 i32", "i32"], - ["delegate_call_contract", "i32 i32 i32 i64 i32", "i32"], - ["static_call_contract", "i32 i32 i32 i64 i32", "i32"], - ["create1", "i32 i32 i32 i32 i32", ""], - ["create2", "i32 i32 i32 i32 i32 i32", ""], - ["read_return_data", "i32 i32 i32", "i32"], - ["return_data_size", "", "i32"], - ["emit_log", "i32 i32 i32", ""], - ["account_balance", "i32 i32", ""], - ["account_code", "i32 i32 i32 i32", "i32"], - ["account_code_size", "i32", "i32"], - ["account_codehash", "i32 i32", ""], - ["evm_gas_left", "", "i64"], - ["evm_ink_left", "", "i64"], - ["block_basefee", "i32", ""], - ["chainid", "", "i64"], - ["block_coinbase", "i32", ""], - ["block_gas_limit", "", "i64"], - ["block_number", "", "i64"], - ["block_timestamp", "", "i64"], - ["contract_address", "i32", ""], - ["math_div", "i32 i32", ""], - ["math_mod", "i32 i32", ""], - ["math_pow", "i32 i32", ""], - ["math_add_mod", "i32 i32 i32", ""], - ["math_mul_mod", "i32 i32 i32", ""], - ["msg_reentrant", "", "i32"], - ["msg_sender", "i32", ""], - ["msg_value", "i32", ""], - ["native_keccak256", "i32 i32 i32", ""], - ["tx_gas_price", "i32", ""], - ["tx_ink_price", "", "i32"], - ["tx_origin", "i32", ""], - ["pay_for_memory_grow", "i32", ""], -]; - -#[derive(StructOpt)] -#[structopt(name = "arbitrator-prover")] -struct Opts { - #[structopt(long)] - path: PathBuf, - #[structopt(long)] - stub: bool, -} - -fn main() -> Result<()> { - let opts = Opts::from_args(); - let file = &mut File::options() - .create(true) - .write(true) - .truncate(true) - .open(opts.path)?; - - match opts.stub { - true => forward_stub(file), - false => forward(file), - } -} - -fn forward(file: &mut File) -> Result<()> { - macro_rules! wln { - ($($text:tt)*) => { - writeln!(file, $($text)*)?; - }; - } - let s = " "; - - wln!( - ";; Copyright 2022-2023, Offchain Labs, Inc.\n\ - ;; For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE\n\ - ;; This file is auto-generated.\n\ - \n\ - (module" - ); - - macro_rules! group { - ($list:expr, $kind:expr) => { - (!$list.is_empty()) - .then(|| format!(" ({} {})", $kind, $list)) - .unwrap_or_default() - }; - } - - wln!("{s};; symbols to re-export"); - for [name, ins, outs] in HOSTIOS { - let params = group!(ins, "param"); - let result = group!(outs, "result"); - wln!( - r#"{s}(import "user_host" "arbitrator_forward__{name}" (func ${name}{params}{result}))"# - ); - } - wln!(); - - wln!("{s};; reserved offsets for future user_host imports"); - for i in HOSTIOS.len()..512 { - wln!("{s}(func $reserved_{i} unreachable)"); - } - wln!(); - - wln!( - "{s};; allows user_host to request a trap\n\ - {s}(global $trap (mut i32) (i32.const 0))\n\ - {s}(func $check\n\ - {s}{s}global.get $trap ;; see if set\n\ - {s}{s}(global.set $trap (i32.const 0)) ;; reset the flag\n\ - {s}{s}(if (then (unreachable)))\n\ - {s})\n\ - {s}(func (export \"forward__set_trap\")\n\ - {s}{s}(global.set $trap (i32.const 1))\n\ - {s})\n" - ); - - wln!("{s};; user linkage"); - for [name, ins, outs] in HOSTIOS { - let params = group!(ins, "param"); - let result = group!(outs, "result"); - wln!("{s}(func (export \"vm_hooks__{name}\"){params}{result}"); - - let gets = (1 + ins.len()) / 4; - for i in 0..gets { - wln!("{s}{s}local.get {i}"); - } - - wln!( - "{s}{s}call ${name}\n\ - {s}{s}call $check\n\ - {s})" - ); - } - - wln!(")"); - Ok(()) -} - -fn forward_stub(file: &mut File) -> Result<()> { - macro_rules! wln { - ($($text:tt)*) => { - writeln!(file, $($text)*)?; - }; - } - let s = " "; - - wln!( - ";; Copyright 2022-2023, Offchain Labs, Inc.\n\ - ;; For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE\n\ - ;; This file is auto-generated.\n\ - \n\ - (module" - ); - - macro_rules! group { - ($list:expr, $kind:expr) => { - (!$list.is_empty()) - .then(|| format!(" ({} {})", $kind, $list)) - .unwrap_or_default() - }; - } - - wln!("{s};; stubs for the symbols we re-export"); - for [name, ins, outs] in HOSTIOS { - let params = group!(ins, "param"); - let result = group!(outs, "result"); - wln!("{s}(func ${name}{params}{result} unreachable)"); - } - wln!(); - - wln!("{s};; reserved offsets for future user_host imports"); - for i in HOSTIOS.len()..512 { - wln!("{s}(func $reserved_{i} unreachable)"); - } - wln!(); - - wln!( - "{s};; allows user_host to request a trap\n\ - {s}(global $trap (mut i32) (i32.const 0))\n\ - {s}(func $check unreachable)\n\ - {s}(func (export \"forward__set_trap\") unreachable)" - ); - - wln!("{s};; user linkage"); - for [name, ins, outs] in HOSTIOS { - let params = group!(ins, "param"); - let result = group!(outs, "result"); - wln!("{s}(func (export \"vm_hooks__{name}\"){params}{result} unreachable)"); - } - - wln!(")"); - Ok(()) -} diff --git a/arbitrator/wasm-testsuite/src/main.rs b/arbitrator/wasm-testsuite/src/main.rs index 2144dcf992..cb861e3a35 100644 --- a/arbitrator/wasm-testsuite/src/main.rs +++ b/arbitrator/wasm-testsuite/src/main.rs @@ -343,6 +343,7 @@ fn main() -> eyre::Result<()> { GlobalState::default(), HashMap::default(), machine::get_empty_preimage_resolver(), + false, ); if let Err(error) = &mech { @@ -429,6 +430,7 @@ fn main() -> eyre::Result<()> { GlobalState::default(), HashMap::default(), machine::get_empty_preimage_resolver(), + false, ) .expect_err(&format!("failed to reject invalid module {}", filename)); } diff --git a/validator/server_arb/machine.go b/validator/server_arb/machine.go index adca9695e2..e77e071d70 100644 --- a/validator/server_arb/machine.go +++ b/validator/server_arb/machine.go @@ -92,7 +92,7 @@ func LoadSimpleMachine(wasm string, libraries []string, debugChain bool) (*Arbit cWasm := C.CString(wasm) cLibraries := CreateCStringList(libraries) debug := usize(arbmath.BoolToUint32(debugChain)) - mach := C.arbitrator_load_machine(cWasm, cLibraries, C.long(len(libraries)), debug) + mach := C.arbitrator_load_machine(cWasm, cLibraries, C.long(len(libraries)), debug, false) C.free(unsafe.Pointer(cWasm)) FreeCStringList(cLibraries, len(libraries)) if mach == nil {