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

Always use a normal segment for first SegmentArena segment #45

Draft
wants to merge 10 commits into
base: notlesh/snos-rc-2024-09-13
Choose a base branch
from

Conversation

notlesh
Copy link

@notlesh notlesh commented Sep 18, 2024

Problem: Starknet OS expects SegmentArena segments to all be temporary except the first segment, which must be normal. This is so that relocation rules for all segments can chain back into the first.

Solution: Use temporary segments only if it's not the first.

Description

The Starknet OS verifies the continuity of the segments in SegmentArenas here, which requires relocation rules to be properly set up.

The requirements for this to work are that each src_ptr is a temporary segment and each dest_ptr is a non-temporary segment (or a temporary segment with an existing rule mapping it to a non-temporary segment).

cairo-vm uses a number of hints to accomplish this, and these are injected by the sierra-to-casm compiler. However, it relies on one additional hint which is not injected anywhere in the case of SNOS.

This hint seems to ensure the same condition needed in SNOS: that the initial segment is a normal segment and that all other segments are temporary segments with relocation rules pointing back to the initial one.

SNOS handles this by simply allocating the initial segment as a normal one as explained here. This seems to alleviate the need to later recreate the segment in relocate_all_segments(), allowing the implementation to work in SNOS without the hint mentioned above.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

kkovaacs and others added 5 commits September 3, 2024 18:07
We've discovered that using the `cairo-vm` crate in our projects brings
in a lot of unnecessary dependencies and in the end leads to our binary
being linked with the `libbz2` library.

Turns out that neither of these is actually required and this happens
because the `zip` crate has a large number of features enabled by
default.

This change disables all `zip` features except `deflate` which the code
actually uses.
* Fix Zero segment location.

* Fixed has_zero_segment naming

* Fix prover input.

* Fixed version reading when no version is supplied

* Added change to changelog.

* fix test_from_serializable()

* fix panic_impl error

* fix cairo version

* remove outdated test

* Enable ensure-no_std on test

* Add correct test

* Rename tset

* Add comment

---------

Co-authored-by: Alon Titelman <[email protected]>
Co-authored-by: Omri Eshhar <[email protected]>
Co-authored-by: Julián González Calderón <[email protected]>
Co-authored-by: OmriEshhar1 <[email protected]>
* update cairo-lang to 2.8.0

* working

* format

* typo

* fix lints

* update rusttoolchain

* remove duplicated imports

* remove unused imports

* remove zip unused dependencies

* uncomment

* undo dependecy upgrade

* update readme

---------

Co-authored-by: Pedro Fontana <[email protected]>
* Update pip cairo-lang to 0.13.2

* Update CHANGELOG

---------

Co-authored-by: Pedro Fontana <[email protected]>
Copy link

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.078 ± 0.047 2.036 2.205 1.01 ± 0.03
head big_factorial 2.067 ± 0.023 2.039 2.104 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.026 ± 0.045 1.983 2.149 1.01 ± 0.02
head big_fibonacci 2.008 ± 0.013 1.993 2.032 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.608 ± 0.050 7.526 7.689 1.00
head blake2s_integration_benchmark 7.663 ± 0.162 7.550 8.092 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.133 ± 0.012 2.110 2.148 1.00 ± 0.01
head compare_arrays_200000 2.123 ± 0.020 2.108 2.155 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.408 ± 0.011 1.396 1.429 1.00
head dict_integration_benchmark 1.446 ± 0.009 1.433 1.469 1.03 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.217 ± 0.021 1.201 1.275 1.00 ± 0.02
head field_arithmetic_get_square_benchmark 1.216 ± 0.007 1.207 1.229 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.672 ± 0.056 7.606 7.776 1.00
head integration_builtins 7.907 ± 0.586 7.619 9.527 1.03 ± 0.08
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.958 ± 0.300 7.820 8.805 1.00 ± 0.05
head keccak_integration_benchmark 7.942 ± 0.205 7.807 8.373 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.121 ± 0.034 2.087 2.213 1.00
head linear_search 2.146 ± 0.062 2.101 2.304 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.483 ± 0.011 1.465 1.500 1.00
head math_cmp_and_pow_integration_benchmark 1.485 ± 0.010 1.469 1.504 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.436 ± 0.011 1.422 1.452 1.00
head math_integration_benchmark 1.440 ± 0.012 1.425 1.461 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.183 ± 0.012 1.166 1.199 1.00
head memory_integration_benchmark 1.200 ± 0.010 1.184 1.215 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.561 ± 0.040 1.537 1.672 1.00 ± 0.03
head operations_with_data_structures_benchmarks 1.558 ± 0.009 1.543 1.570 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 521.8 ± 8.4 516.5 545.4 1.00
head pedersen 525.4 ± 5.1 521.0 537.0 1.01 ± 0.02
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 754.9 ± 3.6 748.1 758.8 1.01 ± 0.01
head poseidon_integration_benchmark 750.0 ± 6.5 735.9 756.7 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.787 ± 0.029 1.760 1.864 1.00 ± 0.02
head secp_integration_benchmark 1.779 ± 0.016 1.760 1.808 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 630.5 ± 2.3 627.8 634.8 1.00
head set_integration_benchmark 633.7 ± 4.9 628.7 644.8 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.269 ± 0.154 4.173 4.693 1.00
head uint256_integration_benchmark 4.292 ± 0.198 4.161 4.828 1.01 ± 0.06

JulianGCalderon and others added 3 commits September 23, 2024 15:24
* Add debug scripts

* Add debugging document

* Add changelog

* Revert changelog

* Improve script usage code blocks

* Remove extra space
* Fix Zero segment location.

* Fixed has_zero_segment naming

* Fix prover input.

* Fixed version reading when no version is supplied

* Added change to changelog.

* fix test_from_serializable()

* fix panic_impl error

* fix cairo version

* remove outdated test

* Enable ensure-no_std on test

* Add correct test

* Rename tset

* Add comment

---------

Co-authored-by: Alon Titelman <[email protected]>
Co-authored-by: Omri Eshhar <[email protected]>
Co-authored-by: Julián González Calderón <[email protected]>
Co-authored-by: OmriEshhar1 <[email protected]>
Copy link

github-actions bot commented Sep 26, 2024

Benchmark Results for modified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
head big_factorial 2.307 ± 0.024 2.282 2.362 1.00
Command Mean [s] Min [s] Max [s] Relative
head big_fibonacci 2.241 ± 0.026 2.211 2.302 1.00
Command Mean [s] Min [s] Max [s] Relative
head blake2s_integration_benchmark 8.172 ± 0.179 7.971 8.630 1.00
Command Mean [s] Min [s] Max [s] Relative
head compare_arrays_200000 2.374 ± 0.038 2.338 2.470 1.00
Command Mean [s] Min [s] Max [s] Relative
head dict_integration_benchmark 1.566 ± 0.006 1.559 1.576 1.00
Command Mean [s] Min [s] Max [s] Relative
head field_arithmetic_get_square_benchmark 1.319 ± 0.011 1.301 1.337 1.00
Command Mean [s] Min [s] Max [s] Relative
head integration_builtins 8.306 ± 0.229 8.130 8.947 1.00
Command Mean [s] Min [s] Max [s] Relative
head keccak_integration_benchmark 8.608 ± 0.500 8.281 9.808 1.00
Command Mean [s] Min [s] Max [s] Relative
head linear_search 2.368 ± 0.031 2.329 2.434 1.00
Command Mean [s] Min [s] Max [s] Relative
head math_cmp_and_pow_integration_benchmark 1.661 ± 0.045 1.633 1.778 1.00
Command Mean [s] Min [s] Max [s] Relative
head math_integration_benchmark 1.594 ± 0.010 1.579 1.609 1.00
Command Mean [s] Min [s] Max [s] Relative
head memory_integration_benchmark 1.329 ± 0.026 1.309 1.398 1.00
Command Mean [s] Min [s] Max [s] Relative
head operations_with_data_structures_benchmarks 1.718 ± 0.006 1.704 1.725 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
head pedersen 556.4 ± 2.8 553.5 560.3 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
head poseidon_integration_benchmark 656.8 ± 6.1 650.3 672.0 1.00
Command Mean [s] Min [s] Max [s] Relative
head secp_integration_benchmark 1.934 ± 0.009 1.923 1.946 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
head set_integration_benchmark 685.2 ± 4.2 677.5 692.7 1.00
Command Mean [s] Min [s] Max [s] Relative
head uint256_integration_benchmark 4.646 ± 0.241 4.515 5.327 1.00

* add default value for MAX_HIGH and MAX_LOW

* update tests
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.

6 participants