From f6b3dc0ccca71d2573daa300379132fe05a6cc56 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Thu, 19 Dec 2024 13:35:25 +0300 Subject: [PATCH] native: support callflags-based native method after HFEchidna Close #3702 Signed-off-by: Ekaterina Pavlova --- pkg/compiler/codegen.go | 1 + pkg/compiler/native_test.go | 7 +++++-- pkg/core/native/native_neo.go | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 0b75167ffd..a6f6904101 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -2334,6 +2334,7 @@ func codeGen(info *buildInfo) (*nef.File, *DebugInfo, error) { if c.callTokens != nil { f.Tokens = c.callTokens } + fmt.Println(f.Tokens) f.Checksum = f.CalculateChecksum() return f, di, vm.IsScriptCorrect(buf, methods) } diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index d3fe17e9bf..f4f8935a57 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -28,6 +28,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/storage" "github.com/nspcc-dev/neo-go/pkg/smartcontract" + "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/smartcontract/nef" "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -277,7 +278,7 @@ func runNativeTestCases(t *testing.T, ctr interop.ContractMD, name string, nativ for i, tc := range nativeTestCases { addNativeTestCase(t, srcBuilder, ctr, i, name, tc.method, tc.params...) } - + fmt.Printf("srcBuilder: %v\n", srcBuilder) ne, di, err := compiler.CompileWithOptions("file.go", strings.NewReader(srcBuilder.String()), nil) require.NoError(t, err) @@ -342,7 +343,8 @@ func runNativeTestCase(t *testing.T, b *nef.File, di *compiler.DebugInfo, ctr in md := getMethod(t, ctr, method, params) result := getTestStackItem(md.MD.ReturnType) isVoid := md.MD.ReturnType == smartcontract.VoidType - + b2 := md.RequiredFlags == callflag.States|callflag.AllowNotify + fmt.Printf("b2: %v\n", b2) v := vm.New() v.LoadToken = func(id int32) error { t := b.Tokens[id] @@ -359,6 +361,7 @@ func runNativeTestCase(t *testing.T, b *nef.File, di *compiler.DebugInfo, ctr in return fmt.Errorf("wrong hasReturn %v", t.HasReturn) } if t.CallFlag != md.RequiredFlags { + fmt.Printf("t.CallFlag: %v\n", t.CallFlag) return fmt.Errorf("wrong flags %v", t.CallFlag) } for range t.ParamCount { diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index 9978e0b97a..d4e507826e 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -192,18 +192,27 @@ func newNEO(cfg config.ProtocolConfiguration) *NEO { desc = newDescriptor("registerCandidate", smartcontract.BoolType, manifest.NewParameter("pubkey", smartcontract.PublicKeyType)) - md = newMethodAndPrice(n.registerCandidate, 0, callflag.States) + md = newMethodAndPrice(n.registerCandidate, 0, callflag.States, config.HFDefault, config.HFEchidna) + n.AddMethod(md, desc) + + md = newMethodAndPrice(n.registerCandidate, 0, callflag.States|callflag.AllowNotify, config.HFEchidna) n.AddMethod(md, desc) desc = newDescriptor("unregisterCandidate", smartcontract.BoolType, manifest.NewParameter("pubkey", smartcontract.PublicKeyType)) - md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States) + md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States, config.HFDefault, config.HFEchidna) + n.AddMethod(md, desc) + + md = newMethodAndPrice(n.unregisterCandidate, 1<<16, callflag.States|callflag.AllowNotify, config.HFEchidna) n.AddMethod(md, desc) desc = newDescriptor("vote", smartcontract.BoolType, manifest.NewParameter("account", smartcontract.Hash160Type), manifest.NewParameter("voteTo", smartcontract.PublicKeyType)) - md = newMethodAndPrice(n.vote, 1<<16, callflag.States) + md = newMethodAndPrice(n.vote, 1<<16, callflag.States, config.HFDefault, config.HFEchidna) + n.AddMethod(md, desc) + + md = newMethodAndPrice(n.vote, 1<<16, callflag.States|callflag.AllowNotify, config.HFEchidna) n.AddMethod(md, desc) desc = newDescriptor("getCandidates", smartcontract.ArrayType)