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

Basic example to run Cairo 1 programs #1370

Merged
merged 70 commits into from
Oct 12, 2023
Merged

Conversation

entropidelic
Copy link
Contributor

This PR shows the minimal steps required for running a Cairo 1 program, as it can be found in the StarkWare's cairo repo.

It is done with a simple fibonacci Cairo 1 program. The sierra code can be read directly from the fibonacci.sierra file or compiled inside the example.

To test it, just run cargo run inside the cairo1-run repo.

@entropidelic entropidelic changed the title Add Cairo 1 run basic example Basic example to run Cairo 1 programs Aug 11, 2023
@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Merging #1370 (4aed840) into main (a47c0c8) will decrease coverage by 0.15%.
The diff coverage is 69.81%.

@@            Coverage Diff             @@
##             main    #1370      +/-   ##
==========================================
- Coverage   96.99%   96.84%   -0.15%     
==========================================
  Files          93       94       +1     
  Lines       38791    39003     +212     
==========================================
+ Hits        37624    37772     +148     
- Misses       1167     1231      +64     
Files Coverage Δ
cairo1-run/src/main.rs 69.81% <69.81%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

github-actions bot commented Aug 11, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 3.610 ± 0.014 3.587 3.636 1.01 ± 0.01
head big_factorial 3.565 ± 0.015 3.540 3.589 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 3.001 ± 0.007 2.991 3.014 1.01 ± 0.00
head big_fibonacci 2.986 ± 0.010 2.972 2.999 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 8.259 ± 0.035 8.211 8.313 1.03 ± 0.01
head blake2s_integration_benchmark 8.024 ± 0.096 7.920 8.239 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 3.013 ± 0.013 2.996 3.034 1.00
head compare_arrays_200000 3.049 ± 0.021 3.033 3.102 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 2.110 ± 0.008 2.099 2.121 1.00 ± 0.00
head dict_integration_benchmark 2.104 ± 0.007 2.092 2.115 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.567 ± 0.008 1.556 1.579 1.00 ± 0.02
head field_arithmetic_get_square_benchmark 1.560 ± 0.023 1.547 1.623 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 8.240 ± 0.027 8.199 8.290 1.03 ± 0.01
head integration_builtins 8.014 ± 0.067 7.953 8.162 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.449 ± 0.011 8.433 8.467 1.02 ± 0.02
head keccak_integration_benchmark 8.244 ± 0.124 8.095 8.434 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 3.067 ± 0.015 3.047 3.086 1.00 ± 0.01
head linear_search 3.060 ± 0.011 3.042 3.076 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 2.228 ± 0.010 2.219 2.249 1.00
head math_cmp_and_pow_integration_benchmark 2.253 ± 0.008 2.245 2.273 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 2.013 ± 0.009 2.002 2.031 1.00
head math_integration_benchmark 2.025 ± 0.008 2.012 2.039 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.750 ± 0.004 1.745 1.757 1.00
head memory_integration_benchmark 1.813 ± 0.031 1.792 1.898 1.04 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.988 ± 0.005 1.981 1.996 1.00
head operations_with_data_structures_benchmarks 2.020 ± 0.006 2.010 2.028 1.02 ± 0.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 761.9 ± 1.1 759.4 763.5 1.00 ± 0.00
head pedersen 760.9 ± 2.3 756.9 764.7 1.00
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.499 ± 0.003 1.495 1.506 1.00 ± 0.00
head poseidon_integration_benchmark 1.499 ± 0.002 1.496 1.503 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 2.535 ± 0.005 2.528 2.542 1.01 ± 0.00
head secp_integration_benchmark 2.514 ± 0.010 2.498 2.530 1.00
Command Mean [s] Min [s] Max [s] Relative
base set_integration_benchmark 1.317 ± 0.002 1.314 1.321 1.01 ± 0.00
head set_integration_benchmark 1.301 ± 0.004 1.295 1.309 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 5.549 ± 0.015 5.530 5.583 1.01 ± 0.01
head uint256_integration_benchmark 5.493 ± 0.047 5.460 5.603 1.00

cairo1-run/Cargo.toml Outdated Show resolved Hide resolved
@mmsc2 mmsc2 marked this pull request as ready for review August 17, 2023 18:45
Copy link
Member

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

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

Is having the entire corelib necessary?
If it is, can we install it using makefile targets instead of having it in the repo? This will also mean less changes when the corelib is updated

Copy link
Member

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

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

Please add an example on how to use this new cli to the readme (similar to the cairo-vm-cli example)

cairo-vm-cli/Cargo.toml Outdated Show resolved Hide resolved
@fmoletta fmoletta marked this pull request as ready for review October 9, 2023 13:41
cairo1-run/src/main.rs Outdated Show resolved Hide resolved
Cargo.toml Outdated
@@ -69,6 +70,12 @@ bitvec = { version = "1", default-features = false, features = ["alloc"] }
cairo-lang-starknet = { version = "2.1.0-rc2", default-features = false }
cairo-lang-casm = { version = "2.1.0-rc2", default-features = false }

cairo-lang-compiler = { version = "2.1.0-rc2", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

here you pin the cairo compiler crates to 2.1.0-rc2 but then you compile the contracts with cairo 2.2.0, this can lead to errors

Copy link
Member

Choose a reason for hiding this comment

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

This is actually cargo working in our favour, as depsite the version being pinned to "2.1.0-rc2", the "2.2.0" version is the one downloaded. But ill change it to avoid confusions

# To match the cairo-vm version used by cairo-lang-runner crate
cairo-vm = {version = "0.8.2", features = ["std"]}

cairo-lang-sierra-type-size = { version = "2.1.0-rc2", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

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

here too

deps:
git clone https://github.com/starkware-libs/cairo.git \
&& cd cairo \
&& git checkout v2.2.0 \
Copy link
Member

Choose a reason for hiding this comment

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

here is where the 2.2.0 version of the compiler is downloaded

@pefontana pefontana added this pull request to the merge queue Oct 12, 2023
Merged via the queue into main with commit 4598416 Oct 12, 2023
43 of 44 checks passed
@pefontana pefontana deleted the add-cairo1-running-example branch October 12, 2023 21:04
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.

None yet

6 participants