-
Notifications
You must be signed in to change notification settings - Fork 210
Add NewHint#31 #991
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
Merged
Merged
Add NewHint#31 #991
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
852575b
add program with div_mod_n
mfachal 6398d8e
make mul_s_inv program execute
mfachal a1712e0
make mul_s_inv program execute
mfachal 4c91f2c
add pack_modn_div_modn and mul_s_inv test
mfachal 7b7af3d
Merge branch 'main' into newhint31-div-mod-n
mfachal 8aed31e
add changes to changelog
mfachal 01d3772
Merge branch 'main' into newhint31-div-mod-n
Oppen 8df096e
fix changelog merge
mfachal 7bbfcb0
fix changelog
mfachal 87e7b71
fix changelog
mfachal 8ffdc04
fix changelog style
mfachal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| %builtins range_check | ||
|
|
||
| // Source: https://github.com/NilFoundation/cairo-placeholder-verification/blob/382924c6f1c4f9673a12a31d19835e00978ab241/src/signatures/ed25519.cairo | ||
|
|
||
| from starkware.cairo.common.cairo_secp.bigint import BASE, BigInt3, bigint_mul, nondet_bigint3 | ||
| from starkware.cairo.common.cairo_secp.constants import N0, N1, N2 | ||
| from starkware.cairo.common.cairo_secp.ec import EcPoint, ec_add, ec_mul | ||
|
|
||
| from starkware.cairo.common.math import assert_nn_le, assert_not_zero | ||
|
|
||
| // Computes x * s^(-1) modulo the size of the elliptic curve (N). | ||
| func mul_s_inv{range_check_ptr}(x : BigInt3, s : BigInt3) -> (res : BigInt3){ | ||
| %{ | ||
| from starkware.cairo.common.cairo_secp.secp_utils import pack | ||
| from starkware.python.math_utils import div_mod, safe_div | ||
|
|
||
| N = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 | ||
| x = pack(ids.x, PRIME) % N | ||
| s = pack(ids.s, PRIME) % N | ||
| value = res = div_mod(x, s, N) | ||
| %} | ||
| let (res) = nondet_bigint3(); | ||
|
|
||
| %{ value = k = safe_div(res * s - x, N) %} | ||
| let (k) = nondet_bigint3(); | ||
|
|
||
| let (res_s) = bigint_mul(res, s); | ||
| let n = BigInt3(N0, N1, N2); | ||
| let (k_n) = bigint_mul(k, n); | ||
|
|
||
| // We should now have res_s = k_n + x. Since the numbers are in unreduced form, | ||
| // we should handle the carry. | ||
|
|
||
| tempvar carry1 = (res_s.d0 - k_n.d0 - x.d0) / BASE; | ||
| assert [range_check_ptr + 0] = carry1 + 2 ** 127; | ||
|
|
||
| tempvar carry2 = (res_s.d1 - k_n.d1 - x.d1 + carry1) / BASE; | ||
| assert [range_check_ptr + 1] = carry2 + 2 ** 127; | ||
|
|
||
| tempvar carry3 = (res_s.d2 - k_n.d2 - x.d2 + carry2) / BASE; | ||
| assert [range_check_ptr + 2] = carry3 + 2 ** 127; | ||
|
|
||
| tempvar carry4 = (res_s.d3 - k_n.d3 + carry3) / BASE; | ||
| assert [range_check_ptr + 3] = carry4 + 2 ** 127; | ||
|
|
||
| assert res_s.d4 - k_n.d4 + carry4 = 0; | ||
|
|
||
| let range_check_ptr = range_check_ptr + 4; | ||
|
|
||
| return (res=res); | ||
| } | ||
|
|
||
| func main{range_check_ptr} () -> (){ | ||
| alloc_locals; | ||
| let bi1 = BigInt3(0x216936D3CD6E53FEC0A4E, 0x231FDD6DC5C692CC760952, 0x5A7B2C9562D608F25D51A); | ||
| let bi2 = BigInt3(0x666666666666666666666, 0x6666666666666666666666, 0x666666666666666666658); | ||
| let res = mul_s_inv(bi1, bi2); | ||
| assert res = res; | ||
| return (); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.