Skip to content

Commit

Permalink
Use constant for Felt::max / 2
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta committed Mar 17, 2023
1 parent 60f23c7 commit 5c0ad0d
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/hint_processor/builtin_hint_processor/ec_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ lazy_static! {
10
)
.unwrap();
static ref FELT_MAX_HALVED: BigUint = Felt252::max_value().to_biguint() / 2_u32;
}

// Recovers the corresponding y coordinate on the elliptic curve
Expand All @@ -217,10 +218,7 @@ fn recover_y(x: &BigUint) -> Option<BigUint> {
// + prime is ommited as it will be CAIRO_PRIME
// + a >= 0 < prime (other cases ommited)
fn is_quad_residue(a: &BigUint) -> bool {
a.is_zero()
|| a.is_one()
|| a.modpow(&(Felt252::max_value().to_biguint() / 2_u32), &CAIRO_PRIME)
.is_one()
a.is_zero() || a.is_one() || a.modpow(&FELT_MAX_HALVED, &CAIRO_PRIME).is_one()
}

#[cfg(test)]
Expand Down

1 comment on commit 5c0ad0d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: 5c0ad0d Previous: 40d8325 Ratio
cairo_run(cairo_programs/benchmarks/factorial_multirun.json) 263974229 ns/iter (± 1286989) 202752642 ns/iter (± 2357613) 1.30
cairo_run(cairo_programs/benchmarks/fibonacci_1000_multirun.json) 117023626 ns/iter (± 570825) 84679294 ns/iter (± 6118116) 1.38
cairo_run(cairo_programs/benchmarks/integration_builtins.json) 434420934 ns/iter (± 14943052) 325599297 ns/iter (± 5771110) 1.33
cairo_run(cairo_programs/benchmarks/linear_search.json) 90443749 ns/iter (± 510483) 66732134 ns/iter (± 458848) 1.36
cairo_run(cairo_programs/benchmarks/keccak_integration_benchmark.json) 1271257660 ns/iter (± 4323839) 942800313 ns/iter (± 2763701) 1.35
cairo_run(cairo_programs/benchmarks/secp_integration_benchmark.json) 1535346604 ns/iter (± 2641973) 1046330812 ns/iter (± 3168476) 1.47
cairo_run(cairo_programs/benchmarks/blake2s_integration_benchmark.json) 1231058188 ns/iter (± 2500716) 891741389 ns/iter (± 2957602) 1.38
cairo_run(cairo_programs/benchmarks/operations_with_data_structures_benchmarks.json) 1828453716 ns/iter (± 5913583) 1404886369 ns/iter (± 6438690) 1.30

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.