core: remove System.Contract.IsStandard

This commit is contained in:
Anna Shaleva 2021-03-16 16:57:13 +03:00
parent a18fbc7bb1
commit 0d9266d407
6 changed files with 0 additions and 98 deletions

View file

@ -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},

View file

@ -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,

View file

@ -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 {

View file

@ -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) {

View file

@ -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},

View file

@ -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.