From bd937bc500ef740259a0155df386e9252e902528 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Sat, 8 Jul 2023 12:22:45 +0300 Subject: [PATCH] Revert "core: remove contract script check on deploy/update" This reverts commit 762a8da76a7f387adb639d9b4d125e126e322634. Signed-off-by: Anna Shaleva --- pkg/core/native/management.go | 6 +++++- pkg/core/native/native_test/management_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/core/native/management.go b/pkg/core/native/management.go index 24f88e076..f78d4080e 100644 --- a/pkg/core/native/management.go +++ b/pkg/core/native/management.go @@ -23,6 +23,8 @@ import ( "github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/util" + "github.com/nspcc-dev/neo-go/pkg/util/bitfield" + "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -715,10 +717,12 @@ func (m *Management) emitNotification(ic *interop.Context, name string, hash uti func checkScriptAndMethods(script []byte, methods []manifest.Method) error { l := len(script) + offsets := bitfield.New(l) for i := range methods { if methods[i].Offset >= l { return fmt.Errorf("method %s/%d: offset is out of the script range", methods[i].Name, len(methods[i].Parameters)) } + offsets.Set(methods[i].Offset) } - return nil + return vm.IsScriptCorrect(script, offsets) } diff --git a/pkg/core/native/native_test/management_test.go b/pkg/core/native/native_test/management_test.go index 04ff15c86..e60f806b7 100644 --- a/pkg/core/native/native_test/management_test.go +++ b/pkg/core/native/native_test/management_test.go @@ -143,6 +143,17 @@ func TestManagement_ContractDeploy(t *testing.T) { managementInvoker.InvokeFail(t, "method add/2: offset is out of the script range", "deploy", nefBytes, manifB) }) + t.Run("bad methods in manifest 2", func(t *testing.T) { + var badManifest = cs1.Manifest + badManifest.ABI.Methods = make([]manifest.Method, len(cs1.Manifest.ABI.Methods)) + copy(badManifest.ABI.Methods, cs1.Manifest.ABI.Methods) + badManifest.ABI.Methods[0].Offset = len(cs1.NEF.Script) - 2 // Ends with `CALLT(X,X);RET`. + + manifB, err := json.Marshal(badManifest) + require.NoError(t, err) + + managementInvoker.InvokeFail(t, "some methods point to wrong offsets (not to instruction boundary)", "deploy", nefBytes, manifB) + }) t.Run("duplicated methods in manifest 1", func(t *testing.T) { badManifest := cs1.Manifest badManifest.ABI.Methods = make([]manifest.Method, len(cs1.Manifest.ABI.Methods))