From ab0fe3dc52c260f1aa85592a79bb72f15d94a524 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 17 Sep 2024 13:26:53 +0000 Subject: [PATCH 1/3] errors for invalid signatures in crypto hooks --- vmhost/errors.go | 3 +++ vmhost/vmhooks/cryptoei.go | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/vmhost/errors.go b/vmhost/errors.go index e57facf55..f5a3faa55 100644 --- a/vmhost/errors.go +++ b/vmhost/errors.go @@ -301,3 +301,6 @@ var ErrNilMapOpcodeAddress = errors.New("nil map opcode address") // ErrOpcodeIsNotAllowed signals that opcode is not allowed for the address var ErrOpcodeIsNotAllowed = errors.New("opcode is not allowed") + +// ErrInvalidSignature signals that a signature verification failed +var ErrInvalidSignature = errors.New("signature is invalid") diff --git a/vmhost/vmhooks/cryptoei.go b/vmhost/vmhooks/cryptoei.go index 5415f34b7..6b3d6096e 100644 --- a/vmhost/vmhooks/cryptoei.go +++ b/vmhost/vmhooks/cryptoei.go @@ -2,6 +2,7 @@ package vmhooks import ( "crypto/elliptic" + "github.com/multiversx/mx-chain-vm-go/crypto/signing/secp256" "github.com/multiversx/mx-chain-vm-go/executor" "github.com/multiversx/mx-chain-vm-go/math" @@ -401,7 +402,7 @@ func ManagedVerifyBLSWithHost( } if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + WithFaultAndHost(host, vmhost.ErrInvalidSignature, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } @@ -659,7 +660,7 @@ func ManagedVerifyCustomSecp256k1WithHost( } if invalidSigErr != nil { - WithFaultAndHost(host, invalidSigErr, runtime.CryptoAPIErrorShouldFailExecution()) + WithFaultAndHost(host, vmhost.ErrInvalidSignature, runtime.CryptoAPIErrorShouldFailExecution()) return -1 } From ddb140f8c2246abb897077d033fb3c8e31b8408b Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 17 Sep 2024 13:40:18 +0000 Subject: [PATCH 2/3] fix tests for errors --- .../basic-features/scenarios/crypto_verify_bls.scen.json | 2 +- .../scenarios/crypto_verify_bls_aggregated_signature.scen.json | 2 +- .../basic-features/scenarios/crypto_verify_bls_share.scen.json | 2 +- .../basic-features/scenarios/crypto_verify_secp256r1.scen.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/features/basic-features/scenarios/crypto_verify_bls.scen.json b/test/features/basic-features/scenarios/crypto_verify_bls.scen.json index fc67a3745..11ec821bf 100644 --- a/test/features/basic-features/scenarios/crypto_verify_bls.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_bls.scen.json @@ -58,7 +58,7 @@ "expect": { "out": [], "status": "10", - "message": "str:err blsSignatureDeserialize 0032a2ddf341c08d1eb7232f05dc34e4454155e676b58c40fddf9a036562ac2c01533d2d557cb49d73aa9d7a89744696", + "message": "signature is invalid", "logs": "*", "gas": "*", "refund": "*" diff --git a/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json b/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json index 546c0d4c9..b2e4a8d2d 100644 --- a/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json @@ -70,7 +70,7 @@ "expect": { "out": [], "status": "10", - "message": "str:err blsSignatureDeserialize 0012858363e8caa5b398d3febdd7bc01bc2fae1fef8f486ff4d84a5f3342f2d38085904eb10b73c0879a45d23585ce8f", + "message": "signature is invalid", "logs": "*", "gas": "*", "refund": "*" diff --git a/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json b/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json index fa7c21611..fad430f36 100644 --- a/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json @@ -58,7 +58,7 @@ "expect": { "out": [], "status": "10", - "message": "str:err blsSignatureDeserialize ff725db195e37aa237cdbbda76270d4a229b6e7a3651104dc58c4349c0388e8546976fe54a04240530b99064e434c90f", + "message": "signature is invalid", "logs": "*", "gas": "*", "refund": "*" diff --git a/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json b/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json index 1c35b4627..1698c1774 100644 --- a/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json @@ -57,7 +57,7 @@ "expect": { "out": [], "status": "10", - "message": "str:signature verification failed", + "message": "signature is invalid", "logs": "*", "gas": "*", "refund": "*" From 18af34aca4d440851c26f4aae234914e29d1b53d Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 17 Sep 2024 13:44:24 +0000 Subject: [PATCH 3/3] fix tests for errors --- .../basic-features/scenarios/crypto_verify_bls.scen.json | 2 +- .../scenarios/crypto_verify_bls_aggregated_signature.scen.json | 2 +- .../basic-features/scenarios/crypto_verify_bls_share.scen.json | 2 +- .../basic-features/scenarios/crypto_verify_secp256r1.scen.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/features/basic-features/scenarios/crypto_verify_bls.scen.json b/test/features/basic-features/scenarios/crypto_verify_bls.scen.json index 11ec821bf..99d683d28 100644 --- a/test/features/basic-features/scenarios/crypto_verify_bls.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_bls.scen.json @@ -58,7 +58,7 @@ "expect": { "out": [], "status": "10", - "message": "signature is invalid", + "message": "str:signature is invalid", "logs": "*", "gas": "*", "refund": "*" diff --git a/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json b/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json index b2e4a8d2d..490fb1de8 100644 --- a/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_bls_aggregated_signature.scen.json @@ -70,7 +70,7 @@ "expect": { "out": [], "status": "10", - "message": "signature is invalid", + "message": "str:signature is invalid", "logs": "*", "gas": "*", "refund": "*" diff --git a/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json b/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json index fad430f36..2fe8473f5 100644 --- a/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_bls_share.scen.json @@ -58,7 +58,7 @@ "expect": { "out": [], "status": "10", - "message": "signature is invalid", + "message": "str:signature is invalid", "logs": "*", "gas": "*", "refund": "*" diff --git a/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json b/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json index 1698c1774..5d22d63d9 100644 --- a/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json +++ b/test/features/basic-features/scenarios/crypto_verify_secp256r1.scen.json @@ -57,7 +57,7 @@ "expect": { "out": [], "status": "10", - "message": "signature is invalid", + "message": "str:signature is invalid", "logs": "*", "gas": "*", "refund": "*"