Skip to content

Commit 6ab9078

Browse files
committed
add verify module
1 parent 5eb7e91 commit 6ab9078

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

wasm_interpreter.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -199,31 +199,28 @@ func (w *WasmIntptr) Run(contract *Contract, input []byte) ([]byte, error) {
199199
return nil, err
200200
}
201201

202+
mainIndex, err := w.verifyModule(module)
203+
202204
vm, err := exec.NewVM(module)
203205
if err != nil {
204206
return nil, fmt.Errorf("failed to create vm: %v", err)
205207
}
206208
vm.RecoverPanic = true
207209
w.vm = vm
208210

209-
for name, entry := range module.Export.Entries {
210-
if name == "main" && entry.Kind == wasm.ExternalFunction {
211-
// Check func signature and output types
212-
sig := module.FunctionIndexSpace[entry.Index].Sig
213-
if len(sig.ParamTypes) == 0 && len(sig.ReturnTypes) == 0 {
214-
_, err := vm.ExecCode(int64(entry.Index))
215-
if err != nil {
216-
w.terminateType = TerminateInvalid
217-
}
211+
sig := module.FunctionIndexSpace[mainIndex].Sig
212+
if len(sig.ParamTypes) == 0 && len(sig.ReturnTypes) == 0 {
213+
_, err := vm.ExecCode(int64(mainIndex))
214+
if err != nil {
215+
w.terminateType = TerminateInvalid
216+
}
218217

219-
if w.StateDB().HasSuicided(contract.Address()) {
220-
err = nil
221-
}
222-
return w.returnData, err
223-
}
224-
break
218+
if w.StateDB().HasSuicided(contract.Address()) {
219+
err = nil
225220
}
221+
return w.returnData, err
226222
}
223+
227224
return nil, errors.New("could not find a valid 'main' function in the code")
228225
}
229226

0 commit comments

Comments
 (0)