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

Handle error in hint UINT256_MUL_DIV_MOD when divides by zero #1367

Merged
merged 9 commits into from
Aug 10, 2023

Conversation

pefontana
Copy link
Member

@pefontana pefontana commented Aug 9, 2023

Handle error in hint UINT256_MUL_DIV_MOD when divides by zero

Description

  • Handle error in hint UINT256_MUL_DIV_MOD when divides by zero
  • Also, checks possible zeros before div_mod_floor with BigUints

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.

@pefontana pefontana changed the title Div by zero bug Handle error in hint UINT256_MUL_DIV_MOD when divides by zero Aug 9, 2023
@pefontana pefontana linked an issue Aug 9, 2023 that may be closed by this pull request
@pefontana pefontana marked this pull request as ready for review August 9, 2023 18:38
@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Merging #1367 (2763354) into main (c249cd9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1367   +/-   ##
=======================================
  Coverage   97.49%   97.49%           
=======================================
  Files          93       93           
  Lines       37854    37857    +3     
=======================================
+ Hits        36904    36907    +3     
  Misses        950      950           
Files Changed Coverage Δ
..._processor/builtin_hint_processor/uint256_utils.rs 99.57% <100.00%> (+<0.01%) ⬆️

📣 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 9, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 4.873 ± 0.010 4.854 4.887 1.00
head big_factorial 4.885 ± 0.030 4.868 4.969 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 4.152 ± 0.028 4.138 4.230 1.00
head big_fibonacci 4.166 ± 0.013 4.146 4.182 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 11.446 ± 0.026 11.420 11.507 1.00 ± 0.00
head blake2s_integration_benchmark 11.432 ± 0.031 11.400 11.497 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 4.205 ± 0.017 4.181 4.232 1.00
head compare_arrays_200000 4.215 ± 0.082 4.168 4.445 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 2.787 ± 0.012 2.776 2.818 1.00 ± 0.01
head dict_integration_benchmark 2.778 ± 0.009 2.764 2.792 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 2.062 ± 0.009 2.051 2.076 1.01 ± 0.01
head field_arithmetic_get_square_benchmark 2.044 ± 0.007 2.034 2.058 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 11.303 ± 0.050 11.247 11.434 1.00
head integration_builtins 11.321 ± 0.116 11.229 11.551 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 11.582 ± 0.094 11.506 11.768 1.00 ± 0.01
head keccak_integration_benchmark 11.580 ± 0.116 11.501 11.850 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 4.188 ± 0.014 4.165 4.215 1.00
head linear_search 4.196 ± 0.021 4.176 4.250 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 3.044 ± 0.014 3.019 3.061 1.00
head math_cmp_and_pow_integration_benchmark 3.059 ± 0.019 3.029 3.098 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 2.744 ± 0.021 2.722 2.798 1.00 ± 0.01
head math_integration_benchmark 2.738 ± 0.006 2.727 2.745 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 2.413 ± 0.010 2.403 2.438 1.00
head memory_integration_benchmark 2.428 ± 0.028 2.404 2.478 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 2.687 ± 0.043 2.666 2.810 1.01 ± 0.02
head operations_with_data_structures_benchmarks 2.673 ± 0.011 2.666 2.704 1.00
Command Mean [s] Min [s] Max [s] Relative
base pedersen 1.002 ± 0.002 1.000 1.005 1.00 ± 0.00
head pedersen 0.999 ± 0.002 0.997 1.002 1.00
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.789 ± 0.006 1.783 1.804 1.00 ± 0.01
head poseidon_integration_benchmark 1.780 ± 0.010 1.775 1.807 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 3.269 ± 0.018 3.258 3.316 1.01 ± 0.01
head secp_integration_benchmark 3.242 ± 0.010 3.230 3.259 1.00
Command Mean [s] Min [s] Max [s] Relative
base set_integration_benchmark 1.824 ± 0.019 1.804 1.847 1.00
head set_integration_benchmark 1.950 ± 0.004 1.943 1.956 1.07 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 7.465 ± 0.021 7.443 7.495 1.00 ± 0.00
head uint256_integration_benchmark 7.458 ± 0.024 7.428 7.495 1.00

Copy link
Member

@Oppen Oppen left a comment

Choose a reason for hiding this comment

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

LGTM, but we need tests for the failing cases as reported by Codecov.

@pefontana
Copy link
Member Author

LGTM, but we need tests for the failing cases as reported by Codecov.

Nice catch @Oppen!!

I remove both of that checks because they were unreacheble
0cfcf7b has a previous check

2766a75 Gets the values from a constant defined in the https://github.com/starkware-libs/cairo-lang/blob/0614f265421735bbb567d9b5897791a51b3705de/src/starkware/cairo/common/math.cairo#L156 library

@Oppen Oppen enabled auto-merge August 10, 2023 20:23
@Oppen Oppen added this pull request to the merge queue Aug 10, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Aug 10, 2023
@pefontana pefontana added this pull request to the merge queue Aug 10, 2023
Merged via the queue into main with commit 21eff70 Aug 10, 2023
38 checks passed
@pefontana pefontana deleted the div-by-zero-bug branch August 10, 2023 23:45
pefontana added a commit that referenced this pull request Aug 11, 2023
* fix bug

* Add test

* Add some checks to div_mod_floors of BigUints

* Update Changelog

* Remove unnecesarry zero check

* Remove unnecesarry zero check

* Remove unnecesary import
pefontana added a commit that referenced this pull request Aug 14, 2023
* Handle error in hint `UINT256_MUL_DIV_MOD` when divides by zero (#1367)

* fix bug

* Add test

* Add some checks to div_mod_floors of BigUints

* Update Changelog

* Remove unnecesarry zero check

* Remove unnecesarry zero check

* Remove unnecesary import

* release 0.6.3

* Fix CI

* Revert "Fix CI"

This reverts commit 2184add.

* Fix CI

* pin nextest version in GH workflow (#1359)

* remove codecov

* Run benchmarks serially in the CI (#1280)

The benchmarks consume a lot of memory.
Since we disabled swap memory usage, the bench runs fail sporadically because of OOM errors.
This makes them run with 1 process instead of 2 in parallel.

* Revert "remove codecov"

This reverts commit f10a7cf.

* Revert "Revert "remove codecov""

This reverts commit fde126e.

---------

Co-authored-by: Tomás <47506558+MegaRedHand@users.noreply.github.com>
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.

hint u256_mul_div_mod panic with division by zero
4 participants