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 process block bug #851

Merged
merged 1 commit into from
Oct 15, 2024
Merged

Fix process block bug #851

merged 1 commit into from
Oct 15, 2024

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Oct 14, 2024

Fixes #845, in conjunction with lambdaclass/sequencer#11.

wrap_sha256_process_block syscall should modify the received state with the new state, but instead of doing this, it copies the value and modifies the copied version, leaving the old state untouched.

This PR fixes it.

All transactions mentioned in the issue are now working correctly.

Checklist

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

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.43%. Comparing base (8175154) to head (e10c0d2).

Files with missing lines Patch % Lines
src/starknet.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #851      +/-   ##
==========================================
- Coverage   82.43%   82.43%   -0.01%     
==========================================
  Files         120      120              
  Lines       34856    34857       +1     
==========================================
  Hits        28733    28733              
- Misses       6123     6124       +1     

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

Copy link

Benchmarking results

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 10.766 ± 0.247 10.531 11.282 22.78 ± 0.54
cairo-native (embedded AOT) 3.166 ± 0.025 3.138 3.211 6.70 ± 0.07
cairo-native (embedded JIT using LLVM's ORC Engine) 3.209 ± 0.027 3.170 3.266 6.79 ± 0.07
cairo-native (standalone AOT) 0.679 ± 0.001 0.678 0.681 1.44 ± 0.01
cairo-native (standalone AOT with -march=native) 0.473 ± 0.003 0.471 0.480 1.00

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 10.831 ± 0.274 10.378 11.222 1383.09 ± 36.33
cairo-native (embedded AOT) 2.698 ± 0.015 2.676 2.723 344.55 ± 3.13
cairo-native (embedded JIT using LLVM's ORC Engine) 2.751 ± 0.034 2.717 2.832 351.34 ± 4.98
cairo-native (standalone AOT) 0.009 ± 0.000 0.009 0.009 1.11 ± 0.01
cairo-native (standalone AOT with -march=native) 0.008 ± 0.000 0.008 0.008 1.00

Benchmark for program logistic_map

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.260 ± 0.038 4.214 4.318 58.97 ± 0.55
cairo-native (embedded AOT) 3.008 ± 0.018 2.980 3.034 41.64 ± 0.27
cairo-native (embedded JIT using LLVM's ORC Engine) 3.223 ± 0.057 3.149 3.297 44.62 ± 0.80
cairo-native (standalone AOT) 0.113 ± 0.001 0.113 0.116 1.57 ± 0.01
cairo-native (standalone AOT with -march=native) 0.072 ± 0.000 0.072 0.073 1.00

Copy link

Benchmark results Main vs HEAD.

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 3.183 ± 0.014 3.167 3.201 1.01 ± 0.01
base factorial_2M.cairo (JIT) 3.213 ± 0.022 3.184 3.256 1.02 ± 0.01
head factorial_2M.cairo (AOT) 3.151 ± 0.022 3.134 3.209 1.00
base factorial_2M.cairo (AOT) 3.176 ± 0.021 3.153 3.227 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 2.707 ± 0.010 2.693 2.725 1.00
base fib_2M.cairo (JIT) 2.760 ± 0.049 2.704 2.851 1.02 ± 0.02
head fib_2M.cairo (AOT) 2.738 ± 0.035 2.681 2.801 1.01 ± 0.01
base fib_2M.cairo (AOT) 2.752 ± 0.023 2.718 2.792 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 3.218 ± 0.020 3.178 3.241 1.05 ± 0.01
base logistic_map.cairo (JIT) 3.285 ± 0.032 3.238 3.334 1.07 ± 0.01
head logistic_map.cairo (AOT) 3.067 ± 0.024 3.044 3.117 1.00
base logistic_map.cairo (AOT) 3.079 ± 0.053 3.000 3.148 1.00 ± 0.02

@edg-l edg-l added the review-ready A PR that is ready for review label Oct 15, 2024
Comment on lines 1750 to +1754
state: *mut [u32; 8],
block: &[u32; 16],
) {
let result = ptr.sha256_process_block(unsafe { &mut *state }, block, gas);
let state_ref = unsafe { state.as_mut().unwrap() };
let result = ptr.sha256_process_block(state_ref, block, gas);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the following would be better:

// ...
            state: &mut [u32; 8],
            block: &[u32; 16],
        ) {
            let result = ptr.sha256_process_block(state, block, gas);
// ...

@edg-l edg-l added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit 1598bad Oct 15, 2024
15 checks passed
@edg-l edg-l deleted the fix-block-process-bug branch October 15, 2024 13:33
JulianGCalderon added a commit that referenced this pull request Oct 15, 2024
edg-l added a commit that referenced this pull request Oct 21, 2024
* Add logs

* Implement Felt252Dict trace dump

* Implement nullabel for trace dump

* Print type id

* Remove print

* add convertion for Sints

* fix mispelled types

* forgot to add feature

* change Sints value to correspond to sierra-emu

* Readd feature

* Add is_infinity field to secp256 point struct (#828)

* add is_infinity to secp point

* clean

* fix

* use same deps as blockifier

* fix

* fix layout

* fix test

* remove some brittle asserts due to random initial data when adding and muling points at infinity

* fix

* remove unused dep

* fixes, missed the value entry/output

* Reset src

* Fix warnings

* Make library public

* Use debug runtime for trace dump

* fix storage's values truncations (#839)

* fix storage's values truncations

* change implementation for i8 i16 i32 i64 too

* format

* Add ptr check to felt dict entry

* Add malloc tracing and fix more memory leaks. (#833)

* Add memory tracing.

* Partial memory fixes.

* Fix arrays.

* Simplify dictionaries. Fix false positive memory leak in dictionary drops.

* Fix zero-sized allocation. Fix warnings. More mem tracing checks.

* Fix mem tracing.

* Fix memory leak in `print` libfunc.

* Fix array slice libfunc.

* Fix starknet memory leaks.

* Fix keccak syscall.

* Fix dict get double free bug.

* Lots of memory fixes.

* More fixes.

* Fix CI.

* Remove old TODOs.

* Fix CI (again).

* Remove TODOs.

* Fix test.

* Maybe fix

* Maybe fix

* Maybe fix

* Dont panic when building circuit partial outputs

* trace dump for Sha256StateHandler

* Builtin costs rework (#837)

* Update to 2.8.4, release docs, alpha

This PR updates cairo to 2.8.4, adds some release docs and updates the
version to alpha.3 to prepare for another release.

* try fix

* cleanup ci, remove panic in link

* rename from jit to from ptr, etc

* crates.io badge

* progress

* progress

* fmt2

* progress

* progress

* fix

* fix bench

* use struct

* Fix felt252 and enum deserialization bugs. (#844)

* Fix felt252 and enum deserialization bugs.

* Fix formatting.

* Also fix the runtime.

* Fix errors.

* try to fix ci

* remove unused deps

---------

Co-authored-by: Edgar Luque <git@edgarluque.com>

* Fix trace dump type conv

* fix aot contract executor not passing builtinstats (#849)

* Fix felt252 and enum deserialization bugs.

* Fix formatting.

* Also fix the runtime.

* Fix errors.

* try to fix ci

* remove unused deps

* fix aot contract executor not passing builtinstats

---------

Co-authored-by: Esteve Soler Arderiu <esteve.soler@lambdaclass.com>
Co-authored-by: Esteve Soler Arderiu <soler.arderiu@gmail.com>

* Fix bug (#851)

* Also fix felt bits in starknet syscall wrappers (#853)

* Also fix felt bits in starknet syscall wrappers

* style

* missed

* fix aot contract executor not passing builtinstats (#849)

* Fix felt252 and enum deserialization bugs.

* Fix formatting.

* Also fix the runtime.

* Fix errors.

* try to fix ci

* remove unused deps

* fix aot contract executor not passing builtinstats

---------

Co-authored-by: Esteve Soler Arderiu <esteve.soler@lambdaclass.com>
Co-authored-by: Esteve Soler Arderiu <soler.arderiu@gmail.com>

* Fix bug (#851)

* Also fix felt bits in starknet syscall wrappers (#853)

* Also fix felt bits in starknet syscall wrappers

* style

* missed

* update version to alpha 4 (#854)

* bytes31

* Better function attributes and re-enable >O1 opt (#843)

* Fix felt252 and enum deserialization bugs.

* Fix formatting.

* Also fix the runtime.

* Fix errors.

* try to fix ci

* remove unused deps

* proper function attributes

* add proper function attrs to optimize better, add some passes, run tests with atleast some opts

* dont use remi

* oops

* maybe with opt level 3 now it works

* test

* works

* readd deleted bench

* remove dbg

* Update bench-hyperfine.sh

* fixci

* comment

* Update src/ffi.rs

Co-authored-by: MrAzteca <azteca1998@users.noreply.github.com>

---------

Co-authored-by: Esteve Soler Arderiu <esteve.soler@lambdaclass.com>
Co-authored-by: Esteve Soler Arderiu <soler.arderiu@gmail.com>
Co-authored-by: MrAzteca <azteca1998@users.noreply.github.com>

* Resolve `CAIRO_NATIVE_RUNTIME_LIBRARY` relative path (#841)

* feat(ffi): resolve runtime relative path using current dir

* chore: remove mentions to old runtime variable

* fix: typo

---------

Co-authored-by: Bohdan Ohorodnii <limposfeed@gmail.com>

* Implement secp

* Fix bytes31

* try to fix ci (#858)

* update implementing libfuncs doc (#856)

* Fix bytes31 bug

* Remove unused dep

---------

Co-authored-by: FrancoGiachetta <francogiachetta27@gmail.com>
Co-authored-by: Edgar <git@edgarluque.com>
Co-authored-by: MrAzteca <azteca1998@users.noreply.github.com>
Co-authored-by: Esteve Soler Arderiu <esteve.soler@lambdaclass.com>
Co-authored-by: Esteve Soler Arderiu <soler.arderiu@gmail.com>
Co-authored-by: Rodrigo <rodrodpino@gmail.com>
Co-authored-by: Bohdan Ohorodnii <limposfeed@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready A PR that is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Native execution error: Wrong hash value
4 participants