-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5233d45
commit 53ab7e5
Showing
7 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use core::types::merkle_tree::{tree_key_to_u8_arr, u8_arr_to_tree_key}; | ||
use core::types::merkle_tree::{TreeKey, TreeValue}; | ||
use core::vm::error::ProcessorError; | ||
use num::{BigUint, Num}; | ||
use secp256k1::{ecdsa, Message, PublicKey, Secp256k1}; | ||
pub fn ecdsa_verify( | ||
x: TreeValue, | ||
y: TreeValue, | ||
r: TreeValue, | ||
s: TreeValue, | ||
msg: TreeValue, | ||
) -> Result<bool, ProcessorError> { | ||
let secp = Secp256k1::new(); | ||
|
||
let x_arr = tree_key_to_u8_arr(&x); | ||
let y_arr = tree_key_to_u8_arr(&y); | ||
|
||
let mut pub_key_bytes = [0u8; 65]; | ||
pub_key_bytes[0] = 4; | ||
pub_key_bytes[1..33].copy_from_slice(&x_arr); | ||
pub_key_bytes[33..].copy_from_slice(&y_arr); | ||
let pubkey = PublicKey::from_slice(&pub_key_bytes) | ||
.map_err(|e| ProcessorError::PubKeyInvalid(e.to_string()))?; | ||
|
||
let mut signature_bytes = [0u8; 64]; | ||
let r_arr = tree_key_to_u8_arr(&r); | ||
let s_arr = tree_key_to_u8_arr(&s); | ||
|
||
signature_bytes[..32].copy_from_slice(&r_arr); | ||
signature_bytes[32..].copy_from_slice(&s_arr); | ||
let sig = ecdsa::Signature::from_compact(&signature_bytes) | ||
.map_err(|e| ProcessorError::SignatureInvalid(e.to_string()))?; | ||
|
||
let msg_arr = tree_key_to_u8_arr(&msg); | ||
let message = | ||
Message::from_slice(&msg_arr).map_err(|e| ProcessorError::MessageInvalid(e.to_string()))?; | ||
Ok(secp.verify_ecdsa(&message, &sig, &pubkey).is_ok()) | ||
} |
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