Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circuit gas diff: Implement u96_limbs_less_than_guarantee_verify #1084

Merged
merged 15 commits into from
Feb 6, 2025

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Feb 3, 2025

Fixes the gas issues related to circuits, by properly implementing u96_limbs_less_than_guarantee_verify

Types

The type CircuitOutputs used to contain an array of gate values, in integer form (u384). This PR changes two things:

  • Now the gate values are stored in struct form (struct of 4 x u96). This was already being done in get_circuit_output, so I moved the logic to the eval_circuit libfunc.
  • Now it also contains the circuit modulus, as it is required for the get_circuit_output libfunc.

The type U96LimbsLessThanGuarantee was a unit type as the related libfunc was not implemented. Now it contains the associated gate value, and the circuit modulus.

Libfuncs

The eval_circuit libfunc was changed to output the updated version of CircuitOutputs.

The get_circuit_output libfunc was changed to output the updated version of U96LimbsLessThanGuarantee.

The u96_limbs_less_than_guarantee_verify libfunc was implemented (it was a noop before this):

  • compares the last limb of the circuit value with the last limb of the modulus.
  • if they differ, it returns the difference.
  • if it does not differ, it returns the received value (U96LimbsLessThanGuarantee), without the last limb.

Copy link

github-actions bot commented Feb 3, 2025

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 3.883 ± 0.027 3.854 3.926 1.02 ± 0.01
base dict_insert.cairo (AOT) 3.809 ± 0.025 3.771 3.840 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 3.815 ± 0.025 3.772 3.855 1.03 ± 0.01
head dict_insert.cairo (AOT) 3.713 ± 0.017 3.688 3.741 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 3.769 ± 0.021 3.733 3.802 1.03 ± 0.01
base dict_snapshot.cairo (AOT) 3.665 ± 0.021 3.636 3.702 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 3.706 ± 0.031 3.637 3.747 1.01 ± 0.02
head dict_snapshot.cairo (AOT) 3.666 ± 0.059 3.576 3.756 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 4.111 ± 0.019 4.079 4.140 1.01 ± 0.01
base factorial_2M.cairo (AOT) 4.077 ± 0.023 4.043 4.112 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 4.038 ± 0.039 3.992 4.097 1.01 ± 0.01
head factorial_2M.cairo (AOT) 4.011 ± 0.033 3.967 4.086 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 3.668 ± 0.029 3.624 3.710 1.02 ± 0.01
base fib_2M.cairo (AOT) 3.599 ± 0.013 3.576 3.615 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 3.602 ± 0.027 3.538 3.627 1.00 ± 0.02
head fib_2M.cairo (AOT) 3.600 ± 0.048 3.521 3.667 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 3.843 ± 0.026 3.805 3.898 1.04 ± 0.01
base linear_search.cairo (AOT) 3.705 ± 0.018 3.675 3.727 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 3.820 ± 0.051 3.776 3.917 1.04 ± 0.02
head linear_search.cairo (AOT) 3.662 ± 0.021 3.622 3.688 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 3.926 ± 0.013 3.906 3.943 1.04 ± 0.01
base logistic_map.cairo (AOT) 3.768 ± 0.023 3.740 3.808 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 3.943 ± 0.031 3.891 3.988 1.06 ± 0.01
head logistic_map.cairo (AOT) 3.729 ± 0.031 3.666 3.779 1.00

Copy link

github-actions bot commented Feb 3, 2025

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 20.930 ± 0.192 20.786 21.437 5.53 ± 0.07
cairo-native (embedded AOT) 3.784 ± 0.030 3.725 3.833 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.838 ± 0.026 3.800 3.869 1.01 ± 0.01

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.845 ± 0.037 5.762 5.886 1.57 ± 0.03
cairo-native (embedded AOT) 3.713 ± 0.060 3.636 3.811 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.758 ± 0.019 3.729 3.790 1.01 ± 0.02

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 14.469 ± 0.074 14.374 14.627 3.58 ± 0.04
cairo-native (embedded AOT) 4.043 ± 0.039 3.994 4.113 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.077 ± 0.025 4.039 4.127 1.01 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 14.443 ± 0.056 14.382 14.538 4.01 ± 0.03
cairo-native (embedded AOT) 3.600 ± 0.027 3.558 3.642 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.642 ± 0.038 3.594 3.726 1.01 ± 0.01

Benchmark for program linear_search

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.837 ± 0.028 5.794 5.866 1.59 ± 0.01
cairo-native (embedded AOT) 3.679 ± 0.021 3.649 3.723 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 3.796 ± 0.019 3.761 3.816 1.03 ± 0.01

Benchmark for program logistic_map

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.913 ± 0.054 5.814 5.996 1.54 ± 0.02
cairo-native (embedded AOT) 3.840 ± 0.017 3.820 3.880 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.033 ± 0.052 3.975 4.122 1.05 ± 0.01

Instead of an array, now its a struct<array, array>, where the second
array is the modulo
It is ultimately returned in struct representation, so now it is
converted sooner (useful for guarantee representation)
@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 99.41520% with 1 line in your changes missing coverage. Please review.

Project coverage is 81.05%. Comparing base (c4cde60) to head (3e609eb).

Files with missing lines Patch % Lines
src/compiler.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1084      +/-   ##
==========================================
+ Coverage   80.93%   81.05%   +0.11%     
==========================================
  Files         108      108              
  Lines       29605    29726     +121     
==========================================
+ Hits        23961    24094     +133     
+ Misses       5644     5632      -12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JulianGCalderon JulianGCalderon mentioned this pull request Feb 5, 2025
5 tasks
@edg-l edg-l added this pull request to the merge queue Feb 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 6, 2025
@edg-l edg-l added this pull request to the merge queue Feb 6, 2025
Merged via the queue into main with commit 0a33cb3 Feb 6, 2025
28 checks passed
@edg-l edg-l deleted the fix-circuits-2 branch February 6, 2025 15:23
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.

4 participants