core: remove Neo.Crypto.CheckMultisigWithECDsaSecp256k1

Koblitz RIP.
This commit is contained in:
Anna Shaleva 2021-03-09 17:38:41 +03:00
parent cdaca7be3e
commit 7126637f73
7 changed files with 32 additions and 73 deletions

View file

@ -20,18 +20,14 @@ import (
"github.com/stretchr/testify/require"
)
func initCHECKMULTISIG(isR1 bool, msg []byte, n int) ([]stackitem.Item, []stackitem.Item, map[string]*keys.PublicKey, error) {
func initCHECKMULTISIG(msg []byte, n int) ([]stackitem.Item, []stackitem.Item, map[string]*keys.PublicKey, error) {
var err error
keyMap := make(map[string]*keys.PublicKey)
pkeys := make([]*keys.PrivateKey, n)
pubs := make([]stackitem.Item, n)
for i := range pubs {
if isR1 {
pkeys[i], err = keys.NewPrivateKey()
} else {
pkeys[i], err = keys.NewSecp256k1PrivateKey()
}
pkeys[i], err = keys.NewPrivateKey()
if err != nil {
return nil, nil, nil, err
}
@ -64,14 +60,10 @@ func subSlice(arr []stackitem.Item, indices []int) []stackitem.Item {
return result
}
func initCheckMultisigVMNoArgs(isR1 bool) *vm.VM {
func initCheckMultisigVMNoArgs() *vm.VM {
buf := make([]byte, 5)
buf[0] = byte(opcode.SYSCALL)
if isR1 {
binary.LittleEndian.PutUint32(buf[1:], ecdsaSecp256r1CheckMultisigID)
} else {
binary.LittleEndian.PutUint32(buf[1:], ecdsaSecp256k1CheckMultisigID)
}
binary.LittleEndian.PutUint32(buf[1:], ecdsaSecp256r1CheckMultisigID)
ic := &interop.Context{Trigger: trigger.Verification}
Register(ic)
@ -80,11 +72,11 @@ func initCheckMultisigVMNoArgs(isR1 bool) *vm.VM {
return v
}
func initCHECKMULTISIGVM(t *testing.T, isR1 bool, n int, ik, is []int) *vm.VM {
v := initCheckMultisigVMNoArgs(isR1)
func initCHECKMULTISIGVM(t *testing.T, n int, ik, is []int) *vm.VM {
v := initCheckMultisigVMNoArgs()
msg := []byte("NEO - An Open Network For Smart Economy")
pubs, sigs, _, err := initCHECKMULTISIG(isR1, msg, n)
pubs, sigs, _, err := initCHECKMULTISIG(msg, n)
require.NoError(t, err)
pubs = subSlice(pubs, ik)
@ -97,8 +89,8 @@ func initCHECKMULTISIGVM(t *testing.T, isR1 bool, n int, ik, is []int) *vm.VM {
return v
}
func testCHECKMULTISIGGood(t *testing.T, isR1 bool, n int, is []int) {
v := initCHECKMULTISIGVM(t, isR1, n, nil, is)
func testCHECKMULTISIGGood(t *testing.T, n int, is []int) {
v := initCHECKMULTISIGVM(t, n, nil, is)
require.NoError(t, v.Run())
assert.Equal(t, 1, v.Estack().Len())
@ -106,25 +98,21 @@ func testCHECKMULTISIGGood(t *testing.T, isR1 bool, n int, is []int) {
}
func TestECDSASecp256r1CheckMultisigGood(t *testing.T) {
testCurveCHECKMULTISIGGood(t, true)
testCurveCHECKMULTISIGGood(t)
}
func TestECDSASecp256k1CheckMultisigGood(t *testing.T) {
testCurveCHECKMULTISIGGood(t, false)
func testCurveCHECKMULTISIGGood(t *testing.T) {
t.Run("3_1", func(t *testing.T) { testCHECKMULTISIGGood(t, 3, []int{1}) })
t.Run("2_2", func(t *testing.T) { testCHECKMULTISIGGood(t, 2, []int{0, 1}) })
t.Run("3_3", func(t *testing.T) { testCHECKMULTISIGGood(t, 3, []int{0, 1, 2}) })
t.Run("3_2", func(t *testing.T) { testCHECKMULTISIGGood(t, 3, []int{0, 2}) })
t.Run("4_2", func(t *testing.T) { testCHECKMULTISIGGood(t, 4, []int{0, 2}) })
t.Run("10_7", func(t *testing.T) { testCHECKMULTISIGGood(t, 10, []int{2, 3, 4, 5, 6, 8, 9}) })
t.Run("12_9", func(t *testing.T) { testCHECKMULTISIGGood(t, 12, []int{0, 1, 4, 5, 6, 7, 8, 9}) })
}
func testCurveCHECKMULTISIGGood(t *testing.T, isR1 bool) {
t.Run("3_1", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 3, []int{1}) })
t.Run("2_2", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 2, []int{0, 1}) })
t.Run("3_3", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 3, []int{0, 1, 2}) })
t.Run("3_2", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 3, []int{0, 2}) })
t.Run("4_2", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 4, []int{0, 2}) })
t.Run("10_7", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 10, []int{2, 3, 4, 5, 6, 8, 9}) })
t.Run("12_9", func(t *testing.T) { testCHECKMULTISIGGood(t, isR1, 12, []int{0, 1, 4, 5, 6, 7, 8, 9}) })
}
func testCHECKMULTISIGBad(t *testing.T, isR1 bool, isErr bool, n int, ik, is []int) {
v := initCHECKMULTISIGVM(t, isR1, n, ik, is)
func testCHECKMULTISIGBad(t *testing.T, isErr bool, n int, ik, is []int) {
v := initCHECKMULTISIGVM(t, n, ik, is)
if isErr {
require.Error(t, v.Run())
@ -136,45 +124,41 @@ func testCHECKMULTISIGBad(t *testing.T, isR1 bool, isErr bool, n int, ik, is []i
}
func TestECDSASecp256r1CheckMultisigBad(t *testing.T) {
testCurveCHECKMULTISIGBad(t, true)
testCurveCHECKMULTISIGBad(t)
}
func TestECDSASecp256k1CheckMultisigBad(t *testing.T) {
testCurveCHECKMULTISIGBad(t, false)
}
func testCurveCHECKMULTISIGBad(t *testing.T, isR1 bool) {
t.Run("1_1 wrong signature", func(t *testing.T) { testCHECKMULTISIGBad(t, isR1, false, 2, []int{0}, []int{1}) })
t.Run("3_2 wrong order", func(t *testing.T) { testCHECKMULTISIGBad(t, isR1, false, 3, []int{0, 2}, []int{2, 0}) })
t.Run("3_2 duplicate sig", func(t *testing.T) { testCHECKMULTISIGBad(t, isR1, false, 3, nil, []int{0, 0}) })
t.Run("1_2 too many signatures", func(t *testing.T) { testCHECKMULTISIGBad(t, isR1, true, 2, []int{0}, []int{0, 1}) })
func testCurveCHECKMULTISIGBad(t *testing.T) {
t.Run("1_1 wrong signature", func(t *testing.T) { testCHECKMULTISIGBad(t, false, 2, []int{0}, []int{1}) })
t.Run("3_2 wrong order", func(t *testing.T) { testCHECKMULTISIGBad(t, false, 3, []int{0, 2}, []int{2, 0}) })
t.Run("3_2 duplicate sig", func(t *testing.T) { testCHECKMULTISIGBad(t, false, 3, nil, []int{0, 0}) })
t.Run("1_2 too many signatures", func(t *testing.T) { testCHECKMULTISIGBad(t, true, 2, []int{0}, []int{0, 1}) })
t.Run("gas limit exceeded", func(t *testing.T) {
v := initCHECKMULTISIGVM(t, isR1, 1, []int{0}, []int{0})
v := initCHECKMULTISIGVM(t, 1, []int{0}, []int{0})
v.GasLimit = fee.ECDSAVerifyPrice - 1
require.Error(t, v.Run())
})
msg := []byte("NEO - An Open Network For Smart Economy")
pubs, sigs, _, err := initCHECKMULTISIG(isR1, msg, 1)
pubs, sigs, _, err := initCHECKMULTISIG(msg, 1)
require.NoError(t, err)
arr := stackitem.NewArray([]stackitem.Item{stackitem.NewArray(nil)})
t.Run("invalid message type", func(t *testing.T) {
v := initCheckMultisigVMNoArgs(isR1)
v := initCheckMultisigVMNoArgs()
v.Estack().PushVal(sigs)
v.Estack().PushVal(pubs)
v.Estack().PushVal(stackitem.NewArray(nil))
require.Error(t, v.Run())
})
t.Run("invalid public keys", func(t *testing.T) {
v := initCheckMultisigVMNoArgs(isR1)
v := initCheckMultisigVMNoArgs()
v.Estack().PushVal(sigs)
v.Estack().PushVal(arr)
v.Estack().PushVal(msg)
require.Error(t, v.Run())
})
t.Run("invalid signatures", func(t *testing.T) {
v := initCheckMultisigVMNoArgs(isR1)
v := initCheckMultisigVMNoArgs()
v.Estack().PushVal(arr)
v.Estack().PushVal(pubs)
v.Estack().PushVal(msg)