Skip to content

Commit

Permalink
updated cargo clippy fix for starknet-crypto, starknet-crypto-codegen…
Browse files Browse the repository at this point in the history
… and starknet-curve
  • Loading branch information
aniketpr01 committed Jun 17, 2024
1 parent 9102b4a commit 18c5b84
Show file tree
Hide file tree
Showing 8 changed files with 320 additions and 15 deletions.
3 changes: 3 additions & 0 deletions starknet-crypto-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ proc-macro = true
starknet-curve = { version = "0.5.0", path = "../starknet-curve" }
syn = "2.0.55"
starknet-types-core = { version = "0.1.3", default-features = false, features = ["curve"] }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions starknet-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ harness = false
[[bench]]
name = "rfc6979_generate_k"
harness = false

[lints]
workspace = true
6 changes: 3 additions & 3 deletions starknet-crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl From<ExtendedSignature> for Signature {

#[cfg(feature = "signature-display")]
impl core::fmt::Display for Signature {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"{}{}",
Expand All @@ -57,7 +57,7 @@ impl core::fmt::Display for Signature {

#[cfg(feature = "signature-display")]
impl core::fmt::Display for ExtendedSignature {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"{}{}{:02x}",
Expand Down Expand Up @@ -278,7 +278,7 @@ mod tests {
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() {
for (private_key, expected_public_key) in key_map {
let private_key = if private_key.len() % 2 != 0 {
format!("0{}", private_key.trim_start_matches("0x"))
} else {
Expand Down
2 changes: 1 addition & 1 deletion starknet-crypto/src/pedersen_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ mod tests {
),
];

for (in1, in2, expected_hash) in test_data.into_iter() {
for (in1, in2, expected_hash) in test_data {
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);
Expand Down
17 changes: 8 additions & 9 deletions starknet-crypto/src/poseidon_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ poseidon_consts!();

/// A hasher for Starknet Poseidon hash.
///
/// Using this hasher is the same as calling [poseidon_hash_many].
/// Using this hasher is the same as calling [`poseidon_hash_many`].
#[derive(Debug, Default)]
pub struct PoseidonHasher {
state: [Felt; 3],
buffer: Option<Felt>,
}

impl PoseidonHasher {
/// Creates a new [PoseidonHasher].
/// Creates a new [`PoseidonHasher`].
pub fn new() -> Self {
Self::default()
}
Expand Down Expand Up @@ -61,15 +61,15 @@ pub fn poseidon_hash(x: Felt, y: Felt) -> Felt {
state[0]
}

/// Computes the Starknet Poseidon hash of a single [Felt].
/// Computes the Starknet Poseidon hash of a single [`Felt`].
pub fn poseidon_hash_single(x: Felt) -> Felt {
let mut state = [x, Felt::ZERO, Felt::ONE];
poseidon_permute_comp(&mut state);

state[0]
}

/// Computes the Starknet Poseidon hash of an arbitrary number of [Felt]s.
/// Computes the Starknet Poseidon hash of an arbitrary number of [`Felt`]s.
///
/// Using this function is the same as using [PoseidonHasher].
pub fn poseidon_hash_many(msgs: &[Felt]) -> Felt {
Expand Down Expand Up @@ -132,11 +132,10 @@ fn round_comp(state: &mut [Felt; 3], idx: usize, full: bool) {
state[2] += POSEIDON_COMP_CONSTS[idx + 2];
state[0] = state[0] * state[0] * state[0];
state[1] = state[1] * state[1] * state[1];
state[2] = state[2] * state[2] * state[2];
} else {
state[2] += POSEIDON_COMP_CONSTS[idx];
state[2] = state[2] * state[2] * state[2];
}
state[2] = state[2] * state[2] * state[2];
mix(state);
}

Expand Down Expand Up @@ -167,7 +166,7 @@ mod tests {
),
];

for (x, y, hash) in test_data.into_iter() {
for (x, y, hash) in test_data {
assert_eq!(poseidon_hash(x, y), hash);
}
}
Expand All @@ -191,7 +190,7 @@ mod tests {
),
];

for (x, hash) in test_data.into_iter() {
for (x, hash) in test_data {
assert_eq!(poseidon_hash_single(x), hash);
}
}
Expand Down Expand Up @@ -243,7 +242,7 @@ mod tests {
),
];

for (input, hash) in test_data.into_iter() {
for (input, hash) in test_data {
// Direct function call
assert_eq!(poseidon_hash_many(&input), hash);

Expand Down
4 changes: 2 additions & 2 deletions starknet-crypto/src/rfc6979.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ mod tests {
}

fn test_generate_k_from_json_str(json_str: &'static str) {
let test_vectors: Vec<Rfc6979TestVecotr> = serde_json::from_str(json_str).unwrap();
let test_vectors: Vec<Rfc6979TestVecotr<'_>> = serde_json::from_str(json_str).unwrap();

for test_vector in test_vectors.iter() {
for test_vector in &test_vectors {
let msg_hash = field_element_from_be_hex(test_vector.msg_hash);
let priv_key = field_element_from_be_hex(test_vector.priv_key);
let seed = field_element_from_be_hex(test_vector.seed);
Expand Down
3 changes: 3 additions & 0 deletions starknet-curve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ keywords = ["ethereum", "starknet", "web3", "no_std"]

[dependencies]
starknet-types-core = { version = "0.1.3", default-features = false, features = ["curve"] }

[lints]
workspace = true
Loading

0 comments on commit 18c5b84

Please sign in to comment.