-
Notifications
You must be signed in to change notification settings - Fork 39
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
6ad2420
commit 1252631
Showing
23 changed files
with
1,314 additions
and
893 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
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,60 @@ | ||
use super::*; | ||
use crate::validator::MsgHash; | ||
use rand::Rng as _; | ||
use std::vec; | ||
use zksync_concurrency::ctx; | ||
|
||
#[test] | ||
fn test_signature_verify() { | ||
let ctx = ctx::test_root(&ctx::RealClock); | ||
let rng = &mut ctx.rng(); | ||
|
||
let msg1: MsgHash = rng.gen(); | ||
let msg2: MsgHash = rng.gen(); | ||
|
||
let key1: SecretKey = rng.gen(); | ||
let key2: SecretKey = rng.gen(); | ||
|
||
let sig1 = key1.sign_hash(&msg1); | ||
|
||
// Matching key and message. | ||
sig1.verify_hash(&msg1, &key1.public()).unwrap(); | ||
|
||
// Mismatching message. | ||
assert!(sig1.verify_hash(&msg2, &key1.public()).is_err()); | ||
|
||
// Mismatching key. | ||
assert!(sig1.verify_hash(&msg1, &key2.public()).is_err()); | ||
} | ||
|
||
#[test] | ||
fn test_agg_signature_verify() { | ||
let ctx = ctx::test_root(&ctx::RealClock); | ||
let rng = &mut ctx.rng(); | ||
|
||
let msg1: MsgHash = rng.gen(); | ||
let msg2: MsgHash = rng.gen(); | ||
|
||
let key1: SecretKey = rng.gen(); | ||
let key2: SecretKey = rng.gen(); | ||
|
||
let sig1 = key1.sign_hash(&msg1); | ||
let sig2 = key2.sign_hash(&msg2); | ||
|
||
let agg_sig = AggregateSignature::aggregate(vec![&sig1, &sig2]); | ||
|
||
// Matching key and message. | ||
agg_sig | ||
.verify_hash([(msg1, &key1.public()), (msg2, &key2.public())].into_iter()) | ||
.unwrap(); | ||
|
||
// Mismatching message. | ||
assert!(agg_sig | ||
.verify_hash([(msg2, &key1.public()), (msg1, &key2.public())].into_iter()) | ||
.is_err()); | ||
|
||
// Mismatching key. | ||
assert!(agg_sig | ||
.verify_hash([(msg1, &key2.public()), (msg2, &key1.public())].into_iter()) | ||
.is_err()); | ||
} |
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
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
Oops, something went wrong.