Skip to content

refactor(ec): store EcState in projective coordinates - #1654

Merged
TomerStarkware merged 1 commit into
mainfrom
tomer/use_projective_ec_points
Aug 20, 2026
Merged

refactor(ec): store EcState in projective coordinates#1654
TomerStarkware merged 1 commit into
mainfrom
tomer/use_projective_ec_points

Conversation

@TomerStarkware

@TomerStarkware TomerStarkware commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

EcState was stored as an affine pair, so every ec_state_add ended in to_affine() — a modular inversion — only for the next add to undo it. Storing the accumulator projectively defers that to a single inversion in ec_state_try_finalize_nz, so the cost of a chain of adds no longer grows with its length.


This change is Reviewable

@TomerStarkware
TomerStarkware requested a review from orizi August 16, 2026 12:13
@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 10.586 ± 0.050 10.513 10.685 5.89 ± 0.05
cairo-native (embedded AOT) 1.798 ± 0.014 1.776 1.816 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 1.813 ± 0.022 1.791 1.856 1.01 ± 0.01

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 523.9 ± 3.4 519.0 529.6 1.00
cairo-native (embedded AOT) 1650.3 ± 6.9 1641.8 1657.6 3.15 ± 0.02
cairo-native (embedded JIT using LLVM's ORC Engine) 1660.6 ± 12.0 1643.0 1677.3 3.17 ± 0.03

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.668 ± 0.040 4.630 4.737 2.72 ± 0.03
cairo-native (embedded AOT) 1.715 ± 0.016 1.697 1.748 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 1.738 ± 0.023 1.707 1.780 1.01 ± 0.02

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.677 ± 0.046 4.621 4.778 2.77 ± 0.05
cairo-native (embedded AOT) 1.691 ± 0.026 1.652 1.737 1.00 ± 0.02
cairo-native (embedded JIT using LLVM's ORC Engine) 1.686 ± 0.025 1.643 1.719 1.00

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 573.3 ± 7.0 563.7 589.4 1.00
cairo-native (embedded AOT) 1688.4 ± 24.0 1651.3 1731.2 2.95 ± 0.06
cairo-native (embedded JIT using LLVM's ORC Engine) 1739.0 ± 15.9 1718.7 1760.0 3.03 ± 0.05

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 491.1 ± 6.4 478.7 497.6 1.00
cairo-native (embedded AOT) 1667.0 ± 19.4 1640.0 1708.3 3.39 ± 0.06
cairo-native (embedded JIT using LLVM's ORC Engine) 1677.5 ± 15.2 1657.9 1698.6 3.42 ± 0.05

@github-actions

github-actions Bot commented Aug 16, 2026

Copy link
Copy Markdown

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 1.475 ± 0.031 1.449 1.539 1.00 ± 0.02
base dict_insert.cairo (AOT) 1.474 ± 0.013 1.456 1.493 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 1.746 ± 0.013 1.725 1.772 1.02 ± 0.03
head dict_insert.cairo (AOT) 1.708 ± 0.040 1.665 1.791 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 1.352 ± 0.018 1.321 1.385 1.00 ± 0.02
base dict_snapshot.cairo (AOT) 1.349 ± 0.018 1.318 1.373 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 1.529 ± 0.019 1.509 1.575 1.02 ± 0.01
head dict_snapshot.cairo (AOT) 1.505 ± 0.007 1.495 1.518 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 1.409 ± 0.019 1.377 1.439 1.02 ± 0.02
base factorial_2M.cairo (AOT) 1.378 ± 0.018 1.352 1.412 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 1.566 ± 0.008 1.554 1.577 1.01 ± 0.01
head factorial_2M.cairo (AOT) 1.551 ± 0.009 1.541 1.565 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 1.386 ± 0.026 1.344 1.433 1.02 ± 0.02
base fib_2M.cairo (AOT) 1.355 ± 0.021 1.318 1.387 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 1.514 ± 0.007 1.499 1.524 1.01 ± 0.01
head fib_2M.cairo (AOT) 1.502 ± 0.009 1.490 1.514 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 1.367 ± 0.017 1.351 1.400 1.01 ± 0.02
base linear_search.cairo (AOT) 1.351 ± 0.013 1.323 1.366 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 1.578 ± 0.012 1.566 1.600 1.02 ± 0.01
head linear_search.cairo (AOT) 1.551 ± 0.010 1.542 1.575 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 1.362 ± 0.014 1.346 1.390 1.02 ± 0.02
base logistic_map.cairo (AOT) 1.335 ± 0.015 1.314 1.362 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 1.548 ± 0.010 1.528 1.558 1.02 ± 0.01
head logistic_map.cairo (AOT) 1.524 ± 0.008 1.507 1.532 1.00

@TomerStarkware
TomerStarkware force-pushed the tomer/use_projective_ec_points branch from bcb9830 to d42c68b Compare August 16, 2026 12:48
`EcState` was stored as an affine pair, so every `ec_state_add` ended in
`to_affine()` — a modular inversion — only for the next add to undo it.
Storing the accumulator projectively defers that to a single inversion in
`ec_state_try_finalize_nz`, so the cost of a chain of adds no longer grows
with its length.
@TomerStarkware
TomerStarkware force-pushed the tomer/use_projective_ec_points branch from d42c68b to 474cceb Compare August 16, 2026 13:02

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@orizi reviewed 19 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@TomerStarkware
TomerStarkware added this pull request to the merge queue Aug 20, 2026
Merged via the queue into main with commit 69f61e9 Aug 20, 2026
15 checks passed
@TomerStarkware
TomerStarkware deleted the tomer/use_projective_ec_points branch August 20, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants