Skip to content

Commit

Permalink
conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Mar 27, 2024
2 parents 4b77465 + 2d59636 commit 966883d
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 66 deletions.
22 changes: 10 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet"
version = "0.9.0"
version = "0.10.0"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down Expand Up @@ -33,14 +33,13 @@ members = [
all-features = true

[dependencies]
starknet-crypto = { version = "0.6.1", path = "./starknet-crypto" }
starknet-core = { version = "0.9.0", path = "./starknet-core", default-features = false }
starknet-providers = { version = "0.9.0", path = "./starknet-providers" }
starknet-contract = { version = "0.8.0", path = "./starknet-contract" }
starknet-signers = { version = "0.7.0", path = "./starknet-signers" }
starknet-accounts = { version = "0.8.0", path = "./starknet-accounts" }
starknet-macros = { version = "0.1.6", path = "./starknet-macros" }
starknet-types-core = "0.0.10"
starknet-crypto = { version = "0.6.2", path = "./starknet-crypto" }
starknet-core = { version = "0.10.0", path = "./starknet-core", default-features = false }
starknet-providers = { version = "0.10.0", path = "./starknet-providers" }
starknet-contract = { version = "0.9.0", path = "./starknet-contract" }
starknet-signers = { version = "0.8.0", path = "./starknet-signers" }
starknet-accounts = { version = "0.9.0", path = "./starknet-accounts" }
starknet-macros = { version = "0.1.7", path = "./starknet-macros" }

[dev-dependencies]
serde_json = "1.0.74"
Expand Down
2 changes: 1 addition & 1 deletion examples/starknet-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"]

[dependencies]
starknet-crypto = { version = "0.6.1", path = "../../starknet-crypto" }
starknet-crypto = { version = "0.6.2", path = "../../starknet-crypto" }
console_error_panic_hook = { version = "0.1.7", optional = true }
wasm-bindgen = "0.2.84"
starknet-types-core = "0.0.10"
Expand Down
8 changes: 4 additions & 4 deletions starknet-accounts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-accounts"
version = "0.8.0"
version = "0.9.0"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -14,9 +14,9 @@ keywords = ["ethereum", "starknet", "web3"]
exclude = ["test-data/**"]

[dependencies]
starknet-core = { version = "0.9.0", path = "../starknet-core" }
starknet-providers = { version = "0.9.0", path = "../starknet-providers" }
starknet-signers = { version = "0.7.0", path = "../starknet-signers" }
starknet-core = { version = "0.10.0", path = "../starknet-core" }
starknet-providers = { version = "0.10.0", path = "../starknet-providers" }
starknet-signers = { version = "0.8.0", path = "../starknet-signers" }
async-trait = "0.1.68"
auto_impl = "1.0.1"
thiserror = "1.0.40"
Expand Down
10 changes: 5 additions & 5 deletions starknet-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-contract"
version = "0.8.0"
version = "0.9.0"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -14,9 +14,9 @@ keywords = ["ethereum", "starknet", "web3"]
exclude = ["test-data/**"]

[dependencies]
starknet-core = { version = "0.9.0", path = "../starknet-core" }
starknet-providers = { version = "0.9.0", path = "../starknet-providers" }
starknet-accounts = { version = "0.8.0", path = "../starknet-accounts" }
starknet-core = { version = "0.10.0", path = "../starknet-core" }
starknet-providers = { version = "0.10.0", path = "../starknet-providers" }
starknet-accounts = { version = "0.9.0", path = "../starknet-accounts" }
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96"
serde_with = "2.3.2"
Expand All @@ -25,6 +25,6 @@ starknet-types-core = "0.0.10"

[dev-dependencies]
rand = { version = "0.8.5", features=["std_rng"] }
starknet-signers = { version = "0.7.0", path = "../starknet-signers" }
starknet-signers = { version = "0.8.0", path = "../starknet-signers" }
tokio = { version = "1.27.0", features = ["full"] }
url = "2.3.1"
4 changes: 2 additions & 2 deletions starknet-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-core"
version = "0.9.0"
version = "0.10.0"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -17,7 +17,7 @@ exclude = ["test-data/**"]
all-features = true

[dependencies]
starknet-crypto = { version = "0.6.1", path = "../starknet-crypto", default-features = false, features = ["alloc"] }
starknet-crypto = { version = "0.6.2", path = "../starknet-crypto", default-features = false, features = ["alloc"] }
base64 = { version = "0.21.0", default-features = false, features = ["alloc"] }
flate2 = { version = "1.0.25", optional = true }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
Expand Down
7 changes: 3 additions & 4 deletions starknet-crypto-codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-crypto-codegen"
version = "0.3.2"
version = "0.3.3"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -16,6 +16,5 @@ keywords = ["ethereum", "starknet", "web3", "no_std"]
proc-macro = true

[dependencies]
starknet-curve = { version = "0.4.1", path = "../starknet-curve" }
syn = { version = "2.0.15", default-features = true }
starknet-types-core = "0.0.10"
starknet-curve = { version = "0.4.2", path = "../starknet-curve" }
syn = { version = "2.0.15", default-features = false }
6 changes: 3 additions & 3 deletions starknet-crypto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "starknet-crypto"
version = "0.6.1"
version = "0.6.2"
authors = ["Jonathan LEI <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand All @@ -14,8 +14,8 @@ keywords = ["ethereum", "starknet", "web3", "no_std"]
exclude = ["test-data/**"]

[dependencies]
starknet-crypto-codegen = { version = "0.3.2", path = "../starknet-crypto-codegen" }
starknet-curve = { version = "0.4.1", path = "../starknet-curve" }
starknet-crypto-codegen = { version = "0.3.3", path = "../starknet-crypto-codegen" }
starknet-curve = { version = "0.4.2", path = "../starknet-curve" }
crypto-bigint = { version = "0.5.1", default-features = false, features = ["generic-array", "zeroize"] }
hmac = { version = "0.12.1", default-features = false }
num-bigint = { version = "0.4.3", default-features = false }
Expand Down
50 changes: 46 additions & 4 deletions starknet-crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ fn mul_by_bits(x: &AffinePoint, y: &Felt) -> AffinePoint {

#[cfg(test)]
mod tests {
#[cfg(not(feature = "std"))]
use alloc::collections::BTreeMap;
#[cfg(feature = "std")]
use std::collections::BTreeMap;

use super::*;
use crate::test_utils::field_element_from_be_hex;

Expand All @@ -215,11 +220,11 @@ mod tests {
let private_key = field_element_from_be_hex(
"03c1e9550e66958296d11b60f8e8e7a7ad990d07fa65d5f7652c4a6c87d4e3cc",
);
let expected_key = field_element_from_be_hex(
let expected_public_key = field_element_from_be_hex(
"077a3b314db07c45076d11f62b6f9e748a39790441823307743cf00d6597ea43",
);

assert_eq!(get_public_key(&private_key), expected_key);
assert_eq!(get_public_key(&private_key), expected_public_key);
}

#[test]
Expand All @@ -228,11 +233,48 @@ mod tests {
let private_key = field_element_from_be_hex(
"0000000000000000000000000000000000000000000000000000000000000012",
);
let expected_key = field_element_from_be_hex(
let expected_public_key = field_element_from_be_hex(
"019661066e96a8b9f06a1d136881ee924dfb6a885239caa5fd3f87a54c6b25c4",
);

assert_eq!(get_public_key(&private_key), expected_key);
assert_eq!(get_public_key(&private_key), expected_public_key);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_get_public_keys_from_json() {
// Precomputed keys can be found here:
// https://github.com/starkware-libs/starkex-for-spot-trading/blob/607f0b4ce507e1d95cd018d206a2797f6ba4aab4/src/starkware/crypto/starkware/crypto/signature/src/config/keys_precomputed.json

// Reading the JSON file
let json_data = include_str!("../test-data/keys_precomputed.json");

// Parsing the JSON
let key_map: BTreeMap<String, String> =
serde_json::from_str(json_data).expect("Unable to parse the JSON");

// Iterating over each element in the JSON
for (private_key, expected_public_key) in key_map.into_iter() {
let private_key = if private_key.len() % 2 != 0 {
format!("0{}", private_key.trim_start_matches("0x"))
} else {
private_key.trim_start_matches("0x").to_owned()
};

let expected_public_key = if expected_public_key.len() % 2 != 0 {
format!("0{}", expected_public_key.trim_start_matches("0x"))
} else {
expected_public_key.trim_start_matches("0x").to_owned()
};

// Assertion
assert_eq!(
get_public_key(&field_element_from_be_hex(
private_key.trim_start_matches("0x")
)),
field_element_from_be_hex(expected_public_key.trim_start_matches("0x"))
);
}
}

#[test]
Expand Down
34 changes: 20 additions & 14 deletions starknet-crypto/src/pedersen_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ pub fn pedersen_hash(x: &Felt, y: &Felt) -> Felt {
add_points(&mut acc, &y[..248], &CURVE_CONSTS_P2); // Add b_low * P3
add_points(&mut acc, &y[248..252], &CURVE_CONSTS_P3); // Add b_high * P4

// Convert to affine
let result = AffinePoint::from(&acc);

// Return x-coordinate
result.x
}
Expand All @@ -61,21 +58,30 @@ mod tests {
use crate::test_utils::field_element_from_be_hex;

// Test case ported from:
// https://github.com/starkware-libs/crypto-cpp/blob/95864fbe11d5287e345432dbe1e80dea3c35fc58/src/starkware/crypto/ffi/crypto_lib_test.go
// https://github.com/starkware-libs/starkex-for-spot-trading/blob/607f0b4ce507e1d95cd018d206a2797f6ba4aab4/src/starkware/crypto/starkware/crypto/signature/test/config/signature_test_data.json

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
fn test_pedersen_hash() {
let in1 = field_element_from_be_hex(
"03d937c035c878245caf64531a5756109c53068da139362728feb561405371cb",
);
let in2 = field_element_from_be_hex(
"0208a0a10250e382e1e4bbe2880906c2791bf6275695e02fbbc6aeff9cd8b31a",
);
let expected_hash = field_element_from_be_hex(
"030e480bed5fe53fa909cc0f8c4d99b8f9f2c016be4c41e13a4848797979c662",
);
let test_data = [
(
"03d937c035c878245caf64531a5756109c53068da139362728feb561405371cb",
"0208a0a10250e382e1e4bbe2880906c2791bf6275695e02fbbc6aeff9cd8b31a",
"030e480bed5fe53fa909cc0f8c4d99b8f9f2c016be4c41e13a4848797979c662",
),
(
"058f580910a6ca59b28927c08fe6c43e2e303ca384badc365795fc645d479d45",
"078734f65a067be9bdb39de18434d71e79f7b6466a4b66bbd979ab9e7515fe0b",
"068cc0b76cddd1dd4ed2301ada9b7c872b23875d5ff837b3a87993e0d9996b87",
),
];

for (in1, in2, expected_hash) in test_data.into_iter() {
let in1 = field_element_from_be_hex(in1);
let in2 = field_element_from_be_hex(in2);
let expected_hash = field_element_from_be_hex(expected_hash);

assert_eq!(pedersen_hash(&in1, &in2), expected_hash);
assert_eq!(pedersen_hash(&in1, &in2), expected_hash);
}
}
}
Loading

0 comments on commit 966883d

Please sign in to comment.