From 86fff4990dfe4ec0970258727d123106c9b86c3e Mon Sep 17 00:00:00 2001 From: rasmus-kirk Date: Tue, 22 Oct 2024 15:54:47 +0200 Subject: [PATCH] Tested `verify_ecdsa_secp256k1_signature` in TestHost --- concordium-std/src/test_env.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/concordium-std/src/test_env.rs b/concordium-std/src/test_env.rs index 8f2d7c99..94b3ae78 100644 --- a/concordium-std/src/test_env.rs +++ b/concordium-std/src/test_env.rs @@ -194,8 +194,9 @@ mod wasm_test { fn set_get_events() { // Testing primitive calls for testing offset and length parameters let event_prim = vec![1u8, 2, 3, 4]; - let store_status = - unsafe { prims::log_event(event_prim.as_ptr(), event_prim.len().try_into().unwrap_abort()) }; + let store_status = unsafe { + prims::log_event(event_prim.as_ptr(), event_prim.len().try_into().unwrap_abort()) + }; let event_size = unsafe { prims::get_event_size(0) }; claim_eq!(store_status, 1); @@ -303,4 +304,28 @@ mod wasm_test { let is_verified = crypto_primitives().verify_ed25519_signature(pk, wrong_sig, msg); claim_eq!(is_verified, false); } + + #[concordium_test] + fn verify_ecdsa_secp256k_signature() { + let _sk_hex = "49f386482744ea6ea0d92b17c73fbc1729e3c061dd9ddf02e85db8d88b2a157b"; + let pk_hex = "03b8fa66dda8feccbfcf15fcab18d2b124570f4af23b7961bfbd61f8c1967aca12"; + let sig_hex = "a9170fc158e040f68dd59ab6c0415cf0b8a8811f92294696aa13dfdc7671407732cb6de20f39ca1fdb159cef3213d980fb32b82b8851c847e8168e125fd20c1c"; + let msg_hash = [ + 11u8, 236, 151, 183, 34, 12, 80, 68, 186, 215, 67, 68, 119, 118, 54, 234, 68, 106, 196, + 109, 214, 155, 169, 75, 236, 168, 229, 227, 168, 60, 84, 140, + ]; + + // Check valid signature + let pk = PublicKeyEcdsaSecp256k1::from_str(pk_hex).unwrap_abort(); + let sig = SignatureEcdsaSecp256k1::from_str(sig_hex).unwrap_abort(); + let is_verified = crypto_primitives().verify_ecdsa_secp256k1_signature(pk, sig, msg_hash); + claim_eq!(is_verified, true); + + // Check invalid signature + let wrong_sig_hex = "111111111111111111111111c0415cf0b8a8811f92294696aa13dfdc7671407732cb6de20f39ca1fdb159cef3213d980fb32b82b8851c847e8168e125fd20c1c"; + let wrong_sig = SignatureEcdsaSecp256k1::from_str(wrong_sig_hex).unwrap_abort(); + let is_verified = + crypto_primitives().verify_ecdsa_secp256k1_signature(pk, wrong_sig, msg_hash); + claim_eq!(is_verified, false); + } }