Skip to content

Commit

Permalink
perf: update lambdaworks to 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Mar 26, 2024
1 parent 14b9548 commit fdd637e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
4 changes: 2 additions & 2 deletions crates/starknet-types-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"

[dependencies]
bitvec = { version = "1.0.1", default-features = false }
lambdaworks-math = { version = "0.5.0", default-features = false}
lambdaworks-math = { version = "0.6.0", default-features = false}

num-traits = { version = "0.2.16", default-features = false }
num-bigint = { version = "0.4.4", default-features = false }
Expand All @@ -24,7 +24,7 @@ lazy_static = { version = "1.4.0", default-features = false, features = [
# Optional
arbitrary = { version = "1.3.0", optional = true }
serde = { version = "1.0.163", optional = true, default-features = false, features = ["alloc"] }
lambdaworks-crypto = { version = "0.5.0", default-features = false, optional = true }
lambdaworks-crypto = { version = "0.6.0", default-features = false, optional = true }
parity-scale-codec = { version = "3.2.2", default-features = false, optional = true }

[features]
Expand Down
15 changes: 5 additions & 10 deletions crates/starknet-types-core/src/hash/pedersen.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
use crate::felt::Felt;
use lambdaworks_crypto::hash::pedersen::Pedersen as PedersenLambdaworks;
use lambdaworks_crypto::hash::pedersen::{Pedersen as PedersenLambdaworks, PedersenStarkCurve};
use lambdaworks_math::field::{
element::FieldElement, fields::fft_friendly::stark_252_prime_field::Stark252PrimeField,
};
use lazy_static::lazy_static;

use super::traits::StarkHash;

pub struct Pedersen;

lazy_static! {
/// Pedersen hasher.
pub static ref PEDERSEN: PedersenLambdaworks = PedersenLambdaworks::default();
}
impl StarkHash for Pedersen {
/// Computes the Pedersen hash of two Felts, as defined
/// in <https://docs.starknet.io/documentation/architecture_and_concepts/Hashing/hash-functions/#pedersen_hash.>
fn hash(felt_0: &Felt, felt_1: &Felt) -> Felt {
Felt(PEDERSEN.hash(&felt_0.0, &felt_1.0))
Felt(PedersenStarkCurve::hash(&felt_0.0, &felt_1.0))
}

/// Computes the Pedersen hash of an array of Felts, as defined
/// in <https://docs.starknet.io/documentation/architecture_and_concepts/Hashing/hash-functions/#array_hashing.>
fn hash_array(felts: &[Felt]) -> Felt {
let data_len = Felt::from(felts.len());
let current_hash: FieldElement<Stark252PrimeField> = felts.iter().fold(
FieldElement::<Stark252PrimeField>::zero(),
|current_hash, felt| PEDERSEN.hash(&current_hash, &felt.0),
FieldElement::zero(),
|current_hash, felt| PedersenStarkCurve::hash(&current_hash, &felt.0),
);
Felt(PEDERSEN.hash(&current_hash, &data_len.0))
Felt(PedersenStarkCurve::hash(&current_hash, &data_len.0))
}
}

Expand Down

0 comments on commit fdd637e

Please sign in to comment.