From 664d9855abf830d3fe6a53fc318d9a754316f45f Mon Sep 17 00:00:00 2001 From: Vindaar Date: Mon, 30 Dec 2024 20:37:25 +0100 Subject: [PATCH] [tests] add test case for ECRecover --- constantine/signatures/ecdsa.nim | 1 + tests/t_ethereum_evm_precompiles.nim | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/constantine/signatures/ecdsa.nim b/constantine/signatures/ecdsa.nim index 2f44069a..20f4fd62 100644 --- a/constantine/signatures/ecdsa.nim +++ b/constantine/signatures/ecdsa.nim @@ -381,6 +381,7 @@ proc recoverPubkeyImpl_vartime*[Name: static Algebra; Sig]( recovered.ccopy(Q.getAffine(), SecretBool validSig) # Copy `Q` if valid # 6. try next `i` in `x1 = r + i·M` x1 += M + proc recoverPubkey*[Pubkey; Sig]( recovered: var Pubkey, signature: Sig, diff --git a/tests/t_ethereum_evm_precompiles.nim b/tests/t_ethereum_evm_precompiles.nim index 69b0c642..b0d87303 100644 --- a/tests/t_ethereum_evm_precompiles.nim +++ b/tests/t_ethereum_evm_precompiles.nim @@ -82,7 +82,9 @@ template runPrecompileTests(filename: string, funcname: untyped, outsize: int, n else: let status = funcname(r, inputbytes) if status != cttEVM_Success: - doAssert test.ExpectedError.len > 0, "[Test Failure]\n" & + # `ecRecover.json` has failing test vectors where no `ExpectedError` exists, but the + # `Expected` output is simply empty. + doAssert test.ExpectedError.len > 0 or test.Expected.len == 0, "[Test Failure]\n" & " " & test.Name & "\n" & " " & funcname.astToStr & "\n" & " " & "Nim proc returned failure, but test expected to pass.\n" & @@ -163,3 +165,5 @@ runPrecompileTests("eip-2537/map_fp2_to_G2_bls.json", eth_evm_bls12381_map_fp2_t runPrecompileTests("eip-2537/fail-map_fp2_to_G2_bls.json", eth_evm_bls12381_map_fp2_to_g2, 256) runPrecompileTests("eip-4844/pointEvaluation.json", eth_evm_kzg_point_evaluation, 64, true) + +runPrecompileTests("ecRecover.json", eth_evm_ecrecover, 32)