Skip to content

Commit

Permalink
lint + array index fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
irfanbozkurt committed Oct 9, 2023
1 parent 60a1d5f commit 201fb2a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crypto/src/hash/pedersen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Pedersen<StarkCurve> {
add_points(&mut acc, &y[..248], &self.params.points_p3); // Add b_low * P3
add_points(&mut acc, &y[248..252], &self.params.points_p4); // Add b_high * P4

acc.x().clone()
acc.to_affine().x().clone()
}
}

Expand All @@ -72,7 +72,7 @@ mod tests {
use super::*;

// 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/crypto-cpp/blob/95864fbe11d5287e345432dbe1e80dea3c35fc58/src/starkware/crypto/ffi/crypto_lib_test.go

#[test]
fn test_stark_curve() {
Expand Down
23 changes: 17 additions & 6 deletions crypto/src/hash/pedersen/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ impl PedersenParameters<StarkCurve> {
// Ordered as shift_point, points_p1, points_p2, points_p3, points_p4
let all_points: Vec<ShortWeierstrassProjectivePoint<StarkCurve>> =
Self::parse_affine_points(field_elements_csv);
assert_eq!(all_points.len(), 1 + 248 + 4 + 248 + 4);
assert_eq!(all_points.len(), 1891); // Hard-coded lookup table size, equal to that of starknet-rs

let (shift_point, remaining) = all_points.split_at(1);
let (points_p1, remaining) = remaining.split_at(248);
let (points_p2, remaining) = remaining.split_at(4);
let (points_p3, points_p4) = remaining.split_at(248);
let (points_p1, remaining) = remaining.split_at(930);
let (points_p2, remaining) = remaining.split_at(15);
let (points_p3, points_p4) = remaining.split_at(930);

let curve_const_bits = 4;
Self {
Expand All @@ -55,11 +55,22 @@ impl PedersenParameters<StarkCurve> {
.chunks(2)
.map(|point| {
ShortWeierstrassProjectivePoint::<StarkCurve>::from_affine(
FieldElement::<Stark252PrimeField>::from_hex_unchecked(point[0]),
FieldElement::<Stark252PrimeField>::from_hex_unchecked(point[1]),
FieldElement::<Stark252PrimeField>::from_hex_unchecked(point[0].trim()),
FieldElement::<Stark252PrimeField>::from_hex_unchecked(point[1].trim()),
)
.unwrap()
})
.collect()
}
}











2 changes: 1 addition & 1 deletion crypto/src/hash/pedersen/stark/points.csv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions math/src/field/fields/fft_friendly/stark_252_prime_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ impl FieldElement<Stark252PrimeField> {
for i in (0..4).rev() {
let limb_bytes = limbs[i].to_le_bytes();
let limb_bytes_starting_index = (3 - i) * 8;
for j in 0..8 {
for (j, byte) in limb_bytes.iter().enumerate() {
let byte_index = (limb_bytes_starting_index + j) * 8;
for k in 0..8 {
let bit_index = byte_index + k;
let bit_value = (limb_bytes[j] >> k) & 1 == 1;
let bit_value = (byte >> k) & 1 == 1;
bits[bit_index] = bit_value;
}
}
Expand Down

0 comments on commit 201fb2a

Please sign in to comment.