diff --git a/arbos/programs/wasm.go b/arbos/programs/wasm.go index 5cd7429cb0..0612a6f0c4 100644 --- a/arbos/programs/wasm.go +++ b/arbos/programs/wasm.go @@ -7,6 +7,7 @@ package programs import ( "errors" + "fmt" "unsafe" "github.com/ethereum/go-ethereum/arbitrum/multigas" @@ -124,10 +125,9 @@ func programRequiresPrepare( //go:wasmimport programs program_prepare func ProgramPrepare( - statedbPtr unsafe.Pointer, + wasmPtr unsafe.Pointer, moduleHashPtr unsafe.Pointer, addressForLoggingPtr unsafe.Pointer, - codePtr unsafe.Pointer, codeSize uint64, codehashPtr unsafe.Pointer, maxWasmSize uint32, @@ -156,7 +156,7 @@ func startProgram(module uint32) uint32 //go:wasmimport programs send_response func sendResponse(req_id uint32) uint32 -func handleProgramPrepare(statedb vm.StateDB, moduleHash common.Hash, addressForLogging common.Address, code []byte, codehash common.Hash, params *StylusParams, time uint64, debugMode bool, program Program, runCtx *core.MessageRunContext) []byte { +func handleProgramPrepare(statedb vm.StateDB, moduleHash common.Hash, programAddress common.Address, code []byte, codehash common.Hash, params *StylusParams, time uint64, debugMode bool, program Program, runCtx *core.MessageRunContext) []byte { requiresPrepare := programRequiresPrepare(unsafe.Pointer(&moduleHash[0])) if requiresPrepare != 0 { var debugInt uint32 @@ -164,13 +164,17 @@ func handleProgramPrepare(statedb vm.StateDB, moduleHash common.Hash, addressFor debugInt = 1 } + wasm, err := getWasm(statedb, programAddress, params) + if err != nil { + panic(fmt.Sprintf("failed to get wasm for program, program address: %v, err: %v", programAddress.Hex(), err)) + } + codeSize := uint64(len(code)) ProgramPrepare( - unsafe.Pointer(&statedb), + unsafe.Pointer(&wasm), unsafe.Pointer(&moduleHash), - unsafe.Pointer(&addressForLogging), - unsafe.Pointer(&code), + unsafe.Pointer(&programAddress), codeSize, unsafe.Pointer(&codehash), params.MaxWasmSize, diff --git a/changelog/bragaigor-nit-4407.md b/changelog/bragaigor-nit-4407.md new file mode 100644 index 0000000000..aa0d27b159 --- /dev/null +++ b/changelog/bragaigor-nit-4407.md @@ -0,0 +1,2 @@ +### Changed +- update ProgramPrepare to accept wasm instead of statedb and code diff --git a/crates/jit/src/program.rs b/crates/jit/src/program.rs index 56e8bf4960..0c8ab24537 100644 --- a/crates/jit/src/program.rs +++ b/crates/jit/src/program.rs @@ -188,10 +188,9 @@ pub fn program_requires_prepare( /// program_prepare pub fn program_prepare( mut _env: WasmEnvMut, - _state_ptr: GuestPtr, + _wasm_ptr: GuestPtr, _module_hash_ptr: GuestPtr, _address_for_logging_ptr: GuestPtr, - _code_ptr: GuestPtr, _code_size: u64, _code_hash_ptr: GuestPtr, _max_wasm_size: u32, diff --git a/crates/wasm-libraries/user-host/src/link.rs b/crates/wasm-libraries/user-host/src/link.rs index 3bca11973b..eeca9fabc5 100644 --- a/crates/wasm-libraries/user-host/src/link.rs +++ b/crates/wasm-libraries/user-host/src/link.rs @@ -147,10 +147,9 @@ pub unsafe extern "C" fn programs__program_requires_prepare(_module_hash_ptr: Gu /// consumes activated program module hash and wasm code #[no_mangle] pub unsafe extern "C" fn programs__program_prepare( - _state_ptr: GuestPtr, + _wasm_ptr: GuestPtr, _module_hash_ptr: GuestPtr, _address_for_logging_ptr: GuestPtr, - _code_ptr: GuestPtr, _code_size: u64, _code_hash_ptr: GuestPtr, _max_wasm_size: u32,