mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
compiler: emit Neo.Crypto.ECDsaVerify syscall instead of CHECKSIG
Also change the name of `VerifySignature` interop, to match syscall's name. It also accepts arguments in different order.
This commit is contained in:
parent
948729137f
commit
4ad29d0867
5 changed files with 20 additions and 15 deletions
|
@ -14,7 +14,7 @@ var (
|
|||
builtinFuncs = []string{
|
||||
"len", "append", "SHA256",
|
||||
"SHA1", "Hash256", "Hash160",
|
||||
"VerifySignature", "AppCall",
|
||||
"AppCall",
|
||||
"FromAddress", "Equals",
|
||||
"panic",
|
||||
}
|
||||
|
|
|
@ -1063,8 +1063,6 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
|||
emit.Opcode(c.prog.BinWriter, opcode.SHA256)
|
||||
case "SHA1":
|
||||
emit.Opcode(c.prog.BinWriter, opcode.SHA1)
|
||||
case "VerifySignature":
|
||||
emit.Opcode(c.prog.BinWriter, opcode.VERIFY)
|
||||
case "AppCall":
|
||||
numArgs := len(expr.Args) - 1
|
||||
c.emitReverse(numArgs)
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package compiler
|
||||
|
||||
var syscalls = map[string]map[string]string{
|
||||
"crypto": {
|
||||
"ECDsaVerify": "Neo.Crypto.ECDsaVerify",
|
||||
},
|
||||
"storage": {
|
||||
"GetContext": "Neo.Storage.GetContext",
|
||||
"Put": "Neo.Storage.Put",
|
||||
|
|
|
@ -5,24 +5,28 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// In this test we only check that needed interop
|
||||
// is called with the provided arguments in the right order.
|
||||
func TestVerifyGood(t *testing.T) {
|
||||
msg := []byte("test message")
|
||||
pub, sig := signMessage(t, msg)
|
||||
src := getVerifyProg(pub, sig, msg)
|
||||
|
||||
eval(t, src, true)
|
||||
}
|
||||
v, p := vmAndCompileInterop(t, src)
|
||||
p.interops[vm.InteropNameToID([]byte("Neo.Crypto.ECDsaVerify"))] = func(v *vm.VM) error {
|
||||
assert.Equal(t, msg, v.Estack().Pop().Bytes())
|
||||
assert.Equal(t, pub, v.Estack().Pop().Bytes())
|
||||
assert.Equal(t, sig, v.Estack().Pop().Bytes())
|
||||
v.Estack().PushVal(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestVerifyBad(t *testing.T) {
|
||||
msg := []byte("test message")
|
||||
pub, sig := signMessage(t, msg)
|
||||
sig[0] = ^sig[0]
|
||||
src := getVerifyProg(pub, sig, msg)
|
||||
|
||||
eval(t, src, false)
|
||||
require.NoError(t, v.Run())
|
||||
}
|
||||
|
||||
func signMessage(t *testing.T, msg []byte) ([]byte, []byte) {
|
||||
|
@ -49,7 +53,7 @@ func getVerifyProg(pub, sig, msg []byte) string {
|
|||
pub := ` + pubS + `
|
||||
sig := ` + sigS + `
|
||||
msg := ` + msgS + `
|
||||
return crypto.VerifySignature(msg, sig, pub)
|
||||
return crypto.ECDsaVerify(msg, pub, sig)
|
||||
}
|
||||
`
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ func SHA256(b []byte) []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
// VerifySignature checks that sig is msg's signature with pub.
|
||||
func VerifySignature(msg []byte, sig []byte, pub []byte) bool {
|
||||
// ECDsaVerify checks that sig is msg's signature with pub.
|
||||
func ECDsaVerify(msg []byte, pub []byte, sig []byte) bool {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue