Skip to content

Commit dc0f425

Browse files
committed
update ProgramPrepare to accept wasm instead of statedb and code
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
1 parent db29e55 commit dc0f425

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

arbos/programs/wasm.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package programs
77

88
import (
99
"errors"
10+
"fmt"
1011
"unsafe"
1112

1213
"github.com/ethereum/go-ethereum/arbitrum/multigas"
@@ -124,10 +125,9 @@ func programRequiresPrepare(
124125

125126
//go:wasmimport programs program_prepare
126127
func ProgramPrepare(
127-
statedbPtr unsafe.Pointer,
128+
wasmPtr unsafe.Pointer,
128129
moduleHashPtr unsafe.Pointer,
129130
addressForLoggingPtr unsafe.Pointer,
130-
codePtr unsafe.Pointer,
131131
codeSize uint64,
132132
codehashPtr unsafe.Pointer,
133133
maxWasmSize uint32,
@@ -156,21 +156,25 @@ func startProgram(module uint32) uint32
156156
//go:wasmimport programs send_response
157157
func sendResponse(req_id uint32) uint32
158158

159-
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 {
159+
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 {
160160
requiresPrepare := programRequiresPrepare(unsafe.Pointer(&moduleHash[0]))
161161
if requiresPrepare != 0 {
162162
var debugInt uint32
163163
if debugMode {
164164
debugInt = 1
165165
}
166166

167+
wasm, err := getWasm(statedb, programAddress, params)
168+
if err != nil {
169+
panic(fmt.Sprintf("failed to get wasm for program, program address: %v, err: %v", programAddress.Hex(), err))
170+
}
171+
167172
codeSize := uint64(len(code))
168173

169174
ProgramPrepare(
170-
unsafe.Pointer(&statedb),
175+
unsafe.Pointer(&wasm),
171176
unsafe.Pointer(&moduleHash),
172-
unsafe.Pointer(&addressForLogging),
173-
unsafe.Pointer(&code),
177+
unsafe.Pointer(&programAddress),
174178
codeSize,
175179
unsafe.Pointer(&codehash),
176180
params.MaxWasmSize,

changelog/bragaigor-nit-4407.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### Changed
2+
- update ProgramPrepare to accept wasm instead of statedb and code

crates/jit/src/program.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ pub fn program_requires_prepare(
188188
/// program_prepare
189189
pub fn program_prepare(
190190
mut _env: WasmEnvMut,
191-
_state_ptr: GuestPtr,
191+
_wasm_ptr: GuestPtr,
192192
_module_hash_ptr: GuestPtr,
193193
_address_for_logging_ptr: GuestPtr,
194-
_code_ptr: GuestPtr,
195194
_code_size: u64,
196195
_code_hash_ptr: GuestPtr,
197196
_max_wasm_size: u32,

crates/wasm-libraries/user-host/src/link.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,9 @@ pub unsafe extern "C" fn programs__program_requires_prepare(_module_hash_ptr: Gu
147147
/// consumes activated program module hash and wasm code
148148
#[no_mangle]
149149
pub unsafe extern "C" fn programs__program_prepare(
150-
_state_ptr: GuestPtr,
150+
_wasm_ptr: GuestPtr,
151151
_module_hash_ptr: GuestPtr,
152152
_address_for_logging_ptr: GuestPtr,
153-
_code_ptr: GuestPtr,
154153
_code_size: u64,
155154
_code_hash_ptr: GuestPtr,
156155
_max_wasm_size: u32,

0 commit comments

Comments
 (0)