From 0d9266d4072065b1b5f0d1af8a3a9c743462c831 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 16 Mar 2021 16:57:13 +0300 Subject: [PATCH] core: remove System.Contract.IsStandard --- pkg/compiler/syscall_test.go | 1 - pkg/core/interop/interopnames/names.go | 2 - pkg/core/interop_system.go | 27 ------------ pkg/core/interop_system_test.go | 61 -------------------------- pkg/core/interops.go | 1 - pkg/interop/contract/contract.go | 6 --- 6 files changed, 98 deletions(-) diff --git a/pkg/compiler/syscall_test.go b/pkg/compiler/syscall_test.go index c9a960629..f0080b476 100644 --- a/pkg/compiler/syscall_test.go +++ b/pkg/compiler/syscall_test.go @@ -64,7 +64,6 @@ func TestSyscallExecution(t *testing.T) { "contract.Call": {interopnames.SystemContractCall, []string{u160, `"m"`, "1", "3"}, false}, "contract.CreateMultisigAccount": {interopnames.SystemContractCreateMultisigAccount, []string{"1", pubs}, false}, "contract.CreateStandardAccount": {interopnames.SystemContractCreateStandardAccount, []string{pub}, false}, - "contract.IsStandard": {interopnames.SystemContractIsStandard, []string{u160}, false}, "contract.GetCallFlags": {interopnames.SystemContractGetCallFlags, nil, false}, "iterator.Create": {interopnames.SystemIteratorCreate, []string{pubs}, false}, "iterator.Next": {interopnames.SystemIteratorNext, []string{"iterator.Iterator{}"}, false}, diff --git a/pkg/core/interop/interopnames/names.go b/pkg/core/interop/interopnames/names.go index 96f7e0ddd..0ad602163 100644 --- a/pkg/core/interop/interopnames/names.go +++ b/pkg/core/interop/interopnames/names.go @@ -10,7 +10,6 @@ const ( SystemContractCallNative = "System.Contract.CallNative" SystemContractCreateMultisigAccount = "System.Contract.CreateMultisigAccount" SystemContractCreateStandardAccount = "System.Contract.CreateStandardAccount" - SystemContractIsStandard = "System.Contract.IsStandard" SystemContractGetCallFlags = "System.Contract.GetCallFlags" SystemContractNativeOnPersist = "System.Contract.NativeOnPersist" SystemContractNativePostPersist = "System.Contract.NativePostPersist" @@ -50,7 +49,6 @@ var names = []string{ SystemContractCallNative, SystemContractCreateMultisigAccount, SystemContractCreateStandardAccount, - SystemContractIsStandard, SystemContractGetCallFlags, SystemContractNativeOnPersist, SystemContractNativePostPersist, diff --git a/pkg/core/interop_system.go b/pkg/core/interop_system.go index bfd04fed0..b20e8a7da 100644 --- a/pkg/core/interop_system.go +++ b/pkg/core/interop_system.go @@ -14,8 +14,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/smartcontract" - "github.com/nspcc-dev/neo-go/pkg/util" - "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" ) @@ -176,31 +174,6 @@ func storageContextAsReadOnly(ic *interop.Context) error { return nil } -// contractIsStandard checks if contract is standard (sig or multisig) contract. -func contractIsStandard(ic *interop.Context) error { - h := ic.VM.Estack().Pop().Bytes() - u, err := util.Uint160DecodeBytesBE(h) - if err != nil { - return err - } - var result bool - cs, _ := ic.GetContract(u) - if cs != nil { - result = vm.IsStandardContract(cs.NEF.Script) - } else { - if tx, ok := ic.Container.(*transaction.Transaction); ok { - for _, witness := range tx.Scripts { - if witness.ScriptHash() == u { - result = vm.IsStandardContract(witness.VerificationScript) - break - } - } - } - } - ic.VM.Estack().PushVal(result) - return nil -} - // contractCreateMultisigAccount calculates multisig contract scripthash for a // given m and a set of public keys. func contractCreateMultisigAccount(ic *interop.Context) error { diff --git a/pkg/core/interop_system_test.go b/pkg/core/interop_system_test.go index bd3084beb..feaaf581a 100644 --- a/pkg/core/interop_system_test.go +++ b/pkg/core/interop_system_test.go @@ -6,9 +6,7 @@ import ( "math/big" "testing" - "github.com/nspcc-dev/dbft/crypto" "github.com/nspcc-dev/neo-go/internal/random" - "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/core/interop" "github.com/nspcc-dev/neo-go/pkg/core/interop/contract" "github.com/nspcc-dev/neo-go/pkg/core/interop/interopnames" @@ -30,65 +28,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestContractIsStandard(t *testing.T) { - v, ic, chain := createVM(t) - - t.Run("contract not stored", func(t *testing.T) { - priv, err := keys.NewPrivateKey() - require.NoError(t, err) - - pub := priv.PublicKey() - tx := transaction.New(netmode.TestNet, []byte{1, 2, 3}, 1) - tx.Scripts = []transaction.Witness{ - { - InvocationScript: []byte{1, 2, 3}, - VerificationScript: pub.GetVerificationScript(), - }, - } - ic.Container = tx - - t.Run("true", func(t *testing.T) { - v.Estack().PushVal(pub.GetScriptHash().BytesBE()) - require.NoError(t, contractIsStandard(ic)) - require.True(t, v.Estack().Pop().Bool()) - }) - - t.Run("false", func(t *testing.T) { - tx.Scripts[0].VerificationScript = []byte{9, 8, 7} - v.Estack().PushVal(pub.GetScriptHash().BytesBE()) - require.NoError(t, contractIsStandard(ic)) - require.False(t, v.Estack().Pop().Bool()) - }) - }) - - t.Run("contract stored, true", func(t *testing.T) { - priv, err := keys.NewPrivateKey() - require.NoError(t, err) - - pub := priv.PublicKey() - ne, err := nef.NewFile(pub.GetVerificationScript()) - require.NoError(t, err) - err = chain.contracts.Management.PutContractState(ic.DAO, - &state.Contract{ContractBase: state.ContractBase{ID: 42, Hash: pub.GetScriptHash(), NEF: *ne}}) - require.NoError(t, err) - - v.Estack().PushVal(pub.GetScriptHash().BytesBE()) - require.NoError(t, contractIsStandard(ic)) - require.True(t, v.Estack().Pop().Bool()) - }) - t.Run("contract stored, false", func(t *testing.T) { - script := []byte{byte(opcode.PUSHT)} - ne, err := nef.NewFile(script) - require.NoError(t, err) - require.NoError(t, chain.contracts.Management.PutContractState(ic.DAO, - &state.Contract{ContractBase: state.ContractBase{ID: 24, Hash: hash.Hash160(script), NEF: *ne}})) - - v.Estack().PushVal(crypto.Hash160(script).BytesBE()) - require.NoError(t, contractIsStandard(ic)) - require.False(t, v.Estack().Pop().Bool()) - }) -} - func TestContractCreateAccount(t *testing.T) { v, ic, _ := createVM(t) t.Run("Good", func(t *testing.T) { diff --git a/pkg/core/interops.go b/pkg/core/interops.go index ee30a429b..9cc2aa553 100644 --- a/pkg/core/interops.go +++ b/pkg/core/interops.go @@ -35,7 +35,6 @@ var systemInterops = []interop.Function{ {Name: interopnames.SystemContractCallNative, Func: native.Call, Price: 0, ParamCount: 1}, {Name: interopnames.SystemContractCreateMultisigAccount, Func: contractCreateMultisigAccount, Price: 1 << 8, ParamCount: 2}, {Name: interopnames.SystemContractCreateStandardAccount, Func: contractCreateStandardAccount, Price: 1 << 8, ParamCount: 1}, - {Name: interopnames.SystemContractIsStandard, Func: contractIsStandard, Price: 1 << 10, RequiredFlags: callflag.ReadStates, ParamCount: 1}, {Name: interopnames.SystemContractGetCallFlags, Func: contractGetCallFlags, Price: 1 << 10}, {Name: interopnames.SystemContractNativeOnPersist, Func: native.OnPersist, Price: 0, RequiredFlags: callflag.WriteStates}, {Name: interopnames.SystemContractNativePostPersist, Func: native.PostPersist, Price: 0, RequiredFlags: callflag.WriteStates}, diff --git a/pkg/interop/contract/contract.go b/pkg/interop/contract/contract.go index 0fe1b88bc..88f4295e3 100644 --- a/pkg/interop/contract/contract.go +++ b/pkg/interop/contract/contract.go @@ -24,12 +24,6 @@ const ( NoneFlag CallFlag = 0 ) -// IsStandard checks if contract with provided hash is a standard signature/multisig contract. -// This function uses `System.Contract.IsStandard` syscall. -func IsStandard(h interop.Hash160) bool { - return neogointernal.Syscall1("System.Contract.IsStandard", h).(bool) -} - // CreateMultisigAccount calculates script hash of an m out of n multisignature // script using given m and a set of public keys bytes. This function uses // `System.Contract.CreateMultisigAccount` syscall.