From fdbbaaf118bc38e74fff4c22a2670e8ed6e75ee3 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Fri, 12 Jan 2024 14:17:06 +0000 Subject: [PATCH 01/43] new cargo project --- Cargo.toml | 2 +- crates/webauthn/tests/Cargo.toml | 9 +++++++++ crates/webauthn/tests/src/main.rs | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 crates/webauthn/tests/Cargo.toml create mode 100644 crates/webauthn/tests/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 7bca6a07..5593f917 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["crates/account_sdk"] +members = ["crates/account_sdk", "crates/webauthn/tests"] [workspace.package] edition = "2021" diff --git a/crates/webauthn/tests/Cargo.toml b/crates/webauthn/tests/Cargo.toml new file mode 100644 index 00000000..810055aa --- /dev/null +++ b/crates/webauthn/tests/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "tests" +edition.workspace = true +version.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cairo-args-runner = "1.0.0" diff --git a/crates/webauthn/tests/src/main.rs b/crates/webauthn/tests/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/crates/webauthn/tests/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From f85b6e3c98a7d1355da34c12453fbaf7f0935275 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Mon, 15 Jan 2024 11:17:52 +0000 Subject: [PATCH 02/43] first tests and build script --- crates/webauthn/auth/src/helpers.cairo | 4 +++ crates/webauthn/tests/Cargo.toml | 3 ++- crates/webauthn/tests/build.rs | 30 +++++++++++++++++++++++ crates/webauthn/tests/src/lib.rs | 6 +++++ crates/webauthn/tests/src/main.rs | 3 --- crates/webauthn/tests/src/webauthn/mod.rs | 14 +++++++++++ 6 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 crates/webauthn/tests/build.rs create mode 100644 crates/webauthn/tests/src/lib.rs delete mode 100644 crates/webauthn/tests/src/main.rs create mode 100644 crates/webauthn/tests/src/webauthn/mod.rs diff --git a/crates/webauthn/auth/src/helpers.cairo b/crates/webauthn/auth/src/helpers.cairo index f225fbff..d079d882 100644 --- a/crates/webauthn/auth/src/helpers.cairo +++ b/crates/webauthn/auth/src/helpers.cairo @@ -14,6 +14,10 @@ trait ContainsTrait { } +fn test_array_contains(arr: Array, val: felt252) -> bool { + arr.contains(@val) +} + impl ArrayTContainsImpl> of ContainsTrait, T> { fn contains(self: @Array, item: @T) -> bool { let la: usize = self.len(); diff --git a/crates/webauthn/tests/Cargo.toml b/crates/webauthn/tests/Cargo.toml index 810055aa..4519f318 100644 --- a/crates/webauthn/tests/Cargo.toml +++ b/crates/webauthn/tests/Cargo.toml @@ -6,4 +6,5 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cairo-args-runner = "1.0.0" +starknet.workspace = true +cairo-args-runner = { path="/home/szymon/dev/cairo-args-runner" } diff --git a/crates/webauthn/tests/build.rs b/crates/webauthn/tests/build.rs new file mode 100644 index 00000000..80fa34c8 --- /dev/null +++ b/crates/webauthn/tests/build.rs @@ -0,0 +1,30 @@ +use core::panic; +use std::{ + env, + io::{self, Write as _}, + process::Command, +}; + +fn main() { + let curr_dir = env::current_dir().expect("Failed to get current directory"); + assert!(curr_dir.ends_with("webauthn/tests")); + + // TODO: Compile each crate separately and concurrently + let output = Command::new("scarb") + .current_dir("../") + .arg("build") + .output() + .expect("Failed to execute 'scarb build' command"); + + if output.status.success() { + io::stderr().write_all(&output.stderr).unwrap(); + } else { + io::stderr().write_all(&output.stdout).unwrap(); + io::stderr().write_all(&output.stderr).unwrap(); + panic!("Command executed with error status: {}", output.status); + } + // This makes sure that the cairo code is compiled again when a change occurs + // It's important since we always want to test against the latest version of the code + println!("cargo:rerun-if-changed=../auth"); + println!("cargo:rerun-if-changed=../session"); +} diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs new file mode 100644 index 00000000..704983cb --- /dev/null +++ b/crates/webauthn/tests/src/lib.rs @@ -0,0 +1,6 @@ +#[cfg(test)] +mod webauthn; + + + + diff --git a/crates/webauthn/tests/src/main.rs b/crates/webauthn/tests/src/main.rs deleted file mode 100644 index e7a11a96..00000000 --- a/crates/webauthn/tests/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/crates/webauthn/tests/src/webauthn/mod.rs b/crates/webauthn/tests/src/webauthn/mod.rs new file mode 100644 index 00000000..9cfcc636 --- /dev/null +++ b/crates/webauthn/tests/src/webauthn/mod.rs @@ -0,0 +1,14 @@ +use cairo_args_runner::{arg_array, felt_vec, arg_value}; +#[test] +fn test_contains_trait() { + let target = "../../../target/dev/webauthn_auth.sierra.json"; + let function = "test_array_contains"; + let args = vec![ + arg_array![5, 1, 2, 4, 8, 16, 6, 1, 2, 3, 4, 5, 6], + arg_value!(2), + ]; + let result = cairo_args_runner::run(target, function, &args).unwrap(); + + assert_eq!(result.len(), 1); + assert_eq!(result[0], true.into()); +} From b34f648031fbcb54cfdd211203c65f21ebe9ef87 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 17 Jan 2024 10:56:32 +0000 Subject: [PATCH 03/43] test gcd basic --- .../tests/src/{webauthn => auth}/mod.rs | 3 + .../webauthn/tests/src/auth/mod_arithmetic.rs | 24 ++++++++ crates/webauthn/tests/src/helpers.rs | 61 +++++++++++++++++++ crates/webauthn/tests/src/lib.rs | 9 +-- 4 files changed, 93 insertions(+), 4 deletions(-) rename crates/webauthn/tests/src/{webauthn => auth}/mod.rs (95%) create mode 100644 crates/webauthn/tests/src/auth/mod_arithmetic.rs create mode 100644 crates/webauthn/tests/src/helpers.rs diff --git a/crates/webauthn/tests/src/webauthn/mod.rs b/crates/webauthn/tests/src/auth/mod.rs similarity index 95% rename from crates/webauthn/tests/src/webauthn/mod.rs rename to crates/webauthn/tests/src/auth/mod.rs index 9cfcc636..5433867f 100644 --- a/crates/webauthn/tests/src/webauthn/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,4 +1,7 @@ use cairo_args_runner::{arg_array, felt_vec, arg_value}; + +mod mod_arithmetic; + #[test] fn test_contains_trait() { let target = "../../../target/dev/webauthn_auth.sierra.json"; diff --git a/crates/webauthn/tests/src/auth/mod_arithmetic.rs b/crates/webauthn/tests/src/auth/mod_arithmetic.rs new file mode 100644 index 00000000..f21b5251 --- /dev/null +++ b/crates/webauthn/tests/src/auth/mod_arithmetic.rs @@ -0,0 +1,24 @@ +use cairo_args_runner::felt_vec; + +use crate::{FunctionReturnLength, Function, FunctionTrait}; + +/// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` +const EXTENDED_GCD: FunctionReturnLength<6> = Function::new("extended_gcd"); + +#[test] +fn test_gcd_basic_1(){ + let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(2, 0, 2, 0)); + assert_eq!(gcd, 2.into()); +} + +#[test] +fn test_gcd_basic_2(){ + let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(100, 0, 200, 0)); + assert_eq!(gcd, 100.into()); +} + +#[test] +fn test_gcd_basic_3(){ + let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(1234, 0, 5678, 0)); + assert_eq!(gcd, 2.into()); +} \ No newline at end of file diff --git a/crates/webauthn/tests/src/helpers.rs b/crates/webauthn/tests/src/helpers.rs new file mode 100644 index 00000000..b8239dfc --- /dev/null +++ b/crates/webauthn/tests/src/helpers.rs @@ -0,0 +1,61 @@ +use cairo_args_runner::{Arg, Felt252}; + +pub const SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_auth.sierra.json"; + +#[derive(Debug, Clone, Copy)] +pub struct FunctionReturnLength<'a, const N: usize> { + pub name: &'a str, +} + +#[derive(Debug, Clone, Copy)] +pub struct FunctionUnspecified<'a> { + pub name: &'a str, +} + +pub enum Function {} + +impl Function { + pub const fn new<'a, const N: usize>(name: &'a str) -> FunctionReturnLength<'a, N> { + FunctionReturnLength { name } + } + pub const fn new_unspecified<'a>(name: &'a str) -> FunctionUnspecified<'a> { + FunctionUnspecified { name } + } +} + +pub trait FunctionTrait +where + T: Into>, +{ + fn run(&self, args: Vec

) -> T; +} + +impl<'a, const N: usize, P> FunctionTrait<[Felt252; N], P> for FunctionReturnLength<'a, N> +where + P: Into, +{ + fn run(&self, args: Vec

) -> [Felt252; N] { + cairo_args_runner::run( + SIERRA_TARGET, + &self.name, + &args.into_iter().map(Into::into).collect::>(), + ) + .unwrap() + .try_into() + .unwrap() + } +} + +impl<'a, P> FunctionTrait, P> for FunctionUnspecified<'a> +where + P: Into, +{ + fn run(&self, args: Vec

) -> Vec { + cairo_args_runner::run( + SIERRA_TARGET, + &self.name, + &args.into_iter().map(Into::into).collect::>(), + ) + .unwrap() + } +} diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs index 704983cb..1732e71d 100644 --- a/crates/webauthn/tests/src/lib.rs +++ b/crates/webauthn/tests/src/lib.rs @@ -1,6 +1,7 @@ #[cfg(test)] -mod webauthn; - - - +mod auth; +#[cfg(test)] +mod helpers; +#[cfg(test)] +pub use helpers::*; From 361e03be5116d73e70258f44003fbe6f1e447450 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Mon, 22 Jan 2024 11:41:56 +0000 Subject: [PATCH 04/43] extract verifying key converter --- Cargo.toml | 1 + crates/account_sdk/Cargo.toml | 2 +- crates/account_sdk/src/webauthn_signer/mod.rs | 32 ++++++++++----- crates/webauthn/tests/Cargo.toml | 4 ++ crates/webauthn/tests/src/auth/mod.rs | 1 + .../tests/src/auth/verify_signature.rs | 40 +++++++++++++++++++ 6 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 crates/webauthn/tests/src/auth/verify_signature.rs diff --git a/Cargo.toml b/Cargo.toml index 5593f917..367b9a16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,4 @@ url = "2" wasm-bindgen = "0.2" webauthn-authenticator-rs = { version = "0.4" } webauthn-rs-proto = "0.4" +account-sdk = { path = "crates/account_sdk" } diff --git a/crates/account_sdk/Cargo.toml b/crates/account_sdk/Cargo.toml index d80a9630..ba4aa23f 100644 --- a/crates/account_sdk/Cargo.toml +++ b/crates/account_sdk/Cargo.toml @@ -6,7 +6,7 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] -crate-type = ["cdylib"] +crate-type = ["lib"] [dependencies] anyhow.workspace = true diff --git a/crates/account_sdk/src/webauthn_signer/mod.rs b/crates/account_sdk/src/webauthn_signer/mod.rs index 603b2bf7..6f0c2490 100644 --- a/crates/account_sdk/src/webauthn_signer/mod.rs +++ b/crates/account_sdk/src/webauthn_signer/mod.rs @@ -34,16 +34,7 @@ impl P256r1Signer { Self { signing_key, rp_id } } pub fn public_key_bytes(&self) -> ([u8; 32], [u8; 32]) { - let verifying_key: VerifyingKey = VerifyingKey::from(&self.signing_key); - let encoded = &verifying_key.to_encoded_point(false); - let (x, y) = match encoded.coordinates() { - Coordinates::Uncompressed { x, y } => (x, y), - _ => panic!("unexpected compression"), - }; - ( - x.as_slice().try_into().unwrap(), - y.as_slice().try_into().unwrap(), - ) + P256VerifyingKeyConverter::new(*self.signing_key.verifying_key()).to_bytes() } pub fn sign(&self, challenge: &[u8]) -> AuthenticatorAssertionResponse { use sha2::{digest::Update, Digest, Sha256}; @@ -70,6 +61,27 @@ impl P256r1Signer { } } +pub struct P256VerifyingKeyConverter { + pub verifying_key: VerifyingKey, +} + +impl P256VerifyingKeyConverter { + pub fn new(verifying_key: VerifyingKey) -> Self { + Self { verifying_key } + } + pub fn to_bytes(&self) -> ([u8; 32], [u8; 32]) { + let encoded = &self.verifying_key.to_encoded_point(false); + let (x, y) = match encoded.coordinates() { + Coordinates::Uncompressed { x, y } => (x, y), + _ => panic!("unexpected compression"), + }; + ( + x.as_slice().try_into().unwrap(), + y.as_slice().try_into().unwrap(), + ) + } +} + #[test] fn test_signer() { let rp_id = "https://localhost:8080".to_string(); diff --git a/crates/webauthn/tests/Cargo.toml b/crates/webauthn/tests/Cargo.toml index 4519f318..4950af63 100644 --- a/crates/webauthn/tests/Cargo.toml +++ b/crates/webauthn/tests/Cargo.toml @@ -8,3 +8,7 @@ version.workspace = true [dependencies] starknet.workspace = true cairo-args-runner = { path="/home/szymon/dev/cairo-args-runner" } +proptest = "1.4.0" +p256.workspace = true +account-sdk.workspace = true +u256 = "0.1.0" diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 5433867f..05bb521e 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,6 +1,7 @@ use cairo_args_runner::{arg_array, felt_vec, arg_value}; mod mod_arithmetic; +mod verify_signature; #[test] fn test_contains_trait() { diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs new file mode 100644 index 00000000..d07d8dc9 --- /dev/null +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -0,0 +1,40 @@ +use account_sdk::webauthn_signer::P256r1Signer; +use cairo_args_runner::Felt252; +use p256::{ + ecdsa::{signature::Signer, SigningKey}, + elliptic_curve::{consts::P256, rand_core::OsRng}, +}; + +use crate::{Function, FunctionUnspecified}; + +const VERIFY_SIGNATURE: FunctionUnspecified = Function::new_unspecified("verify_signature"); + +pub struct CairoU256 { + low: Felt252, + high: Felt252, +} + +impl CairoU256 { + pub fn new(low: Felt252, high: Felt252) -> Self { + Self { low, high } + } + pub fn from_bytes_be(low: &[u8; 16], high: &[u8; 16]) -> Self { + Self::new(Felt252::from_bytes_be(low), Felt252::from_bytes_be(high)) + } + pub fn from_byte_slice_be(bytes: &[u8]) -> Self { + let (low, high): (&[u8; 16], &[u8; 16]) = + (bytes[16..].try_into().unwrap(), bytes[..16].try_into().unwrap()); + Self::from_bytes_be(low, high) + } +} + +#[test] +fn test_verify_signature() { + let message = b"hello world"; + let signing_key = SigningKey::random(&mut OsRng); + let (signature, _): (_, _) = signing_key.sign(message); + let (r, s) = (signature.r(), signature.s()); + let (r, s) = (r.to_bytes(), s.to_bytes()); + let (r, s) = (r.as_slice(), s.as_slice()); + let p = signing_key.verifying_key().to_sec1_bytes(); +} From eb5106f78a922515dfaba4b042afefa9bd4ae3e0 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 23 Jan 2024 11:27:05 +0000 Subject: [PATCH 05/43] verify signature tests --- crates/webauthn/tests/src/auth/mod.rs | 36 +++++- .../webauthn/tests/src/auth/mod_arithmetic.rs | 10 +- .../tests/src/auth/verify_signature.rs | 103 +++++++++++++++--- 3 files changed, 129 insertions(+), 20 deletions(-) diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 05bb521e..3b3f606d 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,8 +1,40 @@ -use cairo_args_runner::{arg_array, felt_vec, arg_value}; +use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; mod mod_arithmetic; mod verify_signature; +pub struct ArgsBuilder { + args: Vec, +} + +impl ArgsBuilder { + pub fn new() -> Self { + Self { args: Vec::new() } + } + #[allow(dead_code)] + pub fn add_one(mut self, arg: impl Into) -> Self { + self.args.push(Arg::Value(arg.into())); + self + } + pub fn add_struct(mut self, args: impl IntoIterator>) -> Self { + self.args + .extend(args.into_iter().map(|arg| Arg::Value(arg.into()))); + self + } + pub fn add_array(mut self, args: impl IntoIterator>) -> Self { + self.args + .push(Arg::Array(args.into_iter().map(|arg| arg.into()).collect())); + self + } + pub fn build(self) -> Vec { + self.args + } +} + +pub trait FeltSerialize { + fn to_felts(self) -> Vec; +} + #[test] fn test_contains_trait() { let target = "../../../target/dev/webauthn_auth.sierra.json"; @@ -12,7 +44,7 @@ fn test_contains_trait() { arg_value!(2), ]; let result = cairo_args_runner::run(target, function, &args).unwrap(); - + assert_eq!(result.len(), 1); assert_eq!(result[0], true.into()); } diff --git a/crates/webauthn/tests/src/auth/mod_arithmetic.rs b/crates/webauthn/tests/src/auth/mod_arithmetic.rs index f21b5251..7eb8ecfb 100644 --- a/crates/webauthn/tests/src/auth/mod_arithmetic.rs +++ b/crates/webauthn/tests/src/auth/mod_arithmetic.rs @@ -1,24 +1,24 @@ use cairo_args_runner::felt_vec; -use crate::{FunctionReturnLength, Function, FunctionTrait}; +use crate::{Function, FunctionReturnLength, FunctionTrait}; /// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` const EXTENDED_GCD: FunctionReturnLength<6> = Function::new("extended_gcd"); #[test] -fn test_gcd_basic_1(){ +fn test_gcd_basic_1() { let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(2, 0, 2, 0)); assert_eq!(gcd, 2.into()); } #[test] -fn test_gcd_basic_2(){ +fn test_gcd_basic_2() { let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(100, 0, 200, 0)); assert_eq!(gcd, 100.into()); } #[test] -fn test_gcd_basic_3(){ +fn test_gcd_basic_3() { let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(1234, 0, 5678, 0)); assert_eq!(gcd, 2.into()); -} \ No newline at end of file +} diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index d07d8dc9..657d1187 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -1,11 +1,13 @@ -use account_sdk::webauthn_signer::P256r1Signer; +use account_sdk::webauthn_signer::P256VerifyingKeyConverter; use cairo_args_runner::Felt252; use p256::{ - ecdsa::{signature::Signer, SigningKey}, - elliptic_curve::{consts::P256, rand_core::OsRng}, + ecdsa::{signature::Signer, Signature, SigningKey}, + elliptic_curve::rand_core::OsRng, }; -use crate::{Function, FunctionUnspecified}; +use crate::{Function, FunctionTrait as _, FunctionUnspecified}; + +use super::{ArgsBuilder, FeltSerialize}; const VERIFY_SIGNATURE: FunctionUnspecified = Function::new_unspecified("verify_signature"); @@ -21,20 +23,95 @@ impl CairoU256 { pub fn from_bytes_be(low: &[u8; 16], high: &[u8; 16]) -> Self { Self::new(Felt252::from_bytes_be(low), Felt252::from_bytes_be(high)) } - pub fn from_byte_slice_be(bytes: &[u8]) -> Self { - let (low, high): (&[u8; 16], &[u8; 16]) = - (bytes[16..].try_into().unwrap(), bytes[..16].try_into().unwrap()); + pub fn from_byte_slice_be(bytes: &[u8; 32]) -> Self { + let (low, high): (&[u8; 16], &[u8; 16]) = ( + bytes[16..].try_into().unwrap(), + bytes[..16].try_into().unwrap(), + ); Self::from_bytes_be(low, high) } } -#[test] -fn test_verify_signature() { - let message = b"hello world"; - let signing_key = SigningKey::random(&mut OsRng); - let (signature, _): (_, _) = signing_key.sign(message); +impl FeltSerialize for CairoU256 { + fn to_felts(self) -> Vec { + vec![self.low, self.high] + } +} + +struct P256r1PublicKey { + x: CairoU256, + y: CairoU256, +} + +impl P256r1PublicKey { + pub fn new(x: CairoU256, y: CairoU256) -> Self { + Self { x, y } + } + pub fn from_bytes_be(x: &[u8; 32], y: &[u8; 32]) -> Self { + Self::new( + CairoU256::from_byte_slice_be(x), + CairoU256::from_byte_slice_be(y), + ) + } +} + +impl FeltSerialize for P256r1PublicKey { + fn to_felts(self) -> Vec { + self.x + .to_felts() + .into_iter() + .chain(self.y.to_felts()) + .collect() + } +} + +fn verify_signature( + hash: &[u8], + auth_data: &[u8], + signing_key: SigningKey, + signature: Signature, +) -> bool { let (r, s) = (signature.r(), signature.s()); let (r, s) = (r.to_bytes(), s.to_bytes()); let (r, s) = (r.as_slice(), s.as_slice()); - let p = signing_key.verifying_key().to_sec1_bytes(); + let (x, y) = P256VerifyingKeyConverter::new(*signing_key.verifying_key()).to_bytes(); + let pub_key = P256r1PublicKey::from_bytes_be(&x, &y); + let args = ArgsBuilder::new() + .add_array(hash.iter().cloned()) + .add_array(auth_data.iter().cloned()) + .add_struct(pub_key.to_felts()) + .add_array(r.into_iter().copied().chain(s.iter().copied())); + let result = VERIFY_SIGNATURE.run(args.build()); + result == vec![0.into(), 0.into()] +} + +#[test] +fn test_verify_signature_1() { + let hash: &[u8] = b"hello world"; + let auth_data = b"dummy auth data"; + let signing_key = SigningKey::random(&mut OsRng); + let (signature, _) = signing_key.sign(&vec![auth_data, hash].concat()); + assert!(verify_signature(hash, auth_data, signing_key, signature)) +} + +#[test] +fn test_verify_signature_2() { + let hash: &[u8] = b"1234567890987654321"; + let auth_data = b"auuuuuuuuuuth daaaaataaaaaaaaaa"; + let signing_key = SigningKey::random(&mut OsRng); + let (signature, _) = signing_key.sign(&vec![auth_data, hash].concat()); + assert!(verify_signature(hash, auth_data, signing_key, signature)) +} + +#[test] +fn test_verify_signature_should_fail_1() { + let hash = b"hello world"; + let auth_data = b"dummy auth data"; + let wrong_hash: &[u8] = b"definetly not hello world"; + let signing_key = SigningKey::random(&mut OsRng); + let (signature, _) = signing_key.sign(&vec![auth_data, wrong_hash].concat()); + assert_eq!( + verify_signature(hash, auth_data, signing_key, signature), + false + ) } From 4fe33e0c51240ebf74432366169163411b1cf845 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 23 Jan 2024 11:31:10 +0000 Subject: [PATCH 06/43] add a test --- crates/webauthn/tests/src/auth/verify_signature.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index 657d1187..6faf219a 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -115,3 +115,16 @@ fn test_verify_signature_should_fail_1() { false ) } + +#[test] +fn test_verify_signature_should_fail_2() { + let hash: &[u8] = b"1234567890987654321"; + let auth_data = b"dummy auth data"; + let signing_key = SigningKey::random(&mut OsRng); + let other_signing_key = SigningKey::random(&mut OsRng); + let (signature, _) = signing_key.sign(&vec![auth_data, hash].concat()); + assert_eq!( + verify_signature(hash, auth_data, other_signing_key, signature), + false + ) +} From 5a209527f10337d026a360b72886ec347297a9e8 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 23 Jan 2024 13:23:05 +0000 Subject: [PATCH 07/43] move types to mod.rs --- crates/webauthn/tests/src/auth/mod.rs | 57 +++++++++++++++++++ .../webauthn/tests/src/auth/verify_ecdsa.rs | 0 .../tests/src/auth/verify_signature.rs | 57 +------------------ 3 files changed, 58 insertions(+), 56 deletions(-) create mode 100644 crates/webauthn/tests/src/auth/verify_ecdsa.rs diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 3b3f606d..215359f8 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -2,11 +2,68 @@ use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; mod mod_arithmetic; mod verify_signature; +mod verify_ecdsa; +#[derive(Debug)] pub struct ArgsBuilder { args: Vec, } +pub struct CairoU256 { + low: Felt252, + high: Felt252, +} + + +impl CairoU256 { + pub fn new(low: Felt252, high: Felt252) -> Self { + Self { low, high } + } + pub fn from_bytes_be(low: &[u8; 16], high: &[u8; 16]) -> Self { + Self::new(Felt252::from_bytes_be(low), Felt252::from_bytes_be(high)) + } + pub fn from_byte_slice_be(bytes: &[u8; 32]) -> Self { + let (low, high): (&[u8; 16], &[u8; 16]) = ( + bytes[16..].try_into().unwrap(), + bytes[..16].try_into().unwrap(), + ); + Self::from_bytes_be(low, high) + } +} + +impl FeltSerialize for CairoU256 { + fn to_felts(self) -> Vec { + vec![self.low, self.high] + } +} + +struct P256r1PublicKey { + x: CairoU256, + y: CairoU256, +} + +impl P256r1PublicKey { + pub fn new(x: CairoU256, y: CairoU256) -> Self { + Self { x, y } + } + pub fn from_bytes_be(x: &[u8; 32], y: &[u8; 32]) -> Self { + Self::new( + CairoU256::from_byte_slice_be(x), + CairoU256::from_byte_slice_be(y), + ) + } +} + +impl FeltSerialize for P256r1PublicKey { + fn to_felts(self) -> Vec { + self.x + .to_felts() + .into_iter() + .chain(self.y.to_felts()) + .collect() + } +} + impl ArgsBuilder { pub fn new() -> Self { Self { args: Vec::new() } diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs new file mode 100644 index 00000000..e69de29b diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index 6faf219a..a2b5939d 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -1,5 +1,4 @@ use account_sdk::webauthn_signer::P256VerifyingKeyConverter; -use cairo_args_runner::Felt252; use p256::{ ecdsa::{signature::Signer, Signature, SigningKey}, elliptic_curve::rand_core::OsRng, @@ -7,64 +6,10 @@ use p256::{ use crate::{Function, FunctionTrait as _, FunctionUnspecified}; -use super::{ArgsBuilder, FeltSerialize}; +use super::{ArgsBuilder, FeltSerialize, P256r1PublicKey}; const VERIFY_SIGNATURE: FunctionUnspecified = Function::new_unspecified("verify_signature"); -pub struct CairoU256 { - low: Felt252, - high: Felt252, -} - -impl CairoU256 { - pub fn new(low: Felt252, high: Felt252) -> Self { - Self { low, high } - } - pub fn from_bytes_be(low: &[u8; 16], high: &[u8; 16]) -> Self { - Self::new(Felt252::from_bytes_be(low), Felt252::from_bytes_be(high)) - } - pub fn from_byte_slice_be(bytes: &[u8; 32]) -> Self { - let (low, high): (&[u8; 16], &[u8; 16]) = ( - bytes[16..].try_into().unwrap(), - bytes[..16].try_into().unwrap(), - ); - Self::from_bytes_be(low, high) - } -} - -impl FeltSerialize for CairoU256 { - fn to_felts(self) -> Vec { - vec![self.low, self.high] - } -} - -struct P256r1PublicKey { - x: CairoU256, - y: CairoU256, -} - -impl P256r1PublicKey { - pub fn new(x: CairoU256, y: CairoU256) -> Self { - Self { x, y } - } - pub fn from_bytes_be(x: &[u8; 32], y: &[u8; 32]) -> Self { - Self::new( - CairoU256::from_byte_slice_be(x), - CairoU256::from_byte_slice_be(y), - ) - } -} - -impl FeltSerialize for P256r1PublicKey { - fn to_felts(self) -> Vec { - self.x - .to_felts() - .into_iter() - .chain(self.y.to_felts()) - .collect() - } -} - fn verify_signature( hash: &[u8], auth_data: &[u8], From 4528b0e74810f5dfb9a830e116dba849a6b475f6 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 23 Jan 2024 13:59:26 +0000 Subject: [PATCH 08/43] add ecdsa tests --- .../auth/src/deserializable_endpoints.cairo | 16 +++++++ crates/webauthn/auth/src/lib.cairo | 1 + crates/webauthn/tests/Cargo.toml | 1 + crates/webauthn/tests/src/auth/mod.rs | 3 +- .../webauthn/tests/src/auth/verify_ecdsa.rs | 44 +++++++++++++++++++ .../tests/src/auth/verify_signature.rs | 6 +-- 6 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 crates/webauthn/auth/src/deserializable_endpoints.cairo diff --git a/crates/webauthn/auth/src/deserializable_endpoints.cairo b/crates/webauthn/auth/src/deserializable_endpoints.cairo new file mode 100644 index 00000000..bdb269dd --- /dev/null +++ b/crates/webauthn/auth/src/deserializable_endpoints.cairo @@ -0,0 +1,16 @@ +use webauthn_auth::types::PublicKey; +use webauthn_auth::ecdsa::VerifyEcdsaError; +use starknet::secp256r1::Secp256r1Point; +use webauthn_auth::errors::{AuthnError, RTSEIntoRTAE, AuthnErrorIntoFelt252}; +use webauthn_auth::ecdsa::verify_hashed_ecdsa; +use core::traits::Into; + +fn verify_hashed_ecdsa_endpoint( + public_key_pt: PublicKey, msg_hash: u256, r: u256, s: u256 +) -> Result<(), VerifyEcdsaError> { + let pub_key_point: Secp256r1Point = match public_key_pt.try_into() { + Option::Some(p) => p, + Option::None => { return Result::Err(VerifyEcdsaError::WrongArgument); } + }; + verify_hashed_ecdsa(pub_key_point, msg_hash, r, s) +} \ No newline at end of file diff --git a/crates/webauthn/auth/src/lib.cairo b/crates/webauthn/auth/src/lib.cairo index becb5bd6..4b6989ce 100644 --- a/crates/webauthn/auth/src/lib.cairo +++ b/crates/webauthn/auth/src/lib.cairo @@ -6,6 +6,7 @@ mod helpers; mod errors; mod component; mod interface; +mod deserializable_endpoints; #[cfg(test)] mod tests; diff --git a/crates/webauthn/tests/Cargo.toml b/crates/webauthn/tests/Cargo.toml index 4950af63..7ed1ae2d 100644 --- a/crates/webauthn/tests/Cargo.toml +++ b/crates/webauthn/tests/Cargo.toml @@ -12,3 +12,4 @@ proptest = "1.4.0" p256.workspace = true account-sdk.workspace = true u256 = "0.1.0" +sha2.workspace = true diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 215359f8..136f7a84 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,8 +1,8 @@ use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; mod mod_arithmetic; -mod verify_signature; mod verify_ecdsa; +mod verify_signature; #[derive(Debug)] pub struct ArgsBuilder { @@ -14,7 +14,6 @@ pub struct CairoU256 { high: Felt252, } - impl CairoU256 { pub fn new(low: Felt252, high: Felt252) -> Self { Self { low, high } diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs index e69de29b..a2d7bb14 100644 --- a/crates/webauthn/tests/src/auth/verify_ecdsa.rs +++ b/crates/webauthn/tests/src/auth/verify_ecdsa.rs @@ -0,0 +1,44 @@ +use account_sdk::webauthn_signer::P256VerifyingKeyConverter; +use p256::{ + ecdsa::{signature::Signer, Signature, SigningKey}, + elliptic_curve::rand_core::OsRng, +}; + +use crate::{Function, FunctionReturnLength, FunctionTrait}; + +use super::{ArgsBuilder, CairoU256, FeltSerialize, P256r1PublicKey}; +use sha2::{digest::Update, Digest, Sha256}; + +const VERIFY_HASHED_ECDSA: FunctionReturnLength<2> = Function::new("verify_hashed_ecdsa_endpoint"); + +fn verify_ecdsa(message: &[u8], signing_key: SigningKey, signature: Signature) -> bool { + let (r, s) = (signature.r(), signature.s()); + let (r, s) = (r.to_bytes(), s.to_bytes()); + let (r, s) = (r.as_slice(), s.as_slice()); + let (r, s) = ( + CairoU256::from_byte_slice_be(r.try_into().unwrap()), + CairoU256::from_byte_slice_be(s.try_into().unwrap()), + ); + let (x, y) = P256VerifyingKeyConverter::new(*signing_key.verifying_key()).to_bytes(); + let pub_key = P256r1PublicKey::from_bytes_be(&x, &y); + + let hash = Sha256::new().chain(message).finalize(); + let hash: &[u8] = hash.as_slice(); + let hash = CairoU256::from_byte_slice_be(hash.try_into().unwrap()); + + let args = ArgsBuilder::new() + .add_struct(pub_key.to_felts()) + .add_struct(hash.to_felts()) + .add_struct(r.to_felts()) + .add_struct(s.to_felts()); + let result = VERIFY_HASHED_ECDSA.run(args.build()); + result == [0.into(), 0.into()] +} + +#[test] +fn verify_ecdsa_1() { + let message: &[u8] = b"hello world"; + let signing_key = SigningKey::random(&mut OsRng); + let (signature, _) = signing_key.sign(message); + assert!(verify_ecdsa(message, signing_key, signature)); +} diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index a2b5939d..8b14f474 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -4,11 +4,11 @@ use p256::{ elliptic_curve::rand_core::OsRng, }; -use crate::{Function, FunctionTrait as _, FunctionUnspecified}; +use crate::{Function, FunctionReturnLength, FunctionTrait as _}; use super::{ArgsBuilder, FeltSerialize, P256r1PublicKey}; -const VERIFY_SIGNATURE: FunctionUnspecified = Function::new_unspecified("verify_signature"); +const VERIFY_SIGNATURE: FunctionReturnLength<2> = Function::new("verify_signature"); fn verify_signature( hash: &[u8], @@ -27,7 +27,7 @@ fn verify_signature( .add_struct(pub_key.to_felts()) .add_array(r.into_iter().copied().chain(s.iter().copied())); let result = VERIFY_SIGNATURE.run(args.build()); - result == vec![0.into(), 0.into()] + result == [0.into(), 0.into()] } #[test] From 0cffae1619f9afa9abab467accf942b29291fef6 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 24 Jan 2024 11:15:16 +0000 Subject: [PATCH 09/43] enable memory inspection --- .../auth/src/deserializable_endpoints.cairo | 9 ++ .../tests/src/auth/expand_auth_data.rs | 62 ++++++++++++++ crates/webauthn/tests/src/auth/mod.rs | 1 + .../webauthn/tests/src/auth/mod_arithmetic.rs | 8 +- .../webauthn/tests/src/auth/verify_ecdsa.rs | 5 +- .../tests/src/auth/verify_signature.rs | 3 +- crates/webauthn/tests/src/helpers.rs | 84 ++++++++++++++----- 7 files changed, 144 insertions(+), 28 deletions(-) create mode 100644 crates/webauthn/tests/src/auth/expand_auth_data.rs diff --git a/crates/webauthn/auth/src/deserializable_endpoints.cairo b/crates/webauthn/auth/src/deserializable_endpoints.cairo index bdb269dd..71190d58 100644 --- a/crates/webauthn/auth/src/deserializable_endpoints.cairo +++ b/crates/webauthn/auth/src/deserializable_endpoints.cairo @@ -4,6 +4,8 @@ use starknet::secp256r1::Secp256r1Point; use webauthn_auth::errors::{AuthnError, RTSEIntoRTAE, AuthnErrorIntoFelt252}; use webauthn_auth::ecdsa::verify_hashed_ecdsa; use core::traits::Into; +use webauthn_auth::webauthn::ImplArrayu8TryIntoAuthData; +use webauthn_auth::types::AuthenticatorData; fn verify_hashed_ecdsa_endpoint( public_key_pt: PublicKey, msg_hash: u256, r: u256, s: u256 @@ -13,4 +15,11 @@ fn verify_hashed_ecdsa_endpoint( Option::None => { return Result::Err(VerifyEcdsaError::WrongArgument); } }; verify_hashed_ecdsa(pub_key_point, msg_hash, r, s) +} + +fn expand_auth_data_endpoint( + auth_data: Array +) -> AuthenticatorData { + let data: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data); + return data.unwrap(); } \ No newline at end of file diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs new file mode 100644 index 00000000..71a9dd94 --- /dev/null +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -0,0 +1,62 @@ +use cairo_args_runner::Felt252; + +use crate::{ + auth::ArgsBuilder, Function, FunctionReturnLength, FunctionTrait, FunctionUnspecified, +}; + +use super::FeltSerialize; + +/// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` +const EXPAND_AUTH_DATA: FunctionUnspecified = + Function::new_unspecified("expand_auth_data_endpoint"); + +pub struct AuthenticatorData { + pub rp_id_hash: [u8; 32], + pub flags: u8, + pub sign_count: u32, +} + +impl AuthenticatorData { + pub fn from_bytes(bytes: &[u8]) -> Self { + let rp_id_hash = bytes[0..32].try_into().unwrap(); + let flags = bytes[32]; + let sign_count = u32::from_be_bytes(bytes[33..37].try_into().unwrap()); + Self { + rp_id_hash, + flags, + sign_count, + } + } +} + +impl FeltSerialize for AuthenticatorData { + fn to_felts(self) -> Vec { + let mut felts: Vec<_> = self.rp_id_hash.iter().cloned().map(Felt252::from).collect(); + felts.push(self.flags.into()); + felts.extend( + self.sign_count + .to_be_bytes() + .iter() + .cloned() + .map(Felt252::from), + ); + felts + } +} + +fn expand_auth_data(auth_data: AuthenticatorData) -> bool { + let result = EXPAND_AUTH_DATA.run(ArgsBuilder::new().add_array(auth_data.to_felts()).build()); + dbg!(result); + true +} + +#[test] +fn test_expand_auth_data_1() { + let d: Vec = (0_u8..32_u8).into_iter().collect(); + let auth_data = AuthenticatorData { + rp_id_hash: d.try_into().unwrap(), + flags: 0, + sign_count: 0, + }; + assert!(expand_auth_data(auth_data)); +} diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 136f7a84..62c5d4ab 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,5 +1,6 @@ use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; +mod expand_auth_data; mod mod_arithmetic; mod verify_ecdsa; mod verify_signature; diff --git a/crates/webauthn/tests/src/auth/mod_arithmetic.rs b/crates/webauthn/tests/src/auth/mod_arithmetic.rs index 7eb8ecfb..4aae770f 100644 --- a/crates/webauthn/tests/src/auth/mod_arithmetic.rs +++ b/crates/webauthn/tests/src/auth/mod_arithmetic.rs @@ -1,4 +1,4 @@ -use cairo_args_runner::felt_vec; +use cairo_args_runner::{felt_vec, Felt252}; use crate::{Function, FunctionReturnLength, FunctionTrait}; @@ -7,18 +7,18 @@ const EXTENDED_GCD: FunctionReturnLength<6> = Function::new("extended_gcd"); #[test] fn test_gcd_basic_1() { - let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(2, 0, 2, 0)); + let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(felt_vec!(2, 0, 2, 0)); assert_eq!(gcd, 2.into()); } #[test] fn test_gcd_basic_2() { - let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(100, 0, 200, 0)); + let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(felt_vec!(100, 0, 200, 0)); assert_eq!(gcd, 100.into()); } #[test] fn test_gcd_basic_3() { - let [gcd, ..] = EXTENDED_GCD.run(felt_vec!(1234, 0, 5678, 0)); + let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(felt_vec!(1234, 0, 5678, 0)); assert_eq!(gcd, 2.into()); } diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs index a2d7bb14..c2c539d2 100644 --- a/crates/webauthn/tests/src/auth/verify_ecdsa.rs +++ b/crates/webauthn/tests/src/auth/verify_ecdsa.rs @@ -1,4 +1,5 @@ use account_sdk::webauthn_signer::P256VerifyingKeyConverter; +use cairo_args_runner::Felt252; use p256::{ ecdsa::{signature::Signer, Signature, SigningKey}, elliptic_curve::rand_core::OsRng, @@ -31,12 +32,12 @@ fn verify_ecdsa(message: &[u8], signing_key: SigningKey, signature: Signature) - .add_struct(hash.to_felts()) .add_struct(r.to_felts()) .add_struct(s.to_felts()); - let result = VERIFY_HASHED_ECDSA.run(args.build()); + let result: [Felt252; 2] = VERIFY_HASHED_ECDSA.run(args.build()); result == [0.into(), 0.into()] } #[test] -fn verify_ecdsa_1() { +fn test_verify_ecdsa_1() { let message: &[u8] = b"hello world"; let signing_key = SigningKey::random(&mut OsRng); let (signature, _) = signing_key.sign(message); diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index 8b14f474..e33cace0 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -1,4 +1,5 @@ use account_sdk::webauthn_signer::P256VerifyingKeyConverter; +use cairo_args_runner::Felt252; use p256::{ ecdsa::{signature::Signer, Signature, SigningKey}, elliptic_curve::rand_core::OsRng, @@ -26,7 +27,7 @@ fn verify_signature( .add_array(auth_data.iter().cloned()) .add_struct(pub_key.to_felts()) .add_array(r.into_iter().copied().chain(s.iter().copied())); - let result = VERIFY_SIGNATURE.run(args.build()); + let result: [Felt252; 2] = VERIFY_SIGNATURE.run(args.build()); result == [0.into(), 0.into()] } diff --git a/crates/webauthn/tests/src/helpers.rs b/crates/webauthn/tests/src/helpers.rs index b8239dfc..318c5e46 100644 --- a/crates/webauthn/tests/src/helpers.rs +++ b/crates/webauthn/tests/src/helpers.rs @@ -1,3 +1,5 @@ +use cairo_args_runner::errors::SierraRunnerError; +use cairo_args_runner::SuccessfulRun; use cairo_args_runner::{Arg, Felt252}; pub const SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_auth.sierra.json"; @@ -23,39 +25,79 @@ impl Function { } } -pub trait FunctionTrait +pub trait FunctionTrait { + fn run(&self, args: P) -> T { + self.transform_result(cairo_args_runner::run_capture_memory( + SIERRA_TARGET, + self.name(), + &self.transform_arguments(args), + )) + } + fn transform_arguments(&self, args: P) -> Vec; + fn transform_result(&self, result: Result) -> T; + fn name(&self) -> &str; +} + +impl<'a, const N: usize, P> FunctionTrait<[Felt252; N], Vec

> for FunctionReturnLength<'a, N> where - T: Into>, + P: Into, { - fn run(&self, args: Vec

) -> T; + fn transform_arguments(&self, args: Vec

) -> Vec { + args.into_iter().map(Into::into).collect() + } + + fn transform_result(&self, result: Result) -> [Felt252; N] { + result.unwrap().value.try_into().unwrap() + } + + fn name(&self) -> &str { + self.name + } +} + +pub struct SpecifiedWithMemory { + result: [Felt252; N], + memory: Vec>, } -impl<'a, const N: usize, P> FunctionTrait<[Felt252; N], P> for FunctionReturnLength<'a, N> +impl<'a, const N: usize, P> FunctionTrait, Vec

> + for FunctionReturnLength<'a, N> where P: Into, { - fn run(&self, args: Vec

) -> [Felt252; N] { - cairo_args_runner::run( - SIERRA_TARGET, - &self.name, - &args.into_iter().map(Into::into).collect::>(), - ) - .unwrap() - .try_into() - .unwrap() + fn transform_arguments(&self, args: Vec

) -> Vec { + args.into_iter().map(Into::into).collect() + } + + fn transform_result( + &self, + result: Result, + ) -> SpecifiedWithMemory { + let r = result.unwrap(); + SpecifiedWithMemory { + result: r.value.try_into().unwrap(), + memory: r.memory, + } + } + + fn name(&self) -> &str { + self.name } } -impl<'a, P> FunctionTrait, P> for FunctionUnspecified<'a> +impl<'a, P> FunctionTrait, Vec

> for FunctionUnspecified<'a> where P: Into, { - fn run(&self, args: Vec

) -> Vec { - cairo_args_runner::run( - SIERRA_TARGET, - &self.name, - &args.into_iter().map(Into::into).collect::>(), - ) - .unwrap() + fn transform_arguments(&self, args: Vec

) -> Vec { + args.into_iter().map(Into::into).collect() + } + + fn transform_result(&self, result: Result) -> Vec { + result.unwrap().value + } + + fn name(&self) -> &str { + self.name } } From c9ba75b584445bb64312f0578cd9caf83f136181 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 24 Jan 2024 11:36:46 +0000 Subject: [PATCH 10/43] expand auth data --- .../tests/src/auth/expand_auth_data.rs | 45 +++++++++++++++---- crates/webauthn/tests/src/helpers.rs | 36 +++------------ 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index 71a9dd94..b3e28099 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -1,15 +1,45 @@ -use cairo_args_runner::Felt252; +use cairo_args_runner::{Arg, Felt252}; +use super::FeltSerialize; use crate::{ auth::ArgsBuilder, Function, FunctionReturnLength, FunctionTrait, FunctionUnspecified, + SpecifiedResultMemory, }; +use cairo_args_runner::SuccessfulRun; -use super::FeltSerialize; +struct AuthDataFunction; + +impl FunctionTrait> for AuthDataFunction { + fn transform_arguments(&self, args: Vec) -> Vec { + args + } + + fn transform_result( + &self, + result: Result, + ) -> AuthenticatorData { + let result = result.unwrap(); + let felts: Vec = result.value; + let rp_id_hash: Vec = result.memory + [felts[0].to_bigint().try_into().unwrap()..felts[1].to_bigint().try_into().unwrap()] + .iter() + .map(|x| x.clone().unwrap().to_bigint().try_into().unwrap()) + .collect(); + AuthenticatorData { + rp_id_hash: rp_id_hash.try_into().unwrap(), + flags: felts[2].to_bigint().try_into().unwrap(), + sign_count: felts[3].to_bigint().try_into().unwrap(), + } + } + + fn name(&self) -> &str { + "expand_auth_data_endpoint" + } +} -/// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` -const EXPAND_AUTH_DATA: FunctionUnspecified = - Function::new_unspecified("expand_auth_data_endpoint"); +const EXPAND_AUTH_DATA: AuthDataFunction = AuthDataFunction; +#[derive(Debug, PartialEq, Clone)] pub struct AuthenticatorData { pub rp_id_hash: [u8; 32], pub flags: u8, @@ -45,9 +75,8 @@ impl FeltSerialize for AuthenticatorData { } fn expand_auth_data(auth_data: AuthenticatorData) -> bool { - let result = EXPAND_AUTH_DATA.run(ArgsBuilder::new().add_array(auth_data.to_felts()).build()); - dbg!(result); - true + let result = EXPAND_AUTH_DATA.run(ArgsBuilder::new().add_array(auth_data.clone().to_felts()).build()); + auth_data == result } #[test] diff --git a/crates/webauthn/tests/src/helpers.rs b/crates/webauthn/tests/src/helpers.rs index 318c5e46..70655c59 100644 --- a/crates/webauthn/tests/src/helpers.rs +++ b/crates/webauthn/tests/src/helpers.rs @@ -38,30 +38,13 @@ pub trait FunctionTrait { fn name(&self) -> &str; } -impl<'a, const N: usize, P> FunctionTrait<[Felt252; N], Vec

> for FunctionReturnLength<'a, N> -where - P: Into, -{ - fn transform_arguments(&self, args: Vec

) -> Vec { - args.into_iter().map(Into::into).collect() - } - - fn transform_result(&self, result: Result) -> [Felt252; N] { - result.unwrap().value.try_into().unwrap() - } - - fn name(&self) -> &str { - self.name - } -} - -pub struct SpecifiedWithMemory { - result: [Felt252; N], +#[derive(Debug, PartialEq)] +pub struct SpecifiedResultMemory { + result: T, memory: Vec>, } -impl<'a, const N: usize, P> FunctionTrait, Vec

> - for FunctionReturnLength<'a, N> +impl<'a, const N: usize, P> FunctionTrait<[Felt252; N], Vec

> for FunctionReturnLength<'a, N> where P: Into, { @@ -69,15 +52,8 @@ where args.into_iter().map(Into::into).collect() } - fn transform_result( - &self, - result: Result, - ) -> SpecifiedWithMemory { - let r = result.unwrap(); - SpecifiedWithMemory { - result: r.value.try_into().unwrap(), - memory: r.memory, - } + fn transform_result(&self, result: Result) -> [Felt252; N] { + result.unwrap().value.try_into().unwrap() } fn name(&self) -> &str { From c4a016ca7d625b425e5d8eaa27421020f81cc8fe Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 09:27:01 +0000 Subject: [PATCH 11/43] extract test --- .../auth/src/deserializable_endpoints.cairo | 5 ++ .../tests/src/auth/expand_auth_data.rs | 11 +-- crates/webauthn/tests/src/auth/helpers.rs | 71 +++++++++++++++++++ crates/webauthn/tests/src/auth/mod.rs | 5 ++ 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 crates/webauthn/tests/src/auth/helpers.rs diff --git a/crates/webauthn/auth/src/deserializable_endpoints.cairo b/crates/webauthn/auth/src/deserializable_endpoints.cairo index 71190d58..640b3e11 100644 --- a/crates/webauthn/auth/src/deserializable_endpoints.cairo +++ b/crates/webauthn/auth/src/deserializable_endpoints.cairo @@ -6,6 +6,7 @@ use webauthn_auth::ecdsa::verify_hashed_ecdsa; use core::traits::Into; use webauthn_auth::webauthn::ImplArrayu8TryIntoAuthData; use webauthn_auth::types::AuthenticatorData; +use webauthn_auth::helpers::extract_u256_from_u8_array; fn verify_hashed_ecdsa_endpoint( public_key_pt: PublicKey, msg_hash: u256, r: u256, s: u256 @@ -22,4 +23,8 @@ fn expand_auth_data_endpoint( ) -> AuthenticatorData { let data: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data); return data.unwrap(); +} + +fn extract_u256_from_u8_array_endpoint(bytes: Array, offset: u32) -> Option { + extract_u256_from_u8_array(@bytes, offset) } \ No newline at end of file diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index b3e28099..109dbc17 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -1,10 +1,7 @@ use cairo_args_runner::{Arg, Felt252}; use super::FeltSerialize; -use crate::{ - auth::ArgsBuilder, Function, FunctionReturnLength, FunctionTrait, FunctionUnspecified, - SpecifiedResultMemory, -}; +use crate::{auth::ArgsBuilder, FunctionTrait}; use cairo_args_runner::SuccessfulRun; struct AuthDataFunction; @@ -75,7 +72,11 @@ impl FeltSerialize for AuthenticatorData { } fn expand_auth_data(auth_data: AuthenticatorData) -> bool { - let result = EXPAND_AUTH_DATA.run(ArgsBuilder::new().add_array(auth_data.clone().to_felts()).build()); + let result = EXPAND_AUTH_DATA.run( + ArgsBuilder::new() + .add_array(auth_data.clone().to_felts()) + .build(), + ); auth_data == result } diff --git a/crates/webauthn/tests/src/auth/helpers.rs b/crates/webauthn/tests/src/auth/helpers.rs new file mode 100644 index 00000000..b31c9dd0 --- /dev/null +++ b/crates/webauthn/tests/src/auth/helpers.rs @@ -0,0 +1,71 @@ +use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; + +use super::CairoU256; +use crate::{auth::ArgsBuilder, FunctionTrait}; +use cairo_args_runner::SuccessfulRun; + +struct Extractu256Fromu8ArrayFunction; + +impl FunctionTrait, (Vec, usize)> for Extractu256Fromu8ArrayFunction { + fn transform_arguments(&self, args: (Vec, usize)) -> Vec { + ArgsBuilder::new().add_array(args.0).add_one(args.1).build() + } + + fn transform_result( + &self, + result: Result, + ) -> Option { + let result = result.unwrap(); + let felts: Vec = result.value; + if felts[0] == Felt252::from(1) { + None + } else { + Some(CairoU256 { + low: felts[1].clone(), + high: felts[2].clone(), + }) + } + } + + fn name(&self) -> &str { + "extract_u256_from_u8_array_endpoint" + } +} + +const EXTRACT_U256_FROM_U8_ARRAY: Extractu256Fromu8ArrayFunction = Extractu256Fromu8ArrayFunction; + +fn serialize_and_extract_u256(val: CairoU256, offset: usize) -> CairoU256 { + let low = val.low.to_bytes_be(); + let high = val.high.to_bytes_be(); + + let bytes = [ + vec![0; offset + 16 - high.len()], + high, + vec![0; 16 - low.len()], + low, + ] + .concat(); + let result = EXTRACT_U256_FROM_U8_ARRAY.run((bytes, offset)); + result.unwrap() +} + +#[test] +fn test_extract_u256_from_u8_array_1() { + let result = EXTRACT_U256_FROM_U8_ARRAY.run(([0u8; 32].to_vec(), 0)); + assert_eq!(result, Some(CairoU256::zero())); +} + +#[test] +fn test_extract_u256_from_u8_array_2() { + let val = CairoU256 { + low: Felt252::from(12345), + high: Felt252::from(98765), + }; + assert_eq!(serialize_and_extract_u256(val.clone(), 0), val); +} + +#[test] +fn test_extract_u256_from_u8_array_fail_1() { + let result = EXTRACT_U256_FROM_U8_ARRAY.run(([0u8; 32].to_vec(), 3)); + assert_eq!(result, None); +} diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 62c5d4ab..ca440267 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,6 +1,7 @@ use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; mod expand_auth_data; +mod helpers; mod mod_arithmetic; mod verify_ecdsa; mod verify_signature; @@ -10,6 +11,7 @@ pub struct ArgsBuilder { args: Vec, } +#[derive(Debug, Clone, PartialEq)] pub struct CairoU256 { low: Felt252, high: Felt252, @@ -29,6 +31,9 @@ impl CairoU256 { ); Self::from_bytes_be(low, high) } + pub fn zero() -> Self { + Self::new(Felt252::from(0), Felt252::from(0)) + } } impl FeltSerialize for CairoU256 { From cb521463e4e82f1de5466681c435fb78acffe6ac Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 09:46:09 +0000 Subject: [PATCH 12/43] cargo clippy --- crates/account_sdk/src/session_token/session.rs | 10 +++------- crates/webauthn/tests/src/auth/expand_auth_data.rs | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/account_sdk/src/session_token/session.rs b/crates/account_sdk/src/session_token/session.rs index 2fef3821..c7ff1854 100644 --- a/crates/account_sdk/src/session_token/session.rs +++ b/crates/account_sdk/src/session_token/session.rs @@ -101,15 +101,11 @@ impl Session { .map(|c| self.call_proof(c).ok_or(SessionError::CallNotInPolicy)) .collect::, SessionError>>()?; - let proofs_flat = proofs.into_iter().fold(Ok(vec![]), |acc, proof| { - acc.and_then(|mut acc| { - acc.extend(proof.1.clone()); - Ok(acc) - }) + let proofs_flat = proofs.into_iter().try_fold(vec![], |mut acc, proof| { + acc.extend(proof.1.clone()); + Ok(acc) })?; - assert!(!self.session_token().is_empty(), "Session token is empty"); - Ok(SessionSignature { signature_type: SESSION_SIGNATURE_TYPE, r: transaction_signature.r, diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index 109dbc17..6d9d0cd3 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -44,6 +44,7 @@ pub struct AuthenticatorData { } impl AuthenticatorData { + #[allow(dead_code)] pub fn from_bytes(bytes: &[u8]) -> Self { let rp_id_hash = bytes[0..32].try_into().unwrap(); let flags = bytes[32]; From b60452b1cdd4be38e04d22f1ab84f28e3bafcfb4 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 09:54:40 +0000 Subject: [PATCH 13/43] change local dependency to the git one --- crates/webauthn/tests/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/webauthn/tests/Cargo.toml b/crates/webauthn/tests/Cargo.toml index 7ed1ae2d..179de6bc 100644 --- a/crates/webauthn/tests/Cargo.toml +++ b/crates/webauthn/tests/Cargo.toml @@ -7,7 +7,7 @@ version.workspace = true [dependencies] starknet.workspace = true -cairo-args-runner = { path="/home/szymon/dev/cairo-args-runner" } +cairo-args-runner = { git="https://github.com/neotheprogramist/cairo-args-runner", branch = "thepinion"} proptest = "1.4.0" p256.workspace = true account-sdk.workspace = true From 0377dffe27ba8505e86ad0e0c4f627325445a3da Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Mon, 29 Jan 2024 10:12:33 +0000 Subject: [PATCH 14/43] revert assertion removal --- crates/account_sdk/src/session_token/session.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/account_sdk/src/session_token/session.rs b/crates/account_sdk/src/session_token/session.rs index c7ff1854..d5f7fe1e 100644 --- a/crates/account_sdk/src/session_token/session.rs +++ b/crates/account_sdk/src/session_token/session.rs @@ -106,6 +106,8 @@ impl Session { Ok(acc) })?; + assert!(!self.session_token().is_empty(), "Session token is empty"); + Ok(SessionSignature { signature_type: SESSION_SIGNATURE_TYPE, r: transaction_signature.r, From ea105c6da5d4e43e5e650d8074137047d6f7869c Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 10:55:24 +0000 Subject: [PATCH 15/43] split parser and extractor --- crates/webauthn/tests/src/auth/helpers.rs | 32 ++-- crates/webauthn/tests/src/auth/mod.rs | 2 +- .../webauthn/tests/src/auth/mod_arithmetic.rs | 24 ++- .../webauthn/tests/src/auth/verify_ecdsa.rs | 11 +- .../tests/src/auth/verify_signature.rs | 11 +- crates/webauthn/tests/src/helpers.rs | 79 --------- crates/webauthn/tests/src/lib.rs | 4 +- crates/webauthn/tests/src/utils.rs | 159 ++++++++++++++++++ 8 files changed, 212 insertions(+), 110 deletions(-) delete mode 100644 crates/webauthn/tests/src/helpers.rs create mode 100644 crates/webauthn/tests/src/utils.rs diff --git a/crates/webauthn/tests/src/auth/helpers.rs b/crates/webauthn/tests/src/auth/helpers.rs index b31c9dd0..069a6da8 100644 --- a/crates/webauthn/tests/src/auth/helpers.rs +++ b/crates/webauthn/tests/src/auth/helpers.rs @@ -1,20 +1,27 @@ use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; -use super::CairoU256; -use crate::{auth::ArgsBuilder, FunctionTrait}; +use super::*; +use crate::*; use cairo_args_runner::SuccessfulRun; -struct Extractu256Fromu8ArrayFunction; +// const EXTRACT_U256_FROM_U8_ARRAY: -impl FunctionTrait, (Vec, usize)> for Extractu256Fromu8ArrayFunction { - fn transform_arguments(&self, args: (Vec, usize)) -> Vec { +struct U256ArrParser; + +impl ArgumentParser for U256ArrParser { + type Args = (Vec, usize); + + fn parse(&self, args: (Vec, usize)) -> Vec { ArgsBuilder::new().add_array(args.0).add_one(args.1).build() } +} + +struct U256Extractor; - fn transform_result( - &self, - result: Result, - ) -> Option { +impl ResultExtractor for U256Extractor { + type Result = Option; + + fn extract(&self, result: Result) -> Self::Result { let result = result.unwrap(); let felts: Vec = result.value; if felts[0] == Felt252::from(1) { @@ -26,13 +33,10 @@ impl FunctionTrait, (Vec, usize)> for Extractu256Fromu8Arr }) } } - - fn name(&self) -> &str { - "extract_u256_from_u8_array_endpoint" - } } -const EXTRACT_U256_FROM_U8_ARRAY: Extractu256Fromu8ArrayFunction = Extractu256Fromu8ArrayFunction; +const EXTRACT_U256_FROM_U8_ARRAY: utils::Function = + Function::new("extract_u256_from_u8_array", U256ArrParser, U256Extractor); fn serialize_and_extract_u256(val: CairoU256, offset: usize) -> CairoU256 { let low = val.low.to_bytes_be(); diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index ca440267..20251106 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,6 +1,6 @@ use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; -mod expand_auth_data; +// mod expand_auth_data; mod helpers; mod mod_arithmetic; mod verify_ecdsa; diff --git a/crates/webauthn/tests/src/auth/mod_arithmetic.rs b/crates/webauthn/tests/src/auth/mod_arithmetic.rs index 4aae770f..bea58fa3 100644 --- a/crates/webauthn/tests/src/auth/mod_arithmetic.rs +++ b/crates/webauthn/tests/src/auth/mod_arithmetic.rs @@ -1,24 +1,36 @@ -use cairo_args_runner::{felt_vec, Felt252}; +use cairo_args_runner::{Arg, Felt252}; -use crate::{Function, FunctionReturnLength, FunctionTrait}; +use crate::*; +use crate::{ConstLenExtractor, Function}; /// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` -const EXTENDED_GCD: FunctionReturnLength<6> = Function::new("extended_gcd"); +const EXTENDED_GCD: Function> = + Function::new("extended_gcd", GCDParser, ConstLenExtractor::new()); + +struct GCDParser; +impl ArgumentParser for GCDParser { + type Args = Vec; + fn parse(&self, args: Self::Args) -> Vec { + args.into_iter() + .map(|arg| Arg::Value(Felt252::from(arg))) + .collect() + } +} #[test] fn test_gcd_basic_1() { - let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(felt_vec!(2, 0, 2, 0)); + let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(vec![2, 0, 2, 0]); assert_eq!(gcd, 2.into()); } #[test] fn test_gcd_basic_2() { - let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(felt_vec!(100, 0, 200, 0)); + let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(vec![100, 0, 200, 0]); assert_eq!(gcd, 100.into()); } #[test] fn test_gcd_basic_3() { - let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(felt_vec!(1234, 0, 5678, 0)); + let [gcd, ..]: [Felt252; 6] = EXTENDED_GCD.run(vec![1234, 0, 5678, 0]); assert_eq!(gcd, 2.into()); } diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs index c2c539d2..f47107a6 100644 --- a/crates/webauthn/tests/src/auth/verify_ecdsa.rs +++ b/crates/webauthn/tests/src/auth/verify_ecdsa.rs @@ -5,12 +5,15 @@ use p256::{ elliptic_curve::rand_core::OsRng, }; -use crate::{Function, FunctionReturnLength, FunctionTrait}; - -use super::{ArgsBuilder, CairoU256, FeltSerialize, P256r1PublicKey}; use sha2::{digest::Update, Digest, Sha256}; -const VERIFY_HASHED_ECDSA: FunctionReturnLength<2> = Function::new("verify_hashed_ecdsa_endpoint"); +use super::*; +use crate::*; +const VERIFY_HASHED_ECDSA: Function> = Function::new( + "verify_hashed_ecdsa_endpoint", + SimpleVecParser::new(), + ConstLenExtractor::new(), +); fn verify_ecdsa(message: &[u8], signing_key: SigningKey, signature: Signature) -> bool { let (r, s) = (signature.r(), signature.s()); diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index e33cace0..5deae25b 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -5,11 +5,14 @@ use p256::{ elliptic_curve::rand_core::OsRng, }; -use crate::{Function, FunctionReturnLength, FunctionTrait as _}; +use super::*; +use crate::*; -use super::{ArgsBuilder, FeltSerialize, P256r1PublicKey}; - -const VERIFY_SIGNATURE: FunctionReturnLength<2> = Function::new("verify_signature"); +const VERIFY_SIGNATURE: Function> = Function::new( + "verify_signature", + SimpleVecParser::new(), + ConstLenExtractor::new(), +); fn verify_signature( hash: &[u8], diff --git a/crates/webauthn/tests/src/helpers.rs b/crates/webauthn/tests/src/helpers.rs deleted file mode 100644 index 70655c59..00000000 --- a/crates/webauthn/tests/src/helpers.rs +++ /dev/null @@ -1,79 +0,0 @@ -use cairo_args_runner::errors::SierraRunnerError; -use cairo_args_runner::SuccessfulRun; -use cairo_args_runner::{Arg, Felt252}; - -pub const SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_auth.sierra.json"; - -#[derive(Debug, Clone, Copy)] -pub struct FunctionReturnLength<'a, const N: usize> { - pub name: &'a str, -} - -#[derive(Debug, Clone, Copy)] -pub struct FunctionUnspecified<'a> { - pub name: &'a str, -} - -pub enum Function {} - -impl Function { - pub const fn new<'a, const N: usize>(name: &'a str) -> FunctionReturnLength<'a, N> { - FunctionReturnLength { name } - } - pub const fn new_unspecified<'a>(name: &'a str) -> FunctionUnspecified<'a> { - FunctionUnspecified { name } - } -} - -pub trait FunctionTrait { - fn run(&self, args: P) -> T { - self.transform_result(cairo_args_runner::run_capture_memory( - SIERRA_TARGET, - self.name(), - &self.transform_arguments(args), - )) - } - fn transform_arguments(&self, args: P) -> Vec; - fn transform_result(&self, result: Result) -> T; - fn name(&self) -> &str; -} - -#[derive(Debug, PartialEq)] -pub struct SpecifiedResultMemory { - result: T, - memory: Vec>, -} - -impl<'a, const N: usize, P> FunctionTrait<[Felt252; N], Vec

> for FunctionReturnLength<'a, N> -where - P: Into, -{ - fn transform_arguments(&self, args: Vec

) -> Vec { - args.into_iter().map(Into::into).collect() - } - - fn transform_result(&self, result: Result) -> [Felt252; N] { - result.unwrap().value.try_into().unwrap() - } - - fn name(&self) -> &str { - self.name - } -} - -impl<'a, P> FunctionTrait, Vec

> for FunctionUnspecified<'a> -where - P: Into, -{ - fn transform_arguments(&self, args: Vec

) -> Vec { - args.into_iter().map(Into::into).collect() - } - - fn transform_result(&self, result: Result) -> Vec { - result.unwrap().value - } - - fn name(&self) -> &str { - self.name - } -} diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs index 1732e71d..442af428 100644 --- a/crates/webauthn/tests/src/lib.rs +++ b/crates/webauthn/tests/src/lib.rs @@ -2,6 +2,6 @@ mod auth; #[cfg(test)] -mod helpers; +mod utils; #[cfg(test)] -pub use helpers::*; +pub use utils::*; diff --git a/crates/webauthn/tests/src/utils.rs b/crates/webauthn/tests/src/utils.rs new file mode 100644 index 00000000..6018f0ae --- /dev/null +++ b/crates/webauthn/tests/src/utils.rs @@ -0,0 +1,159 @@ +use std::marker::PhantomData; + +use cairo_args_runner::errors::SierraRunnerError; +use cairo_args_runner::SuccessfulRun; +use cairo_args_runner::{Arg, Felt252}; + +pub const SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_auth.sierra.json"; + +#[derive(Debug, Clone, Copy)] +pub struct Function<'a, AP, RE> +where + AP: ArgumentParser, + RE: ResultExtractor, +{ + pub name: &'a str, + pub parser: AP, + pub extractor: RE, +} + +pub trait FunctionTrait { + type Args; + type Result; + fn run(self, args: Self::Args) -> Self::Result; +} + +impl<'a, AP, RE> Function<'a, AP, RE> +where + AP: ArgumentParser, + RE: ResultExtractor, +{ + pub const fn new(name: &'a str, parser: AP, extractor: RE) -> Self { + Self { + name, + parser, + extractor, + } + } +} + +impl<'a, AP, RE> FunctionTrait for &'a Function<'a, AP, RE> +where + AP: ArgumentParser, + RE: ResultExtractor, +{ + type Args = AP::Args; + + type Result = RE::Result; + + fn run(self, args: Self::Args) -> Self::Result { + let parsed_args = self.parser.parse(args); + let result = cairo_args_runner::run_capture_memory(SIERRA_TARGET, self.name, &parsed_args); + self.extractor.extract(result) + } +} + +pub trait ArgumentParser { + type Args; + fn parse(&self, args: Self::Args) -> Vec; +} + +pub trait ResultExtractor { + type Result; + fn extract(&self, result: Result) -> Self::Result; +} + +pub struct GenericVecParser +where + T: Into, +{ + _marker: PhantomData, +} + +impl GenericVecParser +where + T: Into, +{ + pub const fn new() -> Self { + Self { + _marker: PhantomData, + } + } +} + +impl ArgumentParser for GenericVecParser +where + T: Into, +{ + type Args = Vec; + fn parse(&self, args: Self::Args) -> Vec { + args.into_iter().map(Into::into).collect() + } +} + +pub struct GenericVecExtractor +where + T: From, +{ + _marker: PhantomData, +} + +impl GenericVecExtractor +where + T: From, +{ + pub const fn new() -> Self { + Self { + _marker: PhantomData, + } + } +} + +impl ResultExtractor for GenericVecExtractor +where + T: From, +{ + type Result = Vec; + fn extract(&self, result: Result) -> Self::Result { + result.unwrap().value.into_iter().map(Into::into).collect() + } +} + +pub struct ConstLenGenericExtractor +where + T: From + std::fmt::Debug, +{ + _marker: PhantomData, +} + +impl ConstLenGenericExtractor +where + T: From + std::fmt::Debug, +{ + pub const fn new() -> Self { + Self { + _marker: PhantomData, + } + } +} + +impl ResultExtractor for ConstLenGenericExtractor +where + T: From + std::fmt::Debug, +{ + type Result = [T; N]; + fn extract(&self, result: Result) -> Self::Result { + result + .unwrap() + .value + .into_iter() + .map(From::from) + .collect::>() + .try_into() + .unwrap() + } +} + +pub type SimpleVecParser = GenericVecParser; +pub type SimpleVecExtractor = GenericVecExtractor; +pub type ConstLenExtractor = ConstLenGenericExtractor; From 4fcaee714629e488ce46347ab168ed9af9bf5de4 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 11:02:52 +0000 Subject: [PATCH 16/43] refactor expand auth data --- .../tests/src/auth/expand_auth_data.rs | 47 +++++++++---------- crates/webauthn/tests/src/auth/mod.rs | 2 +- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index 6d9d0cd3..fd7aa08f 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -1,20 +1,24 @@ -use cairo_args_runner::{Arg, Felt252}; +use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; -use super::FeltSerialize; -use crate::{auth::ArgsBuilder, FunctionTrait}; +use super::{ArgsBuilder, FeltSerialize}; +use crate::{ArgumentParser, Function, FunctionTrait, ResultExtractor}; use cairo_args_runner::SuccessfulRun; -struct AuthDataFunction; +struct AuthDataParser; +impl ArgumentParser for AuthDataParser { + type Args = AuthenticatorData; -impl FunctionTrait> for AuthDataFunction { - fn transform_arguments(&self, args: Vec) -> Vec { - args + fn parse(&self, args: Self::Args) -> Vec { + ArgsBuilder::new().add_array(args.to_felts()).build() } +} + +struct AuthDataExtractor; - fn transform_result( - &self, - result: Result, - ) -> AuthenticatorData { +impl ResultExtractor for AuthDataExtractor { + type Result = AuthenticatorData; + + fn extract(&self, result: Result) -> Self::Result { let result = result.unwrap(); let felts: Vec = result.value; let rp_id_hash: Vec = result.memory @@ -28,13 +32,13 @@ impl FunctionTrait> for AuthDataFunction { sign_count: felts[3].to_bigint().try_into().unwrap(), } } - - fn name(&self) -> &str { - "expand_auth_data_endpoint" - } } -const EXPAND_AUTH_DATA: AuthDataFunction = AuthDataFunction; +const EXPAND_AUTH_DATA: Function = Function::new( + "expand_auth_data_endpoint", + AuthDataParser, + AuthDataExtractor, +); #[derive(Debug, PartialEq, Clone)] pub struct AuthenticatorData { @@ -72,15 +76,6 @@ impl FeltSerialize for AuthenticatorData { } } -fn expand_auth_data(auth_data: AuthenticatorData) -> bool { - let result = EXPAND_AUTH_DATA.run( - ArgsBuilder::new() - .add_array(auth_data.clone().to_felts()) - .build(), - ); - auth_data == result -} - #[test] fn test_expand_auth_data_1() { let d: Vec = (0_u8..32_u8).into_iter().collect(); @@ -89,5 +84,5 @@ fn test_expand_auth_data_1() { flags: 0, sign_count: 0, }; - assert!(expand_auth_data(auth_data)); + assert_eq!(EXPAND_AUTH_DATA.run(auth_data.clone()), auth_data); } diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 20251106..ca440267 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,6 +1,6 @@ use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; -// mod expand_auth_data; +mod expand_auth_data; mod helpers; mod mod_arithmetic; mod verify_ecdsa; From db78b40c5dd8a141dac3f8b5848648b0c5ee223e Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 11:09:58 +0000 Subject: [PATCH 17/43] prelude --- crates/webauthn/tests/src/arg_builder.rs | 34 ++++++++++++++++++ .../tests/src/auth/expand_auth_data.rs | 3 +- crates/webauthn/tests/src/auth/mod.rs | 35 +------------------ .../webauthn/tests/src/auth/mod_arithmetic.rs | 3 +- .../webauthn/tests/src/auth/verify_ecdsa.rs | 2 +- .../tests/src/auth/verify_signature.rs | 1 - crates/webauthn/tests/src/lib.rs | 7 ++-- crates/webauthn/tests/src/prelude.rs | 3 ++ 8 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 crates/webauthn/tests/src/arg_builder.rs create mode 100644 crates/webauthn/tests/src/prelude.rs diff --git a/crates/webauthn/tests/src/arg_builder.rs b/crates/webauthn/tests/src/arg_builder.rs new file mode 100644 index 00000000..b24800bf --- /dev/null +++ b/crates/webauthn/tests/src/arg_builder.rs @@ -0,0 +1,34 @@ +use cairo_args_runner::{Arg, Felt252}; + +#[derive(Debug)] +pub struct ArgsBuilder { + args: Vec, +} + +impl ArgsBuilder { + pub fn new() -> Self { + Self { args: Vec::new() } + } + #[allow(dead_code)] + pub fn add_one(mut self, arg: impl Into) -> Self { + self.args.push(Arg::Value(arg.into())); + self + } + pub fn add_struct(mut self, args: impl IntoIterator>) -> Self { + self.args + .extend(args.into_iter().map(|arg| Arg::Value(arg.into()))); + self + } + pub fn add_array(mut self, args: impl IntoIterator>) -> Self { + self.args + .push(Arg::Array(args.into_iter().map(|arg| arg.into()).collect())); + self + } + pub fn build(self) -> Vec { + self.args + } +} + +pub trait FeltSerialize { + fn to_felts(self) -> Vec; +} diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index fd7aa08f..18f9c1cd 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -1,7 +1,6 @@ use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; -use super::{ArgsBuilder, FeltSerialize}; -use crate::{ArgumentParser, Function, FunctionTrait, ResultExtractor}; +use crate::prelude::*; use cairo_args_runner::SuccessfulRun; struct AuthDataParser; diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index ca440267..2df5b042 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,4 +1,4 @@ -use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; +use crate::prelude::*; mod expand_auth_data; mod helpers; @@ -6,11 +6,6 @@ mod mod_arithmetic; mod verify_ecdsa; mod verify_signature; -#[derive(Debug)] -pub struct ArgsBuilder { - args: Vec, -} - #[derive(Debug, Clone, PartialEq)] pub struct CairoU256 { low: Felt252, @@ -69,34 +64,6 @@ impl FeltSerialize for P256r1PublicKey { } } -impl ArgsBuilder { - pub fn new() -> Self { - Self { args: Vec::new() } - } - #[allow(dead_code)] - pub fn add_one(mut self, arg: impl Into) -> Self { - self.args.push(Arg::Value(arg.into())); - self - } - pub fn add_struct(mut self, args: impl IntoIterator>) -> Self { - self.args - .extend(args.into_iter().map(|arg| Arg::Value(arg.into()))); - self - } - pub fn add_array(mut self, args: impl IntoIterator>) -> Self { - self.args - .push(Arg::Array(args.into_iter().map(|arg| arg.into()).collect())); - self - } - pub fn build(self) -> Vec { - self.args - } -} - -pub trait FeltSerialize { - fn to_felts(self) -> Vec; -} - #[test] fn test_contains_trait() { let target = "../../../target/dev/webauthn_auth.sierra.json"; diff --git a/crates/webauthn/tests/src/auth/mod_arithmetic.rs b/crates/webauthn/tests/src/auth/mod_arithmetic.rs index bea58fa3..34c2c701 100644 --- a/crates/webauthn/tests/src/auth/mod_arithmetic.rs +++ b/crates/webauthn/tests/src/auth/mod_arithmetic.rs @@ -1,7 +1,6 @@ use cairo_args_runner::{Arg, Felt252}; -use crate::*; -use crate::{ConstLenExtractor, Function}; +use crate::prelude::*; /// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` const EXTENDED_GCD: Function> = diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs index f47107a6..312bb277 100644 --- a/crates/webauthn/tests/src/auth/verify_ecdsa.rs +++ b/crates/webauthn/tests/src/auth/verify_ecdsa.rs @@ -8,7 +8,7 @@ use p256::{ use sha2::{digest::Update, Digest, Sha256}; use super::*; -use crate::*; + const VERIFY_HASHED_ECDSA: Function> = Function::new( "verify_hashed_ecdsa_endpoint", SimpleVecParser::new(), diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index 5deae25b..b04e927a 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -6,7 +6,6 @@ use p256::{ }; use super::*; -use crate::*; const VERIFY_SIGNATURE: Function> = Function::new( "verify_signature", diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs index 442af428..88ad638c 100644 --- a/crates/webauthn/tests/src/lib.rs +++ b/crates/webauthn/tests/src/lib.rs @@ -1,7 +1,8 @@ #[cfg(test)] +mod arg_builder; +#[cfg(test)] mod auth; - #[cfg(test)] -mod utils; +pub mod prelude; #[cfg(test)] -pub use utils::*; +mod utils; diff --git a/crates/webauthn/tests/src/prelude.rs b/crates/webauthn/tests/src/prelude.rs new file mode 100644 index 00000000..75ac75c6 --- /dev/null +++ b/crates/webauthn/tests/src/prelude.rs @@ -0,0 +1,3 @@ +pub use crate::arg_builder::*; +pub use crate::utils::*; +pub use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; From d307cbd36516b14443f729abe07181579b01021e Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 11:13:05 +0000 Subject: [PATCH 18/43] add session folder --- crates/webauthn/tests/src/lib.rs | 7 +++++-- crates/webauthn/tests/src/session/mod.rs | 0 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 crates/webauthn/tests/src/session/mod.rs diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs index 88ad638c..fae0c171 100644 --- a/crates/webauthn/tests/src/lib.rs +++ b/crates/webauthn/tests/src/lib.rs @@ -1,8 +1,11 @@ #[cfg(test)] mod arg_builder; #[cfg(test)] -mod auth; -#[cfg(test)] pub mod prelude; #[cfg(test)] mod utils; + +#[cfg(test)] +mod auth; +#[cfg(test)] +mod session; diff --git a/crates/webauthn/tests/src/session/mod.rs b/crates/webauthn/tests/src/session/mod.rs new file mode 100644 index 00000000..e69de29b From a085f3df2d31e2d9eeda03fb3d8a33d7c00165ee Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 17:06:57 +0000 Subject: [PATCH 19/43] signature proof tests --- .../src/deserializable_endpoints.cairo | 20 ++++++ crates/webauthn/session/src/lib.cairo | 1 + .../tests/src/auth/expand_auth_data.rs | 2 +- crates/webauthn/tests/src/auth/helpers.rs | 2 +- .../webauthn/tests/src/auth/mod_arithmetic.rs | 2 +- .../webauthn/tests/src/auth/verify_ecdsa.rs | 2 +- .../tests/src/auth/verify_signature.rs | 2 +- crates/webauthn/tests/src/prelude.rs | 3 +- crates/webauthn/tests/src/session/mod.rs | 1 + .../tests/src/session/signature_proofs.rs | 62 +++++++++++++++++++ crates/webauthn/tests/src/utils.rs | 16 ++++- 11 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 crates/webauthn/session/src/deserializable_endpoints.cairo create mode 100644 crates/webauthn/tests/src/session/signature_proofs.rs diff --git a/crates/webauthn/session/src/deserializable_endpoints.cairo b/crates/webauthn/session/src/deserializable_endpoints.cairo new file mode 100644 index 00000000..ebc57967 --- /dev/null +++ b/crates/webauthn/session/src/deserializable_endpoints.cairo @@ -0,0 +1,20 @@ +use core::array::ArrayTrait; +use webauthn_session::signature::ImplSignatureProofs; + +fn signature_proofs_endpoint( + arr: Array, proof_length: usize +) -> Option>> { + let proofs = ImplSignatureProofs::try_new(arr.span(), proof_length)?; + let mut result: Array> = array![]; + let mut i = 0; + let count = arr.len() / proof_length; + loop { + if i >= count { + break; + } + let proof = proofs.at(i); + result.append(proof); + i += 1; + }; + Option::Some(result) +} diff --git a/crates/webauthn/session/src/lib.cairo b/crates/webauthn/session/src/lib.cairo index 99420445..2e86f55a 100644 --- a/crates/webauthn/session/src/lib.cairo +++ b/crates/webauthn/session/src/lib.cairo @@ -20,6 +20,7 @@ use webauthn_session::hash::{compute_session_hash, compute_call_hash}; mod hash; mod signature; mod interface; +mod deserializable_endpoints; #[cfg(test)] mod tests; diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index 18f9c1cd..f2ff7ffe 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -33,7 +33,7 @@ impl ResultExtractor for AuthDataExtractor { } } -const EXPAND_AUTH_DATA: Function = Function::new( +const EXPAND_AUTH_DATA: Function = Function::new_webauthn( "expand_auth_data_endpoint", AuthDataParser, AuthDataExtractor, diff --git a/crates/webauthn/tests/src/auth/helpers.rs b/crates/webauthn/tests/src/auth/helpers.rs index 069a6da8..09830e24 100644 --- a/crates/webauthn/tests/src/auth/helpers.rs +++ b/crates/webauthn/tests/src/auth/helpers.rs @@ -36,7 +36,7 @@ impl ResultExtractor for U256Extractor { } const EXTRACT_U256_FROM_U8_ARRAY: utils::Function = - Function::new("extract_u256_from_u8_array", U256ArrParser, U256Extractor); + Function::new_webauthn("extract_u256_from_u8_array", U256ArrParser, U256Extractor); fn serialize_and_extract_u256(val: CairoU256, offset: usize) -> CairoU256 { let low = val.low.to_bytes_be(); diff --git a/crates/webauthn/tests/src/auth/mod_arithmetic.rs b/crates/webauthn/tests/src/auth/mod_arithmetic.rs index 34c2c701..f7e2889c 100644 --- a/crates/webauthn/tests/src/auth/mod_arithmetic.rs +++ b/crates/webauthn/tests/src/auth/mod_arithmetic.rs @@ -4,7 +4,7 @@ use crate::prelude::*; /// ```extended_gcd(u256, u256) -> (u256, u256, u256)``` const EXTENDED_GCD: Function> = - Function::new("extended_gcd", GCDParser, ConstLenExtractor::new()); + Function::new_webauthn("extended_gcd", GCDParser, ConstLenExtractor::new()); struct GCDParser; impl ArgumentParser for GCDParser { diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs index 312bb277..6573eb0c 100644 --- a/crates/webauthn/tests/src/auth/verify_ecdsa.rs +++ b/crates/webauthn/tests/src/auth/verify_ecdsa.rs @@ -9,7 +9,7 @@ use sha2::{digest::Update, Digest, Sha256}; use super::*; -const VERIFY_HASHED_ECDSA: Function> = Function::new( +const VERIFY_HASHED_ECDSA: Function> = Function::new_webauthn( "verify_hashed_ecdsa_endpoint", SimpleVecParser::new(), ConstLenExtractor::new(), diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index b04e927a..f3ef010e 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -7,7 +7,7 @@ use p256::{ use super::*; -const VERIFY_SIGNATURE: Function> = Function::new( +const VERIFY_SIGNATURE: Function> = Function::new_webauthn( "verify_signature", SimpleVecParser::new(), ConstLenExtractor::new(), diff --git a/crates/webauthn/tests/src/prelude.rs b/crates/webauthn/tests/src/prelude.rs index 75ac75c6..799b47a0 100644 --- a/crates/webauthn/tests/src/prelude.rs +++ b/crates/webauthn/tests/src/prelude.rs @@ -1,3 +1,4 @@ pub use crate::arg_builder::*; pub use crate::utils::*; -pub use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252}; +pub use cairo_args_runner::errors::SierraRunnerError; +pub use cairo_args_runner::{arg_array, arg_value, felt_vec, Arg, Felt252, SuccessfulRun}; diff --git a/crates/webauthn/tests/src/session/mod.rs b/crates/webauthn/tests/src/session/mod.rs index e69de29b..33ed05ca 100644 --- a/crates/webauthn/tests/src/session/mod.rs +++ b/crates/webauthn/tests/src/session/mod.rs @@ -0,0 +1 @@ +mod signature_proofs; diff --git a/crates/webauthn/tests/src/session/signature_proofs.rs b/crates/webauthn/tests/src/session/signature_proofs.rs new file mode 100644 index 00000000..c04913c8 --- /dev/null +++ b/crates/webauthn/tests/src/session/signature_proofs.rs @@ -0,0 +1,62 @@ +use std::vec; + +use crate::prelude::*; + +struct SignatureProofsParser; + +type SigProofs = Vec>; + +impl ArgumentParser for SignatureProofsParser { + type Args = (SigProofs, usize); + + fn parse(&self, args: (Vec>, usize)) -> Vec { + ArgsBuilder::new() + .add_array(args.0.into_iter().flatten()) + .add_one(args.1) + .build() + } +} + +struct SignatureProofsExtractor; + +impl ResultExtractor for SignatureProofsExtractor { + type Result = SigProofs; + + fn extract(&self, result: Result) -> Self::Result { + let result = result.unwrap(); + let to_u32 = |felt: &Felt252| felt.to_bigint().try_into().unwrap(); + let (start, end): (usize, usize) = (to_u32(&result.value[1]), to_u32(&result.value[2])); + result.memory[start..end] + .iter() + .cloned() + .collect::>>() + .unwrap() + .chunks(2) + .map(|arr| (arr[0].clone(), arr[1].clone())) + .map(|(ref s, ref e)| (to_u32(s), to_u32(e))) + .map(|(s, e)| result.memory[s..e].iter().cloned().collect()) + .collect::>() + .unwrap() + } +} + +const SIGNATURE_PROOFS: Function = + Function::new_session( + "signature_proofs_endpoint", + SignatureProofsParser, + SignatureProofsExtractor, + ); + +#[test] +fn test_signature_proofs_1() { + let proofs = vec![vec![1.into()], vec![2.into()]]; + let result = SIGNATURE_PROOFS.run((proofs.clone(), 1)); + assert_eq!(result, proofs); +} + +#[test] +fn test_signature_proofs_2() { + let proofs: Vec<_> = (0..100).map(|i| vec![Felt252::from(i); 19]).collect(); + let result = SIGNATURE_PROOFS.run((proofs.clone(), 19)); + assert_eq!(result, proofs); +} diff --git a/crates/webauthn/tests/src/utils.rs b/crates/webauthn/tests/src/utils.rs index 6018f0ae..cdb17444 100644 --- a/crates/webauthn/tests/src/utils.rs +++ b/crates/webauthn/tests/src/utils.rs @@ -4,7 +4,8 @@ use cairo_args_runner::errors::SierraRunnerError; use cairo_args_runner::SuccessfulRun; use cairo_args_runner::{Arg, Felt252}; -pub const SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_auth.sierra.json"; +pub const WEBAUTHN_SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_auth.sierra.json"; +pub const SESSION_SIERRA_TARGET: &'static str = "../../../target/dev/webauthn_session.sierra.json"; #[derive(Debug, Clone, Copy)] pub struct Function<'a, AP, RE> @@ -12,6 +13,7 @@ where AP: ArgumentParser, RE: ResultExtractor, { + pub sierra_target: &'a str, pub name: &'a str, pub parser: AP, pub extractor: RE, @@ -28,13 +30,20 @@ where AP: ArgumentParser, RE: ResultExtractor, { - pub const fn new(name: &'a str, parser: AP, extractor: RE) -> Self { + pub const fn new_(sierra_target: &'a str, name: &'a str, parser: AP, extractor: RE) -> Self { Self { + sierra_target, name, parser, extractor, } } + pub const fn new_webauthn(name: &'a str, parser: AP, extractor: RE) -> Self { + Self::new_(WEBAUTHN_SIERRA_TARGET, name, parser, extractor) + } + pub const fn new_session(name: &'a str, parser: AP, extractor: RE) -> Self { + Self::new_(SESSION_SIERRA_TARGET, name, parser, extractor) + } } impl<'a, AP, RE> FunctionTrait for &'a Function<'a, AP, RE> @@ -48,7 +57,8 @@ where fn run(self, args: Self::Args) -> Self::Result { let parsed_args = self.parser.parse(args); - let result = cairo_args_runner::run_capture_memory(SIERRA_TARGET, self.name, &parsed_args); + let result = + cairo_args_runner::run_capture_memory(self.sierra_target, self.name, &parsed_args); self.extractor.extract(result) } } From da01cc09b6988f33e22cf38c9a7681d604e23077 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Thu, 25 Jan 2024 17:14:03 +0000 Subject: [PATCH 20/43] signature deserialization --- crates/webauthn/session/src/tests.cairo | 2 +- .../session/src/tests/signature_deserialization.cairo | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/webauthn/session/src/tests.cairo b/crates/webauthn/session/src/tests.cairo index a88f4b3d..cb8c98db 100644 --- a/crates/webauthn/session/src/tests.cairo +++ b/crates/webauthn/session/src/tests.cairo @@ -3,6 +3,6 @@ mod signature_proofs_gen_test; // mod signature_gen_test; // ^^^ Auto generated tests ^^^ Place your code below this line!!! -// mod signature_deserialization; +mod signature_deserialization; diff --git a/crates/webauthn/session/src/tests/signature_deserialization.cairo b/crates/webauthn/session/src/tests/signature_deserialization.cairo index 17c1ecd9..f5ce63e6 100644 --- a/crates/webauthn/session/src/tests/signature_deserialization.cairo +++ b/crates/webauthn/session/src/tests/signature_deserialization.cairo @@ -3,13 +3,9 @@ use alexandria_data_structures::array_ext::ArrayTraitExt; use core::box::BoxTrait; use core::array::SpanTrait; use starknet::info::{TxInfo, get_tx_info, get_block_timestamp}; -use result::ResultTrait; -use option::OptionTrait; -use array::ArrayTrait; use core::{TryInto, Into}; use starknet::{contract_address::ContractAddress}; - -use webauthn_session::signature::{SessionSignature, FeltSpanTryIntoSignature, SignatureProofs}; +use webauthn_session::signature::{SessionSignature, SignatureProofs}; use webauthn_session::hash::{compute_session_hash, compute_call_hash}; use alexandria_merkle_tree::merkle_tree::{ Hasher, MerkleTree, pedersen::PedersenHasherImpl, MerkleTreeTrait From 9732dbf70ae137fbbe57df7d9a87f8022aae3c78 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Sun, 28 Jan 2024 14:59:53 +0000 Subject: [PATCH 21/43] rename new_ to new --- crates/webauthn/tests/src/utils.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/webauthn/tests/src/utils.rs b/crates/webauthn/tests/src/utils.rs index cdb17444..bb6c4f25 100644 --- a/crates/webauthn/tests/src/utils.rs +++ b/crates/webauthn/tests/src/utils.rs @@ -30,7 +30,7 @@ where AP: ArgumentParser, RE: ResultExtractor, { - pub const fn new_(sierra_target: &'a str, name: &'a str, parser: AP, extractor: RE) -> Self { + pub const fn new(sierra_target: &'a str, name: &'a str, parser: AP, extractor: RE) -> Self { Self { sierra_target, name, @@ -39,10 +39,10 @@ where } } pub const fn new_webauthn(name: &'a str, parser: AP, extractor: RE) -> Self { - Self::new_(WEBAUTHN_SIERRA_TARGET, name, parser, extractor) + Self::new(WEBAUTHN_SIERRA_TARGET, name, parser, extractor) } pub const fn new_session(name: &'a str, parser: AP, extractor: RE) -> Self { - Self::new_(SESSION_SIERRA_TARGET, name, parser, extractor) + Self::new(SESSION_SIERRA_TARGET, name, parser, extractor) } } From 4df1a2c05528905869936eedc1a2f507946a4395 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 10:42:24 +0000 Subject: [PATCH 22/43] session proptests --- crates/webauthn/tests/src/session/mod.rs | 1 + .../src/session/prop_signature_proofs.rs | 34 +++++++++++++++++++ .../tests/src/session/signature_proofs.rs | 8 ++--- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 crates/webauthn/tests/src/session/prop_signature_proofs.rs diff --git a/crates/webauthn/tests/src/session/mod.rs b/crates/webauthn/tests/src/session/mod.rs index 33ed05ca..26d85ad4 100644 --- a/crates/webauthn/tests/src/session/mod.rs +++ b/crates/webauthn/tests/src/session/mod.rs @@ -1 +1,2 @@ +mod prop_signature_proofs; mod signature_proofs; diff --git a/crates/webauthn/tests/src/session/prop_signature_proofs.rs b/crates/webauthn/tests/src/session/prop_signature_proofs.rs new file mode 100644 index 00000000..bb0ef574 --- /dev/null +++ b/crates/webauthn/tests/src/session/prop_signature_proofs.rs @@ -0,0 +1,34 @@ +use cairo_args_runner::Felt252; +use proptest::prelude::*; +use proptest::strategy::Strategy; + +use crate::session::signature_proofs::SIGNATURE_PROOFS; +use crate::utils::FunctionTrait; + +fn felt252_strategy() -> impl Strategy { + prop::collection::vec(any::(), 32..=32).prop_map(|b| Felt252::from_bytes_be(&b)) +} + +fn vec_vec_felt252_strategy( + outer_len: usize, + inner_len: usize, +) -> impl Strategy>, usize)> { + ( + prop::collection::vec( + prop::collection::vec(felt252_strategy(), inner_len..=inner_len), + outer_len..=outer_len, + ), + Just(inner_len), + ) +} + +proptest! { + #[test] + fn test_signature_proofs_proptest( + (proofs, len) in (1_usize..=100, 1_usize..=20) + .prop_flat_map(|(a, b)| vec_vec_felt252_strategy(a, b)) + ) { + let result = SIGNATURE_PROOFS.run((proofs.clone(), len)); + assert_eq!(result, proofs); + } +} diff --git a/crates/webauthn/tests/src/session/signature_proofs.rs b/crates/webauthn/tests/src/session/signature_proofs.rs index c04913c8..598eaf3e 100644 --- a/crates/webauthn/tests/src/session/signature_proofs.rs +++ b/crates/webauthn/tests/src/session/signature_proofs.rs @@ -2,9 +2,9 @@ use std::vec; use crate::prelude::*; -struct SignatureProofsParser; +pub struct SignatureProofsParser; -type SigProofs = Vec>; +pub type SigProofs = Vec>; impl ArgumentParser for SignatureProofsParser { type Args = (SigProofs, usize); @@ -17,7 +17,7 @@ impl ArgumentParser for SignatureProofsParser { } } -struct SignatureProofsExtractor; +pub struct SignatureProofsExtractor; impl ResultExtractor for SignatureProofsExtractor { type Result = SigProofs; @@ -40,7 +40,7 @@ impl ResultExtractor for SignatureProofsExtractor { } } -const SIGNATURE_PROOFS: Function = +pub const SIGNATURE_PROOFS: Function = Function::new_session( "signature_proofs_endpoint", SignatureProofsParser, From 4e2b396de895ff127345ff000bf4fdad6d3ad69f Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 11:07:26 +0000 Subject: [PATCH 23/43] move felt strategy to a separate file --- crates/webauthn/tests/src/lib.rs | 2 ++ crates/webauthn/tests/src/prop_utils.rs | 13 +++++++++++++ .../tests/src/session/prop_signature_proofs.rs | 7 ++----- 3 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 crates/webauthn/tests/src/prop_utils.rs diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs index fae0c171..d1094997 100644 --- a/crates/webauthn/tests/src/lib.rs +++ b/crates/webauthn/tests/src/lib.rs @@ -4,6 +4,8 @@ mod arg_builder; pub mod prelude; #[cfg(test)] mod utils; +#[cfg(test)] +mod prop_utils; #[cfg(test)] mod auth; diff --git a/crates/webauthn/tests/src/prop_utils.rs b/crates/webauthn/tests/src/prop_utils.rs new file mode 100644 index 00000000..e718b3c6 --- /dev/null +++ b/crates/webauthn/tests/src/prop_utils.rs @@ -0,0 +1,13 @@ +use cairo_args_runner::Felt252; +use proptest::prelude::*; +use proptest::strategy::Strategy; + +#[derive(Debug, Clone, Copy)] +pub struct Felt252Strategy; + +impl Felt252Strategy { + pub fn new() -> impl Strategy { + prop::collection::vec(any::(), 32..=32).prop_map(|b| Felt252::from_bytes_be(&b)) + } +} + diff --git a/crates/webauthn/tests/src/session/prop_signature_proofs.rs b/crates/webauthn/tests/src/session/prop_signature_proofs.rs index bb0ef574..b933a66d 100644 --- a/crates/webauthn/tests/src/session/prop_signature_proofs.rs +++ b/crates/webauthn/tests/src/session/prop_signature_proofs.rs @@ -2,20 +2,17 @@ use cairo_args_runner::Felt252; use proptest::prelude::*; use proptest::strategy::Strategy; +use crate::prop_utils::Felt252Strategy; use crate::session::signature_proofs::SIGNATURE_PROOFS; use crate::utils::FunctionTrait; -fn felt252_strategy() -> impl Strategy { - prop::collection::vec(any::(), 32..=32).prop_map(|b| Felt252::from_bytes_be(&b)) -} - fn vec_vec_felt252_strategy( outer_len: usize, inner_len: usize, ) -> impl Strategy>, usize)> { ( prop::collection::vec( - prop::collection::vec(felt252_strategy(), inner_len..=inner_len), + prop::collection::vec(Felt252Strategy::new(), inner_len..=inner_len), outer_len..=outer_len, ), Just(inner_len), From ef9e435c4a228cdbae640e6186875e7882ccfd9f Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 11:44:01 +0000 Subject: [PATCH 24/43] helpers prop test --- crates/webauthn/tests/src/auth/helpers.rs | 14 ++++++++++---- crates/webauthn/tests/src/auth/mod.rs | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/webauthn/tests/src/auth/helpers.rs b/crates/webauthn/tests/src/auth/helpers.rs index 09830e24..14c17c11 100644 --- a/crates/webauthn/tests/src/auth/helpers.rs +++ b/crates/webauthn/tests/src/auth/helpers.rs @@ -1,10 +1,7 @@ -use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; - use super::*; use crate::*; use cairo_args_runner::SuccessfulRun; - -// const EXTRACT_U256_FROM_U8_ARRAY: +use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; struct U256ArrParser; @@ -73,3 +70,12 @@ fn test_extract_u256_from_u8_array_fail_1() { let result = EXTRACT_U256_FROM_U8_ARRAY.run(([0u8; 32].to_vec(), 3)); assert_eq!(result, None); } + +proptest! { + #[test] + fn test_extract_u256_from_u8_array_prop( + val in any::() + ) { + assert_eq!(serialize_and_extract_u256(val.clone(), 0), val); + } +} diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 2df5b042..0db394cc 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -1,3 +1,5 @@ +use proptest::prelude::*; + use crate::prelude::*; mod expand_auth_data; @@ -31,6 +33,17 @@ impl CairoU256 { } } +impl Arbitrary for CairoU256 { + type Parameters = (); + type Strategy = BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + (any::(), any::()) + .prop_map(|(low, high)| Self::new(low.into(), high.into())) + .boxed() + } +} + impl FeltSerialize for CairoU256 { fn to_felts(self) -> Vec { vec![self.low, self.high] From 68b6d9eaeeede658f7798497738aa844f365baa5 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 13:36:44 +0000 Subject: [PATCH 25/43] verify ecdsa prop test --- crates/webauthn/tests/src/auth/mod.rs | 4 ++-- .../webauthn/tests/src/auth/verify_ecdsa.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/webauthn/tests/src/auth/mod.rs b/crates/webauthn/tests/src/auth/mod.rs index 0db394cc..ea2eda8b 100644 --- a/crates/webauthn/tests/src/auth/mod.rs +++ b/crates/webauthn/tests/src/auth/mod.rs @@ -35,9 +35,9 @@ impl CairoU256 { impl Arbitrary for CairoU256 { type Parameters = (); - type Strategy = BoxedStrategy; + type Strategy = BoxedStrategy; - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + fn arbitrary_with(_args: ()) -> BoxedStrategy { (any::(), any::()) .prop_map(|(low, high)| Self::new(low.into(), high.into())) .boxed() diff --git a/crates/webauthn/tests/src/auth/verify_ecdsa.rs b/crates/webauthn/tests/src/auth/verify_ecdsa.rs index 6573eb0c..906d01dd 100644 --- a/crates/webauthn/tests/src/auth/verify_ecdsa.rs +++ b/crates/webauthn/tests/src/auth/verify_ecdsa.rs @@ -2,9 +2,10 @@ use account_sdk::webauthn_signer::P256VerifyingKeyConverter; use cairo_args_runner::Felt252; use p256::{ ecdsa::{signature::Signer, Signature, SigningKey}, - elliptic_curve::rand_core::OsRng, + elliptic_curve::{rand_core::OsRng, SecretKey}, }; +use proptest::collection; use sha2::{digest::Update, Digest, Sha256}; use super::*; @@ -46,3 +47,19 @@ fn test_verify_ecdsa_1() { let (signature, _) = signing_key.sign(message); assert!(verify_ecdsa(message, signing_key, signature)); } + +proptest! { + #[test] + fn test_verify_ecdsa_prop( + (message, signing_key) in + ( + collection::vec(any::(), 1..100), + collection::vec(any::(), 32) + .prop_map(|b| TryInto::<[u8; 32]>::try_into(b).unwrap()) + .prop_map(|b| SigningKey::from(SecretKey::from_bytes(&b.into()).unwrap())) + ), + ) { + let (signature, _) = signing_key.sign(&message); + assert!(verify_ecdsa(&message, signing_key, signature)); + } +} From e97befbba56d37f58ce2ddb8cc01dd51d7d702a7 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 13:37:01 +0000 Subject: [PATCH 26/43] cargo fmt --- crates/webauthn/tests/src/lib.rs | 4 ++-- crates/webauthn/tests/src/prop_utils.rs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/webauthn/tests/src/lib.rs b/crates/webauthn/tests/src/lib.rs index d1094997..675991c3 100644 --- a/crates/webauthn/tests/src/lib.rs +++ b/crates/webauthn/tests/src/lib.rs @@ -3,9 +3,9 @@ mod arg_builder; #[cfg(test)] pub mod prelude; #[cfg(test)] -mod utils; -#[cfg(test)] mod prop_utils; +#[cfg(test)] +mod utils; #[cfg(test)] mod auth; diff --git a/crates/webauthn/tests/src/prop_utils.rs b/crates/webauthn/tests/src/prop_utils.rs index e718b3c6..a5341bd1 100644 --- a/crates/webauthn/tests/src/prop_utils.rs +++ b/crates/webauthn/tests/src/prop_utils.rs @@ -10,4 +10,3 @@ impl Felt252Strategy { prop::collection::vec(any::(), 32..=32).prop_map(|b| Felt252::from_bytes_be(&b)) } } - From 96946699e5318911da5f28496e6abb4f6a2cf073 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 13:57:33 +0000 Subject: [PATCH 27/43] verify signature prop test --- .../tests/src/auth/verify_signature.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/webauthn/tests/src/auth/verify_signature.rs b/crates/webauthn/tests/src/auth/verify_signature.rs index f3ef010e..068be783 100644 --- a/crates/webauthn/tests/src/auth/verify_signature.rs +++ b/crates/webauthn/tests/src/auth/verify_signature.rs @@ -3,7 +3,9 @@ use cairo_args_runner::Felt252; use p256::{ ecdsa::{signature::Signer, Signature, SigningKey}, elliptic_curve::rand_core::OsRng, + SecretKey, }; +use proptest::collection; use super::*; @@ -76,3 +78,20 @@ fn test_verify_signature_should_fail_2() { false ) } + +proptest! { + #[test] + fn test_verify_signature_prop( + (hash, auth_data, signing_key) in + ( + collection::vec(any::(), 1..100), + collection::vec(any::(), 1..100), + collection::vec(any::(), 32) + .prop_map(|b| TryInto::<[u8; 32]>::try_into(b).unwrap()) + .prop_map(|b| SigningKey::from(SecretKey::from_bytes(&b.into()).unwrap())) + ), + ) { + let (signature, _) = signing_key.sign(&vec![auth_data.clone(), hash.clone()].concat()); + assert!(verify_signature(&hash, &auth_data, signing_key, signature)) + } +} From 9f5349eb9170777634abe126a0bfd9562ab75579 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 14:55:28 +0000 Subject: [PATCH 28/43] expand auth data prop test --- .../tests/src/auth/expand_auth_data.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/webauthn/tests/src/auth/expand_auth_data.rs b/crates/webauthn/tests/src/auth/expand_auth_data.rs index f2ff7ffe..143c1e0c 100644 --- a/crates/webauthn/tests/src/auth/expand_auth_data.rs +++ b/crates/webauthn/tests/src/auth/expand_auth_data.rs @@ -1,4 +1,5 @@ use cairo_args_runner::{errors::SierraRunnerError, Arg, Felt252}; +use proptest::{collection, prelude::*}; use crate::prelude::*; use cairo_args_runner::SuccessfulRun; @@ -46,6 +47,21 @@ pub struct AuthenticatorData { pub sign_count: u32, } +impl Arbitrary for AuthenticatorData { + type Parameters = (); + type Strategy = proptest::strategy::BoxedStrategy; + + fn arbitrary_with(_: Self::Parameters) -> Self::Strategy { + (collection::vec(any::(), 32), any::(), any::()) + .prop_map(|(rp_id_hash, flags, sign_count)| Self { + rp_id_hash: rp_id_hash.try_into().unwrap(), + flags, + sign_count, + }) + .boxed() + } +} + impl AuthenticatorData { #[allow(dead_code)] pub fn from_bytes(bytes: &[u8]) -> Self { @@ -85,3 +101,12 @@ fn test_expand_auth_data_1() { }; assert_eq!(EXPAND_AUTH_DATA.run(auth_data.clone()), auth_data); } + +proptest! { + #[test] + fn test_expand_auth_data_prop( + auth_data in any::(), + ) { + assert_eq!(EXPAND_AUTH_DATA.run(auth_data.clone()), auth_data); + } +} From cceaa5925ca0e772e9fb0b4a7f17ee3cc24d7453 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 15:02:07 +0000 Subject: [PATCH 29/43] remove python folder --- .../auth/expand_auth_data_test.py | 71 --- crates/test_gen_scripts/auth/helpers_test.py | 123 ---- crates/test_gen_scripts/auth/suite.py | 18 - .../auth/verify_ecdsa_test.py | 150 ----- .../auth/verify_signature_test.py | 64 -- crates/test_gen_scripts/auth/webauthn_test.py | 552 ------------------ .../deterministic_generator.py | 48 -- crates/test_gen_scripts/main.py | 12 - crates/test_gen_scripts/requirements.txt | 4 - .../session/signature_proofs_test.py | 46 -- .../session/signature_test.py | 61 -- crates/test_gen_scripts/session/suite.py | 14 - crates/test_gen_scripts/structure.py | 160 ----- crates/test_gen_scripts/utils.py | 109 ---- 14 files changed, 1432 deletions(-) delete mode 100644 crates/test_gen_scripts/auth/expand_auth_data_test.py delete mode 100644 crates/test_gen_scripts/auth/helpers_test.py delete mode 100644 crates/test_gen_scripts/auth/suite.py delete mode 100644 crates/test_gen_scripts/auth/verify_ecdsa_test.py delete mode 100644 crates/test_gen_scripts/auth/verify_signature_test.py delete mode 100644 crates/test_gen_scripts/auth/webauthn_test.py delete mode 100644 crates/test_gen_scripts/deterministic_generator.py delete mode 100644 crates/test_gen_scripts/main.py delete mode 100644 crates/test_gen_scripts/requirements.txt delete mode 100644 crates/test_gen_scripts/session/signature_proofs_test.py delete mode 100644 crates/test_gen_scripts/session/signature_test.py delete mode 100644 crates/test_gen_scripts/session/suite.py delete mode 100644 crates/test_gen_scripts/structure.py delete mode 100644 crates/test_gen_scripts/utils.py diff --git a/crates/test_gen_scripts/auth/expand_auth_data_test.py b/crates/test_gen_scripts/auth/expand_auth_data_test.py deleted file mode 100644 index 40f6a580..00000000 --- a/crates/test_gen_scripts/auth/expand_auth_data_test.py +++ /dev/null @@ -1,71 +0,0 @@ -from hashlib import sha256 -from structure import Test, TestFile, TestFileCreatorInterface -from utils import iterable_as_cairo_array - - -class ExpandAuthDataTest(TestFileCreatorInterface): - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("expand_auth_data", python_source_folder) - tf.add_imports(self.get_imports()) - tf.add_blocks(self.get_tests()) - return tf - - def create_expand_test(self, rp_id: bytes, flags: int, sign_count: int, name: str): - rp_id_hash = sha256(rp_id).digest() - auth_data = ( - rp_id_hash + flags.to_bytes(1, "big") + sign_count.to_bytes(4, "big") - ) - text = iterable_as_cairo_array(auth_data, "auth_data") - text += "let ad_o: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data);\n" - text += "let ad = ad_o.unwrap();\n" - text += f"assert(ad.sign_count == {sign_count}, 'Expected equal! count');\n" - text += f"assert(ad.flags == {flags}, 'Expected equal! flags');\n\n" - text += iterable_as_cairo_array(rp_id_hash, "rp_id_hash") - text += f"assert(ad.rp_id_hash == rp_id_hash, 'Expected equal! arrays');\n" - return Test(name, text) - - def create_verify_rp_id_hash_test( - self, rp_id: bytes, flags: int, sign_count: int, name: str - ): - rp_id_hash = sha256(rp_id).digest() - auth_data = ( - rp_id_hash + flags.to_bytes(1, "big") + sign_count.to_bytes(4, "big") - ) - text = iterable_as_cairo_array(auth_data, "auth_data") - text += iterable_as_cairo_array(rp_id, "rp_id") - text += "expand_auth_data_and_verify_rp_id_hash(auth_data, rp_id).unwrap();\n" - return Test(name, text) - - def get_tests(self): - cases = [ - (b"relying-party.id", 0b00010101, 13), - (b"gogiel.srogiel.pl", 0b00011101, 89), - (b"gogiel.srogiel.pl", 0b0101, 2**20), - (b"aaaaaaaaaaaaaa", 0b000101011, 19), - ] - return [ - self.create_expand_test(rp_id, f, c, f"expand_auth_data_{i}") - for i, (rp_id, f, c) in enumerate(cases) - ] + [ - self.create_verify_rp_id_hash_test(rp_id, f, c, f"verify_rp_id_{i}") - for i, (rp_id, f, c) in enumerate(cases) - ] - - def get_imports(self): - return [ - "core::traits::Into", - "core::option::OptionTrait", - "result::ResultTrait", - "webauthn_auth::ecdsa::{verify_ecdsa, verify_hashed_ecdsa, VerifyEcdsaError}", - "webauthn_auth::types::AuthenticatorData", - "webauthn_auth::webauthn::ImplArrayu8TryIntoAuthData", - "webauthn_auth::errors::AuthnErrorIntoFelt252", - "webauthn_auth::webauthn::expand_auth_data_and_verify_rp_id_hash", - "starknet::secp256r1::Secp256r1Impl", - "starknet::secp256r1::Secp256r1Point", - "starknet::SyscallResultTrait", - "array::ArrayTrait", - ] diff --git a/crates/test_gen_scripts/auth/helpers_test.py b/crates/test_gen_scripts/auth/helpers_test.py deleted file mode 100644 index 51d696e5..00000000 --- a/crates/test_gen_scripts/auth/helpers_test.py +++ /dev/null @@ -1,123 +0,0 @@ -from typing import List -from structure import Test, TestFile, TestFileCreatorInterface - - -class HelpersTest(TestFileCreatorInterface): - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("helpers", python_source_folder) - tf.add_imports(self.get_imports()) - tf.add_blocks(self.get_extract_tests()) - tf.add_blocks(self.get_r_s_extract_tests()) - return tf - - def get_imports(self): - return [ - "core::traits::Into", - "core::option::OptionTrait", - "array::ArrayTrait", - "webauthn_auth::helpers::extract_u256_from_u8_array", - "webauthn_auth::helpers::extract_r_and_s_from_array", - ] - - def get_extract_tests(self): - cases = [(0, 0), (0, 100), (2**256 - 1, 0), (2**256 - 2, 100), (1, 32)] - return [ - Test(f"extract_{i}", HelpersTest.generate_good_extract_test(n, o)) - for i, (n, o) in enumerate(cases) - ] - - def get_r_s_extract_tests(self): - cases = [ - (0, 0), - (0, 100), - (2**256 - 1, 2**256 - 1), - (2**256 - 2, 2**256 - 1), - (1, 32), - ] - return [ - Test(f"extract_r_s_{i}", HelpersTest.generate_good_r_s_extract_test(r, s)) - for i, (r, s) in enumerate(cases) - ] - - def get_arrays_equal_tests(self): - nums = [0, 2**31 - 1, 2**32 - 2**15 - 2**7 - 2**5, 2**256 - 1] - pairs_to_check = [(a, b) for a in nums for b in nums] - cases = [((n, m), n == m) for n, m in pairs_to_check] - return ( - [Test("arrays_equal_empty", HelpersTest.generate_array_empty_test())] - + [ - Test( - f"arrays_equal_{i}", HelpersTest.generate_array_equal_test(a, b, e) - ) - for i, ((a, b), e) in enumerate(cases) - ] - + [ - Test( - f"arrays_equal_different_length", - HelpersTest.generate_array_equal_test(0, 0, False, 0, 1), - ) - ] - ) - - def generate_good_extract_test(number, offset) -> str: - arr_name = "byte_repr" - text = generate_cairo_array(number, offset, arr_name) - text += f"""assert( - extract_u256_from_u8_array(@{arr_name}, {offset}_usize).unwrap() - == {number}_u256, - 'Expected equal!' -);""" - return text - - def generate_good_r_s_extract_test(r, s) -> str: - arr_name = "byte_repr" - s_bytes = number_to_b_array(s, 0) - text = generate_cairo_array(r, 0, arr_name) - text += "\n".join(append_bytes_to_cairo_arr(arr_name, s_bytes)) + "\n" - text += f"let (r, s): (u256, u256) = extract_r_and_s_from_array(@{arr_name}).unwrap();\n" - text += f"assert(r == {r}, 'Expected r equal!');\n" - text += f"assert(s == {s}, 'Expected s equal!');" - return text - - def generate_array_equal_test(a, b, should_equal, a_offset=0, b_offset=0): - text = generate_cairo_array(a, a_offset, "a") - text += generate_cairo_array(b, b_offset, "b") - text += f"""assert(arrays_equal(@a, @b) - == {'true' if should_equal else 'false'}, - 'Should {'' if should_equal else 'not'} equal!' -);""" - return text - - def generate_array_empty_test(): - lines = [ - "let a: Array = ArrayTrait::new();", - "let b: Array = ArrayTrait::new();", - "assert(arrays_equal(@a, @b), 'Should equal');", - ] - return "\n".join(lines) - - -def byte_array(number: int): - return number.to_bytes(256 // 8, "big") - - -def shift_array(array: bytes, offset: int): - return b"\x00" * offset + array - - -def number_to_b_array(number, offset=0): - return shift_array(byte_array(number), offset) - - -def append_bytes_to_cairo_arr(arr_name: str, bytes: bytes) -> List[str]: - return [f"{arr_name}.append({hex(b)});" for b in bytes] - - -def generate_cairo_array(number, offset, arr_name) -> str: - byte_arr = number_to_b_array(number, offset) - declare = [f"let mut {arr_name}: Array = ArrayTrait::new();"] - appending = append_bytes_to_cairo_arr(arr_name, byte_arr) - return "\n".join(declare + appending) + "\n" diff --git a/crates/test_gen_scripts/auth/suite.py b/crates/test_gen_scripts/auth/suite.py deleted file mode 100644 index 884d53fa..00000000 --- a/crates/test_gen_scripts/auth/suite.py +++ /dev/null @@ -1,18 +0,0 @@ -from structure import TestSuite -from auth.verify_ecdsa_test import VerifyECDSATest -from auth.helpers_test import HelpersTest -from auth.verify_signature_test import VerifySignatureTest -from auth.expand_auth_data_test import ExpandAuthDataTest -from auth.webauthn_test import WebauthnTest - - -def get_auth_suite(): - suite = TestSuite( - "src/auth/src/tests", "src/auth/src/tests.cairo", "test_gen_scripts/auth" - ) - suite.add_test_file(VerifyECDSATest()) - suite.add_test_file(HelpersTest()) - suite.add_test_file(VerifySignatureTest()) - suite.add_test_file(ExpandAuthDataTest()) - suite.add_test_file(WebauthnTest()) - return suite diff --git a/crates/test_gen_scripts/auth/verify_ecdsa_test.py b/crates/test_gen_scripts/auth/verify_ecdsa_test.py deleted file mode 100644 index af173e74..00000000 --- a/crates/test_gen_scripts/auth/verify_ecdsa_test.py +++ /dev/null @@ -1,150 +0,0 @@ -from structure import Test, TestFile, TestFileCreatorInterface -from utils import get_good_signature, iterable_as_cairo_array - - -class VerifyECDSATest(TestFileCreatorInterface): - # This is the template of the body of the test. - # When creating the tests that should 'pass' correct values (python generated) for - # px, py, r and s will be provided. - # When creating tests that should 'fail' some parameter would be screwed - # and ok_code and err_code would be adjusted accordingly - # The verify_hashed_ecdsa function takes an already hashed message. - # The verify_ecdsa takes raw message (before hashing) and sha256 is used as a hashing function - # This is why we provide an identity function as a hashing function - # for the python library. - TEMPLATE = """let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - {px}, - {py} -) - .unwrap_syscall() - .unwrap(); -let r = {r}; -let s = {s}; -{msg} - -match {func_name}(pub_key, msg, r, s) {{ - Result::Ok => {ok_code}, - Result::Err(m) => {err_code} -}}""" - - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("verify_ecdsa", python_source_folder) - tf.add_imports(self.get_imports()) - tf.add_blocks(self.get_good_tests()) - tf.add_block(self.create_wrong_arguments_test()) - tf.add_block(self.create_invalid_signature_test()) - tf.add_blocks(self.get_good_hashed_tests()) - return tf - - def create_good_test(self, name: str, message: bytes): - (px, py, r, s) = get_good_signature(message) - return Test( - name, - VerifyECDSATest.TEMPLATE.format( - px=px, - py=py, - r=r, - s=s, - msg=f"let msg = {int.from_bytes(message, 'big')};", - ok_code="()", - err_code="assert(false, m.into())", - func_name="verify_hashed_ecdsa", - ), - ) - - def create_good_test_with_hashing(self, name: str, message: bytes): - (px, py, r, s) = get_good_signature(message, True) - return Test( - name, - VerifyECDSATest.TEMPLATE.format( - px=px, - py=py, - r=r, - s=s, - msg=iterable_as_cairo_array(message), - ok_code="()", - err_code="assert(false, m.into())", - func_name="verify_ecdsa", - ), - ) - - def create_wrong_arguments_test(self): - message = b"Not important" - (px, py, _r, _s) = get_good_signature(message) - return Test( - "ecdsa_wrong_arguments", - VerifyECDSATest.TEMPLATE.format( - px=px, - py=py, - # this values are wrong - r=0, - s=0, - msg=f"let msg = {int.from_bytes(message, 'big')};", - ok_code="assert(false, 'Should Error!')", - err_code="""match m { - VerifyEcdsaError::WrongArgument => (), - VerifyEcdsaError::InvalidSignature =>assert(false, 'Wrong Error!'), - VerifyEcdsaError::SyscallError => assert(false, 'Wrong Error!'), - }""", - func_name="verify_hashed_ecdsa", - ), - ) - - def create_invalid_signature_test(self): - message = b"Not important" - (px, py, r, s) = get_good_signature(message) - return Test( - "ecdsa_invalid_signature", - VerifyECDSATest.TEMPLATE.format( - px=px, - py=py, - r=r, - s=s, - # this hash is wrong - msg=f"let msg = {111110000011111};", - ok_code="assert(false, 'Should Error!')", - err_code="""match m { - VerifyEcdsaError::WrongArgument => assert(false, 'Wrong Error!'), - VerifyEcdsaError::InvalidSignature => (), - VerifyEcdsaError::SyscallError => assert(false, 'Wrong Error!'), - }""", - func_name="verify_hashed_ecdsa", - ), - ) - - def get_imports(self): - return [ - "core::traits::Into", - "core::option::OptionTrait", - "webauthn_auth::ecdsa::{verify_ecdsa, verify_hashed_ecdsa, VerifyEcdsaError}", - "starknet::secp256r1::Secp256r1Impl", - "starknet::secp256r1::Secp256r1Point", - "starknet::SyscallResultTrait", - "array::ArrayTrait", - ] - - def get_good_tests(self): - return [ - self.create_good_test(name, message) - for name, message in [ - ("verify_ecdsa_short", b"1"), - ("verify_ecdsa", b"Hello World!"), - ("verify_ecdsa_long", b"This is a longer message!!!!!!!"), - ] - ] - - def get_good_hashed_tests(self): - return [ - self.create_good_test_with_hashing(f"verify_ecdsa_with_hash_{i}", msg) - for i, msg in enumerate( - [ - b"1", - b"Hello World!", - b"Long message, long message, long message, massage, message, long quite long" - * 20, - ] - ) - ] diff --git a/crates/test_gen_scripts/auth/verify_signature_test.py b/crates/test_gen_scripts/auth/verify_signature_test.py deleted file mode 100644 index 3ff8f015..00000000 --- a/crates/test_gen_scripts/auth/verify_signature_test.py +++ /dev/null @@ -1,64 +0,0 @@ -from hashlib import sha256 -from structure import Test, TestFile, TestFileCreatorInterface -from utils import get_raw_signature, iterable_as_cairo_array - -from deterministic_generator import generate_deterministic_string - -class VerifySignatureTest(TestFileCreatorInterface): - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("verify_signature", python_source_folder) - tf.add_imports(self.get_imports()) - tf.add_blocks(self.get_tests()) - return tf - - def create_good_test(self, rp_id: bytes, name: str): - flags = 0b10100000 - sign_count = 0x0001 - rp_id_hash = sha256(rp_id).digest() - auth_data = ( - rp_id_hash + flags.to_bytes(1, "big") + sign_count.to_bytes(4, "big") - ) - hash = sha256(generate_deterministic_string().encode()).digest() - (sig, px, py) = get_raw_signature(auth_data + hash, generate_deterministic_string()) - - text = iterable_as_cairo_array(hash, "hash") - text += iterable_as_cairo_array(auth_data, "auth_data") - text += iterable_as_cairo_array(sig, "sig") - text += ( - "let pk = PublicKey {\n\t x: " + str(px) + ", \n\t y: " + str(py) + "\n};\n" - ) - text += """match verify_signature( - hash, auth_data, pk, sig -) { - Result::Ok => (), - Result::Err(e) => { - assert(false, AuthnErrorIntoFelt252::into(e)) - } -}""" - return Test(name, text) - - def get_tests(self): - return [ - self.create_good_test(rp_id, f"verify_signature_{i}") - for i, rp_id in enumerate( - generate_deterministic_string().encode() for _ in range(10) - ) - ] - - def get_imports(self): - return [ - "core::traits::Into", - "result::ResultTrait", - "core::option::OptionTrait", - "webauthn_auth::ecdsa::{verify_ecdsa, verify_hashed_ecdsa, VerifyEcdsaError}", - "webauthn_auth::types::PublicKey", - "webauthn_auth::webauthn::verify_signature", - "webauthn_auth::errors::AuthnErrorIntoFelt252", - "starknet::secp256r1::Secp256r1Impl", - "starknet::secp256r1::Secp256r1Point", - "starknet::SyscallResultTrait", - "array::ArrayTrait", - ] diff --git a/crates/test_gen_scripts/auth/webauthn_test.py b/crates/test_gen_scripts/auth/webauthn_test.py deleted file mode 100644 index 0fdfc867..00000000 --- a/crates/test_gen_scripts/auth/webauthn_test.py +++ /dev/null @@ -1,552 +0,0 @@ -from structure import Test, TestFile, TestFileCreatorInterface -from webauthn.helpers import ( - base64url_to_bytes, - bytes_to_base64url, - decode_credential_public_key, -) -from starkware.starknet.core.os.transaction_hash.transaction_hash import ( - TransactionHashPrefix, - calculate_transaction_hash_common, -) -from starkware.starknet.definitions.general_config import StarknetChainId -from starkware.starknet.public.abi import get_selector_from_name -from ecdsa import SigningKey, NIST256p -from base64 import urlsafe_b64encode -from pyasn1.codec.der.decoder import decode as der_decoder -from pyasn1.type.univ import Sequence -from pyasn1.type.univ import Integer -from pyasn1.type.namedtype import NamedTypes -from pyasn1.type.namedtype import NamedType -import hashlib -import binascii -from hashlib import sha256 -import os - -from deterministic_generator import generate_next_seed - -TRANSACTION_VERSION = 1 - - -def from_call_to_call_array(calls): - """Transform from Call to CallArray.""" - call_array = [] - calldata = [] - for _, call in enumerate(calls): - assert len(call) == 3, "Invalid call parameters" - entry = ( - call[0], - get_selector_from_name(call[1]), - len(calldata), - len(call[2]), - ) - call_array.append(entry) - calldata.extend(call[2]) - return (call_array, calldata) - - -def get_transaction_hash(prefix, account, calldata, nonce, max_fee): - """Compute the hash of a transaction.""" - return calculate_transaction_hash_common( - tx_hash_prefix=prefix, - version=TRANSACTION_VERSION, - contract_address=account, - entry_point_selector=0, - calldata=calldata, - max_fee=max_fee, - chain_id=StarknetChainId.TESTNET.value, - additional_data=[nonce], - ) - - -def bytes_to_base64url(val: bytes) -> str: - """ - Base64URL-encode the provided bytes - """ - return urlsafe_b64encode(val).decode("utf-8").replace("=", "") - - -def sigencode(r, s, order): - return (r, s) - -def generate_deterministic_key(seed: bytes): - if seed is not None: - rng = DeterministicPRNG(seed) - else: - rng = os.urandom - - return rng - -class DeterministicPRNG: - def __init__(self, seed): - self.seed = seed - - def __call__(self, n): - hash_value = sha256(self.seed).digest() - return hash_value[:n] - -class WebauthnSigner: - def __init__(self): - self.signing_key = SigningKey.generate(curve=NIST256p, entropy=generate_deterministic_key(generate_next_seed())) - pt = self.signing_key.verifying_key.pubkey.point - - self.public_key = (pt.x(), pt.y()) - - def sign_transaction(self, origin, contract_address, calldata, nonce, max_fee): - message_hash = get_transaction_hash( - TransactionHashPrefix.INVOKE, contract_address, calldata, nonce, max_fee - ) - - challenge_bytes = message_hash.to_bytes(32, byteorder="big") - - challenge = bytes_to_base64url(challenge_bytes) - # challenge_parts = [int.from_bytes(challenge_bytes[i:i+3], 'big') for i in range(0, len(challenge_bytes), 3)] - client_data_json = f"""{{"type":"webauthn.get","challenge":"{challenge}","origin":"{origin}","crossOrigin":false}}""" - client_data_bytes = client_data_json.encode("ASCII") - - client_data_hash = hashlib.sha256() - client_data_hash.update(client_data_bytes) - client_data_hash_bytes = client_data_hash.digest() - - # client_data_rem = 4 - (len(client_data_bytes) % 4) - # if client_data_rem == 4: - # client_data_rem = 0 - # if client_data_rem != 0: - # for _ in range(client_data_rem): - # client_data_bytes = client_data_bytes + b'\x00' - - authenticator_data_bytes = bytes.fromhex( - "20a97ec3f8efbc2aca0cf7cabb420b4a09d0aec9905466c9adf79584fa75fed30500000000" - ) - # authenticator_data_rem = 4 - len(authenticator_data_bytes) % 4 - # if authenticator_data_rem == 4: - # authenticator_data_rem = 0 - - (r, s) = self.signing_key.sign_deterministic( - authenticator_data_bytes + client_data_hash_bytes, - hashfunc=hashlib.sha256, - sigencode=sigencode, - ) - - # authenticator_data = [int.from_bytes(authenticator_data_bytes[i:i+4], 'big') for i in range(0, len(authenticator_data_bytes), 4)] - # client_data_json = [int.from_bytes(client_data_bytes[i:i+4], 'big') for i in range(0, len(client_data_bytes), 4)] - - challenge_offset = 36 - # challenge_offset_rem = 0 - # challenge_len = len(challenge_parts) - # challenge_rem = len(challenge_parts) % 3 - - # the hash and signature are returned for other tests to use - return [r, s, challenge_offset, client_data_bytes, authenticator_data_bytes] - - -class DERSig(Sequence): - componentType = NamedTypes(NamedType("r", Integer()), NamedType("s", Integer())) - - -BASE = 2**86 - - -def combine(G0, G1, G2): - return ((G2 * BASE) + G1) * BASE + G0 - - -TEST_CASE = """let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - {x}, - {y} -); -let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); -let r: u256 = {param_r}; -let s: u256 = {param_s}; -let type_offset = 9_usize; -let challenge_offset = {challenge_offset}; -let mut challenge = ArrayTrait::::new(); -{challenge} -let origin_offset = 91; -let mut origin = ArrayTrait::::new(); -origin.append(0x68); -origin.append(0x74); -origin.append(0x74); -origin.append(0x70); -origin.append(0x73); -origin.append(0x3A); -origin.append(0x2F); -origin.append(0x2F); -origin.append(0x63); -origin.append(0x6F); -origin.append(0x6E); -origin.append(0x74); -origin.append(0x72); -origin.append(0x6F); -origin.append(0x6C); -origin.append(0x6C); -origin.append(0x65); -origin.append(0x72); -origin.append(0x2D); -origin.append(0x65); -origin.append(0x31); -origin.append(0x33); -origin.append(0x70); -origin.append(0x74); -origin.append(0x39); -origin.append(0x77); -origin.append(0x77); -origin.append(0x76); -origin.append(0x2E); -origin.append(0x70); -origin.append(0x72); -origin.append(0x65); -origin.append(0x76); -origin.append(0x69); -origin.append(0x65); -origin.append(0x77); -origin.append(0x2E); -origin.append(0x63); -origin.append(0x61); -origin.append(0x72); -origin.append(0x74); -origin.append(0x72); -origin.append(0x69); -origin.append(0x64); -origin.append(0x67); -origin.append(0x65); -origin.append(0x2E); -origin.append(0x67); -origin.append(0x67); -let mut client_data_json = ArrayTrait::::new(); -{client_data_json} -let mut authenticator_data = ArrayTrait::::new(); -{authenticator_data} -let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data -); -match verify_result {{ - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) -}} -""" - - -class WebauthnTest(TestFileCreatorInterface): - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("webauthn", python_source_folder) - tf.add_imports(self.get_imports()) - tf.add_blocks(self.get_tests()) - return tf - - def create_hardcoded_test(self, item, name: str): - pubkey = decode_credential_public_key(base64url_to_bytes(item["pubkey"])) - authenticator_data_bytes = bytes.fromhex(item["authenticator_data"]) - client_data_bytes = bytes.fromhex(item["client_data"]) - challenge_bytes = base64url_to_bytes(item["challenge"]) - - sig, rest = der_decoder( - binascii.unhexlify(item["signature"]), asn1Spec=DERSig() - ) - if len(rest) != 0: - raise Exception("Bad encoding") - - param_r = int(sig["r"]) - param_s = int(sig["s"]) - - for _ in range(32 - len(challenge_bytes)): - challenge_bytes = challenge_bytes + b"\x00" - - challenge_offset_bytes = client_data_bytes.find(b'"challenge":"') + len( - b'"challenge":"' - ) - - challenge = "" - for c in challenge_bytes: - challenge += "challenge.append({});\n".format(c) - - client_data_json = "" - for c in client_data_bytes: - client_data_json += "client_data_json.append({});\n".format(c) - - authenticator_data = "" - for c in authenticator_data_bytes: - authenticator_data += "authenticator_data.append({});\n".format(c) - - return Test( - name, - TEST_CASE.format( - x=int.from_bytes(pubkey.x, "big"), - y=int.from_bytes(pubkey.y, "big"), - param_r=param_r, - param_s=param_s, - challenge_offset=challenge_offset_bytes, - challenge=challenge, - client_data_json=client_data_json, - authenticator_data=authenticator_data, - ), - ) - - def create_invoke_test(self, item, name: str): - pubkey_bytes = base64url_to_bytes(item["pubkey"]) - decoded_public_key = decode_credential_public_key(pubkey_bytes) - - sig = [int(part, 16) for part in item["signature"]] - - param_r = combine(sig[1], sig[2], sig[3]) - param_s = combine(sig[4], sig[5], sig[6]) - - client_data_json_len = int(sig[9]) - client_data_json_rem = int(sig[10]) - - client_data_json_parts = [] - for j in range(11, 11 + client_data_json_len): - client_data_json_parts.append(int(sig[j])) - - client_data_bytes = b"" - for c in client_data_json_parts: - client_data_bytes += c.to_bytes(4, "big") - - if client_data_json_rem != 0: - client_data_bytes = client_data_bytes[: -1 * client_data_json_rem] - - client_data_json = "" - for c in client_data_bytes: - client_data_json += "client_data_json.append({});\n".format(c) - - authenticator_data_len = int(sig[11 + client_data_json_len]) - authenticator_data_rem = int(sig[12 + client_data_json_len]) - - authenticator_data_bytes = b"" - for j in range( - 13 + client_data_json_len, - 13 + client_data_json_len + authenticator_data_len, - ): - authenticator_data_bytes += sig[j].to_bytes(4, "big") - - if authenticator_data_rem != 0: - authenticator_data_bytes = authenticator_data_bytes[ - : -1 * authenticator_data_rem - ] - # print(authenticator_data_bytes.hex(), len(authenticator_data_bytes)) - - authenticator_data = "" - for c in authenticator_data_bytes: - authenticator_data += "authenticator_data.append({});\n".format(c) - - challenge_bytes = int(item["transaction_hash"], 16).to_bytes( - 32, byteorder="big" - ) - challenge = bytes_to_base64url(challenge_bytes) - - # challenge_parts = [int.from_bytes( - # challenge_bytes[i:i+3], 'big') for i in range(0, len(challenge_bytes), 3)] - challenge = "" - for c in challenge_bytes: - challenge += "challenge.append({});\n".format(c) - - challenge_offset_bytes = 36 - - return Test( - name, - TEST_CASE.format( - x=int.from_bytes(decoded_public_key.x, "big"), - y=int.from_bytes(decoded_public_key.y, "big"), - param_r=param_r, - param_s=param_s, - challenge_offset=challenge_offset_bytes, - challenge=challenge, - client_data_json=client_data_json, - authenticator_data=authenticator_data, - ), - ) - - def create_signer_test(self, item, name: str): - signer = WebauthnSigner() - - (contract_address, calls, nonce, max_fee) = item["transaction"] - - build_calls = [] - for call in calls: - build_call = list(call) - build_call[0] = hex(build_call[0]) - build_calls.append(build_call) - - (_, calldata) = from_call_to_call_array(build_calls) - message_hash = get_transaction_hash( - TransactionHashPrefix.INVOKE, contract_address, calldata, nonce, max_fee - ) - - ( - param_r, - param_s, - challenge_offset, - client_data_bytes, - authenticator_data_bytes, - ) = signer.sign_transaction( - item["origin"], contract_address, calldata, nonce, max_fee - ) - - challenge_bytes = message_hash.to_bytes(32, byteorder="big") - # challenge_parts = [int.from_bytes( - # challenge_bytes[i:i+3], 'big') for i in range(0, len(challenge_bytes), 3)] - challenge = "" - for c in challenge_bytes: - challenge += "challenge.append({});\n".format(c) - - client_data_json = "" - for c in client_data_bytes: - client_data_json += "client_data_json.append({});\n".format(c) - - authenticator_data = "" - for c in authenticator_data_bytes: - authenticator_data += "authenticator_data.append({});\n".format(c) - - return Test( - name, - TEST_CASE.format( - x=signer.public_key[0], - y=signer.public_key[1], - param_r=param_r, - param_s=param_s, - challenge_offset=challenge_offset, - challenge=challenge, - client_data_json=client_data_json, - authenticator_data=authenticator_data, - ), - ) - - def get_tests(self): - tests = [] - - data = [ - { - # b'{"type":"webauthn.get","challenge":"ALFEyQPE2bC7XWUmuMoDOAuCooKDVi-Y9vFKIpgFJGM","origin":"https://controller-git-tarrence-eng-195-credential-registration-976697.preview.cartridge.gg","crossOrigin":false}' - "pubkey": "pQECAyYgASFYILy4sqBJQupsn3ttx5Af1lK8i75VKbji6u5EqOVkHzUaIlggABPNyK5iEFpOWlFjtoZuW8rVDoLLTIar7jFXqGIVaZU=", - "challenge": "ALFEyQPE2bC7XWUmuMoDOAuCooKDVi-Y9vFKIpgFJGM", - "authenticator_data": "20a97ec3f8efbc2aca0cf7cabb420b4a09d0aec9905466c9adf79584fa75fed30500000000", - "client_data": "7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a22414c464579515045326243375857556d754d6f444f4175436f6f4b4456692d593976464b497067464a474d222c226f726967696e223a2268747470733a2f2f636f6e74726f6c6c65722d6769742d74617272656e63652d656e672d3139352d63726564656e7469616c2d726567697374726174696f6e2d3937363639372e707265766965772e6361727472696467652e6767222c2263726f73734f726967696e223a66616c73657d", - "signature": "3046022100a6fc623a319a674ed15f72b544b9ddb277ccfa90e1b49269fdb3e4c6c41771ef022100b728edcbd35b9995e0e82b15456960d89b99884dd9aabf36295fd99ad23a9f3c", - } - ] - for i, item in enumerate(data): - tests.append(self.create_hardcoded_test(item, f"base_{i}")) - - invokes = [ - { - "pubkey": "pQECAyYgASFYIBr47ohkRPowA6P7lim1UiuXH57qEg8+rb6zPzSHoM33IlggWknbZgnGuMxKrlSFgeT+L+zPwoBRepj34rxq/oxkOdI=", - "signature": [ - "0x0", - "0x1d6dd918cd1d34c268295", - "0x154d4da8d3cc79014e7b93", - "0x957373f5ff88d2d69ee4", - "0x304d3a94f27306e32a2186", - "0xaaa6c62c6c2ca14c725ea", - "0xfc557b7a588de600e1aab", - "0x9", - "0x0", - "0x24", - "0x0", - "0x7b227479", - "0x7065223a", - "0x22776562", - "0x61757468", - "0x6e2e6765", - "0x74222c22", - "0x6368616c", - "0x6c656e67", - "0x65223a22", - "0x41786c73", - "0x504b4231", - "0x63357434", - "0x52356c53", - "0x7135634e", - "0x50575969", - "0x65416552", - "0x56446e33", - "0x70774256", - "0x59413146", - "0x75504522", - "0x2c226f72", - "0x6967696e", - "0x223a2268", - "0x74747073", - "0x3a2f2f63", - "0x6f6e7472", - "0x6f6c6c65", - "0x722e6361", - "0x72747269", - "0x6467652e", - "0x6767222c", - "0x2263726f", - "0x73734f72", - "0x6967696e", - "0x223a6661", - "0x6c73657d", - "0xa", - "0x3", - "0x20a97ec3", - "0xf8efbc2a", - "0xca0cf7ca", - "0xbb420b4a", - "0x9d0aec9", - "0x905466c9", - "0xadf79584", - "0xfa75fed3", - "0x1d000000", - "0x0", - ], - "transaction_hash": "0x3196c3ca075739b78479952ab970d3d66227807915439f7a70055600d45b8f1", - } - ] - for i, item in enumerate(invokes): - tests.append(self.create_invoke_test(item, f"invoke_{i}")) - - cases = [ - { - "origin": "https://controller.cartridge.gg", - "transaction": (420, [(1234, "add_public_key", [0])], 0, 0), - }, - { - "origin": "a", - "transaction": (420, [(1234, "add_public_key", [0])], 0, 0), - }, - { - "origin": "aa", - "transaction": (420, [(1234, "add_public_key", [0])], 0, 0), - }, - { - "origin": "aaa", - "transaction": (420, [(1234, "add_public_key", [0])], 0, 0), - }, - { - "origin": "aaaa", - "transaction": (420, [(1234, "add_public_key", [0])], 0, 0), - }, - { - "origin": "aaaaa", - "transaction": (420, [(1234, "add_public_key", [0])], 0, 0), - }, - ] - for i, item in enumerate(cases): - tests.append(self.create_signer_test(item, f"signer_{i}")) - - return tests - - def get_imports(self): - return [ - "webauthn_auth::webauthn::verify", - "array::ArrayTrait", - "webauthn_auth::types::PublicKey", - "webauthn_auth::errors::AuthnErrorIntoFelt252", - "core::option::OptionTrait", - "core::result::ResultTrait", - "starknet::secp256r1::Secp256Trait", - "starknet::secp256r1::Secp256r1Point", - ] diff --git a/crates/test_gen_scripts/deterministic_generator.py b/crates/test_gen_scripts/deterministic_generator.py deleted file mode 100644 index e83704f7..00000000 --- a/crates/test_gen_scripts/deterministic_generator.py +++ /dev/null @@ -1,48 +0,0 @@ -from typing import Any, Generator -import string - -def get_seed_generator() -> Generator[bytes, Any, None]: - cur_seed = 1 - while True: - cur_seed += 1 - byte_length = (cur_seed.bit_length() + 7) // 8 - yield cur_seed.to_bytes(byte_length, "big") - - -_SEED_GENERATOR = get_seed_generator() - - -def generate_next_seed() -> bytes: - """ - Generate and return the next seed from a global sequence. - - This function operates on a global context and deterministically - produces a sequence of seeds. Each invocation returns a different seed. - The same sequence of seeds is produced every time the Python script is run. - - Returns: - bytes: The next seed in the sequence. - """ - global _SEED_GENERATOR - return next(_SEED_GENERATOR) - -def get_string_generator() -> Generator[str, None, None]: - characters = string.ascii_letters + string.digits - cur_seed = 5 - cur_string = "aaaaa" - while True: - cur_seed += 1 - - if(len(cur_string) >= 100): - cur_string[100 % cur_seed] = cur_seed[((100 % cur_seed) + 1) % len(characters)] - else: - cur_string += characters[cur_seed % len(characters)] - - yield cur_string - -_STRING_GENERATOR = get_string_generator() - -def generate_deterministic_string() -> str: - global _STRING_GENERATOR - return next(_STRING_GENERATOR) - diff --git a/crates/test_gen_scripts/main.py b/crates/test_gen_scripts/main.py deleted file mode 100644 index 01a0fc60..00000000 --- a/crates/test_gen_scripts/main.py +++ /dev/null @@ -1,12 +0,0 @@ -from auth.suite import get_auth_suite -from session.suite import get_session_suite - - -def main(): - suites = [get_auth_suite(), get_session_suite()] - for suite in suites: - suite.generate(delete_old_tests=True) - - -if __name__ == "__main__": - main() diff --git a/crates/test_gen_scripts/requirements.txt b/crates/test_gen_scripts/requirements.txt deleted file mode 100644 index 44417217..00000000 --- a/crates/test_gen_scripts/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -cairo-lang -cairo-nile -pyasn1 -webauthn diff --git a/crates/test_gen_scripts/session/signature_proofs_test.py b/crates/test_gen_scripts/session/signature_proofs_test.py deleted file mode 100644 index 3c6c77f3..00000000 --- a/crates/test_gen_scripts/session/signature_proofs_test.py +++ /dev/null @@ -1,46 +0,0 @@ -from structure import Test, TestFile, TestFileCreatorInterface -from utils import iterable_as_cairo_array, assert_option_is_none - - -class SignatureProofsTest(TestFileCreatorInterface): - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("signature_proofs", python_source_folder) - tf.add_imports(self.get_imports()) - for l in [3, 12, 100]: - tf.add_block(self.get_test(l)) - return tf - - def get_imports(self): - return [ - "core::traits::Into", - "core::option::OptionTrait", - "array::ArrayTrait", - "webauthn_session::signature::ImplSignatureProofs", - ] - - def get_test(self, length: int): - body = iterable_as_cairo_array( - bytes([i % 256 for i in range(length)]), "proofs", "felt252" - ) - for proof_size in [i + 1 for i in range(length)]: - value = f"ImplSignatureProofs::try_new(proofs.span(), {proof_size})" - if length % proof_size == 0: - proof_count = length // proof_size - body += "{\n\t" - body += "\n\t".join( - [ - f"let option = {value}.unwrap();", - f"assert(option.len() == {proof_count}, 'Wrong length');", - f"assert(option.at(0).len() == {proof_size}, 'Wrong length');", - f"assert(*option.at(0).at(0) == 0, 'Should equal');", - f"assert(*option.at({proof_count - 1}).at(0) == {(length - proof_size) % 255}, 'Should equal');", - f"assert(*option.at({proof_count - 1}).at({proof_size - 1}) == {(length - 1) % 255}, 'Should equal');", - ] - ) - body += "\n}\n" - else: - body += assert_option_is_none(value) - return Test(f"signature_proofs_{length}", body, length * 100000) diff --git a/crates/test_gen_scripts/session/signature_test.py b/crates/test_gen_scripts/session/signature_test.py deleted file mode 100644 index 719c3d7d..00000000 --- a/crates/test_gen_scripts/session/signature_test.py +++ /dev/null @@ -1,61 +0,0 @@ -from utils import iterable_as_cairo_array -from structure import Test, TestFile, TestFileCreatorInterface - - -class SignatureTest(TestFileCreatorInterface): - def __init__(self) -> None: - super().__init__() - - def test_file(self, python_source_folder: str) -> TestFile: - tf = TestFile("signature", python_source_folder) - tf.add_imports(self.get_imports()) - for name, count, size, token in [ - ("small", 2, 3, 5), - ("medium", 10, 10, 40), - ("large", 100, 10, 100), - ]: - tf.add_block(self.get_test(name, count, size, token)) - return tf - - def get_imports(self): - return [ - "core::traits::Into", - "core::option::OptionTrait", - "array::ArrayTrait", - "webauthn_session::signature::FeltSpanTryIntoSignature", - "webauthn_session::signature::ImplSignatureProofs", - ] - - def get_test(self, name, number_of_proofs, single_proof_len, session_token_len): - r = 1830 - s = 1863 - session_key = 1918 - session_expires = 1694114435 - root = 1922 - proofs = [i * 100 for i in range(single_proof_len * number_of_proofs)] - session_token = [i + 2000 for i in range(session_token_len)] - - sig = ( - [0, r, s, session_key, session_expires, root, single_proof_len, len(proofs)] - + proofs - + [len(session_token)] - + session_token - ) - - body = iterable_as_cairo_array(sig, "sig", "felt252") - body += iterable_as_cairo_array(proofs, "proofs", "felt252") - body += iterable_as_cairo_array(session_token, "session_token", "felt252") - body += f"let sig = FeltSpanTryIntoSignature::try_into(sig.span()).unwrap();\n" - body += "\n".join( - [ - f"assert({r} == sig.r, 'Expect equal!');", - f"assert({s} == sig.s, 'Expect equal!');", - f"assert({session_key} == sig.session_key, 'Expect equal!');", - f"assert({root} == sig.root, 'Expect equal!');", - f"assert({number_of_proofs} == sig.proofs.len(), 'Expect equal!');", - f"assert({session_token_len} == sig.session_token.len(), 'Expect equal!');", - f"assert({proofs[-1]} == *sig.proofs.at({number_of_proofs - 1}).at({single_proof_len - 1}), 'Expect equal!');", - f"assert({session_token[-1]} == *sig.session_token.at({session_token_len - 1}), 'Expect equal!');", - ] - ) - return Test(f"span_into_signature_{name}", body) diff --git a/crates/test_gen_scripts/session/suite.py b/crates/test_gen_scripts/session/suite.py deleted file mode 100644 index fb17de0a..00000000 --- a/crates/test_gen_scripts/session/suite.py +++ /dev/null @@ -1,14 +0,0 @@ -from structure import TestSuite -from session.signature_proofs_test import SignatureProofsTest -from session.signature_test import SignatureTest - - -def get_session_suite(): - suite = TestSuite( - "src/session/src/tests", - "src/session/src/tests.cairo", - "test_gen_scripts/session", - ) - suite.add_test_file(SignatureProofsTest()) - suite.add_test_file(SignatureTest()) - return suite diff --git a/crates/test_gen_scripts/structure.py b/crates/test_gen_scripts/structure.py deleted file mode 100644 index 26516650..00000000 --- a/crates/test_gen_scripts/structure.py +++ /dev/null @@ -1,160 +0,0 @@ -import os -from abc import ABC, abstractmethod - - -class CodeBlock(ABC): - @abstractmethod - def to_text(self) -> str: - pass - - -class Test(CodeBlock): - name: str - body: str - gas: int - - def __init__(self, name: str, body: str, gas: int = 200000000000) -> None: - super().__init__() - self.name = name - self.body = body - self.gas = gas - - def to_text(self) -> str: - text = "\n".join( - ["#[test]", f"#[available_gas({self.gas})]", f"fn test_{self.name}() {{"] - ) - - lines = self.body.split("\n") - text += "\n\t" + "\n\t".join(lines) - text += "\n" + "}" + "\n" - - return text - - -class SimpleBlock(CodeBlock): - body: str - - def __init__(self, body) -> None: - super().__init__() - self.body = body - - def to_text(self) -> str: - return self.body - - -class TestFile: - name: str - path: str - imports: list[str] - tests: list[CodeBlock] - python_suite_folder: str - - def __init__(self, name: str, python_suite_folder: str) -> None: - self.imports = [] - self.tests = [] - self.name = name - self.python_suite_folder = python_suite_folder - - def add_block(self, block: CodeBlock): - self.tests.append(block) - - def add_blocks(self, blocks: list[CodeBlock]): - self.tests += blocks - - def add_imports(self, imports: list[str]): - self.imports += imports - - def file_name(self): - return self.name + "_gen_test.cairo" - - def write_to_file(self, path: str): - with open(path + "/" + self.file_name(), "w") as file: - contents = "// This file is script-generated.\n" - contents += "// Don't modify it manually!\n" - contents += ( - f"// See {self.python_suite_folder}/{self.name}_test.py for details\n" - ) - for i in self.imports: - contents += "use " + i + ";\n" - - contents += "\n" - - for t in self.tests: - contents += t.to_text() + "\n" - file.write(contents) - - -class TestFileCreatorInterface(ABC): - @abstractmethod - def test_file(self, python_source_folder) -> TestFile: - pass - - -class TestSuite: - path: str - mod_file_path: str - test_files: list[TestFile] - python_source_folder: str - - splitter = "// ^^^ Auto generated tests ^^^ Place your code below this line!!!" - - def __init__( - self, path: str, mod_file_path: str, python_source_folder: str - ) -> None: - self.path = path - self.mod_file_path = mod_file_path - self.test_files = [] - self.python_source_folder = python_source_folder - - def add_test_file(self, file: TestFileCreatorInterface): - self.test_files.append(file.test_file(self.python_source_folder)) - - def generate(self, delete_old_tests=False): - if not os.path.exists(self.path): - os.makedirs(self.path) - - if delete_old_tests: - self.delete_old() - - self.manipulate_mod_file() - - for tf in self.test_files: - tf.write_to_file(self.path) - - def manipulate_mod_file(self): - with open(self.mod_file_path, "a+") as file: - pass - with open(self.mod_file_path, "r") as file: - content = file.read() - - custom = content.split(TestSuite.splitter)[-1] - generated = "\n".join([f"mod {t.name}_gen_test;" for t in self.test_files]) - - new_content = ( - "\n".join( - [ - "// Place your code below auto generated tests' modules!!!", - generated, - TestSuite.splitter, - custom.strip(), - ] - ) - + "\n" - ) - - with open(self.mod_file_path, "w") as file: - file.write(new_content) - - def has_file(self, file_name: str): - return file_name in [f"{tf.name}_gen_test.cairo" for tf in self.test_files] - - def delete_old(self): - for file_name in os.listdir(self.path): - if file_name.endswith("_gen_test.cairo") and not self.has_file(file_name): - file_path = os.path.join(self.path, file_name) - try: - # Remove the file - os.remove(file_path) - print(f"Deleted: {file_path}") - except Exception as e: - print(f"Error deleting file {file_path}. Reason: {e}") diff --git a/crates/test_gen_scripts/utils.py b/crates/test_gen_scripts/utils.py deleted file mode 100644 index 54caa110..00000000 --- a/crates/test_gen_scripts/utils.py +++ /dev/null @@ -1,109 +0,0 @@ -import random -import string -import os -from hashlib import sha256 -from ecdsa import SigningKey, NIST256p, util -from deterministic_generator import generate_next_seed - - -def generate_deterministic_key(seed: bytes): - if seed is not None: - rng = DeterministicPRNG(seed) - else: - rng = os.urandom - - sk = SigningKey.generate(curve=NIST256p, entropy=rng) - return sk - - -class DeterministicPRNG: - def __init__(self, seed): - self.seed = seed - - def __call__(self, n): - hash_value = sha256(self.seed).digest() - return hash_value[:n] - - -def get_good_signature(message: bytes, hash=False): - sk = generate_deterministic_key(generate_next_seed()) - vk = sk.get_verifying_key() - - signature = ( - sk.sign_deterministic(message, hashfunc=sha256) - if hash - else sk.sign_deterministic(message, hashfunc=my_hash) - ) - - (px, py) = (vk.pubkey.point.x(), vk.pubkey.point.y()) - r, s = util.sigdecode_string(signature, sk.curve.order) - - return (px, py, r, s) - - -def get_raw_signature(message: bytes, sk): - sk = generate_deterministic_key(generate_next_seed()) - vk = sk.get_verifying_key() - sig = sk.sign_deterministic(message, hashfunc=sha256) - (px, py) = (vk.pubkey.point.x(), vk.pubkey.point.y()) - return (sig, px, py) - - -def get_random_string(a: int, b: int): - characters = string.ascii_letters + string.digits - return "".join(random.choice(characters) for _ in range(random.randint(a, b))) - - -def iterable_as_cairo_array(iterable, name: str = "msg", type: str = "u8") -> str: - declare = [f"let mut {name}: Array<{type}> = ArrayTrait::new();"] - lines = [f"{name}.append({b});" for b in iterable] - return "\n".join(declare + lines) + "\n" - - -def assert_option_is_some(value: str) -> str: - return """match {option_value} {{ - Option::Some(_) => (), - Option::None => assert(false, 'Should be Some') -}}; -""".format( - option_value=value - ) - - -def assert_option_is_none(value: str) -> str: - return """match {option_value} {{ - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () -}}; -""".format( - option_value=value - ) - - -# Dummy hash function returning an object of class IdentityHasher -def my_hash(message=b""): - return IdentityHasher(message) - - -class IdentityHasher: - block_size = 64 - val: bytes - - def __init__(self, val=b"") -> None: - self.val = val - - def update(self, val): - self.val += val - - def digest(self): - return self.val - - def hexdigest(self): - return self.val.hex() - - @property - def digest_size(self): - return len(self.val) - - def copy(self): - return IdentityHasher(self.val) From 068a981c43e22c58ba5546a0c2b60f59dc917ece Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 15:02:52 +0000 Subject: [PATCH 30/43] remove auth gen tests --- crates/webauthn/auth/src/tests.cairo | 7 - .../src/tests/expand_auth_data_gen_test.cairo | 588 ----- .../auth/src/tests/helpers_gen_test.cairo | 821 ------ .../src/tests/verify_ecdsa_gen_test.cairo | 1684 ------------ .../src/tests/verify_signature_gen_test.cairo | 1505 ----------- .../auth/src/tests/webauthn_gen_test.cairo | 2332 ----------------- 6 files changed, 6937 deletions(-) delete mode 100644 crates/webauthn/auth/src/tests/expand_auth_data_gen_test.cairo delete mode 100644 crates/webauthn/auth/src/tests/helpers_gen_test.cairo delete mode 100644 crates/webauthn/auth/src/tests/verify_ecdsa_gen_test.cairo delete mode 100644 crates/webauthn/auth/src/tests/verify_signature_gen_test.cairo delete mode 100644 crates/webauthn/auth/src/tests/webauthn_gen_test.cairo diff --git a/crates/webauthn/auth/src/tests.cairo b/crates/webauthn/auth/src/tests.cairo index 7f81c14d..f57eae35 100644 --- a/crates/webauthn/auth/src/tests.cairo +++ b/crates/webauthn/auth/src/tests.cairo @@ -1,9 +1,2 @@ -// Place your code below auto generated tests' modules!!! -mod verify_ecdsa_gen_test; -mod helpers_gen_test; -mod verify_signature_gen_test; -mod expand_auth_data_gen_test; -// mod webauthn_gen_test; -// ^^^ Auto generated tests ^^^ Place your code below this line!!! mod mod_arithmetic_test; mod verify_user_flags_test; diff --git a/crates/webauthn/auth/src/tests/expand_auth_data_gen_test.cairo b/crates/webauthn/auth/src/tests/expand_auth_data_gen_test.cairo deleted file mode 100644 index 01b64f30..00000000 --- a/crates/webauthn/auth/src/tests/expand_auth_data_gen_test.cairo +++ /dev/null @@ -1,588 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/auth/expand_auth_data_test.py for details -use core::traits::Into; -use core::option::OptionTrait; -use core::result::ResultTrait; -use webauthn_auth::ecdsa::{verify_ecdsa, verify_hashed_ecdsa, VerifyEcdsaError}; -use webauthn_auth::types::AuthenticatorData; -use webauthn_auth::webauthn::ImplArrayu8TryIntoAuthData; -use webauthn_auth::errors::AuthnErrorIntoFelt252; -use webauthn_auth::webauthn::expand_auth_data_and_verify_rp_id_hash; -use starknet::secp256r1::Secp256r1Impl; -use starknet::secp256r1::Secp256r1Point; -use starknet::SyscallResultTrait; -use core::array::ArrayTrait; - -#[test] -#[available_gas(200000000000)] -fn test_expand_auth_data_0() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(199); - auth_data.append(133); - auth_data.append(107); - auth_data.append(211); - auth_data.append(38); - auth_data.append(106); - auth_data.append(24); - auth_data.append(253); - auth_data.append(170); - auth_data.append(126); - auth_data.append(55); - auth_data.append(232); - auth_data.append(29); - auth_data.append(141); - auth_data.append(89); - auth_data.append(87); - auth_data.append(10); - auth_data.append(255); - auth_data.append(243); - auth_data.append(80); - auth_data.append(59); - auth_data.append(59); - auth_data.append(8); - auth_data.append(99); - auth_data.append(150); - auth_data.append(7); - auth_data.append(131); - auth_data.append(162); - auth_data.append(35); - auth_data.append(174); - auth_data.append(161); - auth_data.append(82); - auth_data.append(21); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(13); - let ad_o: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data); - let ad = ad_o.unwrap(); - assert(ad.sign_count == 13, 'Expected equal! count'); - assert(ad.flags == 21, 'Expected equal! flags'); - - let mut rp_id_hash: Array = ArrayTrait::new(); - rp_id_hash.append(199); - rp_id_hash.append(133); - rp_id_hash.append(107); - rp_id_hash.append(211); - rp_id_hash.append(38); - rp_id_hash.append(106); - rp_id_hash.append(24); - rp_id_hash.append(253); - rp_id_hash.append(170); - rp_id_hash.append(126); - rp_id_hash.append(55); - rp_id_hash.append(232); - rp_id_hash.append(29); - rp_id_hash.append(141); - rp_id_hash.append(89); - rp_id_hash.append(87); - rp_id_hash.append(10); - rp_id_hash.append(255); - rp_id_hash.append(243); - rp_id_hash.append(80); - rp_id_hash.append(59); - rp_id_hash.append(59); - rp_id_hash.append(8); - rp_id_hash.append(99); - rp_id_hash.append(150); - rp_id_hash.append(7); - rp_id_hash.append(131); - rp_id_hash.append(162); - rp_id_hash.append(35); - rp_id_hash.append(174); - rp_id_hash.append(161); - rp_id_hash.append(82); - assert(ad.rp_id_hash == rp_id_hash, 'Expected equal! arrays'); -} - -#[test] -#[available_gas(200000000000)] -fn test_expand_auth_data_1() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(136); - auth_data.append(11); - auth_data.append(43); - auth_data.append(231); - auth_data.append(131); - auth_data.append(139); - auth_data.append(48); - auth_data.append(171); - auth_data.append(85); - auth_data.append(83); - auth_data.append(113); - auth_data.append(16); - auth_data.append(166); - auth_data.append(171); - auth_data.append(139); - auth_data.append(208); - auth_data.append(253); - auth_data.append(145); - auth_data.append(233); - auth_data.append(66); - auth_data.append(82); - auth_data.append(34); - auth_data.append(112); - auth_data.append(41); - auth_data.append(52); - auth_data.append(41); - auth_data.append(122); - auth_data.append(199); - auth_data.append(152); - auth_data.append(7); - auth_data.append(113); - auth_data.append(102); - auth_data.append(29); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(89); - let ad_o: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data); - let ad = ad_o.unwrap(); - assert(ad.sign_count == 89, 'Expected equal! count'); - assert(ad.flags == 29, 'Expected equal! flags'); - - let mut rp_id_hash: Array = ArrayTrait::new(); - rp_id_hash.append(136); - rp_id_hash.append(11); - rp_id_hash.append(43); - rp_id_hash.append(231); - rp_id_hash.append(131); - rp_id_hash.append(139); - rp_id_hash.append(48); - rp_id_hash.append(171); - rp_id_hash.append(85); - rp_id_hash.append(83); - rp_id_hash.append(113); - rp_id_hash.append(16); - rp_id_hash.append(166); - rp_id_hash.append(171); - rp_id_hash.append(139); - rp_id_hash.append(208); - rp_id_hash.append(253); - rp_id_hash.append(145); - rp_id_hash.append(233); - rp_id_hash.append(66); - rp_id_hash.append(82); - rp_id_hash.append(34); - rp_id_hash.append(112); - rp_id_hash.append(41); - rp_id_hash.append(52); - rp_id_hash.append(41); - rp_id_hash.append(122); - rp_id_hash.append(199); - rp_id_hash.append(152); - rp_id_hash.append(7); - rp_id_hash.append(113); - rp_id_hash.append(102); - assert(ad.rp_id_hash == rp_id_hash, 'Expected equal! arrays'); -} - -#[test] -#[available_gas(200000000000)] -fn test_expand_auth_data_2() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(136); - auth_data.append(11); - auth_data.append(43); - auth_data.append(231); - auth_data.append(131); - auth_data.append(139); - auth_data.append(48); - auth_data.append(171); - auth_data.append(85); - auth_data.append(83); - auth_data.append(113); - auth_data.append(16); - auth_data.append(166); - auth_data.append(171); - auth_data.append(139); - auth_data.append(208); - auth_data.append(253); - auth_data.append(145); - auth_data.append(233); - auth_data.append(66); - auth_data.append(82); - auth_data.append(34); - auth_data.append(112); - auth_data.append(41); - auth_data.append(52); - auth_data.append(41); - auth_data.append(122); - auth_data.append(199); - auth_data.append(152); - auth_data.append(7); - auth_data.append(113); - auth_data.append(102); - auth_data.append(5); - auth_data.append(0); - auth_data.append(16); - auth_data.append(0); - auth_data.append(0); - let ad_o: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data); - let ad = ad_o.unwrap(); - assert(ad.sign_count == 1048576, 'Expected equal! count'); - assert(ad.flags == 5, 'Expected equal! flags'); - - let mut rp_id_hash: Array = ArrayTrait::new(); - rp_id_hash.append(136); - rp_id_hash.append(11); - rp_id_hash.append(43); - rp_id_hash.append(231); - rp_id_hash.append(131); - rp_id_hash.append(139); - rp_id_hash.append(48); - rp_id_hash.append(171); - rp_id_hash.append(85); - rp_id_hash.append(83); - rp_id_hash.append(113); - rp_id_hash.append(16); - rp_id_hash.append(166); - rp_id_hash.append(171); - rp_id_hash.append(139); - rp_id_hash.append(208); - rp_id_hash.append(253); - rp_id_hash.append(145); - rp_id_hash.append(233); - rp_id_hash.append(66); - rp_id_hash.append(82); - rp_id_hash.append(34); - rp_id_hash.append(112); - rp_id_hash.append(41); - rp_id_hash.append(52); - rp_id_hash.append(41); - rp_id_hash.append(122); - rp_id_hash.append(199); - rp_id_hash.append(152); - rp_id_hash.append(7); - rp_id_hash.append(113); - rp_id_hash.append(102); - assert(ad.rp_id_hash == rp_id_hash, 'Expected equal! arrays'); -} - -#[test] -#[available_gas(200000000000)] -fn test_expand_auth_data_3() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(130); - auth_data.append(202); - auth_data.append(183); - auth_data.append(223); - auth_data.append(10); - auth_data.append(191); - auth_data.append(185); - auth_data.append(217); - auth_data.append(93); - auth_data.append(202); - auth_data.append(78); - auth_data.append(89); - auth_data.append(55); - auth_data.append(206); - auth_data.append(41); - auth_data.append(104); - auth_data.append(199); - auth_data.append(152); - auth_data.append(199); - auth_data.append(38); - auth_data.append(254); - auth_data.append(164); - auth_data.append(140); - auth_data.append(1); - auth_data.append(107); - auth_data.append(249); - auth_data.append(118); - auth_data.append(50); - auth_data.append(33); - auth_data.append(239); - auth_data.append(218); - auth_data.append(19); - auth_data.append(43); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(19); - let ad_o: Option = ImplArrayu8TryIntoAuthData::try_into(auth_data); - let ad = ad_o.unwrap(); - assert(ad.sign_count == 19, 'Expected equal! count'); - assert(ad.flags == 43, 'Expected equal! flags'); - - let mut rp_id_hash: Array = ArrayTrait::new(); - rp_id_hash.append(130); - rp_id_hash.append(202); - rp_id_hash.append(183); - rp_id_hash.append(223); - rp_id_hash.append(10); - rp_id_hash.append(191); - rp_id_hash.append(185); - rp_id_hash.append(217); - rp_id_hash.append(93); - rp_id_hash.append(202); - rp_id_hash.append(78); - rp_id_hash.append(89); - rp_id_hash.append(55); - rp_id_hash.append(206); - rp_id_hash.append(41); - rp_id_hash.append(104); - rp_id_hash.append(199); - rp_id_hash.append(152); - rp_id_hash.append(199); - rp_id_hash.append(38); - rp_id_hash.append(254); - rp_id_hash.append(164); - rp_id_hash.append(140); - rp_id_hash.append(1); - rp_id_hash.append(107); - rp_id_hash.append(249); - rp_id_hash.append(118); - rp_id_hash.append(50); - rp_id_hash.append(33); - rp_id_hash.append(239); - rp_id_hash.append(218); - rp_id_hash.append(19); - assert(ad.rp_id_hash == rp_id_hash, 'Expected equal! arrays'); -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_rp_id_0() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(199); - auth_data.append(133); - auth_data.append(107); - auth_data.append(211); - auth_data.append(38); - auth_data.append(106); - auth_data.append(24); - auth_data.append(253); - auth_data.append(170); - auth_data.append(126); - auth_data.append(55); - auth_data.append(232); - auth_data.append(29); - auth_data.append(141); - auth_data.append(89); - auth_data.append(87); - auth_data.append(10); - auth_data.append(255); - auth_data.append(243); - auth_data.append(80); - auth_data.append(59); - auth_data.append(59); - auth_data.append(8); - auth_data.append(99); - auth_data.append(150); - auth_data.append(7); - auth_data.append(131); - auth_data.append(162); - auth_data.append(35); - auth_data.append(174); - auth_data.append(161); - auth_data.append(82); - auth_data.append(21); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(13); - let mut rp_id: Array = ArrayTrait::new(); - rp_id.append(114); - rp_id.append(101); - rp_id.append(108); - rp_id.append(121); - rp_id.append(105); - rp_id.append(110); - rp_id.append(103); - rp_id.append(45); - rp_id.append(112); - rp_id.append(97); - rp_id.append(114); - rp_id.append(116); - rp_id.append(121); - rp_id.append(46); - rp_id.append(105); - rp_id.append(100); - expand_auth_data_and_verify_rp_id_hash(auth_data, rp_id).unwrap(); -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_rp_id_1() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(136); - auth_data.append(11); - auth_data.append(43); - auth_data.append(231); - auth_data.append(131); - auth_data.append(139); - auth_data.append(48); - auth_data.append(171); - auth_data.append(85); - auth_data.append(83); - auth_data.append(113); - auth_data.append(16); - auth_data.append(166); - auth_data.append(171); - auth_data.append(139); - auth_data.append(208); - auth_data.append(253); - auth_data.append(145); - auth_data.append(233); - auth_data.append(66); - auth_data.append(82); - auth_data.append(34); - auth_data.append(112); - auth_data.append(41); - auth_data.append(52); - auth_data.append(41); - auth_data.append(122); - auth_data.append(199); - auth_data.append(152); - auth_data.append(7); - auth_data.append(113); - auth_data.append(102); - auth_data.append(29); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(89); - let mut rp_id: Array = ArrayTrait::new(); - rp_id.append(103); - rp_id.append(111); - rp_id.append(103); - rp_id.append(105); - rp_id.append(101); - rp_id.append(108); - rp_id.append(46); - rp_id.append(115); - rp_id.append(114); - rp_id.append(111); - rp_id.append(103); - rp_id.append(105); - rp_id.append(101); - rp_id.append(108); - rp_id.append(46); - rp_id.append(112); - rp_id.append(108); - expand_auth_data_and_verify_rp_id_hash(auth_data, rp_id).unwrap(); -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_rp_id_2() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(136); - auth_data.append(11); - auth_data.append(43); - auth_data.append(231); - auth_data.append(131); - auth_data.append(139); - auth_data.append(48); - auth_data.append(171); - auth_data.append(85); - auth_data.append(83); - auth_data.append(113); - auth_data.append(16); - auth_data.append(166); - auth_data.append(171); - auth_data.append(139); - auth_data.append(208); - auth_data.append(253); - auth_data.append(145); - auth_data.append(233); - auth_data.append(66); - auth_data.append(82); - auth_data.append(34); - auth_data.append(112); - auth_data.append(41); - auth_data.append(52); - auth_data.append(41); - auth_data.append(122); - auth_data.append(199); - auth_data.append(152); - auth_data.append(7); - auth_data.append(113); - auth_data.append(102); - auth_data.append(5); - auth_data.append(0); - auth_data.append(16); - auth_data.append(0); - auth_data.append(0); - let mut rp_id: Array = ArrayTrait::new(); - rp_id.append(103); - rp_id.append(111); - rp_id.append(103); - rp_id.append(105); - rp_id.append(101); - rp_id.append(108); - rp_id.append(46); - rp_id.append(115); - rp_id.append(114); - rp_id.append(111); - rp_id.append(103); - rp_id.append(105); - rp_id.append(101); - rp_id.append(108); - rp_id.append(46); - rp_id.append(112); - rp_id.append(108); - expand_auth_data_and_verify_rp_id_hash(auth_data, rp_id).unwrap(); -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_rp_id_3() { - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(130); - auth_data.append(202); - auth_data.append(183); - auth_data.append(223); - auth_data.append(10); - auth_data.append(191); - auth_data.append(185); - auth_data.append(217); - auth_data.append(93); - auth_data.append(202); - auth_data.append(78); - auth_data.append(89); - auth_data.append(55); - auth_data.append(206); - auth_data.append(41); - auth_data.append(104); - auth_data.append(199); - auth_data.append(152); - auth_data.append(199); - auth_data.append(38); - auth_data.append(254); - auth_data.append(164); - auth_data.append(140); - auth_data.append(1); - auth_data.append(107); - auth_data.append(249); - auth_data.append(118); - auth_data.append(50); - auth_data.append(33); - auth_data.append(239); - auth_data.append(218); - auth_data.append(19); - auth_data.append(43); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(19); - let mut rp_id: Array = ArrayTrait::new(); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - rp_id.append(97); - expand_auth_data_and_verify_rp_id_hash(auth_data, rp_id).unwrap(); -} - diff --git a/crates/webauthn/auth/src/tests/helpers_gen_test.cairo b/crates/webauthn/auth/src/tests/helpers_gen_test.cairo deleted file mode 100644 index 7e04efa3..00000000 --- a/crates/webauthn/auth/src/tests/helpers_gen_test.cairo +++ /dev/null @@ -1,821 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/auth/helpers_test.py for details -use core::traits::Into; -use core::option::OptionTrait; -use core::array::ArrayTrait; -use webauthn_auth::helpers::extract_u256_from_u8_array; -use webauthn_auth::helpers::extract_r_and_s_from_array; - -#[test] -#[available_gas(200000000000)] -fn test_extract_0() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - assert(extract_u256_from_u8_array(@byte_repr, 0_usize).unwrap() == 0_u256, 'Expected equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_1() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - assert(extract_u256_from_u8_array(@byte_repr, 100_usize).unwrap() == 0_u256, 'Expected equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_2() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - assert( - extract_u256_from_u8_array(@byte_repr, 0_usize) - .unwrap() == 115792089237316195423570985008687907853269984665640564039457584007913129639935_u256, - 'Expected equal!' - ); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_3() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xfe); - assert( - extract_u256_from_u8_array(@byte_repr, 100_usize) - .unwrap() == 115792089237316195423570985008687907853269984665640564039457584007913129639934_u256, - 'Expected equal!' - ); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_4() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x1); - assert(extract_u256_from_u8_array(@byte_repr, 32_usize).unwrap() == 1_u256, 'Expected equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_r_s_0() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - let (r, s): (u256, u256) = extract_r_and_s_from_array(@byte_repr).unwrap(); - assert(r == 0, 'Expected r equal!'); - assert(s == 0, 'Expected s equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_r_s_1() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x64); - let (r, s): (u256, u256) = extract_r_and_s_from_array(@byte_repr).unwrap(); - assert(r == 0, 'Expected r equal!'); - assert(s == 100, 'Expected s equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_r_s_2() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - let (r, s): (u256, u256) = extract_r_and_s_from_array(@byte_repr).unwrap(); - assert( - r == 115792089237316195423570985008687907853269984665640564039457584007913129639935, - 'Expected r equal!' - ); - assert( - s == 115792089237316195423570985008687907853269984665640564039457584007913129639935, - 'Expected s equal!' - ); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_r_s_3() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xfe); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - byte_repr.append(0xff); - let (r, s): (u256, u256) = extract_r_and_s_from_array(@byte_repr).unwrap(); - assert( - r == 115792089237316195423570985008687907853269984665640564039457584007913129639934, - 'Expected r equal!' - ); - assert( - s == 115792089237316195423570985008687907853269984665640564039457584007913129639935, - 'Expected s equal!' - ); -} - -#[test] -#[available_gas(200000000000)] -fn test_extract_r_s_4() { - let mut byte_repr: Array = ArrayTrait::new(); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x1); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x0); - byte_repr.append(0x20); - let (r, s): (u256, u256) = extract_r_and_s_from_array(@byte_repr).unwrap(); - assert(r == 1, 'Expected r equal!'); - assert(s == 32, 'Expected s equal!'); -} - diff --git a/crates/webauthn/auth/src/tests/verify_ecdsa_gen_test.cairo b/crates/webauthn/auth/src/tests/verify_ecdsa_gen_test.cairo deleted file mode 100644 index b02c515e..00000000 --- a/crates/webauthn/auth/src/tests/verify_ecdsa_gen_test.cairo +++ /dev/null @@ -1,1684 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/auth/verify_ecdsa_test.py for details -use core::traits::Into; -use core::option::OptionTrait; -use webauthn_auth::ecdsa::{verify_ecdsa, verify_hashed_ecdsa, VerifyEcdsaError}; -use starknet::secp256r1::Secp256r1Impl; -use starknet::secp256r1::Secp256r1Point; -use starknet::SyscallResultTrait; -use core::array::ArrayTrait; - -#[test] -#[available_gas(200000000000)] -fn test_verify_ecdsa_short() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 104967586276524112165136420848571543889145022871617809227185613247970118558132, - 28809706358176254426074279673041700809583625420180899505741393676573453514447 - ) - .unwrap_syscall() - .unwrap(); - let r = 79364783178742134120913787145164583790566075005035662073306427443971593843265; - let s = 36313441733522294486110370329220969980572073931196577859562304402597565468050; - let msg = 49; - - match verify_hashed_ecdsa(pub_key, msg, r, s) { - Result::Ok => (), - Result::Err(m) => assert(false, m.into()) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_ecdsa() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 27237424464717925226734467403244825045764765679531526392809217560971234466358, - 82522091563855458175654860271914998673340069431892183237430309568312627552739 - ) - .unwrap_syscall() - .unwrap(); - let r = 79364783178742134120913787145164583790566075005035662073306427443971593843265; - let s = 65105624630169976359797824046269372454600670026490117407700846853616880704368; - let msg = 22405534230753928650781647905; - - match verify_hashed_ecdsa(pub_key, msg, r, s) { - Result::Ok => (), - Result::Err(m) => assert(false, m.into()) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_ecdsa_long() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 41333331735073650300404911283037366833232717073870890565279616601502493443927, - 14217282685076489745284362089110589799385184630260301771012776617852869168065 - ) - .unwrap_syscall() - .unwrap(); - let r = 79364783178742134120913787145164583790566075005035662073306427443971593843265; - let s = 112062922225078897814704333943366274156032662338331559714575580492472740723604; - let msg = 149135777980097582634002128993283245052269503470703527156581804847063441697; - - match verify_hashed_ecdsa(pub_key, msg, r, s) { - Result::Ok => (), - Result::Err(m) => assert(false, m.into()) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_ecdsa_wrong_arguments() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 45952810195398558920159698647156160642291199962841872162052852684325877694854, - 66386443636666670788260778608114221626042772088428690542544872035672363254822 - ) - .unwrap_syscall() - .unwrap(); - let r = 0; - let s = 0; - let msg = 6214289900658384436962189733492; - - match verify_hashed_ecdsa(pub_key, msg, r, s) { - Result::Ok => assert(false, 'Should Error!'), - Result::Err(m) => match m { - VerifyEcdsaError::WrongArgument => (), - VerifyEcdsaError::InvalidSignature => assert(false, 'Wrong Error!'), - VerifyEcdsaError::SyscallError => assert(false, 'Wrong Error!'), - } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_ecdsa_invalid_signature() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 114750935567617339149598951072303419259910290949386824116593044947197163717466, - 47872416276833956358490440574030618656134365248976030776883679107221494105601 - ) - .unwrap_syscall() - .unwrap(); - let r = 79364783178742134120913787145164583790566075005035662073306427443971593843265; - let s = 45538762814753548408808823150356737110699092986799905345547115567824474688226; - let msg = 111110000011111; - - match verify_hashed_ecdsa(pub_key, msg, r, s) { - Result::Ok => assert(false, 'Should Error!'), - Result::Err(m) => match m { - VerifyEcdsaError::WrongArgument => assert(false, 'Wrong Error!'), - VerifyEcdsaError::InvalidSignature => (), - VerifyEcdsaError::SyscallError => assert(false, 'Wrong Error!'), - } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_ecdsa_with_hash_0() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 114906017793844862128420241273315741583045397200227148829941799213154178196075, - 108734509218921878287967812543141597812935540186734684878405990000174143039071 - ) - .unwrap_syscall() - .unwrap(); - let r = 108993386922339555010294940194545771300856233334906688782821216646243612982338; - let s = 41172670282101844143990966509766938327352604244710833820927277701255268221780; - let mut msg: Array = ArrayTrait::new(); - msg.append(49); - - match verify_ecdsa(pub_key, msg, r, s) { - Result::Ok => (), - Result::Err(m) => assert(false, m.into()) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_ecdsa_with_hash_1() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 48174285237460894162152238330777686199724145865840043865633137687186890637301, - 38950671956891038298454792502239925043185519553196903450835607918954333441441 - ) - .unwrap_syscall() - .unwrap(); - let r = 97901390883848089689745938806699606428744049504215506391080054617968864254375; - let s = 23608271914464816668258320556234807388164003833367302916599108982636629535090; - let mut msg: Array = ArrayTrait::new(); - msg.append(72); - msg.append(101); - msg.append(108); - msg.append(108); - msg.append(111); - msg.append(32); - msg.append(87); - msg.append(111); - msg.append(114); - msg.append(108); - msg.append(100); - msg.append(33); - - match verify_ecdsa(pub_key, msg, r, s) { - Result::Ok => (), - Result::Err(m) => assert(false, m.into()) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_ecdsa_with_hash_2() { - let pub_key = Secp256r1Impl::secp256_ec_new_syscall( - 404844216656579887342799566333683034109782116281433269575396442665862513010, - 102679718498148086353801141039218240746270449740628270777190804045649534507109 - ) - .unwrap_syscall() - .unwrap(); - let r = 99982404968689791745691571317260244946777106445753726930121654924343190245808; - let s = 75104799203881911401770458838467736803209016854311036041180603238807679572632; - let mut msg: Array = ArrayTrait::new(); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(76); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(97); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(109); - msg.append(101); - msg.append(115); - msg.append(115); - msg.append(97); - msg.append(103); - msg.append(101); - msg.append(44); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - msg.append(32); - msg.append(113); - msg.append(117); - msg.append(105); - msg.append(116); - msg.append(101); - msg.append(32); - msg.append(108); - msg.append(111); - msg.append(110); - msg.append(103); - - match verify_ecdsa(pub_key, msg, r, s) { - Result::Ok => (), - Result::Err(m) => assert(false, m.into()) - } -} - diff --git a/crates/webauthn/auth/src/tests/verify_signature_gen_test.cairo b/crates/webauthn/auth/src/tests/verify_signature_gen_test.cairo deleted file mode 100644 index 30548225..00000000 --- a/crates/webauthn/auth/src/tests/verify_signature_gen_test.cairo +++ /dev/null @@ -1,1505 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/auth/verify_signature_test.py for details -use core::traits::Into; -use core::result::ResultTrait; -use core::option::OptionTrait; -use webauthn_auth::ecdsa::{verify_ecdsa, verify_hashed_ecdsa, VerifyEcdsaError}; -use webauthn_auth::types::PublicKey; -use webauthn_auth::webauthn::verify_signature; -use webauthn_auth::errors::AuthnErrorIntoFelt252; -use starknet::secp256r1::Secp256r1Impl; -use starknet::secp256r1::Secp256r1Point; -use starknet::SyscallResultTrait; -use core::array::ArrayTrait; - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_0() { - let mut hash: Array = ArrayTrait::new(); - hash.append(239); - hash.append(154); - hash.append(119); - hash.append(180); - hash.append(115); - hash.append(70); - hash.append(207); - hash.append(76); - hash.append(241); - hash.append(100); - hash.append(113); - hash.append(244); - hash.append(118); - hash.append(192); - hash.append(2); - hash.append(50); - hash.append(30); - hash.append(41); - hash.append(140); - hash.append(80); - hash.append(107); - hash.append(87); - hash.append(147); - hash.append(152); - hash.append(189); - hash.append(84); - hash.append(224); - hash.append(131); - hash.append(152); - hash.append(14); - hash.append(248); - hash.append(250); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(29); - auth_data.append(155); - auth_data.append(166); - auth_data.append(227); - auth_data.append(103); - auth_data.append(118); - auth_data.append(148); - auth_data.append(222); - auth_data.append(108); - auth_data.append(127); - auth_data.append(109); - auth_data.append(131); - auth_data.append(227); - auth_data.append(15); - auth_data.append(134); - auth_data.append(234); - auth_data.append(105); - auth_data.append(224); - auth_data.append(10); - auth_data.append(163); - auth_data.append(52); - auth_data.append(190); - auth_data.append(116); - auth_data.append(192); - auth_data.append(37); - auth_data.append(151); - auth_data.append(138); - auth_data.append(198); - auth_data.append(247); - auth_data.append(224); - auth_data.append(140); - auth_data.append(240); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(236); - sig.append(160); - sig.append(99); - sig.append(35); - sig.append(39); - sig.append(147); - sig.append(22); - sig.append(98); - sig.append(165); - sig.append(61); - sig.append(158); - sig.append(239); - sig.append(151); - sig.append(42); - sig.append(194); - sig.append(9); - sig.append(154); - sig.append(245); - sig.append(210); - sig.append(212); - sig.append(8); - sig.append(149); - sig.append(72); - sig.append(141); - sig.append(61); - sig.append(59); - sig.append(135); - sig.append(228); - sig.append(195); - sig.append(198); - sig.append(232); - sig.append(94); - sig.append(246); - sig.append(170); - sig.append(189); - sig.append(254); - sig.append(186); - sig.append(202); - sig.append(164); - sig.append(136); - sig.append(214); - sig.append(113); - sig.append(202); - sig.append(157); - sig.append(25); - sig.append(141); - sig.append(253); - sig.append(83); - sig.append(132); - sig.append(242); - sig.append(92); - sig.append(181); - sig.append(100); - sig.append(104); - sig.append(235); - sig.append(255); - sig.append(114); - sig.append(60); - sig.append(81); - sig.append(101); - sig.append(228); - sig.append(96); - sig.append(227); - sig.append(221); - let pk = PublicKey { - x: 18402001900564500889004704668336102227098588485669975709359617526132369465595, - y: 56315231545714385312866284337279074439496847607020809877028943275342675128637 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_1() { - let mut hash: Array = ArrayTrait::new(); - hash.append(213); - hash.append(253); - hash.append(63); - hash.append(128); - hash.append(70); - hash.append(120); - hash.append(88); - hash.append(158); - hash.append(174); - hash.append(116); - hash.append(74); - hash.append(114); - hash.append(214); - hash.append(165); - hash.append(168); - hash.append(66); - hash.append(109); - hash.append(199); - hash.append(90); - hash.append(105); - hash.append(240); - hash.append(14); - hash.append(125); - hash.append(60); - hash.append(138); - hash.append(72); - hash.append(64); - hash.append(58); - hash.append(176); - hash.append(84); - hash.append(223); - hash.append(235); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(118); - auth_data.append(91); - auth_data.append(180); - auth_data.append(178); - auth_data.append(54); - auth_data.append(58); - auth_data.append(196); - auth_data.append(61); - auth_data.append(15); - auth_data.append(41); - auth_data.append(147); - auth_data.append(51); - auth_data.append(236); - auth_data.append(174); - auth_data.append(21); - auth_data.append(101); - auth_data.append(249); - auth_data.append(172); - auth_data.append(228); - auth_data.append(10); - auth_data.append(110); - auth_data.append(52); - auth_data.append(165); - auth_data.append(52); - auth_data.append(104); - auth_data.append(15); - auth_data.append(244); - auth_data.append(217); - auth_data.append(134); - auth_data.append(168); - auth_data.append(84); - auth_data.append(20); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(34); - sig.append(25); - sig.append(38); - sig.append(89); - sig.append(165); - sig.append(254); - sig.append(105); - sig.append(254); - sig.append(147); - sig.append(154); - sig.append(166); - sig.append(34); - sig.append(190); - sig.append(222); - sig.append(63); - sig.append(235); - sig.append(46); - sig.append(105); - sig.append(183); - sig.append(203); - sig.append(132); - sig.append(114); - sig.append(242); - sig.append(185); - sig.append(53); - sig.append(103); - sig.append(78); - sig.append(213); - sig.append(11); - sig.append(109); - sig.append(195); - sig.append(110); - sig.append(21); - sig.append(189); - sig.append(33); - sig.append(60); - sig.append(245); - sig.append(204); - sig.append(199); - sig.append(136); - sig.append(205); - sig.append(114); - sig.append(181); - sig.append(28); - sig.append(140); - sig.append(118); - sig.append(90); - sig.append(146); - sig.append(127); - sig.append(116); - sig.append(87); - sig.append(51); - sig.append(201); - sig.append(180); - sig.append(98); - sig.append(237); - sig.append(92); - sig.append(13); - sig.append(215); - sig.append(38); - sig.append(209); - sig.append(21); - sig.append(134); - sig.append(102); - let pk = PublicKey { - x: 112797896264292481534431361613645043582257874001226283739794718177061038274421, - y: 71254303448759786391236781267253775396313759687154837559045155662916049626819 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_2() { - let mut hash: Array = ArrayTrait::new(); - hash.append(211); - hash.append(68); - hash.append(97); - hash.append(75); - hash.append(144); - hash.append(226); - hash.append(164); - hash.append(130); - hash.append(159); - hash.append(20); - hash.append(10); - hash.append(9); - hash.append(129); - hash.append(100); - hash.append(251); - hash.append(74); - hash.append(136); - hash.append(206); - hash.append(190); - hash.append(146); - hash.append(117); - hash.append(164); - hash.append(44); - hash.append(176); - hash.append(71); - hash.append(45); - hash.append(252); - hash.append(211); - hash.append(169); - hash.append(26); - hash.append(207); - hash.append(161); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(30); - auth_data.append(218); - auth_data.append(222); - auth_data.append(95); - auth_data.append(203); - auth_data.append(115); - auth_data.append(145); - auth_data.append(229); - auth_data.append(183); - auth_data.append(108); - auth_data.append(6); - auth_data.append(13); - auth_data.append(160); - auth_data.append(250); - auth_data.append(40); - auth_data.append(68); - auth_data.append(3); - auth_data.append(205); - auth_data.append(154); - auth_data.append(36); - auth_data.append(15); - auth_data.append(129); - auth_data.append(120); - auth_data.append(245); - auth_data.append(145); - auth_data.append(87); - auth_data.append(136); - auth_data.append(7); - auth_data.append(247); - auth_data.append(174); - auth_data.append(132); - auth_data.append(91); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(107); - sig.append(23); - sig.append(100); - sig.append(46); - sig.append(68); - sig.append(91); - sig.append(152); - sig.append(43); - sig.append(4); - sig.append(60); - sig.append(35); - sig.append(244); - sig.append(82); - sig.append(245); - sig.append(49); - sig.append(242); - sig.append(243); - sig.append(197); - sig.append(78); - sig.append(138); - sig.append(10); - sig.append(213); - sig.append(212); - sig.append(11); - sig.append(68); - sig.append(44); - sig.append(107); - sig.append(161); - sig.append(14); - sig.append(6); - sig.append(243); - sig.append(155); - sig.append(20); - sig.append(11); - sig.append(81); - sig.append(188); - sig.append(82); - sig.append(2); - sig.append(20); - sig.append(38); - sig.append(251); - sig.append(87); - sig.append(15); - sig.append(130); - sig.append(119); - sig.append(241); - sig.append(141); - sig.append(41); - sig.append(220); - sig.append(104); - sig.append(64); - sig.append(186); - sig.append(140); - sig.append(127); - sig.append(254); - sig.append(61); - sig.append(238); - sig.append(114); - sig.append(136); - sig.append(46); - sig.append(102); - sig.append(166); - sig.append(121); - sig.append(37); - let pk = PublicKey { - x: 51433912458511107164458704190198697145314552054458208226930830323647644118402, - y: 112403046405652821248888504113111252163791181090021947887817912033775374958572 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_3() { - let mut hash: Array = ArrayTrait::new(); - hash.append(25); - hash.append(59); - hash.append(103); - hash.append(164); - hash.append(218); - hash.append(33); - hash.append(223); - hash.append(167); - hash.append(153); - hash.append(187); - hash.append(94); - hash.append(235); - hash.append(246); - hash.append(253); - hash.append(11); - hash.append(164); - hash.append(124); - hash.append(17); - hash.append(229); - hash.append(119); - hash.append(120); - hash.append(211); - hash.append(213); - hash.append(48); - hash.append(227); - hash.append(132); - hash.append(123); - hash.append(105); - hash.append(68); - hash.append(90); - hash.append(220); - hash.append(91); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(144); - auth_data.append(245); - auth_data.append(182); - auth_data.append(50); - auth_data.append(226); - auth_data.append(177); - auth_data.append(115); - auth_data.append(221); - auth_data.append(160); - auth_data.append(154); - auth_data.append(221); - auth_data.append(223); - auth_data.append(136); - auth_data.append(126); - auth_data.append(6); - auth_data.append(90); - auth_data.append(69); - auth_data.append(131); - auth_data.append(130); - auth_data.append(132); - auth_data.append(71); - auth_data.append(160); - auth_data.append(54); - auth_data.append(137); - auth_data.append(118); - auth_data.append(44); - auth_data.append(130); - auth_data.append(218); - auth_data.append(222); - auth_data.append(59); - auth_data.append(180); - auth_data.append(41); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(129); - sig.append(94); - sig.append(151); - sig.append(76); - sig.append(123); - sig.append(16); - sig.append(86); - sig.append(162); - sig.append(147); - sig.append(119); - sig.append(223); - sig.append(219); - sig.append(201); - sig.append(120); - sig.append(116); - sig.append(201); - sig.append(131); - sig.append(185); - sig.append(246); - sig.append(210); - sig.append(119); - sig.append(97); - sig.append(65); - sig.append(68); - sig.append(27); - sig.append(228); - sig.append(233); - sig.append(92); - sig.append(130); - sig.append(58); - sig.append(39); - sig.append(146); - sig.append(154); - sig.append(138); - sig.append(143); - sig.append(191); - sig.append(114); - sig.append(46); - sig.append(90); - sig.append(66); - sig.append(127); - sig.append(170); - sig.append(87); - sig.append(213); - sig.append(146); - sig.append(76); - sig.append(167); - sig.append(145); - sig.append(206); - sig.append(62); - sig.append(166); - sig.append(201); - sig.append(165); - sig.append(101); - sig.append(29); - sig.append(150); - sig.append(251); - sig.append(174); - sig.append(101); - sig.append(208); - sig.append(41); - sig.append(14); - sig.append(89); - sig.append(93); - let pk = PublicKey { - x: 26655792660337593206437930429691368551299146009750983293670143519242799702553, - y: 87647649830268020426432082113220492680354126267818401024181802724337495711729 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_4() { - let mut hash: Array = ArrayTrait::new(); - hash.append(184); - hash.append(155); - hash.append(72); - hash.append(178); - hash.append(217); - hash.append(209); - hash.append(91); - hash.append(143); - hash.append(145); - hash.append(47); - hash.append(199); - hash.append(9); - hash.append(5); - hash.append(125); - hash.append(237); - hash.append(78); - hash.append(161); - hash.append(234); - hash.append(157); - hash.append(3); - hash.append(214); - hash.append(13); - hash.append(200); - hash.append(63); - hash.append(245); - hash.append(248); - hash.append(222); - hash.append(245); - hash.append(230); - hash.append(126); - hash.append(136); - hash.append(62); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(6); - auth_data.append(224); - auth_data.append(187); - auth_data.append(1); - auth_data.append(23); - auth_data.append(229); - auth_data.append(224); - auth_data.append(177); - auth_data.append(59); - auth_data.append(234); - auth_data.append(132); - auth_data.append(48); - auth_data.append(87); - auth_data.append(190); - auth_data.append(94); - auth_data.append(132); - auth_data.append(110); - auth_data.append(183); - auth_data.append(47); - auth_data.append(136); - auth_data.append(218); - auth_data.append(62); - auth_data.append(220); - auth_data.append(228); - auth_data.append(0); - auth_data.append(63); - auth_data.append(60); - auth_data.append(16); - auth_data.append(79); - auth_data.append(6); - auth_data.append(79); - auth_data.append(143); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(173); - sig.append(237); - sig.append(143); - sig.append(122); - sig.append(3); - sig.append(75); - sig.append(172); - sig.append(61); - sig.append(87); - sig.append(140); - sig.append(95); - sig.append(10); - sig.append(116); - sig.append(206); - sig.append(39); - sig.append(174); - sig.append(47); - sig.append(63); - sig.append(147); - sig.append(190); - sig.append(224); - sig.append(210); - sig.append(75); - sig.append(184); - sig.append(42); - sig.append(242); - sig.append(194); - sig.append(200); - sig.append(148); - sig.append(62); - sig.append(200); - sig.append(119); - sig.append(163); - sig.append(136); - sig.append(95); - sig.append(133); - sig.append(50); - sig.append(248); - sig.append(228); - sig.append(241); - sig.append(129); - sig.append(89); - sig.append(33); - sig.append(78); - sig.append(78); - sig.append(121); - sig.append(127); - sig.append(61); - sig.append(148); - sig.append(202); - sig.append(104); - sig.append(64); - sig.append(60); - sig.append(28); - sig.append(215); - sig.append(77); - sig.append(137); - sig.append(56); - sig.append(40); - sig.append(229); - sig.append(190); - sig.append(132); - sig.append(75); - sig.append(223); - let pk = PublicKey { - x: 47572600532379441151045920284709874249474522633466997383982335761970678959876, - y: 85305581203708391567186488089708763898401471937002945701110635066199442145291 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_5() { - let mut hash: Array = ArrayTrait::new(); - hash.append(123); - hash.append(173); - hash.append(255); - hash.append(118); - hash.append(82); - hash.append(169); - hash.append(125); - hash.append(30); - hash.append(79); - hash.append(61); - hash.append(109); - hash.append(82); - hash.append(85); - hash.append(213); - hash.append(92); - hash.append(136); - hash.append(167); - hash.append(248); - hash.append(117); - hash.append(31); - hash.append(40); - hash.append(86); - hash.append(56); - hash.append(52); - hash.append(142); - hash.append(148); - hash.append(110); - hash.append(62); - hash.append(154); - hash.append(8); - hash.append(217); - hash.append(252); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(245); - auth_data.append(85); - auth_data.append(121); - auth_data.append(79); - auth_data.append(232); - auth_data.append(35); - auth_data.append(240); - auth_data.append(146); - auth_data.append(136); - auth_data.append(158); - auth_data.append(123); - auth_data.append(25); - auth_data.append(176); - auth_data.append(171); - auth_data.append(37); - auth_data.append(187); - auth_data.append(203); - auth_data.append(228); - auth_data.append(202); - auth_data.append(70); - auth_data.append(71); - auth_data.append(139); - auth_data.append(50); - auth_data.append(10); - auth_data.append(28); - auth_data.append(247); - auth_data.append(36); - auth_data.append(44); - auth_data.append(164); - auth_data.append(58); - auth_data.append(128); - auth_data.append(52); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(161); - sig.append(170); - sig.append(135); - sig.append(198); - sig.append(123); - sig.append(226); - sig.append(89); - sig.append(194); - sig.append(104); - sig.append(118); - sig.append(99); - sig.append(87); - sig.append(19); - sig.append(71); - sig.append(122); - sig.append(120); - sig.append(215); - sig.append(191); - sig.append(105); - sig.append(49); - sig.append(42); - sig.append(109); - sig.append(27); - sig.append(171); - sig.append(46); - sig.append(57); - sig.append(130); - sig.append(206); - sig.append(130); - sig.append(131); - sig.append(248); - sig.append(140); - sig.append(182); - sig.append(101); - sig.append(227); - sig.append(20); - sig.append(90); - sig.append(3); - sig.append(136); - sig.append(149); - sig.append(211); - sig.append(110); - sig.append(202); - sig.append(192); - sig.append(157); - sig.append(119); - sig.append(224); - sig.append(55); - sig.append(96); - sig.append(12); - sig.append(194); - sig.append(78); - sig.append(123); - sig.append(164); - sig.append(197); - sig.append(195); - sig.append(29); - sig.append(201); - sig.append(255); - sig.append(194); - sig.append(116); - sig.append(45); - sig.append(85); - sig.append(58); - let pk = PublicKey { - x: 39578401308924283432437067501887348529389950866763012362525829892470443745454, - y: 78253439005499503492755414344006496144808387110494692382363936679841383828479 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_6() { - let mut hash: Array = ArrayTrait::new(); - hash.append(144); - hash.append(104); - hash.append(226); - hash.append(101); - hash.append(169); - hash.append(19); - hash.append(138); - hash.append(13); - hash.append(213); - hash.append(38); - hash.append(50); - hash.append(24); - hash.append(11); - hash.append(66); - hash.append(73); - hash.append(141); - hash.append(197); - hash.append(139); - hash.append(250); - hash.append(49); - hash.append(38); - hash.append(201); - hash.append(196); - hash.append(95); - hash.append(166); - hash.append(203); - hash.append(39); - hash.append(251); - hash.append(117); - hash.append(36); - hash.append(8); - hash.append(44); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(245); - auth_data.append(173); - auth_data.append(127); - auth_data.append(113); - auth_data.append(162); - auth_data.append(247); - auth_data.append(253); - auth_data.append(82); - auth_data.append(37); - auth_data.append(196); - auth_data.append(123); - auth_data.append(92); - auth_data.append(145); - auth_data.append(124); - auth_data.append(57); - auth_data.append(136); - auth_data.append(20); - auth_data.append(185); - auth_data.append(236); - auth_data.append(203); - auth_data.append(3); - auth_data.append(13); - auth_data.append(222); - auth_data.append(234); - auth_data.append(23); - auth_data.append(234); - auth_data.append(62); - auth_data.append(15); - auth_data.append(136); - auth_data.append(79); - auth_data.append(49); - auth_data.append(162); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(131); - sig.append(127); - sig.append(79); - sig.append(167); - sig.append(221); - sig.append(58); - sig.append(122); - sig.append(54); - sig.append(85); - sig.append(146); - sig.append(113); - sig.append(191); - sig.append(142); - sig.append(255); - sig.append(93); - sig.append(143); - sig.append(157); - sig.append(255); - sig.append(174); - sig.append(10); - sig.append(248); - sig.append(246); - sig.append(91); - sig.append(64); - sig.append(189); - sig.append(46); - sig.append(159); - sig.append(126); - sig.append(141); - sig.append(235); - sig.append(228); - sig.append(86); - sig.append(100); - sig.append(248); - sig.append(210); - sig.append(168); - sig.append(130); - sig.append(83); - sig.append(15); - sig.append(106); - sig.append(18); - sig.append(99); - sig.append(91); - sig.append(191); - sig.append(97); - sig.append(144); - sig.append(206); - sig.append(167); - sig.append(15); - sig.append(116); - sig.append(119); - sig.append(236); - sig.append(207); - sig.append(163); - sig.append(66); - sig.append(35); - sig.append(154); - sig.append(180); - sig.append(202); - sig.append(49); - sig.append(43); - sig.append(186); - sig.append(253); - sig.append(211); - let pk = PublicKey { - x: 67365681697757700628404517949260347494570105912034116860017275083225091294720, - y: 93925313539503161466451469350916731670456653279334430131251267841915015029278 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_7() { - let mut hash: Array = ArrayTrait::new(); - hash.append(178); - hash.append(77); - hash.append(5); - hash.append(232); - hash.append(60); - hash.append(191); - hash.append(57); - hash.append(208); - hash.append(225); - hash.append(53); - hash.append(112); - hash.append(144); - hash.append(76); - hash.append(246); - hash.append(108); - hash.append(73); - hash.append(195); - hash.append(120); - hash.append(86); - hash.append(98); - hash.append(172); - hash.append(187); - hash.append(14); - hash.append(19); - hash.append(210); - hash.append(86); - hash.append(98); - hash.append(158); - hash.append(217); - hash.append(57); - hash.append(210); - hash.append(63); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(35); - auth_data.append(215); - auth_data.append(144); - auth_data.append(78); - auth_data.append(38); - auth_data.append(83); - auth_data.append(144); - auth_data.append(23); - auth_data.append(153); - auth_data.append(63); - auth_data.append(29); - auth_data.append(88); - auth_data.append(68); - auth_data.append(27); - auth_data.append(145); - auth_data.append(225); - auth_data.append(237); - auth_data.append(187); - auth_data.append(127); - auth_data.append(59); - auth_data.append(70); - auth_data.append(96); - auth_data.append(7); - auth_data.append(218); - auth_data.append(60); - auth_data.append(224); - auth_data.append(93); - auth_data.append(141); - auth_data.append(239); - auth_data.append(24); - auth_data.append(144); - auth_data.append(107); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(98); - sig.append(253); - sig.append(196); - sig.append(51); - sig.append(116); - sig.append(93); - sig.append(22); - sig.append(65); - sig.append(22); - sig.append(248); - sig.append(105); - sig.append(100); - sig.append(77); - sig.append(144); - sig.append(82); - sig.append(176); - sig.append(95); - sig.append(59); - sig.append(22); - sig.append(192); - sig.append(8); - sig.append(93); - sig.append(11); - sig.append(192); - sig.append(31); - sig.append(0); - sig.append(140); - sig.append(242); - sig.append(191); - sig.append(35); - sig.append(111); - sig.append(250); - sig.append(140); - sig.append(18); - sig.append(143); - sig.append(119); - sig.append(24); - sig.append(89); - sig.append(71); - sig.append(221); - sig.append(40); - sig.append(230); - sig.append(180); - sig.append(235); - sig.append(56); - sig.append(237); - sig.append(144); - sig.append(157); - sig.append(60); - sig.append(49); - sig.append(202); - sig.append(76); - sig.append(18); - sig.append(153); - sig.append(118); - sig.append(211); - sig.append(28); - sig.append(167); - sig.append(17); - sig.append(120); - sig.append(92); - sig.append(53); - sig.append(85); - sig.append(49); - let pk = PublicKey { - x: 8224356367265768767057607377397261915465988419375715666541799790686347956240, - y: 75033738894578806783998461043031027362697173626033998447728546152702025758148 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_8() { - let mut hash: Array = ArrayTrait::new(); - hash.append(123); - hash.append(113); - hash.append(85); - hash.append(74); - hash.append(250); - hash.append(50); - hash.append(131); - hash.append(169); - hash.append(174); - hash.append(117); - hash.append(144); - hash.append(92); - hash.append(122); - hash.append(44); - hash.append(232); - hash.append(208); - hash.append(195); - hash.append(163); - hash.append(222); - hash.append(49); - hash.append(207); - hash.append(117); - hash.append(42); - hash.append(164); - hash.append(197); - hash.append(157); - hash.append(210); - hash.append(82); - hash.append(145); - hash.append(57); - hash.append(32); - hash.append(16); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(38); - auth_data.append(161); - auth_data.append(98); - auth_data.append(218); - auth_data.append(33); - auth_data.append(80); - auth_data.append(155); - auth_data.append(114); - auth_data.append(226); - auth_data.append(239); - auth_data.append(177); - auth_data.append(121); - auth_data.append(233); - auth_data.append(157); - auth_data.append(53); - auth_data.append(132); - auth_data.append(227); - auth_data.append(133); - auth_data.append(206); - auth_data.append(104); - auth_data.append(169); - auth_data.append(25); - auth_data.append(95); - auth_data.append(77); - auth_data.append(14); - auth_data.append(255); - auth_data.append(120); - auth_data.append(7); - auth_data.append(9); - auth_data.append(9); - auth_data.append(40); - auth_data.append(59); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(174); - sig.append(85); - sig.append(195); - sig.append(18); - sig.append(100); - sig.append(238); - sig.append(97); - sig.append(64); - sig.append(7); - sig.append(157); - sig.append(90); - sig.append(201); - sig.append(106); - sig.append(70); - sig.append(87); - sig.append(18); - sig.append(127); - sig.append(130); - sig.append(86); - sig.append(28); - sig.append(174); - sig.append(196); - sig.append(52); - sig.append(143); - sig.append(242); - sig.append(141); - sig.append(248); - sig.append(77); - sig.append(123); - sig.append(190); - sig.append(194); - sig.append(107); - sig.append(228); - sig.append(28); - sig.append(164); - sig.append(52); - sig.append(6); - sig.append(100); - sig.append(134); - sig.append(40); - sig.append(23); - sig.append(43); - sig.append(116); - sig.append(249); - sig.append(205); - sig.append(191); - sig.append(98); - sig.append(227); - sig.append(148); - sig.append(176); - sig.append(7); - sig.append(187); - sig.append(0); - sig.append(144); - sig.append(183); - sig.append(207); - sig.append(238); - sig.append(115); - sig.append(67); - sig.append(92); - sig.append(20); - sig.append(255); - sig.append(152); - sig.append(125); - let pk = PublicKey { - x: 9982668974529383302778758602941864963283087685644977679397133457725659362678, - y: 114869384173757787338829461233949046798368628089022310000877937680719146988237 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - -#[test] -#[available_gas(200000000000)] -fn test_verify_signature_9() { - let mut hash: Array = ArrayTrait::new(); - hash.append(45); - hash.append(137); - hash.append(242); - hash.append(63); - hash.append(129); - hash.append(155); - hash.append(19); - hash.append(219); - hash.append(172); - hash.append(203); - hash.append(176); - hash.append(90); - hash.append(86); - hash.append(6); - hash.append(73); - hash.append(120); - hash.append(217); - hash.append(110); - hash.append(110); - hash.append(216); - hash.append(26); - hash.append(224); - hash.append(240); - hash.append(179); - hash.append(94); - hash.append(167); - hash.append(170); - hash.append(200); - hash.append(180); - hash.append(101); - hash.append(197); - hash.append(187); - let mut auth_data: Array = ArrayTrait::new(); - auth_data.append(128); - auth_data.append(76); - auth_data.append(153); - auth_data.append(178); - auth_data.append(42); - auth_data.append(71); - auth_data.append(23); - auth_data.append(25); - auth_data.append(182); - auth_data.append(208); - auth_data.append(198); - auth_data.append(136); - auth_data.append(248); - auth_data.append(119); - auth_data.append(113); - auth_data.append(158); - auth_data.append(107); - auth_data.append(136); - auth_data.append(31); - auth_data.append(158); - auth_data.append(229); - auth_data.append(161); - auth_data.append(214); - auth_data.append(244); - auth_data.append(166); - auth_data.append(84); - auth_data.append(231); - auth_data.append(175); - auth_data.append(69); - auth_data.append(178); - auth_data.append(212); - auth_data.append(111); - auth_data.append(160); - auth_data.append(0); - auth_data.append(0); - auth_data.append(0); - auth_data.append(1); - let mut sig: Array = ArrayTrait::new(); - sig.append(157); - sig.append(38); - sig.append(66); - sig.append(221); - sig.append(15); - sig.append(100); - sig.append(35); - sig.append(159); - sig.append(48); - sig.append(208); - sig.append(236); - sig.append(166); - sig.append(237); - sig.append(159); - sig.append(196); - sig.append(189); - sig.append(180); - sig.append(97); - sig.append(168); - sig.append(48); - sig.append(145); - sig.append(97); - sig.append(163); - sig.append(233); - sig.append(225); - sig.append(4); - sig.append(195); - sig.append(165); - sig.append(15); - sig.append(29); - sig.append(84); - sig.append(151); - sig.append(77); - sig.append(97); - sig.append(74); - sig.append(2); - sig.append(61); - sig.append(4); - sig.append(150); - sig.append(222); - sig.append(128); - sig.append(117); - sig.append(140); - sig.append(151); - sig.append(235); - sig.append(181); - sig.append(18); - sig.append(58); - sig.append(34); - sig.append(166); - sig.append(206); - sig.append(174); - sig.append(81); - sig.append(101); - sig.append(251); - sig.append(86); - sig.append(192); - sig.append(127); - sig.append(33); - sig.append(223); - sig.append(123); - sig.append(95); - sig.append(92); - sig.append(42); - let pk = PublicKey { - x: 39174334694137262116319847864691620993131612292957985065736629505783469788732, - y: 86528844267632478584308498647954992010741347159791994455419023713380217581025 - }; - match verify_signature(hash, auth_data, pk, sig) { - Result::Ok => (), - Result::Err(e) => { assert(false, AuthnErrorIntoFelt252::into(e)) } - } -} - diff --git a/crates/webauthn/auth/src/tests/webauthn_gen_test.cairo b/crates/webauthn/auth/src/tests/webauthn_gen_test.cairo deleted file mode 100644 index 129d6cbb..00000000 --- a/crates/webauthn/auth/src/tests/webauthn_gen_test.cairo +++ /dev/null @@ -1,2332 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/auth/webauthn_test.py for details -use webauthn_auth::webauthn::verify; -use array::ArrayTrait; -use webauthn_auth::types::PublicKey; -use webauthn_auth::errors::AuthnErrorIntoFelt252; -use core::option::OptionTrait; -use core::result::ResultTrait; -use starknet::secp256r1::Secp256Trait; -use starknet::secp256r1::Secp256r1Point; - -#[test] -#[available_gas(200000000000)] -fn test_base_0() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 85361148225729824017625108732123897247053575672172763810522989717862412662042, - 34990362585894687818855246831758567645528911684717374214517047635026995605 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 75529856265189085717597548073817449083775048352765043385708233156408636830191; - let s: u256 = 82845566382340822813767408921328436369277471334456847186275564885436721176380; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(0); - challenge.append(177); - challenge.append(68); - challenge.append(201); - challenge.append(3); - challenge.append(196); - challenge.append(217); - challenge.append(176); - challenge.append(187); - challenge.append(93); - challenge.append(101); - challenge.append(38); - challenge.append(184); - challenge.append(202); - challenge.append(3); - challenge.append(56); - challenge.append(11); - challenge.append(130); - challenge.append(162); - challenge.append(130); - challenge.append(131); - challenge.append(86); - challenge.append(47); - challenge.append(152); - challenge.append(246); - challenge.append(241); - challenge.append(74); - challenge.append(34); - challenge.append(152); - challenge.append(5); - challenge.append(36); - challenge.append(99); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(65); - client_data_json.append(76); - client_data_json.append(70); - client_data_json.append(69); - client_data_json.append(121); - client_data_json.append(81); - client_data_json.append(80); - client_data_json.append(69); - client_data_json.append(50); - client_data_json.append(98); - client_data_json.append(67); - client_data_json.append(55); - client_data_json.append(88); - client_data_json.append(87); - client_data_json.append(85); - client_data_json.append(109); - client_data_json.append(117); - client_data_json.append(77); - client_data_json.append(111); - client_data_json.append(68); - client_data_json.append(79); - client_data_json.append(65); - client_data_json.append(117); - client_data_json.append(67); - client_data_json.append(111); - client_data_json.append(111); - client_data_json.append(75); - client_data_json.append(68); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(45); - client_data_json.append(89); - client_data_json.append(57); - client_data_json.append(118); - client_data_json.append(70); - client_data_json.append(75); - client_data_json.append(73); - client_data_json.append(112); - client_data_json.append(103); - client_data_json.append(70); - client_data_json.append(74); - client_data_json.append(71); - client_data_json.append(77); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(104); - client_data_json.append(116); - client_data_json.append(116); - client_data_json.append(112); - client_data_json.append(115); - client_data_json.append(58); - client_data_json.append(47); - client_data_json.append(47); - client_data_json.append(99); - client_data_json.append(111); - client_data_json.append(110); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(114); - client_data_json.append(45); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(116); - client_data_json.append(45); - client_data_json.append(116); - client_data_json.append(97); - client_data_json.append(114); - client_data_json.append(114); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(99); - client_data_json.append(101); - client_data_json.append(45); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(45); - client_data_json.append(49); - client_data_json.append(57); - client_data_json.append(53); - client_data_json.append(45); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(101); - client_data_json.append(100); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(116); - client_data_json.append(105); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(45); - client_data_json.append(114); - client_data_json.append(101); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(115); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(97); - client_data_json.append(116); - client_data_json.append(105); - client_data_json.append(111); - client_data_json.append(110); - client_data_json.append(45); - client_data_json.append(57); - client_data_json.append(55); - client_data_json.append(54); - client_data_json.append(54); - client_data_json.append(57); - client_data_json.append(55); - client_data_json.append(46); - client_data_json.append(112); - client_data_json.append(114); - client_data_json.append(101); - client_data_json.append(118); - client_data_json.append(105); - client_data_json.append(101); - client_data_json.append(119); - client_data_json.append(46); - client_data_json.append(99); - client_data_json.append(97); - client_data_json.append(114); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(100); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(103); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_invoke_0() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 12199958427972853078342900924373082655716152998831359676272227347648944852471, - 40838650441616864252057946687346584368660292489182225806979362323951322937810 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 4224912636517746297930360738386846214394232358661750834726272476578302034581; - let s: u256 = 114133872056729296473578296149289564274974794137806170048811309580668266750342; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(3); - challenge.append(25); - challenge.append(108); - challenge.append(60); - challenge.append(160); - challenge.append(117); - challenge.append(115); - challenge.append(155); - challenge.append(120); - challenge.append(71); - challenge.append(153); - challenge.append(82); - challenge.append(171); - challenge.append(151); - challenge.append(13); - challenge.append(61); - challenge.append(102); - challenge.append(34); - challenge.append(120); - challenge.append(7); - challenge.append(145); - challenge.append(84); - challenge.append(57); - challenge.append(247); - challenge.append(167); - challenge.append(0); - challenge.append(85); - challenge.append(96); - challenge.append(13); - challenge.append(69); - challenge.append(184); - challenge.append(241); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(65); - client_data_json.append(120); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(80); - client_data_json.append(75); - client_data_json.append(66); - client_data_json.append(49); - client_data_json.append(99); - client_data_json.append(53); - client_data_json.append(116); - client_data_json.append(52); - client_data_json.append(82); - client_data_json.append(53); - client_data_json.append(108); - client_data_json.append(83); - client_data_json.append(113); - client_data_json.append(53); - client_data_json.append(99); - client_data_json.append(78); - client_data_json.append(80); - client_data_json.append(87); - client_data_json.append(89); - client_data_json.append(105); - client_data_json.append(101); - client_data_json.append(65); - client_data_json.append(101); - client_data_json.append(82); - client_data_json.append(86); - client_data_json.append(68); - client_data_json.append(110); - client_data_json.append(51); - client_data_json.append(112); - client_data_json.append(119); - client_data_json.append(66); - client_data_json.append(86); - client_data_json.append(89); - client_data_json.append(65); - client_data_json.append(49); - client_data_json.append(70); - client_data_json.append(117); - client_data_json.append(80); - client_data_json.append(69); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(104); - client_data_json.append(116); - client_data_json.append(116); - client_data_json.append(112); - client_data_json.append(115); - client_data_json.append(58); - client_data_json.append(47); - client_data_json.append(47); - client_data_json.append(99); - client_data_json.append(111); - client_data_json.append(110); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(114); - client_data_json.append(46); - client_data_json.append(99); - client_data_json.append(97); - client_data_json.append(114); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(100); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(103); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(29); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_signer_0() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 106189252477060125234911311951425199174108390369899998556213294614894934259623, - 41661558292263448294840684426406611663196416084498931256280395639558515496388 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 87085027144277167349997172439294072006551608681077098757500174610102900608273; - let s: u256 = 2893425465637470339233778786442651774958115401665850823595662945206871086323; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(6); - challenge.append(58); - challenge.append(153); - challenge.append(157); - challenge.append(39); - challenge.append(33); - challenge.append(87); - challenge.append(210); - challenge.append(184); - challenge.append(177); - challenge.append(106); - challenge.append(213); - challenge.append(136); - challenge.append(44); - challenge.append(177); - challenge.append(9); - challenge.append(230); - challenge.append(56); - challenge.append(158); - challenge.append(56); - challenge.append(180); - challenge.append(165); - challenge.append(220); - challenge.append(108); - challenge.append(105); - challenge.append(207); - challenge.append(246); - challenge.append(245); - challenge.append(21); - challenge.append(226); - challenge.append(30); - challenge.append(31); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(66); - client_data_json.append(106); - client_data_json.append(113); - client_data_json.append(90); - client_data_json.append(110); - client_data_json.append(83); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(86); - client_data_json.append(57); - client_data_json.append(75); - client_data_json.append(52); - client_data_json.append(115); - client_data_json.append(87); - client_data_json.append(114); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(67); - client_data_json.append(121); - client_data_json.append(120); - client_data_json.append(67); - client_data_json.append(101); - client_data_json.append(89); - client_data_json.append(52); - client_data_json.append(110); - client_data_json.append(106); - client_data_json.append(105); - client_data_json.append(48); - client_data_json.append(112); - client_data_json.append(100); - client_data_json.append(120); - client_data_json.append(115); - client_data_json.append(97); - client_data_json.append(99); - client_data_json.append(95); - client_data_json.append(50); - client_data_json.append(57); - client_data_json.append(82); - client_data_json.append(88); - client_data_json.append(105); - client_data_json.append(72); - client_data_json.append(104); - client_data_json.append(56); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(104); - client_data_json.append(116); - client_data_json.append(116); - client_data_json.append(112); - client_data_json.append(115); - client_data_json.append(58); - client_data_json.append(47); - client_data_json.append(47); - client_data_json.append(99); - client_data_json.append(111); - client_data_json.append(110); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(114); - client_data_json.append(46); - client_data_json.append(99); - client_data_json.append(97); - client_data_json.append(114); - client_data_json.append(116); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(100); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(103); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_signer_1() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 96851743063263007738706913833786308759844038768142987956904443895054347767182, - 29540588794758527153860235661532078813296479645077711694824648860535355949170 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 55242741617847301706003397622588195416830206147881247818072131657302723541742; - let s: u256 = 25074483594504282885134314526801121711813390313388798862593296119600505916900; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(6); - challenge.append(58); - challenge.append(153); - challenge.append(157); - challenge.append(39); - challenge.append(33); - challenge.append(87); - challenge.append(210); - challenge.append(184); - challenge.append(177); - challenge.append(106); - challenge.append(213); - challenge.append(136); - challenge.append(44); - challenge.append(177); - challenge.append(9); - challenge.append(230); - challenge.append(56); - challenge.append(158); - challenge.append(56); - challenge.append(180); - challenge.append(165); - challenge.append(220); - challenge.append(108); - challenge.append(105); - challenge.append(207); - challenge.append(246); - challenge.append(245); - challenge.append(21); - challenge.append(226); - challenge.append(30); - challenge.append(31); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(66); - client_data_json.append(106); - client_data_json.append(113); - client_data_json.append(90); - client_data_json.append(110); - client_data_json.append(83); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(86); - client_data_json.append(57); - client_data_json.append(75); - client_data_json.append(52); - client_data_json.append(115); - client_data_json.append(87); - client_data_json.append(114); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(67); - client_data_json.append(121); - client_data_json.append(120); - client_data_json.append(67); - client_data_json.append(101); - client_data_json.append(89); - client_data_json.append(52); - client_data_json.append(110); - client_data_json.append(106); - client_data_json.append(105); - client_data_json.append(48); - client_data_json.append(112); - client_data_json.append(100); - client_data_json.append(120); - client_data_json.append(115); - client_data_json.append(97); - client_data_json.append(99); - client_data_json.append(95); - client_data_json.append(50); - client_data_json.append(57); - client_data_json.append(82); - client_data_json.append(88); - client_data_json.append(105); - client_data_json.append(72); - client_data_json.append(104); - client_data_json.append(56); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(97); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_signer_2() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 25774920860043301270711571298728266053843601948811713436024200312379975476251, - 69482522505710552321740643395256981436103363918803584937479364015454398353527 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 55652792103888387695825069220100478782517250037198391569168985227560159799679; - let s: u256 = 29170388488226020787704640345453971608481476390224222553010521095983797464907; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(6); - challenge.append(58); - challenge.append(153); - challenge.append(157); - challenge.append(39); - challenge.append(33); - challenge.append(87); - challenge.append(210); - challenge.append(184); - challenge.append(177); - challenge.append(106); - challenge.append(213); - challenge.append(136); - challenge.append(44); - challenge.append(177); - challenge.append(9); - challenge.append(230); - challenge.append(56); - challenge.append(158); - challenge.append(56); - challenge.append(180); - challenge.append(165); - challenge.append(220); - challenge.append(108); - challenge.append(105); - challenge.append(207); - challenge.append(246); - challenge.append(245); - challenge.append(21); - challenge.append(226); - challenge.append(30); - challenge.append(31); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(66); - client_data_json.append(106); - client_data_json.append(113); - client_data_json.append(90); - client_data_json.append(110); - client_data_json.append(83); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(86); - client_data_json.append(57); - client_data_json.append(75); - client_data_json.append(52); - client_data_json.append(115); - client_data_json.append(87); - client_data_json.append(114); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(67); - client_data_json.append(121); - client_data_json.append(120); - client_data_json.append(67); - client_data_json.append(101); - client_data_json.append(89); - client_data_json.append(52); - client_data_json.append(110); - client_data_json.append(106); - client_data_json.append(105); - client_data_json.append(48); - client_data_json.append(112); - client_data_json.append(100); - client_data_json.append(120); - client_data_json.append(115); - client_data_json.append(97); - client_data_json.append(99); - client_data_json.append(95); - client_data_json.append(50); - client_data_json.append(57); - client_data_json.append(82); - client_data_json.append(88); - client_data_json.append(105); - client_data_json.append(72); - client_data_json.append(104); - client_data_json.append(56); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_signer_3() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 103782073039005998480272228341674151719865826262135436817108640877507168515262, - 110421733025816405564298377809281211443300780470122229917344915075845056949847 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 53293063382632950957502493229120254600804204291685889604470839989156184543995; - let s: u256 = 103235316892093219243911839168471349589367108301135541996754679060911921781002; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(6); - challenge.append(58); - challenge.append(153); - challenge.append(157); - challenge.append(39); - challenge.append(33); - challenge.append(87); - challenge.append(210); - challenge.append(184); - challenge.append(177); - challenge.append(106); - challenge.append(213); - challenge.append(136); - challenge.append(44); - challenge.append(177); - challenge.append(9); - challenge.append(230); - challenge.append(56); - challenge.append(158); - challenge.append(56); - challenge.append(180); - challenge.append(165); - challenge.append(220); - challenge.append(108); - challenge.append(105); - challenge.append(207); - challenge.append(246); - challenge.append(245); - challenge.append(21); - challenge.append(226); - challenge.append(30); - challenge.append(31); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(66); - client_data_json.append(106); - client_data_json.append(113); - client_data_json.append(90); - client_data_json.append(110); - client_data_json.append(83); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(86); - client_data_json.append(57); - client_data_json.append(75); - client_data_json.append(52); - client_data_json.append(115); - client_data_json.append(87); - client_data_json.append(114); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(67); - client_data_json.append(121); - client_data_json.append(120); - client_data_json.append(67); - client_data_json.append(101); - client_data_json.append(89); - client_data_json.append(52); - client_data_json.append(110); - client_data_json.append(106); - client_data_json.append(105); - client_data_json.append(48); - client_data_json.append(112); - client_data_json.append(100); - client_data_json.append(120); - client_data_json.append(115); - client_data_json.append(97); - client_data_json.append(99); - client_data_json.append(95); - client_data_json.append(50); - client_data_json.append(57); - client_data_json.append(82); - client_data_json.append(88); - client_data_json.append(105); - client_data_json.append(72); - client_data_json.append(104); - client_data_json.append(56); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_signer_4() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 9824492985817915502939841643039607067090875739814860213476480124123868671451, - 57904430583802378906259669468394677538758927904640314864706197045252400660288 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 32583859991320738962480847594439764166175102957375063282825300983031099353926; - let s: u256 = 58139603410539280095256069225486472369088881730562573499249561068924397933055; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(6); - challenge.append(58); - challenge.append(153); - challenge.append(157); - challenge.append(39); - challenge.append(33); - challenge.append(87); - challenge.append(210); - challenge.append(184); - challenge.append(177); - challenge.append(106); - challenge.append(213); - challenge.append(136); - challenge.append(44); - challenge.append(177); - challenge.append(9); - challenge.append(230); - challenge.append(56); - challenge.append(158); - challenge.append(56); - challenge.append(180); - challenge.append(165); - challenge.append(220); - challenge.append(108); - challenge.append(105); - challenge.append(207); - challenge.append(246); - challenge.append(245); - challenge.append(21); - challenge.append(226); - challenge.append(30); - challenge.append(31); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(66); - client_data_json.append(106); - client_data_json.append(113); - client_data_json.append(90); - client_data_json.append(110); - client_data_json.append(83); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(86); - client_data_json.append(57); - client_data_json.append(75); - client_data_json.append(52); - client_data_json.append(115); - client_data_json.append(87); - client_data_json.append(114); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(67); - client_data_json.append(121); - client_data_json.append(120); - client_data_json.append(67); - client_data_json.append(101); - client_data_json.append(89); - client_data_json.append(52); - client_data_json.append(110); - client_data_json.append(106); - client_data_json.append(105); - client_data_json.append(48); - client_data_json.append(112); - client_data_json.append(100); - client_data_json.append(120); - client_data_json.append(115); - client_data_json.append(97); - client_data_json.append(99); - client_data_json.append(95); - client_data_json.append(50); - client_data_json.append(57); - client_data_json.append(82); - client_data_json.append(88); - client_data_json.append(105); - client_data_json.append(72); - client_data_json.append(104); - client_data_json.append(56); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - -#[test] -#[available_gas(200000000000)] -fn test_signer_5() { - let public_key_pt: Result> = Secp256Trait::secp256_ec_new_syscall( - 102899840237491218024726533604679744895589094142503267806969877639642499394955, - 81817755410816594170790450908055808309470077766923751980218287380144130073107 - ); - let public_key_pt: Secp256r1Point = public_key_pt.unwrap().unwrap(); - let r: u256 = 108410630390478502606835362430751399848206112566791906072574272120420374247354; - let s: u256 = 77120129140505682175103609270923435384646815918932327582748302233628874067854; - let type_offset = 9_usize; - let challenge_offset = 36; - let mut challenge = ArrayTrait::::new(); - challenge.append(6); - challenge.append(58); - challenge.append(153); - challenge.append(157); - challenge.append(39); - challenge.append(33); - challenge.append(87); - challenge.append(210); - challenge.append(184); - challenge.append(177); - challenge.append(106); - challenge.append(213); - challenge.append(136); - challenge.append(44); - challenge.append(177); - challenge.append(9); - challenge.append(230); - challenge.append(56); - challenge.append(158); - challenge.append(56); - challenge.append(180); - challenge.append(165); - challenge.append(220); - challenge.append(108); - challenge.append(105); - challenge.append(207); - challenge.append(246); - challenge.append(245); - challenge.append(21); - challenge.append(226); - challenge.append(30); - challenge.append(31); - - let origin_offset = 91; - let mut origin = ArrayTrait::::new(); - origin.append(0x68); - origin.append(0x74); - origin.append(0x74); - origin.append(0x70); - origin.append(0x73); - origin.append(0x3A); - origin.append(0x2F); - origin.append(0x2F); - origin.append(0x63); - origin.append(0x6F); - origin.append(0x6E); - origin.append(0x74); - origin.append(0x72); - origin.append(0x6F); - origin.append(0x6C); - origin.append(0x6C); - origin.append(0x65); - origin.append(0x72); - origin.append(0x2D); - origin.append(0x65); - origin.append(0x31); - origin.append(0x33); - origin.append(0x70); - origin.append(0x74); - origin.append(0x39); - origin.append(0x77); - origin.append(0x77); - origin.append(0x76); - origin.append(0x2E); - origin.append(0x70); - origin.append(0x72); - origin.append(0x65); - origin.append(0x76); - origin.append(0x69); - origin.append(0x65); - origin.append(0x77); - origin.append(0x2E); - origin.append(0x63); - origin.append(0x61); - origin.append(0x72); - origin.append(0x74); - origin.append(0x72); - origin.append(0x69); - origin.append(0x64); - origin.append(0x67); - origin.append(0x65); - origin.append(0x2E); - origin.append(0x67); - origin.append(0x67); - let mut client_data_json = ArrayTrait::::new(); - client_data_json.append(123); - client_data_json.append(34); - client_data_json.append(116); - client_data_json.append(121); - client_data_json.append(112); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(119); - client_data_json.append(101); - client_data_json.append(98); - client_data_json.append(97); - client_data_json.append(117); - client_data_json.append(116); - client_data_json.append(104); - client_data_json.append(110); - client_data_json.append(46); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(116); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(108); - client_data_json.append(101); - client_data_json.append(110); - client_data_json.append(103); - client_data_json.append(101); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(66); - client_data_json.append(106); - client_data_json.append(113); - client_data_json.append(90); - client_data_json.append(110); - client_data_json.append(83); - client_data_json.append(99); - client_data_json.append(104); - client_data_json.append(86); - client_data_json.append(57); - client_data_json.append(75); - client_data_json.append(52); - client_data_json.append(115); - client_data_json.append(87); - client_data_json.append(114); - client_data_json.append(86); - client_data_json.append(105); - client_data_json.append(67); - client_data_json.append(121); - client_data_json.append(120); - client_data_json.append(67); - client_data_json.append(101); - client_data_json.append(89); - client_data_json.append(52); - client_data_json.append(110); - client_data_json.append(106); - client_data_json.append(105); - client_data_json.append(48); - client_data_json.append(112); - client_data_json.append(100); - client_data_json.append(120); - client_data_json.append(115); - client_data_json.append(97); - client_data_json.append(99); - client_data_json.append(95); - client_data_json.append(50); - client_data_json.append(57); - client_data_json.append(82); - client_data_json.append(88); - client_data_json.append(105); - client_data_json.append(72); - client_data_json.append(104); - client_data_json.append(56); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(111); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(34); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(97); - client_data_json.append(34); - client_data_json.append(44); - client_data_json.append(34); - client_data_json.append(99); - client_data_json.append(114); - client_data_json.append(111); - client_data_json.append(115); - client_data_json.append(115); - client_data_json.append(79); - client_data_json.append(114); - client_data_json.append(105); - client_data_json.append(103); - client_data_json.append(105); - client_data_json.append(110); - client_data_json.append(34); - client_data_json.append(58); - client_data_json.append(102); - client_data_json.append(97); - client_data_json.append(108); - client_data_json.append(115); - client_data_json.append(101); - client_data_json.append(125); - - let mut authenticator_data = ArrayTrait::::new(); - authenticator_data.append(32); - authenticator_data.append(169); - authenticator_data.append(126); - authenticator_data.append(195); - authenticator_data.append(248); - authenticator_data.append(239); - authenticator_data.append(188); - authenticator_data.append(42); - authenticator_data.append(202); - authenticator_data.append(12); - authenticator_data.append(247); - authenticator_data.append(202); - authenticator_data.append(187); - authenticator_data.append(66); - authenticator_data.append(11); - authenticator_data.append(74); - authenticator_data.append(9); - authenticator_data.append(208); - authenticator_data.append(174); - authenticator_data.append(201); - authenticator_data.append(144); - authenticator_data.append(84); - authenticator_data.append(102); - authenticator_data.append(201); - authenticator_data.append(173); - authenticator_data.append(247); - authenticator_data.append(149); - authenticator_data.append(132); - authenticator_data.append(250); - authenticator_data.append(117); - authenticator_data.append(254); - authenticator_data.append(211); - authenticator_data.append(5); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - authenticator_data.append(0); - - let verify_result = verify( - public_key_pt, - r, - s, - type_offset, - challenge_offset, - origin_offset, - client_data_json, - challenge, - origin, - authenticator_data - ); - match verify_result { - Result::Ok => (), - Result::Err(e) => assert(false, AuthnErrorIntoFelt252::into(e)) - } -} - From c5ab07c42eb4ab2f71c435c8808f4d0eb56d0c01 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 15:24:20 +0000 Subject: [PATCH 31/43] remove session gen tests --- crates/webauthn/session/src/tests.cairo | 5 - .../src/tests/signature_gen_test.cairo | 2589 ----------------- .../src/tests/signature_proofs_gen_test.cairo | 669 ----- 3 files changed, 3263 deletions(-) delete mode 100644 crates/webauthn/session/src/tests/signature_gen_test.cairo delete mode 100644 crates/webauthn/session/src/tests/signature_proofs_gen_test.cairo diff --git a/crates/webauthn/session/src/tests.cairo b/crates/webauthn/session/src/tests.cairo index cb8c98db..0ff6179a 100644 --- a/crates/webauthn/session/src/tests.cairo +++ b/crates/webauthn/session/src/tests.cairo @@ -1,8 +1,3 @@ -// Place your code below auto generated tests' modules!!! -mod signature_proofs_gen_test; -// mod signature_gen_test; -// ^^^ Auto generated tests ^^^ Place your code below this line!!! - mod signature_deserialization; diff --git a/crates/webauthn/session/src/tests/signature_gen_test.cairo b/crates/webauthn/session/src/tests/signature_gen_test.cairo deleted file mode 100644 index e57a47ec..00000000 --- a/crates/webauthn/session/src/tests/signature_gen_test.cairo +++ /dev/null @@ -1,2589 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/session/signature_test.py for details -use core::traits::Into; -use core::option::OptionTrait; -use array::ArrayTrait; -use webauthn_session::signature::FeltSpanTryIntoSignature; -use webauthn_session::signature::ImplSignatureProofs; - -#[test] -#[available_gas(200000000000)] -fn test_span_into_signature_small() { - let mut sig: Array = ArrayTrait::new(); - sig.append(0); - sig.append(1830); - sig.append(1863); - sig.append(1918); - sig.append(1694114435); - sig.append(1922); - sig.append(3); - sig.append(6); - sig.append(0); - sig.append(100); - sig.append(200); - sig.append(300); - sig.append(400); - sig.append(500); - sig.append(5); - sig.append(2000); - sig.append(2001); - sig.append(2002); - sig.append(2003); - sig.append(2004); - let mut proofs: Array = ArrayTrait::new(); - proofs.append(0); - proofs.append(100); - proofs.append(200); - proofs.append(300); - proofs.append(400); - proofs.append(500); - let mut session_token: Array = ArrayTrait::new(); - session_token.append(2000); - session_token.append(2001); - session_token.append(2002); - session_token.append(2003); - session_token.append(2004); - let sig = FeltSpanTryIntoSignature::try_into(sig.span()).unwrap(); - assert(1830 == sig.r, 'Expect equal!'); - assert(1863 == sig.s, 'Expect equal!'); - assert(1918 == sig.session_key, 'Expect equal!'); - assert(1922 == sig.root, 'Expect equal!'); - assert(2 == sig.proofs.len(), 'Expect equal!'); - assert(5 == sig.session_token.len(), 'Expect equal!'); - assert(500 == *sig.proofs.at(1).at(2), 'Expect equal!'); - assert(2004 == *sig.session_token.at(4), 'Expect equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_span_into_signature_medium() { - let mut sig: Array = ArrayTrait::new(); - sig.append(0); - sig.append(1830); - sig.append(1863); - sig.append(1918); - sig.append(1694114435); - sig.append(1922); - sig.append(10); - sig.append(100); - sig.append(0); - sig.append(100); - sig.append(200); - sig.append(300); - sig.append(400); - sig.append(500); - sig.append(600); - sig.append(700); - sig.append(800); - sig.append(900); - sig.append(1000); - sig.append(1100); - sig.append(1200); - sig.append(1300); - sig.append(1400); - sig.append(1500); - sig.append(1600); - sig.append(1700); - sig.append(1800); - sig.append(1900); - sig.append(2000); - sig.append(2100); - sig.append(2200); - sig.append(2300); - sig.append(2400); - sig.append(2500); - sig.append(2600); - sig.append(2700); - sig.append(2800); - sig.append(2900); - sig.append(3000); - sig.append(3100); - sig.append(3200); - sig.append(3300); - sig.append(3400); - sig.append(3500); - sig.append(3600); - sig.append(3700); - sig.append(3800); - sig.append(3900); - sig.append(4000); - sig.append(4100); - sig.append(4200); - sig.append(4300); - sig.append(4400); - sig.append(4500); - sig.append(4600); - sig.append(4700); - sig.append(4800); - sig.append(4900); - sig.append(5000); - sig.append(5100); - sig.append(5200); - sig.append(5300); - sig.append(5400); - sig.append(5500); - sig.append(5600); - sig.append(5700); - sig.append(5800); - sig.append(5900); - sig.append(6000); - sig.append(6100); - sig.append(6200); - sig.append(6300); - sig.append(6400); - sig.append(6500); - sig.append(6600); - sig.append(6700); - sig.append(6800); - sig.append(6900); - sig.append(7000); - sig.append(7100); - sig.append(7200); - sig.append(7300); - sig.append(7400); - sig.append(7500); - sig.append(7600); - sig.append(7700); - sig.append(7800); - sig.append(7900); - sig.append(8000); - sig.append(8100); - sig.append(8200); - sig.append(8300); - sig.append(8400); - sig.append(8500); - sig.append(8600); - sig.append(8700); - sig.append(8800); - sig.append(8900); - sig.append(9000); - sig.append(9100); - sig.append(9200); - sig.append(9300); - sig.append(9400); - sig.append(9500); - sig.append(9600); - sig.append(9700); - sig.append(9800); - sig.append(9900); - sig.append(40); - sig.append(2000); - sig.append(2001); - sig.append(2002); - sig.append(2003); - sig.append(2004); - sig.append(2005); - sig.append(2006); - sig.append(2007); - sig.append(2008); - sig.append(2009); - sig.append(2010); - sig.append(2011); - sig.append(2012); - sig.append(2013); - sig.append(2014); - sig.append(2015); - sig.append(2016); - sig.append(2017); - sig.append(2018); - sig.append(2019); - sig.append(2020); - sig.append(2021); - sig.append(2022); - sig.append(2023); - sig.append(2024); - sig.append(2025); - sig.append(2026); - sig.append(2027); - sig.append(2028); - sig.append(2029); - sig.append(2030); - sig.append(2031); - sig.append(2032); - sig.append(2033); - sig.append(2034); - sig.append(2035); - sig.append(2036); - sig.append(2037); - sig.append(2038); - sig.append(2039); - let mut proofs: Array = ArrayTrait::new(); - proofs.append(0); - proofs.append(100); - proofs.append(200); - proofs.append(300); - proofs.append(400); - proofs.append(500); - proofs.append(600); - proofs.append(700); - proofs.append(800); - proofs.append(900); - proofs.append(1000); - proofs.append(1100); - proofs.append(1200); - proofs.append(1300); - proofs.append(1400); - proofs.append(1500); - proofs.append(1600); - proofs.append(1700); - proofs.append(1800); - proofs.append(1900); - proofs.append(2000); - proofs.append(2100); - proofs.append(2200); - proofs.append(2300); - proofs.append(2400); - proofs.append(2500); - proofs.append(2600); - proofs.append(2700); - proofs.append(2800); - proofs.append(2900); - proofs.append(3000); - proofs.append(3100); - proofs.append(3200); - proofs.append(3300); - proofs.append(3400); - proofs.append(3500); - proofs.append(3600); - proofs.append(3700); - proofs.append(3800); - proofs.append(3900); - proofs.append(4000); - proofs.append(4100); - proofs.append(4200); - proofs.append(4300); - proofs.append(4400); - proofs.append(4500); - proofs.append(4600); - proofs.append(4700); - proofs.append(4800); - proofs.append(4900); - proofs.append(5000); - proofs.append(5100); - proofs.append(5200); - proofs.append(5300); - proofs.append(5400); - proofs.append(5500); - proofs.append(5600); - proofs.append(5700); - proofs.append(5800); - proofs.append(5900); - proofs.append(6000); - proofs.append(6100); - proofs.append(6200); - proofs.append(6300); - proofs.append(6400); - proofs.append(6500); - proofs.append(6600); - proofs.append(6700); - proofs.append(6800); - proofs.append(6900); - proofs.append(7000); - proofs.append(7100); - proofs.append(7200); - proofs.append(7300); - proofs.append(7400); - proofs.append(7500); - proofs.append(7600); - proofs.append(7700); - proofs.append(7800); - proofs.append(7900); - proofs.append(8000); - proofs.append(8100); - proofs.append(8200); - proofs.append(8300); - proofs.append(8400); - proofs.append(8500); - proofs.append(8600); - proofs.append(8700); - proofs.append(8800); - proofs.append(8900); - proofs.append(9000); - proofs.append(9100); - proofs.append(9200); - proofs.append(9300); - proofs.append(9400); - proofs.append(9500); - proofs.append(9600); - proofs.append(9700); - proofs.append(9800); - proofs.append(9900); - let mut session_token: Array = ArrayTrait::new(); - session_token.append(2000); - session_token.append(2001); - session_token.append(2002); - session_token.append(2003); - session_token.append(2004); - session_token.append(2005); - session_token.append(2006); - session_token.append(2007); - session_token.append(2008); - session_token.append(2009); - session_token.append(2010); - session_token.append(2011); - session_token.append(2012); - session_token.append(2013); - session_token.append(2014); - session_token.append(2015); - session_token.append(2016); - session_token.append(2017); - session_token.append(2018); - session_token.append(2019); - session_token.append(2020); - session_token.append(2021); - session_token.append(2022); - session_token.append(2023); - session_token.append(2024); - session_token.append(2025); - session_token.append(2026); - session_token.append(2027); - session_token.append(2028); - session_token.append(2029); - session_token.append(2030); - session_token.append(2031); - session_token.append(2032); - session_token.append(2033); - session_token.append(2034); - session_token.append(2035); - session_token.append(2036); - session_token.append(2037); - session_token.append(2038); - session_token.append(2039); - let sig = FeltSpanTryIntoSignature::try_into(sig.span()).unwrap(); - assert(1830 == sig.r, 'Expect equal!'); - assert(1863 == sig.s, 'Expect equal!'); - assert(1918 == sig.session_key, 'Expect equal!'); - assert(1922 == sig.root, 'Expect equal!'); - assert(10 == sig.proofs.len(), 'Expect equal!'); - assert(40 == sig.session_token.len(), 'Expect equal!'); - assert(9900 == *sig.proofs.at(9).at(9), 'Expect equal!'); - assert(2039 == *sig.session_token.at(39), 'Expect equal!'); -} - -#[test] -#[available_gas(200000000000)] -fn test_span_into_signature_large() { - let mut sig: Array = ArrayTrait::new(); - sig.append(0); - sig.append(1830); - sig.append(1863); - sig.append(1918); - sig.append(1694114435); - sig.append(1922); - sig.append(10); - sig.append(1000); - sig.append(0); - sig.append(100); - sig.append(200); - sig.append(300); - sig.append(400); - sig.append(500); - sig.append(600); - sig.append(700); - sig.append(800); - sig.append(900); - sig.append(1000); - sig.append(1100); - sig.append(1200); - sig.append(1300); - sig.append(1400); - sig.append(1500); - sig.append(1600); - sig.append(1700); - sig.append(1800); - sig.append(1900); - sig.append(2000); - sig.append(2100); - sig.append(2200); - sig.append(2300); - sig.append(2400); - sig.append(2500); - sig.append(2600); - sig.append(2700); - sig.append(2800); - sig.append(2900); - sig.append(3000); - sig.append(3100); - sig.append(3200); - sig.append(3300); - sig.append(3400); - sig.append(3500); - sig.append(3600); - sig.append(3700); - sig.append(3800); - sig.append(3900); - sig.append(4000); - sig.append(4100); - sig.append(4200); - sig.append(4300); - sig.append(4400); - sig.append(4500); - sig.append(4600); - sig.append(4700); - sig.append(4800); - sig.append(4900); - sig.append(5000); - sig.append(5100); - sig.append(5200); - sig.append(5300); - sig.append(5400); - sig.append(5500); - sig.append(5600); - sig.append(5700); - sig.append(5800); - sig.append(5900); - sig.append(6000); - sig.append(6100); - sig.append(6200); - sig.append(6300); - sig.append(6400); - sig.append(6500); - sig.append(6600); - sig.append(6700); - sig.append(6800); - sig.append(6900); - sig.append(7000); - sig.append(7100); - sig.append(7200); - sig.append(7300); - sig.append(7400); - sig.append(7500); - sig.append(7600); - sig.append(7700); - sig.append(7800); - sig.append(7900); - sig.append(8000); - sig.append(8100); - sig.append(8200); - sig.append(8300); - sig.append(8400); - sig.append(8500); - sig.append(8600); - sig.append(8700); - sig.append(8800); - sig.append(8900); - sig.append(9000); - sig.append(9100); - sig.append(9200); - sig.append(9300); - sig.append(9400); - sig.append(9500); - sig.append(9600); - sig.append(9700); - sig.append(9800); - sig.append(9900); - sig.append(10000); - sig.append(10100); - sig.append(10200); - sig.append(10300); - sig.append(10400); - sig.append(10500); - sig.append(10600); - sig.append(10700); - sig.append(10800); - sig.append(10900); - sig.append(11000); - sig.append(11100); - sig.append(11200); - sig.append(11300); - sig.append(11400); - sig.append(11500); - sig.append(11600); - sig.append(11700); - sig.append(11800); - sig.append(11900); - sig.append(12000); - sig.append(12100); - sig.append(12200); - sig.append(12300); - sig.append(12400); - sig.append(12500); - sig.append(12600); - sig.append(12700); - sig.append(12800); - sig.append(12900); - sig.append(13000); - sig.append(13100); - sig.append(13200); - sig.append(13300); - sig.append(13400); - sig.append(13500); - sig.append(13600); - sig.append(13700); - sig.append(13800); - sig.append(13900); - sig.append(14000); - sig.append(14100); - sig.append(14200); - sig.append(14300); - sig.append(14400); - sig.append(14500); - sig.append(14600); - sig.append(14700); - sig.append(14800); - sig.append(14900); - sig.append(15000); - sig.append(15100); - sig.append(15200); - sig.append(15300); - sig.append(15400); - sig.append(15500); - sig.append(15600); - sig.append(15700); - sig.append(15800); - sig.append(15900); - sig.append(16000); - sig.append(16100); - sig.append(16200); - sig.append(16300); - sig.append(16400); - sig.append(16500); - sig.append(16600); - sig.append(16700); - sig.append(16800); - sig.append(16900); - sig.append(17000); - sig.append(17100); - sig.append(17200); - sig.append(17300); - sig.append(17400); - sig.append(17500); - sig.append(17600); - sig.append(17700); - sig.append(17800); - sig.append(17900); - sig.append(18000); - sig.append(18100); - sig.append(18200); - sig.append(18300); - sig.append(18400); - sig.append(18500); - sig.append(18600); - sig.append(18700); - sig.append(18800); - sig.append(18900); - sig.append(19000); - sig.append(19100); - sig.append(19200); - sig.append(19300); - sig.append(19400); - sig.append(19500); - sig.append(19600); - sig.append(19700); - sig.append(19800); - sig.append(19900); - sig.append(20000); - sig.append(20100); - sig.append(20200); - sig.append(20300); - sig.append(20400); - sig.append(20500); - sig.append(20600); - sig.append(20700); - sig.append(20800); - sig.append(20900); - sig.append(21000); - sig.append(21100); - sig.append(21200); - sig.append(21300); - sig.append(21400); - sig.append(21500); - sig.append(21600); - sig.append(21700); - sig.append(21800); - sig.append(21900); - sig.append(22000); - sig.append(22100); - sig.append(22200); - sig.append(22300); - sig.append(22400); - sig.append(22500); - sig.append(22600); - sig.append(22700); - sig.append(22800); - sig.append(22900); - sig.append(23000); - sig.append(23100); - sig.append(23200); - sig.append(23300); - sig.append(23400); - sig.append(23500); - sig.append(23600); - sig.append(23700); - sig.append(23800); - sig.append(23900); - sig.append(24000); - sig.append(24100); - sig.append(24200); - sig.append(24300); - sig.append(24400); - sig.append(24500); - sig.append(24600); - sig.append(24700); - sig.append(24800); - sig.append(24900); - sig.append(25000); - sig.append(25100); - sig.append(25200); - sig.append(25300); - sig.append(25400); - sig.append(25500); - sig.append(25600); - sig.append(25700); - sig.append(25800); - sig.append(25900); - sig.append(26000); - sig.append(26100); - sig.append(26200); - sig.append(26300); - sig.append(26400); - sig.append(26500); - sig.append(26600); - sig.append(26700); - sig.append(26800); - sig.append(26900); - sig.append(27000); - sig.append(27100); - sig.append(27200); - sig.append(27300); - sig.append(27400); - sig.append(27500); - sig.append(27600); - sig.append(27700); - sig.append(27800); - sig.append(27900); - sig.append(28000); - sig.append(28100); - sig.append(28200); - sig.append(28300); - sig.append(28400); - sig.append(28500); - sig.append(28600); - sig.append(28700); - sig.append(28800); - sig.append(28900); - sig.append(29000); - sig.append(29100); - sig.append(29200); - sig.append(29300); - sig.append(29400); - sig.append(29500); - sig.append(29600); - sig.append(29700); - sig.append(29800); - sig.append(29900); - sig.append(30000); - sig.append(30100); - sig.append(30200); - sig.append(30300); - sig.append(30400); - sig.append(30500); - sig.append(30600); - sig.append(30700); - sig.append(30800); - sig.append(30900); - sig.append(31000); - sig.append(31100); - sig.append(31200); - sig.append(31300); - sig.append(31400); - sig.append(31500); - sig.append(31600); - sig.append(31700); - sig.append(31800); - sig.append(31900); - sig.append(32000); - sig.append(32100); - sig.append(32200); - sig.append(32300); - sig.append(32400); - sig.append(32500); - sig.append(32600); - sig.append(32700); - sig.append(32800); - sig.append(32900); - sig.append(33000); - sig.append(33100); - sig.append(33200); - sig.append(33300); - sig.append(33400); - sig.append(33500); - sig.append(33600); - sig.append(33700); - sig.append(33800); - sig.append(33900); - sig.append(34000); - sig.append(34100); - sig.append(34200); - sig.append(34300); - sig.append(34400); - sig.append(34500); - sig.append(34600); - sig.append(34700); - sig.append(34800); - sig.append(34900); - sig.append(35000); - sig.append(35100); - sig.append(35200); - sig.append(35300); - sig.append(35400); - sig.append(35500); - sig.append(35600); - sig.append(35700); - sig.append(35800); - sig.append(35900); - sig.append(36000); - sig.append(36100); - sig.append(36200); - sig.append(36300); - sig.append(36400); - sig.append(36500); - sig.append(36600); - sig.append(36700); - sig.append(36800); - sig.append(36900); - sig.append(37000); - sig.append(37100); - sig.append(37200); - sig.append(37300); - sig.append(37400); - sig.append(37500); - sig.append(37600); - sig.append(37700); - sig.append(37800); - sig.append(37900); - sig.append(38000); - sig.append(38100); - sig.append(38200); - sig.append(38300); - sig.append(38400); - sig.append(38500); - sig.append(38600); - sig.append(38700); - sig.append(38800); - sig.append(38900); - sig.append(39000); - sig.append(39100); - sig.append(39200); - sig.append(39300); - sig.append(39400); - sig.append(39500); - sig.append(39600); - sig.append(39700); - sig.append(39800); - sig.append(39900); - sig.append(40000); - sig.append(40100); - sig.append(40200); - sig.append(40300); - sig.append(40400); - sig.append(40500); - sig.append(40600); - sig.append(40700); - sig.append(40800); - sig.append(40900); - sig.append(41000); - sig.append(41100); - sig.append(41200); - sig.append(41300); - sig.append(41400); - sig.append(41500); - sig.append(41600); - sig.append(41700); - sig.append(41800); - sig.append(41900); - sig.append(42000); - sig.append(42100); - sig.append(42200); - sig.append(42300); - sig.append(42400); - sig.append(42500); - sig.append(42600); - sig.append(42700); - sig.append(42800); - sig.append(42900); - sig.append(43000); - sig.append(43100); - sig.append(43200); - sig.append(43300); - sig.append(43400); - sig.append(43500); - sig.append(43600); - sig.append(43700); - sig.append(43800); - sig.append(43900); - sig.append(44000); - sig.append(44100); - sig.append(44200); - sig.append(44300); - sig.append(44400); - sig.append(44500); - sig.append(44600); - sig.append(44700); - sig.append(44800); - sig.append(44900); - sig.append(45000); - sig.append(45100); - sig.append(45200); - sig.append(45300); - sig.append(45400); - sig.append(45500); - sig.append(45600); - sig.append(45700); - sig.append(45800); - sig.append(45900); - sig.append(46000); - sig.append(46100); - sig.append(46200); - sig.append(46300); - sig.append(46400); - sig.append(46500); - sig.append(46600); - sig.append(46700); - sig.append(46800); - sig.append(46900); - sig.append(47000); - sig.append(47100); - sig.append(47200); - sig.append(47300); - sig.append(47400); - sig.append(47500); - sig.append(47600); - sig.append(47700); - sig.append(47800); - sig.append(47900); - sig.append(48000); - sig.append(48100); - sig.append(48200); - sig.append(48300); - sig.append(48400); - sig.append(48500); - sig.append(48600); - sig.append(48700); - sig.append(48800); - sig.append(48900); - sig.append(49000); - sig.append(49100); - sig.append(49200); - sig.append(49300); - sig.append(49400); - sig.append(49500); - sig.append(49600); - sig.append(49700); - sig.append(49800); - sig.append(49900); - sig.append(50000); - sig.append(50100); - sig.append(50200); - sig.append(50300); - sig.append(50400); - sig.append(50500); - sig.append(50600); - sig.append(50700); - sig.append(50800); - sig.append(50900); - sig.append(51000); - sig.append(51100); - sig.append(51200); - sig.append(51300); - sig.append(51400); - sig.append(51500); - sig.append(51600); - sig.append(51700); - sig.append(51800); - sig.append(51900); - sig.append(52000); - sig.append(52100); - sig.append(52200); - sig.append(52300); - sig.append(52400); - sig.append(52500); - sig.append(52600); - sig.append(52700); - sig.append(52800); - sig.append(52900); - sig.append(53000); - sig.append(53100); - sig.append(53200); - sig.append(53300); - sig.append(53400); - sig.append(53500); - sig.append(53600); - sig.append(53700); - sig.append(53800); - sig.append(53900); - sig.append(54000); - sig.append(54100); - sig.append(54200); - sig.append(54300); - sig.append(54400); - sig.append(54500); - sig.append(54600); - sig.append(54700); - sig.append(54800); - sig.append(54900); - sig.append(55000); - sig.append(55100); - sig.append(55200); - sig.append(55300); - sig.append(55400); - sig.append(55500); - sig.append(55600); - sig.append(55700); - sig.append(55800); - sig.append(55900); - sig.append(56000); - sig.append(56100); - sig.append(56200); - sig.append(56300); - sig.append(56400); - sig.append(56500); - sig.append(56600); - sig.append(56700); - sig.append(56800); - sig.append(56900); - sig.append(57000); - sig.append(57100); - sig.append(57200); - sig.append(57300); - sig.append(57400); - sig.append(57500); - sig.append(57600); - sig.append(57700); - sig.append(57800); - sig.append(57900); - sig.append(58000); - sig.append(58100); - sig.append(58200); - sig.append(58300); - sig.append(58400); - sig.append(58500); - sig.append(58600); - sig.append(58700); - sig.append(58800); - sig.append(58900); - sig.append(59000); - sig.append(59100); - sig.append(59200); - sig.append(59300); - sig.append(59400); - sig.append(59500); - sig.append(59600); - sig.append(59700); - sig.append(59800); - sig.append(59900); - sig.append(60000); - sig.append(60100); - sig.append(60200); - sig.append(60300); - sig.append(60400); - sig.append(60500); - sig.append(60600); - sig.append(60700); - sig.append(60800); - sig.append(60900); - sig.append(61000); - sig.append(61100); - sig.append(61200); - sig.append(61300); - sig.append(61400); - sig.append(61500); - sig.append(61600); - sig.append(61700); - sig.append(61800); - sig.append(61900); - sig.append(62000); - sig.append(62100); - sig.append(62200); - sig.append(62300); - sig.append(62400); - sig.append(62500); - sig.append(62600); - sig.append(62700); - sig.append(62800); - sig.append(62900); - sig.append(63000); - sig.append(63100); - sig.append(63200); - sig.append(63300); - sig.append(63400); - sig.append(63500); - sig.append(63600); - sig.append(63700); - sig.append(63800); - sig.append(63900); - sig.append(64000); - sig.append(64100); - sig.append(64200); - sig.append(64300); - sig.append(64400); - sig.append(64500); - sig.append(64600); - sig.append(64700); - sig.append(64800); - sig.append(64900); - sig.append(65000); - sig.append(65100); - sig.append(65200); - sig.append(65300); - sig.append(65400); - sig.append(65500); - sig.append(65600); - sig.append(65700); - sig.append(65800); - sig.append(65900); - sig.append(66000); - sig.append(66100); - sig.append(66200); - sig.append(66300); - sig.append(66400); - sig.append(66500); - sig.append(66600); - sig.append(66700); - sig.append(66800); - sig.append(66900); - sig.append(67000); - sig.append(67100); - sig.append(67200); - sig.append(67300); - sig.append(67400); - sig.append(67500); - sig.append(67600); - sig.append(67700); - sig.append(67800); - sig.append(67900); - sig.append(68000); - sig.append(68100); - sig.append(68200); - sig.append(68300); - sig.append(68400); - sig.append(68500); - sig.append(68600); - sig.append(68700); - sig.append(68800); - sig.append(68900); - sig.append(69000); - sig.append(69100); - sig.append(69200); - sig.append(69300); - sig.append(69400); - sig.append(69500); - sig.append(69600); - sig.append(69700); - sig.append(69800); - sig.append(69900); - sig.append(70000); - sig.append(70100); - sig.append(70200); - sig.append(70300); - sig.append(70400); - sig.append(70500); - sig.append(70600); - sig.append(70700); - sig.append(70800); - sig.append(70900); - sig.append(71000); - sig.append(71100); - sig.append(71200); - sig.append(71300); - sig.append(71400); - sig.append(71500); - sig.append(71600); - sig.append(71700); - sig.append(71800); - sig.append(71900); - sig.append(72000); - sig.append(72100); - sig.append(72200); - sig.append(72300); - sig.append(72400); - sig.append(72500); - sig.append(72600); - sig.append(72700); - sig.append(72800); - sig.append(72900); - sig.append(73000); - sig.append(73100); - sig.append(73200); - sig.append(73300); - sig.append(73400); - sig.append(73500); - sig.append(73600); - sig.append(73700); - sig.append(73800); - sig.append(73900); - sig.append(74000); - sig.append(74100); - sig.append(74200); - sig.append(74300); - sig.append(74400); - sig.append(74500); - sig.append(74600); - sig.append(74700); - sig.append(74800); - sig.append(74900); - sig.append(75000); - sig.append(75100); - sig.append(75200); - sig.append(75300); - sig.append(75400); - sig.append(75500); - sig.append(75600); - sig.append(75700); - sig.append(75800); - sig.append(75900); - sig.append(76000); - sig.append(76100); - sig.append(76200); - sig.append(76300); - sig.append(76400); - sig.append(76500); - sig.append(76600); - sig.append(76700); - sig.append(76800); - sig.append(76900); - sig.append(77000); - sig.append(77100); - sig.append(77200); - sig.append(77300); - sig.append(77400); - sig.append(77500); - sig.append(77600); - sig.append(77700); - sig.append(77800); - sig.append(77900); - sig.append(78000); - sig.append(78100); - sig.append(78200); - sig.append(78300); - sig.append(78400); - sig.append(78500); - sig.append(78600); - sig.append(78700); - sig.append(78800); - sig.append(78900); - sig.append(79000); - sig.append(79100); - sig.append(79200); - sig.append(79300); - sig.append(79400); - sig.append(79500); - sig.append(79600); - sig.append(79700); - sig.append(79800); - sig.append(79900); - sig.append(80000); - sig.append(80100); - sig.append(80200); - sig.append(80300); - sig.append(80400); - sig.append(80500); - sig.append(80600); - sig.append(80700); - sig.append(80800); - sig.append(80900); - sig.append(81000); - sig.append(81100); - sig.append(81200); - sig.append(81300); - sig.append(81400); - sig.append(81500); - sig.append(81600); - sig.append(81700); - sig.append(81800); - sig.append(81900); - sig.append(82000); - sig.append(82100); - sig.append(82200); - sig.append(82300); - sig.append(82400); - sig.append(82500); - sig.append(82600); - sig.append(82700); - sig.append(82800); - sig.append(82900); - sig.append(83000); - sig.append(83100); - sig.append(83200); - sig.append(83300); - sig.append(83400); - sig.append(83500); - sig.append(83600); - sig.append(83700); - sig.append(83800); - sig.append(83900); - sig.append(84000); - sig.append(84100); - sig.append(84200); - sig.append(84300); - sig.append(84400); - sig.append(84500); - sig.append(84600); - sig.append(84700); - sig.append(84800); - sig.append(84900); - sig.append(85000); - sig.append(85100); - sig.append(85200); - sig.append(85300); - sig.append(85400); - sig.append(85500); - sig.append(85600); - sig.append(85700); - sig.append(85800); - sig.append(85900); - sig.append(86000); - sig.append(86100); - sig.append(86200); - sig.append(86300); - sig.append(86400); - sig.append(86500); - sig.append(86600); - sig.append(86700); - sig.append(86800); - sig.append(86900); - sig.append(87000); - sig.append(87100); - sig.append(87200); - sig.append(87300); - sig.append(87400); - sig.append(87500); - sig.append(87600); - sig.append(87700); - sig.append(87800); - sig.append(87900); - sig.append(88000); - sig.append(88100); - sig.append(88200); - sig.append(88300); - sig.append(88400); - sig.append(88500); - sig.append(88600); - sig.append(88700); - sig.append(88800); - sig.append(88900); - sig.append(89000); - sig.append(89100); - sig.append(89200); - sig.append(89300); - sig.append(89400); - sig.append(89500); - sig.append(89600); - sig.append(89700); - sig.append(89800); - sig.append(89900); - sig.append(90000); - sig.append(90100); - sig.append(90200); - sig.append(90300); - sig.append(90400); - sig.append(90500); - sig.append(90600); - sig.append(90700); - sig.append(90800); - sig.append(90900); - sig.append(91000); - sig.append(91100); - sig.append(91200); - sig.append(91300); - sig.append(91400); - sig.append(91500); - sig.append(91600); - sig.append(91700); - sig.append(91800); - sig.append(91900); - sig.append(92000); - sig.append(92100); - sig.append(92200); - sig.append(92300); - sig.append(92400); - sig.append(92500); - sig.append(92600); - sig.append(92700); - sig.append(92800); - sig.append(92900); - sig.append(93000); - sig.append(93100); - sig.append(93200); - sig.append(93300); - sig.append(93400); - sig.append(93500); - sig.append(93600); - sig.append(93700); - sig.append(93800); - sig.append(93900); - sig.append(94000); - sig.append(94100); - sig.append(94200); - sig.append(94300); - sig.append(94400); - sig.append(94500); - sig.append(94600); - sig.append(94700); - sig.append(94800); - sig.append(94900); - sig.append(95000); - sig.append(95100); - sig.append(95200); - sig.append(95300); - sig.append(95400); - sig.append(95500); - sig.append(95600); - sig.append(95700); - sig.append(95800); - sig.append(95900); - sig.append(96000); - sig.append(96100); - sig.append(96200); - sig.append(96300); - sig.append(96400); - sig.append(96500); - sig.append(96600); - sig.append(96700); - sig.append(96800); - sig.append(96900); - sig.append(97000); - sig.append(97100); - sig.append(97200); - sig.append(97300); - sig.append(97400); - sig.append(97500); - sig.append(97600); - sig.append(97700); - sig.append(97800); - sig.append(97900); - sig.append(98000); - sig.append(98100); - sig.append(98200); - sig.append(98300); - sig.append(98400); - sig.append(98500); - sig.append(98600); - sig.append(98700); - sig.append(98800); - sig.append(98900); - sig.append(99000); - sig.append(99100); - sig.append(99200); - sig.append(99300); - sig.append(99400); - sig.append(99500); - sig.append(99600); - sig.append(99700); - sig.append(99800); - sig.append(99900); - sig.append(100); - sig.append(2000); - sig.append(2001); - sig.append(2002); - sig.append(2003); - sig.append(2004); - sig.append(2005); - sig.append(2006); - sig.append(2007); - sig.append(2008); - sig.append(2009); - sig.append(2010); - sig.append(2011); - sig.append(2012); - sig.append(2013); - sig.append(2014); - sig.append(2015); - sig.append(2016); - sig.append(2017); - sig.append(2018); - sig.append(2019); - sig.append(2020); - sig.append(2021); - sig.append(2022); - sig.append(2023); - sig.append(2024); - sig.append(2025); - sig.append(2026); - sig.append(2027); - sig.append(2028); - sig.append(2029); - sig.append(2030); - sig.append(2031); - sig.append(2032); - sig.append(2033); - sig.append(2034); - sig.append(2035); - sig.append(2036); - sig.append(2037); - sig.append(2038); - sig.append(2039); - sig.append(2040); - sig.append(2041); - sig.append(2042); - sig.append(2043); - sig.append(2044); - sig.append(2045); - sig.append(2046); - sig.append(2047); - sig.append(2048); - sig.append(2049); - sig.append(2050); - sig.append(2051); - sig.append(2052); - sig.append(2053); - sig.append(2054); - sig.append(2055); - sig.append(2056); - sig.append(2057); - sig.append(2058); - sig.append(2059); - sig.append(2060); - sig.append(2061); - sig.append(2062); - sig.append(2063); - sig.append(2064); - sig.append(2065); - sig.append(2066); - sig.append(2067); - sig.append(2068); - sig.append(2069); - sig.append(2070); - sig.append(2071); - sig.append(2072); - sig.append(2073); - sig.append(2074); - sig.append(2075); - sig.append(2076); - sig.append(2077); - sig.append(2078); - sig.append(2079); - sig.append(2080); - sig.append(2081); - sig.append(2082); - sig.append(2083); - sig.append(2084); - sig.append(2085); - sig.append(2086); - sig.append(2087); - sig.append(2088); - sig.append(2089); - sig.append(2090); - sig.append(2091); - sig.append(2092); - sig.append(2093); - sig.append(2094); - sig.append(2095); - sig.append(2096); - sig.append(2097); - sig.append(2098); - sig.append(2099); - let mut proofs: Array = ArrayTrait::new(); - proofs.append(0); - proofs.append(100); - proofs.append(200); - proofs.append(300); - proofs.append(400); - proofs.append(500); - proofs.append(600); - proofs.append(700); - proofs.append(800); - proofs.append(900); - proofs.append(1000); - proofs.append(1100); - proofs.append(1200); - proofs.append(1300); - proofs.append(1400); - proofs.append(1500); - proofs.append(1600); - proofs.append(1700); - proofs.append(1800); - proofs.append(1900); - proofs.append(2000); - proofs.append(2100); - proofs.append(2200); - proofs.append(2300); - proofs.append(2400); - proofs.append(2500); - proofs.append(2600); - proofs.append(2700); - proofs.append(2800); - proofs.append(2900); - proofs.append(3000); - proofs.append(3100); - proofs.append(3200); - proofs.append(3300); - proofs.append(3400); - proofs.append(3500); - proofs.append(3600); - proofs.append(3700); - proofs.append(3800); - proofs.append(3900); - proofs.append(4000); - proofs.append(4100); - proofs.append(4200); - proofs.append(4300); - proofs.append(4400); - proofs.append(4500); - proofs.append(4600); - proofs.append(4700); - proofs.append(4800); - proofs.append(4900); - proofs.append(5000); - proofs.append(5100); - proofs.append(5200); - proofs.append(5300); - proofs.append(5400); - proofs.append(5500); - proofs.append(5600); - proofs.append(5700); - proofs.append(5800); - proofs.append(5900); - proofs.append(6000); - proofs.append(6100); - proofs.append(6200); - proofs.append(6300); - proofs.append(6400); - proofs.append(6500); - proofs.append(6600); - proofs.append(6700); - proofs.append(6800); - proofs.append(6900); - proofs.append(7000); - proofs.append(7100); - proofs.append(7200); - proofs.append(7300); - proofs.append(7400); - proofs.append(7500); - proofs.append(7600); - proofs.append(7700); - proofs.append(7800); - proofs.append(7900); - proofs.append(8000); - proofs.append(8100); - proofs.append(8200); - proofs.append(8300); - proofs.append(8400); - proofs.append(8500); - proofs.append(8600); - proofs.append(8700); - proofs.append(8800); - proofs.append(8900); - proofs.append(9000); - proofs.append(9100); - proofs.append(9200); - proofs.append(9300); - proofs.append(9400); - proofs.append(9500); - proofs.append(9600); - proofs.append(9700); - proofs.append(9800); - proofs.append(9900); - proofs.append(10000); - proofs.append(10100); - proofs.append(10200); - proofs.append(10300); - proofs.append(10400); - proofs.append(10500); - proofs.append(10600); - proofs.append(10700); - proofs.append(10800); - proofs.append(10900); - proofs.append(11000); - proofs.append(11100); - proofs.append(11200); - proofs.append(11300); - proofs.append(11400); - proofs.append(11500); - proofs.append(11600); - proofs.append(11700); - proofs.append(11800); - proofs.append(11900); - proofs.append(12000); - proofs.append(12100); - proofs.append(12200); - proofs.append(12300); - proofs.append(12400); - proofs.append(12500); - proofs.append(12600); - proofs.append(12700); - proofs.append(12800); - proofs.append(12900); - proofs.append(13000); - proofs.append(13100); - proofs.append(13200); - proofs.append(13300); - proofs.append(13400); - proofs.append(13500); - proofs.append(13600); - proofs.append(13700); - proofs.append(13800); - proofs.append(13900); - proofs.append(14000); - proofs.append(14100); - proofs.append(14200); - proofs.append(14300); - proofs.append(14400); - proofs.append(14500); - proofs.append(14600); - proofs.append(14700); - proofs.append(14800); - proofs.append(14900); - proofs.append(15000); - proofs.append(15100); - proofs.append(15200); - proofs.append(15300); - proofs.append(15400); - proofs.append(15500); - proofs.append(15600); - proofs.append(15700); - proofs.append(15800); - proofs.append(15900); - proofs.append(16000); - proofs.append(16100); - proofs.append(16200); - proofs.append(16300); - proofs.append(16400); - proofs.append(16500); - proofs.append(16600); - proofs.append(16700); - proofs.append(16800); - proofs.append(16900); - proofs.append(17000); - proofs.append(17100); - proofs.append(17200); - proofs.append(17300); - proofs.append(17400); - proofs.append(17500); - proofs.append(17600); - proofs.append(17700); - proofs.append(17800); - proofs.append(17900); - proofs.append(18000); - proofs.append(18100); - proofs.append(18200); - proofs.append(18300); - proofs.append(18400); - proofs.append(18500); - proofs.append(18600); - proofs.append(18700); - proofs.append(18800); - proofs.append(18900); - proofs.append(19000); - proofs.append(19100); - proofs.append(19200); - proofs.append(19300); - proofs.append(19400); - proofs.append(19500); - proofs.append(19600); - proofs.append(19700); - proofs.append(19800); - proofs.append(19900); - proofs.append(20000); - proofs.append(20100); - proofs.append(20200); - proofs.append(20300); - proofs.append(20400); - proofs.append(20500); - proofs.append(20600); - proofs.append(20700); - proofs.append(20800); - proofs.append(20900); - proofs.append(21000); - proofs.append(21100); - proofs.append(21200); - proofs.append(21300); - proofs.append(21400); - proofs.append(21500); - proofs.append(21600); - proofs.append(21700); - proofs.append(21800); - proofs.append(21900); - proofs.append(22000); - proofs.append(22100); - proofs.append(22200); - proofs.append(22300); - proofs.append(22400); - proofs.append(22500); - proofs.append(22600); - proofs.append(22700); - proofs.append(22800); - proofs.append(22900); - proofs.append(23000); - proofs.append(23100); - proofs.append(23200); - proofs.append(23300); - proofs.append(23400); - proofs.append(23500); - proofs.append(23600); - proofs.append(23700); - proofs.append(23800); - proofs.append(23900); - proofs.append(24000); - proofs.append(24100); - proofs.append(24200); - proofs.append(24300); - proofs.append(24400); - proofs.append(24500); - proofs.append(24600); - proofs.append(24700); - proofs.append(24800); - proofs.append(24900); - proofs.append(25000); - proofs.append(25100); - proofs.append(25200); - proofs.append(25300); - proofs.append(25400); - proofs.append(25500); - proofs.append(25600); - proofs.append(25700); - proofs.append(25800); - proofs.append(25900); - proofs.append(26000); - proofs.append(26100); - proofs.append(26200); - proofs.append(26300); - proofs.append(26400); - proofs.append(26500); - proofs.append(26600); - proofs.append(26700); - proofs.append(26800); - proofs.append(26900); - proofs.append(27000); - proofs.append(27100); - proofs.append(27200); - proofs.append(27300); - proofs.append(27400); - proofs.append(27500); - proofs.append(27600); - proofs.append(27700); - proofs.append(27800); - proofs.append(27900); - proofs.append(28000); - proofs.append(28100); - proofs.append(28200); - proofs.append(28300); - proofs.append(28400); - proofs.append(28500); - proofs.append(28600); - proofs.append(28700); - proofs.append(28800); - proofs.append(28900); - proofs.append(29000); - proofs.append(29100); - proofs.append(29200); - proofs.append(29300); - proofs.append(29400); - proofs.append(29500); - proofs.append(29600); - proofs.append(29700); - proofs.append(29800); - proofs.append(29900); - proofs.append(30000); - proofs.append(30100); - proofs.append(30200); - proofs.append(30300); - proofs.append(30400); - proofs.append(30500); - proofs.append(30600); - proofs.append(30700); - proofs.append(30800); - proofs.append(30900); - proofs.append(31000); - proofs.append(31100); - proofs.append(31200); - proofs.append(31300); - proofs.append(31400); - proofs.append(31500); - proofs.append(31600); - proofs.append(31700); - proofs.append(31800); - proofs.append(31900); - proofs.append(32000); - proofs.append(32100); - proofs.append(32200); - proofs.append(32300); - proofs.append(32400); - proofs.append(32500); - proofs.append(32600); - proofs.append(32700); - proofs.append(32800); - proofs.append(32900); - proofs.append(33000); - proofs.append(33100); - proofs.append(33200); - proofs.append(33300); - proofs.append(33400); - proofs.append(33500); - proofs.append(33600); - proofs.append(33700); - proofs.append(33800); - proofs.append(33900); - proofs.append(34000); - proofs.append(34100); - proofs.append(34200); - proofs.append(34300); - proofs.append(34400); - proofs.append(34500); - proofs.append(34600); - proofs.append(34700); - proofs.append(34800); - proofs.append(34900); - proofs.append(35000); - proofs.append(35100); - proofs.append(35200); - proofs.append(35300); - proofs.append(35400); - proofs.append(35500); - proofs.append(35600); - proofs.append(35700); - proofs.append(35800); - proofs.append(35900); - proofs.append(36000); - proofs.append(36100); - proofs.append(36200); - proofs.append(36300); - proofs.append(36400); - proofs.append(36500); - proofs.append(36600); - proofs.append(36700); - proofs.append(36800); - proofs.append(36900); - proofs.append(37000); - proofs.append(37100); - proofs.append(37200); - proofs.append(37300); - proofs.append(37400); - proofs.append(37500); - proofs.append(37600); - proofs.append(37700); - proofs.append(37800); - proofs.append(37900); - proofs.append(38000); - proofs.append(38100); - proofs.append(38200); - proofs.append(38300); - proofs.append(38400); - proofs.append(38500); - proofs.append(38600); - proofs.append(38700); - proofs.append(38800); - proofs.append(38900); - proofs.append(39000); - proofs.append(39100); - proofs.append(39200); - proofs.append(39300); - proofs.append(39400); - proofs.append(39500); - proofs.append(39600); - proofs.append(39700); - proofs.append(39800); - proofs.append(39900); - proofs.append(40000); - proofs.append(40100); - proofs.append(40200); - proofs.append(40300); - proofs.append(40400); - proofs.append(40500); - proofs.append(40600); - proofs.append(40700); - proofs.append(40800); - proofs.append(40900); - proofs.append(41000); - proofs.append(41100); - proofs.append(41200); - proofs.append(41300); - proofs.append(41400); - proofs.append(41500); - proofs.append(41600); - proofs.append(41700); - proofs.append(41800); - proofs.append(41900); - proofs.append(42000); - proofs.append(42100); - proofs.append(42200); - proofs.append(42300); - proofs.append(42400); - proofs.append(42500); - proofs.append(42600); - proofs.append(42700); - proofs.append(42800); - proofs.append(42900); - proofs.append(43000); - proofs.append(43100); - proofs.append(43200); - proofs.append(43300); - proofs.append(43400); - proofs.append(43500); - proofs.append(43600); - proofs.append(43700); - proofs.append(43800); - proofs.append(43900); - proofs.append(44000); - proofs.append(44100); - proofs.append(44200); - proofs.append(44300); - proofs.append(44400); - proofs.append(44500); - proofs.append(44600); - proofs.append(44700); - proofs.append(44800); - proofs.append(44900); - proofs.append(45000); - proofs.append(45100); - proofs.append(45200); - proofs.append(45300); - proofs.append(45400); - proofs.append(45500); - proofs.append(45600); - proofs.append(45700); - proofs.append(45800); - proofs.append(45900); - proofs.append(46000); - proofs.append(46100); - proofs.append(46200); - proofs.append(46300); - proofs.append(46400); - proofs.append(46500); - proofs.append(46600); - proofs.append(46700); - proofs.append(46800); - proofs.append(46900); - proofs.append(47000); - proofs.append(47100); - proofs.append(47200); - proofs.append(47300); - proofs.append(47400); - proofs.append(47500); - proofs.append(47600); - proofs.append(47700); - proofs.append(47800); - proofs.append(47900); - proofs.append(48000); - proofs.append(48100); - proofs.append(48200); - proofs.append(48300); - proofs.append(48400); - proofs.append(48500); - proofs.append(48600); - proofs.append(48700); - proofs.append(48800); - proofs.append(48900); - proofs.append(49000); - proofs.append(49100); - proofs.append(49200); - proofs.append(49300); - proofs.append(49400); - proofs.append(49500); - proofs.append(49600); - proofs.append(49700); - proofs.append(49800); - proofs.append(49900); - proofs.append(50000); - proofs.append(50100); - proofs.append(50200); - proofs.append(50300); - proofs.append(50400); - proofs.append(50500); - proofs.append(50600); - proofs.append(50700); - proofs.append(50800); - proofs.append(50900); - proofs.append(51000); - proofs.append(51100); - proofs.append(51200); - proofs.append(51300); - proofs.append(51400); - proofs.append(51500); - proofs.append(51600); - proofs.append(51700); - proofs.append(51800); - proofs.append(51900); - proofs.append(52000); - proofs.append(52100); - proofs.append(52200); - proofs.append(52300); - proofs.append(52400); - proofs.append(52500); - proofs.append(52600); - proofs.append(52700); - proofs.append(52800); - proofs.append(52900); - proofs.append(53000); - proofs.append(53100); - proofs.append(53200); - proofs.append(53300); - proofs.append(53400); - proofs.append(53500); - proofs.append(53600); - proofs.append(53700); - proofs.append(53800); - proofs.append(53900); - proofs.append(54000); - proofs.append(54100); - proofs.append(54200); - proofs.append(54300); - proofs.append(54400); - proofs.append(54500); - proofs.append(54600); - proofs.append(54700); - proofs.append(54800); - proofs.append(54900); - proofs.append(55000); - proofs.append(55100); - proofs.append(55200); - proofs.append(55300); - proofs.append(55400); - proofs.append(55500); - proofs.append(55600); - proofs.append(55700); - proofs.append(55800); - proofs.append(55900); - proofs.append(56000); - proofs.append(56100); - proofs.append(56200); - proofs.append(56300); - proofs.append(56400); - proofs.append(56500); - proofs.append(56600); - proofs.append(56700); - proofs.append(56800); - proofs.append(56900); - proofs.append(57000); - proofs.append(57100); - proofs.append(57200); - proofs.append(57300); - proofs.append(57400); - proofs.append(57500); - proofs.append(57600); - proofs.append(57700); - proofs.append(57800); - proofs.append(57900); - proofs.append(58000); - proofs.append(58100); - proofs.append(58200); - proofs.append(58300); - proofs.append(58400); - proofs.append(58500); - proofs.append(58600); - proofs.append(58700); - proofs.append(58800); - proofs.append(58900); - proofs.append(59000); - proofs.append(59100); - proofs.append(59200); - proofs.append(59300); - proofs.append(59400); - proofs.append(59500); - proofs.append(59600); - proofs.append(59700); - proofs.append(59800); - proofs.append(59900); - proofs.append(60000); - proofs.append(60100); - proofs.append(60200); - proofs.append(60300); - proofs.append(60400); - proofs.append(60500); - proofs.append(60600); - proofs.append(60700); - proofs.append(60800); - proofs.append(60900); - proofs.append(61000); - proofs.append(61100); - proofs.append(61200); - proofs.append(61300); - proofs.append(61400); - proofs.append(61500); - proofs.append(61600); - proofs.append(61700); - proofs.append(61800); - proofs.append(61900); - proofs.append(62000); - proofs.append(62100); - proofs.append(62200); - proofs.append(62300); - proofs.append(62400); - proofs.append(62500); - proofs.append(62600); - proofs.append(62700); - proofs.append(62800); - proofs.append(62900); - proofs.append(63000); - proofs.append(63100); - proofs.append(63200); - proofs.append(63300); - proofs.append(63400); - proofs.append(63500); - proofs.append(63600); - proofs.append(63700); - proofs.append(63800); - proofs.append(63900); - proofs.append(64000); - proofs.append(64100); - proofs.append(64200); - proofs.append(64300); - proofs.append(64400); - proofs.append(64500); - proofs.append(64600); - proofs.append(64700); - proofs.append(64800); - proofs.append(64900); - proofs.append(65000); - proofs.append(65100); - proofs.append(65200); - proofs.append(65300); - proofs.append(65400); - proofs.append(65500); - proofs.append(65600); - proofs.append(65700); - proofs.append(65800); - proofs.append(65900); - proofs.append(66000); - proofs.append(66100); - proofs.append(66200); - proofs.append(66300); - proofs.append(66400); - proofs.append(66500); - proofs.append(66600); - proofs.append(66700); - proofs.append(66800); - proofs.append(66900); - proofs.append(67000); - proofs.append(67100); - proofs.append(67200); - proofs.append(67300); - proofs.append(67400); - proofs.append(67500); - proofs.append(67600); - proofs.append(67700); - proofs.append(67800); - proofs.append(67900); - proofs.append(68000); - proofs.append(68100); - proofs.append(68200); - proofs.append(68300); - proofs.append(68400); - proofs.append(68500); - proofs.append(68600); - proofs.append(68700); - proofs.append(68800); - proofs.append(68900); - proofs.append(69000); - proofs.append(69100); - proofs.append(69200); - proofs.append(69300); - proofs.append(69400); - proofs.append(69500); - proofs.append(69600); - proofs.append(69700); - proofs.append(69800); - proofs.append(69900); - proofs.append(70000); - proofs.append(70100); - proofs.append(70200); - proofs.append(70300); - proofs.append(70400); - proofs.append(70500); - proofs.append(70600); - proofs.append(70700); - proofs.append(70800); - proofs.append(70900); - proofs.append(71000); - proofs.append(71100); - proofs.append(71200); - proofs.append(71300); - proofs.append(71400); - proofs.append(71500); - proofs.append(71600); - proofs.append(71700); - proofs.append(71800); - proofs.append(71900); - proofs.append(72000); - proofs.append(72100); - proofs.append(72200); - proofs.append(72300); - proofs.append(72400); - proofs.append(72500); - proofs.append(72600); - proofs.append(72700); - proofs.append(72800); - proofs.append(72900); - proofs.append(73000); - proofs.append(73100); - proofs.append(73200); - proofs.append(73300); - proofs.append(73400); - proofs.append(73500); - proofs.append(73600); - proofs.append(73700); - proofs.append(73800); - proofs.append(73900); - proofs.append(74000); - proofs.append(74100); - proofs.append(74200); - proofs.append(74300); - proofs.append(74400); - proofs.append(74500); - proofs.append(74600); - proofs.append(74700); - proofs.append(74800); - proofs.append(74900); - proofs.append(75000); - proofs.append(75100); - proofs.append(75200); - proofs.append(75300); - proofs.append(75400); - proofs.append(75500); - proofs.append(75600); - proofs.append(75700); - proofs.append(75800); - proofs.append(75900); - proofs.append(76000); - proofs.append(76100); - proofs.append(76200); - proofs.append(76300); - proofs.append(76400); - proofs.append(76500); - proofs.append(76600); - proofs.append(76700); - proofs.append(76800); - proofs.append(76900); - proofs.append(77000); - proofs.append(77100); - proofs.append(77200); - proofs.append(77300); - proofs.append(77400); - proofs.append(77500); - proofs.append(77600); - proofs.append(77700); - proofs.append(77800); - proofs.append(77900); - proofs.append(78000); - proofs.append(78100); - proofs.append(78200); - proofs.append(78300); - proofs.append(78400); - proofs.append(78500); - proofs.append(78600); - proofs.append(78700); - proofs.append(78800); - proofs.append(78900); - proofs.append(79000); - proofs.append(79100); - proofs.append(79200); - proofs.append(79300); - proofs.append(79400); - proofs.append(79500); - proofs.append(79600); - proofs.append(79700); - proofs.append(79800); - proofs.append(79900); - proofs.append(80000); - proofs.append(80100); - proofs.append(80200); - proofs.append(80300); - proofs.append(80400); - proofs.append(80500); - proofs.append(80600); - proofs.append(80700); - proofs.append(80800); - proofs.append(80900); - proofs.append(81000); - proofs.append(81100); - proofs.append(81200); - proofs.append(81300); - proofs.append(81400); - proofs.append(81500); - proofs.append(81600); - proofs.append(81700); - proofs.append(81800); - proofs.append(81900); - proofs.append(82000); - proofs.append(82100); - proofs.append(82200); - proofs.append(82300); - proofs.append(82400); - proofs.append(82500); - proofs.append(82600); - proofs.append(82700); - proofs.append(82800); - proofs.append(82900); - proofs.append(83000); - proofs.append(83100); - proofs.append(83200); - proofs.append(83300); - proofs.append(83400); - proofs.append(83500); - proofs.append(83600); - proofs.append(83700); - proofs.append(83800); - proofs.append(83900); - proofs.append(84000); - proofs.append(84100); - proofs.append(84200); - proofs.append(84300); - proofs.append(84400); - proofs.append(84500); - proofs.append(84600); - proofs.append(84700); - proofs.append(84800); - proofs.append(84900); - proofs.append(85000); - proofs.append(85100); - proofs.append(85200); - proofs.append(85300); - proofs.append(85400); - proofs.append(85500); - proofs.append(85600); - proofs.append(85700); - proofs.append(85800); - proofs.append(85900); - proofs.append(86000); - proofs.append(86100); - proofs.append(86200); - proofs.append(86300); - proofs.append(86400); - proofs.append(86500); - proofs.append(86600); - proofs.append(86700); - proofs.append(86800); - proofs.append(86900); - proofs.append(87000); - proofs.append(87100); - proofs.append(87200); - proofs.append(87300); - proofs.append(87400); - proofs.append(87500); - proofs.append(87600); - proofs.append(87700); - proofs.append(87800); - proofs.append(87900); - proofs.append(88000); - proofs.append(88100); - proofs.append(88200); - proofs.append(88300); - proofs.append(88400); - proofs.append(88500); - proofs.append(88600); - proofs.append(88700); - proofs.append(88800); - proofs.append(88900); - proofs.append(89000); - proofs.append(89100); - proofs.append(89200); - proofs.append(89300); - proofs.append(89400); - proofs.append(89500); - proofs.append(89600); - proofs.append(89700); - proofs.append(89800); - proofs.append(89900); - proofs.append(90000); - proofs.append(90100); - proofs.append(90200); - proofs.append(90300); - proofs.append(90400); - proofs.append(90500); - proofs.append(90600); - proofs.append(90700); - proofs.append(90800); - proofs.append(90900); - proofs.append(91000); - proofs.append(91100); - proofs.append(91200); - proofs.append(91300); - proofs.append(91400); - proofs.append(91500); - proofs.append(91600); - proofs.append(91700); - proofs.append(91800); - proofs.append(91900); - proofs.append(92000); - proofs.append(92100); - proofs.append(92200); - proofs.append(92300); - proofs.append(92400); - proofs.append(92500); - proofs.append(92600); - proofs.append(92700); - proofs.append(92800); - proofs.append(92900); - proofs.append(93000); - proofs.append(93100); - proofs.append(93200); - proofs.append(93300); - proofs.append(93400); - proofs.append(93500); - proofs.append(93600); - proofs.append(93700); - proofs.append(93800); - proofs.append(93900); - proofs.append(94000); - proofs.append(94100); - proofs.append(94200); - proofs.append(94300); - proofs.append(94400); - proofs.append(94500); - proofs.append(94600); - proofs.append(94700); - proofs.append(94800); - proofs.append(94900); - proofs.append(95000); - proofs.append(95100); - proofs.append(95200); - proofs.append(95300); - proofs.append(95400); - proofs.append(95500); - proofs.append(95600); - proofs.append(95700); - proofs.append(95800); - proofs.append(95900); - proofs.append(96000); - proofs.append(96100); - proofs.append(96200); - proofs.append(96300); - proofs.append(96400); - proofs.append(96500); - proofs.append(96600); - proofs.append(96700); - proofs.append(96800); - proofs.append(96900); - proofs.append(97000); - proofs.append(97100); - proofs.append(97200); - proofs.append(97300); - proofs.append(97400); - proofs.append(97500); - proofs.append(97600); - proofs.append(97700); - proofs.append(97800); - proofs.append(97900); - proofs.append(98000); - proofs.append(98100); - proofs.append(98200); - proofs.append(98300); - proofs.append(98400); - proofs.append(98500); - proofs.append(98600); - proofs.append(98700); - proofs.append(98800); - proofs.append(98900); - proofs.append(99000); - proofs.append(99100); - proofs.append(99200); - proofs.append(99300); - proofs.append(99400); - proofs.append(99500); - proofs.append(99600); - proofs.append(99700); - proofs.append(99800); - proofs.append(99900); - let mut session_token: Array = ArrayTrait::new(); - session_token.append(2000); - session_token.append(2001); - session_token.append(2002); - session_token.append(2003); - session_token.append(2004); - session_token.append(2005); - session_token.append(2006); - session_token.append(2007); - session_token.append(2008); - session_token.append(2009); - session_token.append(2010); - session_token.append(2011); - session_token.append(2012); - session_token.append(2013); - session_token.append(2014); - session_token.append(2015); - session_token.append(2016); - session_token.append(2017); - session_token.append(2018); - session_token.append(2019); - session_token.append(2020); - session_token.append(2021); - session_token.append(2022); - session_token.append(2023); - session_token.append(2024); - session_token.append(2025); - session_token.append(2026); - session_token.append(2027); - session_token.append(2028); - session_token.append(2029); - session_token.append(2030); - session_token.append(2031); - session_token.append(2032); - session_token.append(2033); - session_token.append(2034); - session_token.append(2035); - session_token.append(2036); - session_token.append(2037); - session_token.append(2038); - session_token.append(2039); - session_token.append(2040); - session_token.append(2041); - session_token.append(2042); - session_token.append(2043); - session_token.append(2044); - session_token.append(2045); - session_token.append(2046); - session_token.append(2047); - session_token.append(2048); - session_token.append(2049); - session_token.append(2050); - session_token.append(2051); - session_token.append(2052); - session_token.append(2053); - session_token.append(2054); - session_token.append(2055); - session_token.append(2056); - session_token.append(2057); - session_token.append(2058); - session_token.append(2059); - session_token.append(2060); - session_token.append(2061); - session_token.append(2062); - session_token.append(2063); - session_token.append(2064); - session_token.append(2065); - session_token.append(2066); - session_token.append(2067); - session_token.append(2068); - session_token.append(2069); - session_token.append(2070); - session_token.append(2071); - session_token.append(2072); - session_token.append(2073); - session_token.append(2074); - session_token.append(2075); - session_token.append(2076); - session_token.append(2077); - session_token.append(2078); - session_token.append(2079); - session_token.append(2080); - session_token.append(2081); - session_token.append(2082); - session_token.append(2083); - session_token.append(2084); - session_token.append(2085); - session_token.append(2086); - session_token.append(2087); - session_token.append(2088); - session_token.append(2089); - session_token.append(2090); - session_token.append(2091); - session_token.append(2092); - session_token.append(2093); - session_token.append(2094); - session_token.append(2095); - session_token.append(2096); - session_token.append(2097); - session_token.append(2098); - session_token.append(2099); - let sig = FeltSpanTryIntoSignature::try_into(sig.span()).unwrap(); - assert(1830 == sig.r, 'Expect equal!'); - assert(1863 == sig.s, 'Expect equal!'); - assert(1918 == sig.session_key, 'Expect equal!'); - assert(1922 == sig.root, 'Expect equal!'); - assert(100 == sig.proofs.len(), 'Expect equal!'); - assert(100 == sig.session_token.len(), 'Expect equal!'); - assert(99900 == *sig.proofs.at(99).at(9), 'Expect equal!'); - assert(2099 == *sig.session_token.at(99), 'Expect equal!'); -} - diff --git a/crates/webauthn/session/src/tests/signature_proofs_gen_test.cairo b/crates/webauthn/session/src/tests/signature_proofs_gen_test.cairo deleted file mode 100644 index b7b9f2f5..00000000 --- a/crates/webauthn/session/src/tests/signature_proofs_gen_test.cairo +++ /dev/null @@ -1,669 +0,0 @@ -// This file is script-generated. -// Don't modify it manually! -// See test_gen_scripts/session/signature_proofs_test.py for details -use core::traits::Into; -use core::option::OptionTrait; -use core::array::ArrayTrait; -use webauthn_session::signature::ImplSignatureProofs; - -#[test] -#[available_gas(300000)] -fn test_signature_proofs_3() { - let mut proofs: Array = ArrayTrait::new(); - proofs.append(0); - proofs.append(1); - proofs.append(2); - { - let option = ImplSignatureProofs::try_new(proofs.span(), 1).unwrap(); - assert(option.len() == 3, 'Wrong length'); - assert(option.at(0).len() == 1, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(2).at(0) == 2, 'Should equal'); - assert(*option.at(2).at(0) == 2, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 2) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 3).unwrap(); - assert(option.len() == 1, 'Wrong length'); - assert(option.at(0).len() == 3, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(0).at(2) == 2, 'Should equal'); - } -} - -#[test] -#[available_gas(1200000)] -fn test_signature_proofs_12() { - let mut proofs: Array = ArrayTrait::new(); - proofs.append(0); - proofs.append(1); - proofs.append(2); - proofs.append(3); - proofs.append(4); - proofs.append(5); - proofs.append(6); - proofs.append(7); - proofs.append(8); - proofs.append(9); - proofs.append(10); - proofs.append(11); - { - let option = ImplSignatureProofs::try_new(proofs.span(), 1).unwrap(); - assert(option.len() == 12, 'Wrong length'); - assert(option.at(0).len() == 1, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(11).at(0) == 11, 'Should equal'); - assert(*option.at(11).at(0) == 11, 'Should equal'); - } - { - let option = ImplSignatureProofs::try_new(proofs.span(), 2).unwrap(); - assert(option.len() == 6, 'Wrong length'); - assert(option.at(0).len() == 2, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(5).at(0) == 10, 'Should equal'); - assert(*option.at(5).at(1) == 11, 'Should equal'); - } - { - let option = ImplSignatureProofs::try_new(proofs.span(), 3).unwrap(); - assert(option.len() == 4, 'Wrong length'); - assert(option.at(0).len() == 3, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(3).at(0) == 9, 'Should equal'); - assert(*option.at(3).at(2) == 11, 'Should equal'); - } - { - let option = ImplSignatureProofs::try_new(proofs.span(), 4).unwrap(); - assert(option.len() == 3, 'Wrong length'); - assert(option.at(0).len() == 4, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(2).at(0) == 8, 'Should equal'); - assert(*option.at(2).at(3) == 11, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 5) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 6).unwrap(); - assert(option.len() == 2, 'Wrong length'); - assert(option.at(0).len() == 6, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(1).at(0) == 6, 'Should equal'); - assert(*option.at(1).at(5) == 11, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 7) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 8) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 9) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 10) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 11) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 12).unwrap(); - assert(option.len() == 1, 'Wrong length'); - assert(option.at(0).len() == 12, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(0).at(11) == 11, 'Should equal'); - } -} - -#[test] -#[available_gas(10000000)] -fn test_signature_proofs_100() { - let mut proofs: Array = ArrayTrait::new(); - proofs.append(0); - proofs.append(1); - proofs.append(2); - proofs.append(3); - proofs.append(4); - proofs.append(5); - proofs.append(6); - proofs.append(7); - proofs.append(8); - proofs.append(9); - proofs.append(10); - proofs.append(11); - proofs.append(12); - proofs.append(13); - proofs.append(14); - proofs.append(15); - proofs.append(16); - proofs.append(17); - proofs.append(18); - proofs.append(19); - proofs.append(20); - proofs.append(21); - proofs.append(22); - proofs.append(23); - proofs.append(24); - proofs.append(25); - proofs.append(26); - proofs.append(27); - proofs.append(28); - proofs.append(29); - proofs.append(30); - proofs.append(31); - proofs.append(32); - proofs.append(33); - proofs.append(34); - proofs.append(35); - proofs.append(36); - proofs.append(37); - proofs.append(38); - proofs.append(39); - proofs.append(40); - proofs.append(41); - proofs.append(42); - proofs.append(43); - proofs.append(44); - proofs.append(45); - proofs.append(46); - proofs.append(47); - proofs.append(48); - proofs.append(49); - proofs.append(50); - proofs.append(51); - proofs.append(52); - proofs.append(53); - proofs.append(54); - proofs.append(55); - proofs.append(56); - proofs.append(57); - proofs.append(58); - proofs.append(59); - proofs.append(60); - proofs.append(61); - proofs.append(62); - proofs.append(63); - proofs.append(64); - proofs.append(65); - proofs.append(66); - proofs.append(67); - proofs.append(68); - proofs.append(69); - proofs.append(70); - proofs.append(71); - proofs.append(72); - proofs.append(73); - proofs.append(74); - proofs.append(75); - proofs.append(76); - proofs.append(77); - proofs.append(78); - proofs.append(79); - proofs.append(80); - proofs.append(81); - proofs.append(82); - proofs.append(83); - proofs.append(84); - proofs.append(85); - proofs.append(86); - proofs.append(87); - proofs.append(88); - proofs.append(89); - proofs.append(90); - proofs.append(91); - proofs.append(92); - proofs.append(93); - proofs.append(94); - proofs.append(95); - proofs.append(96); - proofs.append(97); - proofs.append(98); - proofs.append(99); - { - let option = ImplSignatureProofs::try_new(proofs.span(), 1).unwrap(); - assert(option.len() == 100, 'Wrong length'); - assert(option.at(0).len() == 1, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(99).at(0) == 99, 'Should equal'); - assert(*option.at(99).at(0) == 99, 'Should equal'); - } - { - let option = ImplSignatureProofs::try_new(proofs.span(), 2).unwrap(); - assert(option.len() == 50, 'Wrong length'); - assert(option.at(0).len() == 2, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(49).at(0) == 98, 'Should equal'); - assert(*option.at(49).at(1) == 99, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 3) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 4).unwrap(); - assert(option.len() == 25, 'Wrong length'); - assert(option.at(0).len() == 4, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(24).at(0) == 96, 'Should equal'); - assert(*option.at(24).at(3) == 99, 'Should equal'); - } - { - let option = ImplSignatureProofs::try_new(proofs.span(), 5).unwrap(); - assert(option.len() == 20, 'Wrong length'); - assert(option.at(0).len() == 5, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(19).at(0) == 95, 'Should equal'); - assert(*option.at(19).at(4) == 99, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 6) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 7) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 8) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 9) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 10).unwrap(); - assert(option.len() == 10, 'Wrong length'); - assert(option.at(0).len() == 10, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(9).at(0) == 90, 'Should equal'); - assert(*option.at(9).at(9) == 99, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 11) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 12) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 13) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 14) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 15) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 16) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 17) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 18) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 19) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 20).unwrap(); - assert(option.len() == 5, 'Wrong length'); - assert(option.at(0).len() == 20, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(4).at(0) == 80, 'Should equal'); - assert(*option.at(4).at(19) == 99, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 21) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 22) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 23) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 24) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 25).unwrap(); - assert(option.len() == 4, 'Wrong length'); - assert(option.at(0).len() == 25, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(3).at(0) == 75, 'Should equal'); - assert(*option.at(3).at(24) == 99, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 26) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 27) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 28) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 29) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 30) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 31) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 32) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 33) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 34) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 35) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 36) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 37) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 38) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 39) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 40) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 41) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 42) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 43) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 44) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 45) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 46) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 47) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 48) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 49) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 50).unwrap(); - assert(option.len() == 2, 'Wrong length'); - assert(option.at(0).len() == 50, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(1).at(0) == 50, 'Should equal'); - assert(*option.at(1).at(49) == 99, 'Should equal'); - } - match ImplSignatureProofs::try_new(proofs.span(), 51) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 52) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 53) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 54) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 55) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 56) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 57) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 58) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 59) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 60) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 61) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 62) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 63) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 64) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 65) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 66) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 67) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 68) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 69) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 70) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 71) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 72) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 73) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 74) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 75) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 76) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 77) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 78) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 79) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 80) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 81) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 82) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 83) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 84) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 85) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 86) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 87) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 88) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 89) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 90) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 91) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 92) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 93) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 94) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 95) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 96) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 97) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 98) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - match ImplSignatureProofs::try_new(proofs.span(), 99) { - Option::Some(_) => assert(false, 'Should be None!'), - Option::None => () - }; - { - let option = ImplSignatureProofs::try_new(proofs.span(), 100).unwrap(); - assert(option.len() == 1, 'Wrong length'); - assert(option.at(0).len() == 100, 'Wrong length'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(0).at(0) == 0, 'Should equal'); - assert(*option.at(0).at(99) == 99, 'Should equal'); - } -} - From 5da59afe5d79c6a48facfa9101b1d9a69394824d Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 31 Jan 2024 15:31:44 +0000 Subject: [PATCH 32/43] update readme --- README.md | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 4cd22c68..dc307301 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ The project consists of several subfolders located in the ```crates``` directory - **account_sdk** - a rust project to export and test functions for interacting with the custom account contract. - **cartidge_account** - a cairo project with a custom account contract. -- **test_gen_scripts** - a python library to programatically generate cryptographic cairo tests. - **webauthn** - cairo components to use in contracts. The project has a global rust workspace. @@ -45,39 +44,14 @@ cargo test The scarb builds the contract and saves the compiled code in the `cartridge_account/target` folder. The tests then fetch (at compile time) the comipled code and deploy it to the local network. Note that obviously the contract needs to be recompiled for any changes to be applied in the compiled code. -## src +## webauthn This is a cairo project with backend methods that will allow for various authentication methods in the custom contact. Written based on [this specification](https://www.w3.org/TR/webauthn/). ### Running the tests -Some of the tests are auto-generated using python scripts. -See the `test_gen_scripts` for details. -The tests in `src/tests/` which end in `_gen_test.cairo` are auto-generated and might be changed by the python script. You can write your tests manually, but make sure the name of the test file doesn't end in `_gen_test.cairo`, and you place the import "`use ...;`" below the auto-generated imports in `src/tests.cairo`. - -To run the tests: - -```shell -scarb test -``` - -To again generate the tests: - -```shell -python test_gen_scripts/main.py -``` - -## test_gen_scripts - -This is a python library to programatically generate cryptographic cairo tests. - -### Python Enviroment - -Use pyenv to have specific version of python easily. -We use python3.9 - -```sh -pip install -r requirements.txt -python test_gen_scripts/main.py +You can run scarb test to run a few hand-written tests inside each ```auth``` and ```session``` crates. The bulk of the tests are located in the ```tests``` directory. These tests are written in rust and use property based testing provided by the [proptest](https://docs.rs/proptest/latest/proptest/) crate and use [cairo args runner](https://github.com/neotheprogramist/cairo-args-runner) to interface with and call cairo functions. To run these tests ```cd``` to the ```crates/webauthn/tests``` directory and run: +```bash +cargo test ``` From 2fa4fa729261b2afc967eea0aba2842b380a8302 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 27 Feb 2024 13:02:26 +0000 Subject: [PATCH 33/43] update args runner version --- crates/webauthn/tests/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/webauthn/tests/Cargo.toml b/crates/webauthn/tests/Cargo.toml index 179de6bc..dda19544 100644 --- a/crates/webauthn/tests/Cargo.toml +++ b/crates/webauthn/tests/Cargo.toml @@ -7,7 +7,7 @@ version.workspace = true [dependencies] starknet.workspace = true -cairo-args-runner = { git="https://github.com/neotheprogramist/cairo-args-runner", branch = "thepinion"} +cairo-args-runner = { git="https://github.com/neotheprogramist/cairo-args-runner", rev="5bafcbaa7090ee1a61271e5f5e654d045037a201"} proptest = "1.4.0" p256.workspace = true account-sdk.workspace = true From d4ed08a923ddfb8a191bd22a775c66d8828e1f51 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Mon, 26 Feb 2024 16:33:44 +0000 Subject: [PATCH 34/43] fix compile errors --- Scarb.toml | 4 ++-- crates/cartridge_account/src/lib.cairo | 2 +- crates/cartridge_account/tests/test_account.cairo | 2 +- crates/webauthn/auth/src/component.cairo | 8 ++++---- crates/webauthn/auth/src/webauthn.cairo | 10 +++++----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index 9cca8b9f..fe7844a4 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -13,8 +13,8 @@ version = "0.1.0" alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } -openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.8.0" } +openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.9.0" } snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.14.0" } -starknet = "2.4.3" +starknet = "2.5.3" webauthn_auth = { path = "crates/webauthn/auth" } webauthn_session = { path = "crates/webauthn/session" } diff --git a/crates/cartridge_account/src/lib.cairo b/crates/cartridge_account/src/lib.cairo index c1c54331..298edf03 100644 --- a/crates/cartridge_account/src/lib.cairo +++ b/crates/cartridge_account/src/lib.cairo @@ -240,6 +240,6 @@ mod Account { fn _execute_single_call(call: Call) -> Span { let Call{to, selector, calldata } = call; - starknet::call_contract_syscall(to, selector, calldata.span()).unwrap() + starknet::call_contract_syscall(to, selector, calldata).unwrap() } } diff --git a/crates/cartridge_account/tests/test_account.cairo b/crates/cartridge_account/tests/test_account.cairo index 2b4e8936..785f3962 100644 --- a/crates/cartridge_account/tests/test_account.cairo +++ b/crates/cartridge_account/tests/test_account.cairo @@ -92,7 +92,7 @@ impl TransferCallImpl of TransferCallTrait { let mut calldata = array![]; calldata.append_serde(self.recipient); calldata.append_serde(self.amount); - Call { to: self.erc20, selector: selectors::transfer, calldata: calldata } + Call { to: self.erc20, selector: selectors::transfer, calldata: calldata.span() } } } diff --git a/crates/webauthn/auth/src/component.cairo b/crates/webauthn/auth/src/component.cairo index bc15d10b..94179972 100644 --- a/crates/webauthn/auth/src/component.cairo +++ b/crates/webauthn/auth/src/component.cairo @@ -62,13 +62,13 @@ mod webauthn_component { fn verify_webauthn_signer( self: @ComponentState, signature: WebauthnSignature, tx_hash: felt252, ) -> bool { - let pub = match self.get_webauthn_pub_key() { - Option::Some(pub) => pub, + let pub_key = match self.get_webauthn_pub_key() { + Option::Some(pub_key) => pub_key, Option::None => { return false; } }; - let pub_key = match Secp256r1Impl::secp256_ec_new_syscall(pub.x, pub.y) { + let pub_key = match Secp256r1Impl::secp256_ec_new_syscall(pub_key.x, pub_key.y) { Result::Ok(pub_key) => pub_key, - Result::Err(e) => { return false; } + Result::Err(_) => { return false; } }; let pub_key = match pub_key { Option::Some(pub_key) => pub_key, diff --git a/crates/webauthn/auth/src/webauthn.cairo b/crates/webauthn/auth/src/webauthn.cairo index 2027e1c3..629a8505 100644 --- a/crates/webauthn/auth/src/webauthn.cairo +++ b/crates/webauthn/auth/src/webauthn.cairo @@ -45,7 +45,7 @@ trait WebauthnAuthenticatorTrait { fn verify( - pub: Secp256r1Point, // public key as point on elliptic curve + pub_key: Secp256r1Point, // public key as point on elliptic curve r: u256, // 'r' part from ecdsa s: u256, // 's' part from ecdsa type_offset: usize, // offset to 'type' field in json @@ -86,9 +86,9 @@ fn verify( // Compute message ready for verification. let result = concatenate(@authenticator_data, @client_data_hash); - match verify_ecdsa(pub, result, r, s) { + match verify_ecdsa(pub_key, result, r, s) { Result::Ok => Result::Ok(()), - Result::Err(e) => AuthnError::InvalidSignature.into() + Result::Err(_) => AuthnError::InvalidSignature.into() } } @@ -148,7 +148,7 @@ fn find_and_verify_credential_source< PublicKey >::into(store.retrieve_public_key(credential.raw_id))?; let pk_2 = match response.user_handle { - Option::Some(handle) => RTSEIntoRTAE::< + Option::Some(_handle) => RTSEIntoRTAE::< PublicKey >::into(store.retrieve_public_key(credential.raw_id))?, Option::None => { return AuthnError::IdentifiedUsersMismatch.into(); }, @@ -245,6 +245,6 @@ fn verify_signature( }; match verify_ecdsa(pub_key_point, concatenation, r, s) { Result::Ok => Result::Ok(()), - Result::Err(e) => AuthnError::InvalidSignature.into() + Result::Err(_) => AuthnError::InvalidSignature.into() } } From d9b1ec840f9a54d61c3bf876cda28356bcc86950 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 27 Feb 2024 08:56:26 +0000 Subject: [PATCH 35/43] remove most warnings --- Scarb.toml | 8 ++++---- crates/webauthn/session/src/lib.cairo | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index fe7844a4..5fe89040 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -10,11 +10,11 @@ edition = "2023_10" version = "0.1.0" [workspace.dependencies] -alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } -alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } -alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } +alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } +alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria",tag="cairo-v2.5.4" } +alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.9.0" } -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.14.0" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.18.0" } starknet = "2.5.3" webauthn_auth = { path = "crates/webauthn/auth" } webauthn_session = { path = "crates/webauthn/session" } diff --git a/crates/webauthn/session/src/lib.cairo b/crates/webauthn/session/src/lib.cairo index 2e86f55a..9be137ef 100644 --- a/crates/webauthn/session/src/lib.cairo +++ b/crates/webauthn/session/src/lib.cairo @@ -115,7 +115,7 @@ mod session_component { // Hashing all the calls loop { - let pub_key = match calls.pop_front() { + let _pub_key = match calls.pop_front() { Option::Some(single) => { leaves.append(compute_call_hash(@single)); }, Option::None(_) => { break; }, }; From 3052b97cd87e3fa763434d243daa78e84740d5d6 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 27 Feb 2024 09:03:35 +0000 Subject: [PATCH 36/43] fix the failing test by reverting the dependency update --- Scarb.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scarb.toml b/Scarb.toml index 5fe89040..cff0565e 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -12,7 +12,7 @@ version = "0.1.0" [workspace.dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria",tag="cairo-v2.5.4" } -alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } +alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.9.0" } snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.18.0" } starknet = "2.5.3" From 03144f4d2d2e7609935d72410d12c5e9c2079859 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 27 Feb 2024 09:14:21 +0000 Subject: [PATCH 37/43] remove more warnings --- crates/cartridge_account/src/erc20.cairo | 2 +- crates/cartridge_account/src/lib.cairo | 6 +++--- crates/cartridge_account/tests/test_account.cairo | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/cartridge_account/src/erc20.cairo b/crates/cartridge_account/src/erc20.cairo index 37a20d2e..b31e3d34 100644 --- a/crates/cartridge_account/src/erc20.cairo +++ b/crates/cartridge_account/src/erc20.cairo @@ -57,7 +57,7 @@ mod ERC20 { } #[generate_trait] - #[external(v0)] + #[abi(per_item)] impl ExternalImpl of ExternalTrait { fn burn(ref self: ContractState, value: u256) { let caller = get_caller_address(); diff --git a/crates/cartridge_account/src/lib.cairo b/crates/cartridge_account/src/lib.cairo index 298edf03..b118b21f 100644 --- a/crates/cartridge_account/src/lib.cairo +++ b/crates/cartridge_account/src/lib.cairo @@ -94,7 +94,7 @@ mod Account { // External // - #[external(v0)] + #[abi(embed_v0)] impl SRC6Impl of interface::ISRC6 { fn __execute__(self: @ContractState, mut calls: Array) -> Array> { // Avoid calls from other contracts @@ -126,14 +126,14 @@ mod Account { } } - #[external(v0)] + #[abi(embed_v0)] impl DeclarerImpl of interface::IDeclarer { fn __validate_declare__(self: @ContractState, class_hash: felt252) -> felt252 { self.validate_ecdsa_transaction() } } - #[external(v0)] + #[abi(embed_v0)] impl PublicKeyImpl of super::IPublicKey { fn get_public_key(self: @ContractState) -> felt252 { self.Account_public_key.read() diff --git a/crates/cartridge_account/tests/test_account.cairo b/crates/cartridge_account/tests/test_account.cairo index 785f3962..e04f01b0 100644 --- a/crates/cartridge_account/tests/test_account.cairo +++ b/crates/cartridge_account/tests/test_account.cairo @@ -121,7 +121,7 @@ fn test_account() { let recipient = contract_address_const::<0x123>(); let call = TransferCall { erc20: erc20_address, recipient: recipient, amount: 200 }.to_call(); - let ret = account.__execute__(array![call]); + let _ret = account.__execute__(array![call]); // Verify that the transfer of tokens was succesful assert(erc20.balance_of(account_address) == 800, 'Should have remained'); From 0cd0fadbf86b83991b17ff4e4c8f6487f41db432 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Tue, 27 Feb 2024 09:32:27 +0000 Subject: [PATCH 38/43] bump tool versions --- .tool-versions | 4 ++-- crates/cartridge_account/src/lib.cairo | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.tool-versions b/.tool-versions index 5e1f44fe..f0fa06cc 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -scarb 2.4.3 -starknet-foundry 0.14.0 +scarb 2.5.4 +starknet-foundry 0.18.0 python 3.9.18 dojo 0.4.4 \ No newline at end of file diff --git a/crates/cartridge_account/src/lib.cairo b/crates/cartridge_account/src/lib.cairo index b118b21f..5247d258 100644 --- a/crates/cartridge_account/src/lib.cairo +++ b/crates/cartridge_account/src/lib.cairo @@ -94,6 +94,7 @@ mod Account { // External // + // TODO: Remove this warning #[abi(embed_v0)] impl SRC6Impl of interface::ISRC6 { fn __execute__(self: @ContractState, mut calls: Array) -> Array> { From 2f938f1e5fcc418aadd205e8fc8ed1a6fb9d7f83 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 28 Feb 2024 11:02:29 +0000 Subject: [PATCH 39/43] remove devnet runner test --- crates/account_sdk/src/tests/runners_test.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/account_sdk/src/tests/runners_test.rs b/crates/account_sdk/src/tests/runners_test.rs index adabf34f..448b1f2d 100644 --- a/crates/account_sdk/src/tests/runners_test.rs +++ b/crates/account_sdk/src/tests/runners_test.rs @@ -1,11 +1,6 @@ -use super::runners::{devnet_runner::DevnetRunner, katana_runner::KatanaRunner, TestnetRunner}; +use super::runners::{katana_runner::KatanaRunner, TestnetRunner}; #[test] fn test_katana_runner() { KatanaRunner::load(); } - -#[test] -fn test_devnet_runner() { - DevnetRunner::load(); -} From b7fd26b3a9a33977505219508b09ac244fe93fc3 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 28 Feb 2024 23:00:06 +0000 Subject: [PATCH 40/43] bump merkle_tree version and update test --- Scarb.toml | 4 ++-- crates/account_sdk/src/session_token/hash.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index cff0565e..de97dcee 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -11,8 +11,8 @@ version = "0.1.0" [workspace.dependencies] alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } -alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria",tag="cairo-v2.5.4" } -alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", rev = "085f17c87cf6d168032ef5840c39b8e18012284f" } +alexandria_encoding = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } +alexandria_merkle_tree = { git = "https://github.com/keep-starknet-strange/alexandria", tag="cairo-v2.5.4" } openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts", tag = "v0.9.0" } snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.18.0" } starknet = "2.5.3" diff --git a/crates/account_sdk/src/session_token/hash.rs b/crates/account_sdk/src/session_token/hash.rs index 9e01dc7e..f923aa37 100644 --- a/crates/account_sdk/src/session_token/hash.rs +++ b/crates/account_sdk/src/session_token/hash.rs @@ -142,11 +142,11 @@ fn get_next_level(nodes: &Vec) -> Vec { #[test] fn merkle_tree_poseidon_test() { // [Setup] Merkle tree. - let root = felt!("0x7abc09d19c8a03abd4333a23f7823975c7bdd325170f0d32612b8baa1457d47"); + let root = felt!("0x48924a3b2a7a7b7cc1c9371357e95e322899880a6534bdfe24e96a828b9d780"); let leaf = felt!("0x1"); let valid_proof = vec![ felt!("0x2"), - felt!("0x47ef3ad11ad3f8fc055281f1721acd537563ec134036bc4bd4de2af151f0832"), + felt!("0x338eb608d7e48306d01f5a8d4275dd85a52ba79aaf7a1a7b35808ba573c3669"), ]; let leaves = vec![felt!("0x1"), felt!("0x2"), felt!("0x3")]; From a0789d4fbec46d1e547353a0ac365aba171839d6 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 28 Feb 2024 23:05:05 +0000 Subject: [PATCH 41/43] change hashing to reflext alexandria fix --- crates/account_sdk/src/session_token/hash.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/crates/account_sdk/src/session_token/hash.rs b/crates/account_sdk/src/session_token/hash.rs index f923aa37..65db854d 100644 --- a/crates/account_sdk/src/session_token/hash.rs +++ b/crates/account_sdk/src/session_token/hash.rs @@ -1,5 +1,5 @@ use starknet::{core::types::FieldElement, macros::felt}; -use starknet_crypto::PoseidonHasher; +use starknet_crypto::{poseidon_hash, PoseidonHasher}; use crate::abigen::account::{Call, SessionSignature}; @@ -18,13 +18,6 @@ const POLICY_TYPE_HASH: FieldElement = const STARKNET_MESSAGE_FELT: FieldElement = felt!("0x537461726b4e6574204d657373616765"); -fn hash_two_elements(a: FieldElement, b: FieldElement) -> FieldElement { - let mut hasher = PoseidonHasher::new(); - hasher.update(a); - hasher.update(b); - hasher.finalize() -} - pub fn compute_session_hash( signature: SessionSignature, chain_id: FieldElement, @@ -89,9 +82,9 @@ pub fn compute_root(mut current_node: FieldElement, mut proof: Vec // We need to check if the current node is smaller than the current element of the proof. // If it is, we need to swap the order of the hash. current_node = if current_node < proof_element { - hash_two_elements(current_node, proof_element) + poseidon_hash(current_node, proof_element) } else { - hash_two_elements(proof_element, current_node) + poseidon_hash(proof_element, current_node) }; } } @@ -129,9 +122,9 @@ fn get_next_level(nodes: &Vec) -> Vec { let right = nodes[i * 2 + 1]; let node = if left < right { - hash_two_elements(left, right) + poseidon_hash(left, right) } else { - hash_two_elements(right, left) + poseidon_hash(right, left) }; next_level.push(node); } From 6da9eaf4a20d18649fa5ce2b80ed182b04b43d00 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Wed, 28 Feb 2024 23:25:53 +0000 Subject: [PATCH 42/43] use a function from std lib when checking point bounds --- crates/webauthn/auth/src/ecdsa.cairo | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/crates/webauthn/auth/src/ecdsa.cairo b/crates/webauthn/auth/src/ecdsa.cairo index 0e2d4993..4cce080a 100644 --- a/crates/webauthn/auth/src/ecdsa.cairo +++ b/crates/webauthn/auth/src/ecdsa.cairo @@ -1,6 +1,6 @@ use core::array::ArrayTrait; use core::debug::PrintTrait; -use core::starknet::secp256_trait::Secp256PointTrait; +use core::starknet::secp256_trait::{Secp256PointTrait, is_signature_entry_valid}; use starknet::secp256r1::Secp256r1Point; use starknet::secp256r1::Secp256r1Impl; use starknet::secp256r1::Secp256r1PointImpl; @@ -39,7 +39,8 @@ fn verify_ecdsa( fn verify_hashed_ecdsa( public_key_pt: Secp256r1Point, msg_hash: u256, r: u256, s: u256 ) -> Result<(), VerifyEcdsaError> { - if check_bounds(r, s) == false { + if !is_signature_entry_valid::(r) + || !is_signature_entry_valid::(s) { return Result::Err(VerifyEcdsaError::WrongArgument); } @@ -96,19 +97,3 @@ impl ImplVerifyEcdsaErrorIntoFelt252 of Into { } } } - -#[derive(Drop)] -fn check_bounds(r: u256, s: u256) -> bool { - let n = Secp256r1Impl::get_curve_size(); - if r > n { - false - } else if s > n { - false - } else if r < 1 { - false - } else if s < 1 { - false - } else { - true - } -} From a22e7f6b70804ac11ba4fcb29b3a618fb17de909 Mon Sep 17 00:00:00 2001 From: Szymon Wojtulewicz Date: Mon, 11 Mar 2024 12:03:52 +0000 Subject: [PATCH 43/43] cargo clippy --- crates/account_sdk/src/session_token/hash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/account_sdk/src/session_token/hash.rs b/crates/account_sdk/src/session_token/hash.rs index 65db854d..65d63ba5 100644 --- a/crates/account_sdk/src/session_token/hash.rs +++ b/crates/account_sdk/src/session_token/hash.rs @@ -115,7 +115,7 @@ fn compute_proof(mut nodes: Vec, index: usize, proof: &mut Vec) -> Vec { +fn get_next_level(nodes: &[FieldElement]) -> Vec { let mut next_level: Vec = Vec::with_capacity(nodes.len() / 2); for i in 0..nodes.len() / 2 { let left = nodes[i * 2];