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): Implement NewHint#39 #1037

Merged
merged 46 commits into from
Apr 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
17716c4
Add test
fmoletta Apr 20, 2023
e867c2b
Ignore builtin segments in get_memory_holes
fmoletta Apr 20, 2023
c560497
Improve test
fmoletta Apr 20, 2023
ed5329f
Add memory holes check for cairo_run_test tests
fmoletta Apr 20, 2023
c15445b
Fix broken condition
fmoletta Apr 20, 2023
f252960
Make memory_holes check optional & customizable
fmoletta Apr 20, 2023
063f9c4
Fix bounds
fmoletta Apr 20, 2023
6e3ed8b
Add a test with deliberately created memory holes
fmoletta Apr 20, 2023
9fa2dc8
Fix test value
fmoletta Apr 20, 2023
d36bf3f
Remove duplicated tests + add memory hole value to some tests
fmoletta Apr 20, 2023
ece99eb
Add memory holes value + remove duplicated tests + fix typo
fmoletta Apr 20, 2023
1f867fb
Fix test values
fmoletta Apr 20, 2023
ac9c795
Add changelog entry
fmoletta Apr 20, 2023
356a187
Link PR in Changelog
fmoletta Apr 20, 2023
0f89514
Merge branch 'main' of github.com:lambdaclass/cairo-rs into fix-get-m…
fmoletta Apr 20, 2023
67e2622
Mark breaking change in changelog
fmoletta Apr 21, 2023
4a17d58
Merge branch 'main' of github.com:lambdaclass/cairo-rs into fix-get-m…
fmoletta Apr 21, 2023
e114745
fmt
fmoletta Apr 21, 2023
3ecf882
Fix test value
fmoletta Apr 21, 2023
342efdb
Fix codecov-patch diff
fmoletta Apr 21, 2023
67e3b70
Add hint code
fmoletta Apr 21, 2023
4779307
Add integration test
fmoletta Apr 21, 2023
cbe3b5d
Add untracked file
fmoletta Apr 21, 2023
81a99e5
Merge branch 'main' into div-mod-n-packed-hint
fmoletta Apr 21, 2023
a71552d
Add changelog entry
fmoletta Apr 21, 2023
75bb911
Rename hint
fmoletta Apr 21, 2023
53ade42
Merge branch 'main' into div-mod-n-packed-hint
fmoletta Apr 21, 2023
23c7d8f
Fix test
fmoletta Apr 21, 2023
992c7fe
Fix test
fmoletta Apr 21, 2023
b434052
Add hint code + hint impl + unit test
fmoletta Apr 21, 2023
ad46d43
fmt
fmoletta Apr 21, 2023
c078fc2
Add integration test
fmoletta Apr 21, 2023
ad87b73
Add changelog entry
fmoletta Apr 21, 2023
86f7094
Merge branch 'main' into new-hint-38
fmoletta Apr 21, 2023
1ad1716
Implement hint + add tests
fmoletta Apr 21, 2023
2f60b81
Add changelog entry
fmoletta Apr 21, 2023
d183b6b
Remove indent from hint string
fmoletta Apr 21, 2023
535f9c8
Merge branch 'div-mod-n-packed-hint' into new-hint-38
fmoletta Apr 21, 2023
5ee243b
Merge branch 'new-hint-38' into new-hint-39
fmoletta Apr 21, 2023
6cd45c2
Add wasm import
fmoletta Apr 21, 2023
7316d57
Merge branch 'div-mod-n-packed-hint' into new-hint-38
fmoletta Apr 21, 2023
a44b045
Merge branch 'new-hint-38' into new-hint-39
fmoletta Apr 21, 2023
1545cc7
Update CHANGELOG.md
fmoletta Apr 21, 2023
050b6bf
Update CHANGELOG.md
fmoletta Apr 21, 2023
8efc71c
Merge branch 'main' of github.com:lambdaclass/cairo-rs into new-hint-39
fmoletta Apr 24, 2023
42d8f05
Merge branch 'main' of github.com:lambdaclass/cairo-rs into new-hint-39
fmoletta Apr 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' of github.com:lambdaclass/cairo-rs into fix-get-m…
…emory-holes
fmoletta committed Apr 20, 2023
commit 0f89514f023522c00fc52bcabc89e3bbca9d7071
81 changes: 78 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,9 +4,84 @@

* Fix `CairoRunner::get_memory_holes` [#1027](https://github.com/lambdaclass/cairo-rs/pull/1027):

* Skip builtin segements when counting memory holes
* Check amount of memory holes for all tests in cairo_run_test
* Remove duplicated tests in cairo_run_test
* Skip builtin segements when counting memory holes
* Check amount of memory holes for all tests in cairo_run_test
* Remove duplicated tests in cairo_run_test

* Implement hints on field_arithmetic lib[#985](https://github.com/lambdaclass/cairo-rs/pull/983)

`BuiltinHintProcessor` now supports the following hint:

```python
%{
from starkware.python.math_utils import is_quad_residue, sqrt

def split(num: int, num_bits_shift: int = 128, length: int = 3):
a = []
for _ in range(length):
a.append( num & ((1 << num_bits_shift) - 1) )
num = num >> num_bits_shift
return tuple(a)

def pack(z, num_bits_shift: int = 128) -> int:
limbs = (z.d0, z.d1, z.d2)
return sum(limb << (num_bits_shift * i) for i, limb in enumerate(limbs))


generator = pack(ids.generator)
x = pack(ids.x)
p = pack(ids.p)

success_x = is_quad_residue(x, p)
root_x = sqrt(x, p) if success_x else None

success_gx = is_quad_residue(generator*x, p)
root_gx = sqrt(generator*x, p) if success_gx else None

# Check that one is 0 and the other is 1
if x != 0:
assert success_x + success_gx ==1

# `None` means that no root was found, but we need to transform these into a felt no matter what
if root_x == None:
root_x = 0
if root_gx == None:
root_gx = 0
ids.success_x = int(success_x)
split_root_x = split(root_x)
split_root_gx = split(root_gx)
ids.sqrt_x.d0 = split_root_x[0]
ids.sqrt_x.d1 = split_root_x[1]
ids.sqrt_x.d2 = split_root_x[2]
ids.sqrt_gx.d0 = split_root_gx[0]
ids.sqrt_gx.d1 = split_root_gx[1]
ids.sqrt_gx.d2 = split_root_gx[2]
%}
```

* Add missing hint on uint256_improvements lib [#1016](https://github.com/lambdaclass/cairo-rs/pull/1016):

`BuiltinHintProcessor` now supports the following hint:

```python
def split(num: int, num_bits_shift: int = 128, length: int = 2):
a = []
for _ in range(length):
a.append( num & ((1 << num_bits_shift) - 1) )
num = num >> num_bits_shift
return tuple(a)

def pack(z, num_bits_shift: int = 128) -> int:
limbs = (z.low, z.high)
return sum(limb << (num_bits_shift * i) for i, limb in enumerate(limbs))

a = pack(ids.a)
b = pack(ids.b)
res = (a - b)%2**256
res_split = split(res)
ids.res.low = res_split[0]
ids.res.high = res_split[1]
```

* Add methor `Program::data_len(&self) -> usize` to get the number of data cells in a given program [#1022](https://github.com/lambdaclass/cairo-rs/pull/1022)

7 changes: 7 additions & 0 deletions src/tests/cairo_run_test.rs
Original file line number Diff line number Diff line change
@@ -708,6 +708,13 @@ fn uint384_extension() {
run_program_simple_with_memory_holes(program_data.as_slice(), 20);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn field_arithmetic() {
let program_data = include_bytes!("../../cairo_programs/field_arithmetic.json");
run_program_simple_with_memory_holes(program_data.as_slice(), 192);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn ed25519_field() {
You are viewing a condensed version of this merge commit. You can view the full changes here.