From a77357227aa217d3f5dbfa309cbac580949fa3ba Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 23 Jun 2020 21:39:26 +0300 Subject: [PATCH] vm: fix caller's script hash returned from VM Regular CALLs don't update it, only Contract.Call does. Fixes the following mismatch on preview2 testnet: file BlockStorage_100000/dump-block-49000.json: block 48644, changes number mismatch: 6 vs 4 --- pkg/vm/context.go | 3 +++ pkg/vm/vm.go | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/vm/context.go b/pkg/vm/context.go index 8fa7afd98..bfbf2f2bb 100644 --- a/pkg/vm/context.go +++ b/pkg/vm/context.go @@ -41,6 +41,9 @@ type Context struct { // Script hash of the prog. scriptHash util.Uint160 + // Caller's contract script hash. + callingScriptHash util.Uint160 + // Call flags this context was created with. callFlag smartcontract.CallFlag } diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 1c201dfd7..90d16014b 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -276,9 +276,11 @@ func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag) { // 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, f smartcontract.CallFlag) { + shash := v.GetCurrentScriptHash() v.LoadScriptWithFlags(b, f) ctx := v.Context() ctx.scriptHash = hash + ctx.callingScriptHash = shash } // Context returns the current executed context. Nil if there is no context, @@ -1607,7 +1609,7 @@ func (v *VM) bytesToPublicKey(b []byte) *keys.PublicKey { // GetCallingScriptHash implements ScriptHashGetter interface func (v *VM) GetCallingScriptHash() util.Uint160 { - return v.getContextScriptHash(1) + return v.Context().callingScriptHash } // GetEntryScriptHash implements ScriptHashGetter interface