diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index 285060312..a42dcde98 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -442,7 +442,7 @@ func contractCallExInternal(ic *interop.Context, v *vm.VM, h []byte, method stac return errors.New("disallowed method call") } } - v.LoadScript(cs.Script) + v.LoadScriptWithHash(cs.Script, u) v.Estack().PushVal(args) v.Estack().PushVal(method) return nil diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 7503e5869..1163029f8 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -268,6 +268,15 @@ func (v *VM) LoadScript(b []byte) { v.istack.PushVal(ctx) } +// LoadScriptWithHash if similar to the LoadScript method, but it also loads +// given script hash directly into the Context to avoid its recalculations. It's +// up to user of this function to make sure the script and hash match each other. +func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160) { + v.LoadScript(b) + ctx := v.Context() + ctx.scriptHash = hash +} + // Context returns the current executed context. Nil if there is no context, // which implies no program is loaded. func (v *VM) Context() *Context {