-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(multisig): adjust diverging behavior in signature verification
- Loading branch information
Showing
3 changed files
with
59 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,37 @@ | ||
use cosmwasm_crypto::secp256k1_verify; | ||
|
||
// TODO: Logic specific to secp256k1 will most likely be handled by core in the future. | ||
use crate::key::Signature; | ||
use crate::ContractError; | ||
|
||
pub fn ecdsa_verify( | ||
msg_hash: &[u8], | ||
sig: &Signature, | ||
pub_key: &[u8], | ||
) -> Result<bool, ContractError> { | ||
secp256k1_verify(msg_hash, sig.as_ref(), pub_key).map_err(|err| { | ||
pub fn ecdsa_verify(msg_hash: &[u8], sig: &[u8], pub_key: &[u8]) -> Result<bool, ContractError> { | ||
secp256k1_verify(msg_hash, sig, pub_key).map_err(|err| { | ||
ContractError::SignatureVerificationFailed { | ||
reason: err.to_string(), | ||
} | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use cosmwasm_std::HexBinary; | ||
|
||
use crate::test::common::ecdsa_test_data; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn should_fail_sig_verification_instead_of_truncating() { | ||
let sig_with_extra_byte = ecdsa_test_data::signature().to_hex() + "00"; | ||
|
||
let signature = HexBinary::from_hex(&sig_with_extra_byte).unwrap().to_vec(); | ||
let message = ecdsa_test_data::message().to_vec(); | ||
let public_key = ecdsa_test_data::pub_key().to_vec(); | ||
|
||
let result = ecdsa_verify(&message, &signature, &public_key); | ||
assert_eq!( | ||
result.unwrap_err(), | ||
ContractError::SignatureVerificationFailed { | ||
reason: "Invalid signature format".into(), | ||
} | ||
); | ||
} | ||
} |