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

feat(hints): add NewHint#47 #1030

Merged
merged 34 commits into from
Apr 24, 2023
Merged

feat(hints): add NewHint#47 #1030

merged 34 commits into from
Apr 24, 2023

Conversation

MegaRedHand
Copy link
Contributor

Description

This PR adds the missing hint NewHint#47, now known as UINT512_UNSIGNED_DIV_REM.

In addition to that:

  • splits tests and libraries for the uint384 and uint384_extension cairo contracts, to reuse them in other contracts.
  • unifies pack and split into a generic function in uint_utils.rs, and changes UintNNN specific pack and split to use the generic ones.
  • specifies full import path in some macros, and fix resulting "unused import" errors.
  • add Uint512 type (maybe this types could be implemented with a generic or macro?)

- uint384
- uint384_extension

I need this changes for later tests
Pack and split were unified into a generic function in `uint_utils.rs`.
UintNNN specific functions were changed to `uNNN_pack` and `uNNN_split`, that internally use the generic ones.

Some macros were using items without specifying full path, and I fixed this.
With this change a lot of imports weren't needed anymore, and so were removed to appease clippy.

Also add the groundwork for the new hint to be implemented.
@github-actions
Copy link

github-actions bot commented Apr 21, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 3.104 ± 0.048 3.042 3.190 1.00
head blake2s_integration_benchmark 3.189 ± 0.074 3.087 3.298 1.03 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 3.681 ± 0.031 3.640 3.734 1.00
head compare_arrays_200000 3.760 ± 0.073 3.668 3.920 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 2.798 ± 0.035 2.746 2.855 1.00
head dict_integration_benchmark 2.935 ± 0.119 2.773 3.159 1.05 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base factorial_multirun 4.695 ± 0.190 4.468 4.987 1.00
head factorial_multirun 4.752 ± 0.176 4.563 5.070 1.01 ± 0.06
Command Mean [s] Min [s] Max [s] Relative
base fibonacci_1000_multirun 3.766 ± 0.113 3.602 3.907 1.02 ± 0.04
head fibonacci_1000_multirun 3.678 ± 0.061 3.589 3.807 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 3.649 ± 0.055 3.573 3.764 1.02 ± 0.02
head integration_builtins 3.578 ± 0.046 3.531 3.688 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 3.402 ± 0.058 3.335 3.538 1.00
head keccak_integration_benchmark 3.486 ± 0.055 3.427 3.604 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 3.837 ± 0.101 3.752 4.072 1.00
head linear_search 3.859 ± 0.050 3.771 3.945 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 3.160 ± 0.059 3.086 3.245 1.00
head math_cmp_and_pow_integration_benchmark 3.211 ± 0.050 3.156 3.326 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 2.864 ± 0.028 2.820 2.899 1.00
head math_integration_benchmark 2.932 ± 0.056 2.875 3.051 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 2.564 ± 0.037 2.508 2.617 1.00
head memory_integration_benchmark 2.613 ± 0.065 2.564 2.751 1.02 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 2.485 ± 0.024 2.445 2.524 1.00
head operations_with_data_structures_benchmarks 2.545 ± 0.043 2.500 2.626 1.02 ± 0.02
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 899.7 ± 67.4 864.8 1090.0 1.01 ± 0.08
head pedersen 892.5 ± 17.0 872.6 933.7 1.00
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.649 ± 0.021 1.627 1.698 1.00
head poseidon_integration_benchmark 1.685 ± 0.055 1.623 1.804 1.02 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 2.974 ± 0.081 2.890 3.151 1.01 ± 0.03
head secp_integration_benchmark 2.944 ± 0.050 2.887 3.030 1.00
Command Mean [s] Min [s] Max [s] Relative
base set_integration_benchmark 2.290 ± 0.029 2.242 2.326 1.00 ± 0.02
head set_integration_benchmark 2.287 ± 0.031 2.246 2.344 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.168 ± 0.077 4.093 4.310 1.00
head uint256_integration_benchmark 4.268 ± 0.038 4.214 4.332 1.02 ± 0.02

@MegaRedHand MegaRedHand mentioned this pull request Apr 21, 2023
@github-actions
Copy link

github-actions bot commented Apr 21, 2023

Benchmark Results for modified programs 🚀

Command Mean [ms] Min [ms] Max [ms] Relative
head field_arithmetic_get_square_benchmark 128.3 ± 0.6 127.2 129.2 1.00

Was using wrong pack function
MegaRedHand and others added 2 commits April 24, 2023 15:23
Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
@pefontana pefontana added the whitelisted-hint Implementation of hint on whitelist directory label Apr 24, 2023
@codecov
Copy link

codecov bot commented Apr 24, 2023

Codecov Report

Merging #1030 (679121e) into main (fb73125) will decrease coverage by 0.01%.
The diff coverage is 98.37%.

@@            Coverage Diff             @@
##             main    #1030      +/-   ##
==========================================
- Coverage   98.08%   98.07%   -0.01%     
==========================================
  Files          81       84       +3     
  Lines       33126    33275     +149     
==========================================
+ Hits        32491    32635     +144     
- Misses        635      640       +5     
Impacted Files Coverage Δ
..._processor/builtin_hint_processor/blake2s_utils.rs 99.74% <ø> (ø)
...uiltin_hint_processor/cairo_keccak/keccak_hints.rs 93.93% <ø> (ø)
...rocessor/builtin_hint_processor/dict_hint_utils.rs 99.22% <ø> (ø)
...int_processor/builtin_hint_processor/hint_utils.rs 94.59% <ø> (ø)
...t_processor/builtin_hint_processor/keccak_utils.rs 99.25% <ø> (ø)
...int_processor/builtin_hint_processor/math_utils.rs 97.81% <ø> (ø)
...cessor/builtin_hint_processor/memcpy_hint_utils.rs 100.00% <ø> (ø)
...t_processor/builtin_hint_processor/memset_utils.rs 100.00% <ø> (ø)
...processor/builtin_hint_processor/poseidon_utils.rs 100.00% <ø> (ø)
...hint_processor/builtin_hint_processor/pow_utils.rs 100.00% <ø> (ø)
... and 33 more

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

@MegaRedHand MegaRedHand added this pull request to the merge queue Apr 24, 2023
Merged via the queue into main with commit 1a5a94e Apr 24, 2023
15 checks passed
@MegaRedHand MegaRedHand deleted the newhint47-u512_udiv_rem branch April 24, 2023 22:12
kariy pushed a commit to dojoengine/cairo-rs that referenced this pull request Jun 23, 2023
* Refactor some cairo_programs as library

- uint384
- uint384_extension

I need this changes for later tests

* Refactor pack and split, macro hygiene

Pack and split were unified into a generic function in `uint_utils.rs`.
UintNNN specific functions were changed to `uNNN_pack` and `uNNN_split`, that internally use the generic ones.

Some macros were using items without specifying full path, and I fixed this.
With this change a lot of imports weren't needed anymore, and so were removed to appease clippy.

Also add the groundwork for the new hint to be implemented.

* Add NewHint#47

* Update changelog

* Add stdlib prelude import

* Import HashMap from stdlib

* Fix contracts

* Fix wasm-tests

* Change bitmask to `u128::MAX`

* Revert "Change bitmask to `u128::MAX`"

This reverts commit 7a1bea7.

* Compare memory_holes with correct amount

* Rename uint512 -> fq, fq -> fq_test; Add comment

* Fix contract compilation errors

* Fix compilation error

* Fix cairo_run_fq test

* Move changelog entry

* Fix failing tests

* Fix compilation errors

* Fix test error

Was using wrong pack function

* Define empty mains on libraries

* Use bare array instead of vec

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>

* Make pack and split methods instead of functions

* Fix merge errors

* Fix errors and add BigInt3::split86

* Make u512_pack and split functions into methods

* Re-add disappeared newline inside hint

* Fix compilation errors

---------

Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
whitelisted-hint Implementation of hint on whitelist directory
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants