forked from TrueCloudLab/neoneo-go
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{
|
builtinFuncs = []string{
|
||||||
"len", "append", "SHA256",
|
"len", "append", "SHA256",
|
||||||
"SHA1", "Hash256", "Hash160",
|
"SHA1", "Hash256", "Hash160",
|
||||||
"VerifySignature", "AppCall",
|
"AppCall",
|
||||||
"FromAddress", "Equals",
|
"FromAddress", "Equals",
|
||||||
"panic",
|
"panic",
|
||||||
}
|
}
|
||||||
|
|
|
@ -1063,8 +1063,6 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.SHA256)
|
emit.Opcode(c.prog.BinWriter, opcode.SHA256)
|
||||||
case "SHA1":
|
case "SHA1":
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.SHA1)
|
emit.Opcode(c.prog.BinWriter, opcode.SHA1)
|
||||||
case "VerifySignature":
|
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.VERIFY)
|
|
||||||
case "AppCall":
|
case "AppCall":
|
||||||
numArgs := len(expr.Args) - 1
|
numArgs := len(expr.Args) - 1
|
||||||
c.emitReverse(numArgs)
|
c.emitReverse(numArgs)
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
var syscalls = map[string]map[string]string{
|
var syscalls = map[string]map[string]string{
|
||||||
|
"crypto": {
|
||||||
|
"ECDsaVerify": "Neo.Crypto.ECDsaVerify",
|
||||||
|
},
|
||||||
"storage": {
|
"storage": {
|
||||||
"GetContext": "Neo.Storage.GetContext",
|
"GetContext": "Neo.Storage.GetContext",
|
||||||
"Put": "Neo.Storage.Put",
|
"Put": "Neo.Storage.Put",
|
||||||
|
|
|
@ -5,24 +5,28 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"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"
|
"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) {
|
func TestVerifyGood(t *testing.T) {
|
||||||
msg := []byte("test message")
|
msg := []byte("test message")
|
||||||
pub, sig := signMessage(t, msg)
|
pub, sig := signMessage(t, msg)
|
||||||
src := getVerifyProg(pub, sig, 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) {
|
require.NoError(t, v.Run())
|
||||||
msg := []byte("test message")
|
|
||||||
pub, sig := signMessage(t, msg)
|
|
||||||
sig[0] = ^sig[0]
|
|
||||||
src := getVerifyProg(pub, sig, msg)
|
|
||||||
|
|
||||||
eval(t, src, false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func signMessage(t *testing.T, msg []byte) ([]byte, []byte) {
|
func signMessage(t *testing.T, msg []byte) ([]byte, []byte) {
|
||||||
|
@ -49,7 +53,7 @@ func getVerifyProg(pub, sig, msg []byte) string {
|
||||||
pub := ` + pubS + `
|
pub := ` + pubS + `
|
||||||
sig := ` + sigS + `
|
sig := ` + sigS + `
|
||||||
msg := ` + msgS + `
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifySignature checks that sig is msg's signature with pub.
|
// ECDsaVerify checks that sig is msg's signature with pub.
|
||||||
func VerifySignature(msg []byte, sig []byte, pub []byte) bool {
|
func ECDsaVerify(msg []byte, pub []byte, sig []byte) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue