Skip to content

Commit

Permalink
test comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed May 2, 2024
1 parent bbe3998 commit 01239d1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions onchain/src/bip340.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ mod tests {

#[test]
fn test_5() {
// public key not on the curve
let px: u256 = 0xeefdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34;
let rx: u256 = 0x6cff5c3ba86c69ea4b7376f31a9bcb4f74c1976089b2d9963da2e5543e177769;
let s: u256 = 0x69e89b4c5564d00349106b8497785dd7d1d713a8ae82b32fa79d5f7fc407d39b;
Expand All @@ -179,6 +180,7 @@ mod tests {

#[test]
fn test_6() {
// has_even_y(R) is false
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0xfff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556;
let s: u256 = 0x3cc27944640ac607cd107ae10923d9ef7a73c643e166be5ebeafa34b1ac553e2;
Expand All @@ -189,6 +191,7 @@ mod tests {

#[test]
fn test_7() {
// negated message
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0x1fa62e331edbc21c394792d2ab1100a7b432b013df3f6ff4f99fcb33e0e1515f;
let s: u256 = 0x28890b3edb6e7189b630448b515ce4f8622a954cfe545735aaea5134fccdb2bd;
Expand All @@ -199,6 +202,7 @@ mod tests {

#[test]
fn test_8() {
// negated s value
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0x6cff5c3ba86c69ea4b7376f31a9bcb4f74c1976089b2d9963da2e5543e177769;
let s: u256 = 0x961764b3aa9b2ffcb6ef947b6887a226e8d7c93e00c5ed0c1834ff0d0c2e6da6;
Expand All @@ -209,6 +213,8 @@ mod tests {

#[test]
fn test_9() {
// sG - eP is infinite. Test fails in single verification if has_even_y(inf) is defined as
// true and x(inf) as 0
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0x0;
let s: u256 = 0x123dda8328af9c23a94c1feecfd123ba4fb73476f0d594dcb65c6425bd186051;
Expand All @@ -219,6 +225,8 @@ mod tests {

#[test]
fn test_10() {
// sG - eP is infinite. Test fails in single verification if has_even_y(inf) is defined as
// true and x(inf) as 1
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0x1;
let s: u256 = 0x7615fbaf5ae28864013c099742deadb4dba87f11ac6754f93780d5a1837cf197;
Expand All @@ -229,6 +237,7 @@ mod tests {

#[test]
fn test_11() {
// sig[0:32] is not an X coordinate on the curve
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0x4a298dacae57395a15d0795ddbfd1dcb564da82b0f269bc70a74f8220429ba1d;
let s: u256 = 0x69e89b4c5564d00349106b8497785dd7d1d713a8ae82b32fa79d5f7fc407d39b;
Expand All @@ -238,6 +247,7 @@ mod tests {

#[test]
fn test_12() {
// sig[0:32] is equal to field size
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f;
let s: u256 = 0x69e89b4c5564d00349106b8497785dd7d1d713a8ae82b32fa79d5f7fc407d39b;
Expand All @@ -247,6 +257,7 @@ mod tests {

#[test]
fn test_13() {
// sig[32:64] is equal to curve order
let px: u256 = 0xdff1d77f2a671c5f36183726db2341be58feae1da2deced843240f7b502ba659;
let rx: u256 = 0x6cff5c3ba86c69ea4b7376f31a9bcb4f74c1976089b2d9963da2e5543e177769;
let s: u256 = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141;
Expand All @@ -256,6 +267,7 @@ mod tests {

#[test]
fn test_14() {
// public key is not a valid X coordinate because it exceeds the field size
let px: u256 = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc30;
let rx: u256 = 0x6cff5c3ba86c69ea4b7376f31a9bcb4f74c1976089b2d9963da2e5543e177769;
let s: u256 = 0x69e89b4c5564d00349106b8497785dd7d1d713a8ae82b32fa79d5f7fc407d39b;
Expand All @@ -265,6 +277,7 @@ mod tests {

#[test]
fn test_15() {
// message of size 0
let px: u256 = 0x778caa53b4393ac467774d09497a87224bf9fab6f6e68b23086497324d6fd117;
let rx: u256 = 0x71535db165ecd9fbbc046e5ffaea61186bb6ad436732fccc25291a55895464cf;
let s: u256 = 0x6069ce26bf03466228f19a3a62db8a649f2d560fac652827d1af0574e427ab63;
Expand All @@ -274,6 +287,7 @@ mod tests {

#[test]
fn test_16() {
// message of size 1
let px: u256 = 0x778caa53b4393ac467774d09497a87224bf9fab6f6e68b23086497324d6fd117;
let rx: u256 = 0x8a20a0afef64124649232e0693c583ab1b9934ae63b4c3511f3ae1134c6a303;
let s: u256 = 0xea3173bfea6683bd101fa5aa5dbc1996fe7cacfc5a577d33ec14564cec2bacbf;
Expand All @@ -283,6 +297,7 @@ mod tests {

#[test]
fn test_17() {
// message of size 17
let px: u256 = 0x778caa53b4393ac467774d09497a87224bf9fab6f6e68b23086497324d6fd117;
let rx: u256 = 0x5130f39a4059b43bc7cac09a19ece52b5d8699d1a71e3c52da9afdb6b50ac370;
let s: u256 = 0xc4a482b77bf960f8681540e25b6771ece1e5a37fd80e5a51897c5566a97ea5a5;
Expand All @@ -293,6 +308,7 @@ mod tests {

#[test]
fn test_18() {
// message of size 100
let px: u256 = 0x778caa53b4393ac467774d09497a87224bf9fab6f6e68b23086497324d6fd117;
let rx: u256 = 0x403b12b0d8555a344175ea7ec746566303321e5dbfa8be6f091635163eca79a8;
let s: u256 = 0x585ed3e3170807e7c03b720fc54c7b23897fcba0e9d0b4a06894cfd249f22367;
Expand All @@ -311,10 +327,10 @@ mod tests {

assert_eq!(verify(px, rx, s, m), true);
}

#[test]
fn test_19() {
// signiture of message joyboy, generated with actual nos2x extension
// signiture of message: joyboy, generated in broswer with nos2x extension
let px: u256 = 0x98298b0b4a0d586771e7f84c742394b5013d37c16af0924bd7ee62ec6a517a5d;
let rx: u256 = 0x3b7a0877cefa952d536fc167446a22f017922743db5cddd912b7890b7c5c34fe;
let s: u256 = 0x2591fff0a4ac15d3ed5d3f767e686e771ec456af2fb53ffba163e509e16b0eba;
Expand Down

0 comments on commit 01239d1

Please sign in to comment.