diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index 90dd5e318..fb25eab49 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -14,7 +14,7 @@ var ( builtinFuncs = []string{ "len", "append", "SHA256", "SHA1", "Hash256", "Hash160", - "VerifySignature", "AppCall", + "AppCall", "FromAddress", "Equals", "panic", } diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 34c3171ae..610cafd7c 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -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) diff --git a/pkg/compiler/syscall.go b/pkg/compiler/syscall.go index 01234955b..633335b4b 100644 --- a/pkg/compiler/syscall.go +++ b/pkg/compiler/syscall.go @@ -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", diff --git a/pkg/compiler/verify_test.go b/pkg/compiler/verify_test.go index 754a6d7a8..8d0151625 100644 --- a/pkg/compiler/verify_test.go +++ b/pkg/compiler/verify_test.go @@ -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) } ` } diff --git a/pkg/interop/crypto/crypto.go b/pkg/interop/crypto/crypto.go index fe8d527f5..cce23b916 100644 --- a/pkg/interop/crypto/crypto.go +++ b/pkg/interop/crypto/crypto.go @@ -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 }