-
Notifications
You must be signed in to change notification settings - Fork 210
feat(hints): Implement NewHint#59 #1053
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
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
70711f6
Add hint
fmoletta 724e445
Add integration test
fmoletta 72bcde3
Merge branch 'main' of github.com:lambdaclass/cairo-rs into new-hint-59
fmoletta 75f6e65
Add changelog entry
fmoletta 27b9b45
Merge branch 'main' into new-hint-59
Oppen 4b7fd8e
Typo
Oppen 9372e0d
Fix invoked hint
Oppen c4b8f36
Update src/tests/cairo_run_test.rs
fmoletta 921c688
Fix ec_double_assign_new_y
fmoletta 317066e
Merge branch 'main' into new-hint-59
Oppen 32c84d7
fixes
fmoletta 42bdcd7
Merge branch 'new-hint-59' of github.com:lambdaclass/cairo-rs into ne…
fmoletta 5b31de9
Fix integration test
fmoletta 3b835c9
Clippy
fmoletta 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,85 @@ | ||
| %builtins range_check | ||
| from starkware.cairo.common.cairo_secp.bigint import BigInt3, nondet_bigint3, UnreducedBigInt3 | ||
| from starkware.cairo.common.cairo_secp.field import ( | ||
| is_zero, | ||
| unreduced_sqr, | ||
| unreduced_mul | ||
| ) | ||
| from starkware.cairo.common.cairo_secp.ec import EcPoint, compute_doubling_slope, verify_zero | ||
|
|
||
| // Computes the addition of a given point to itself. | ||
| // | ||
| // Arguments: | ||
| // point - the point to operate on. | ||
| // | ||
| // Returns: | ||
| // res - a point representing point + point. | ||
| func ec_double{range_check_ptr}(point: EcPoint) -> (res: EcPoint) { | ||
| // The zero point. | ||
| if (point.x.d0 == 0) { | ||
| if (point.x.d1 == 0) { | ||
| if (point.x.d2 == 0) { | ||
| return (res=point); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let (slope: BigInt3) = compute_doubling_slope(point); | ||
| let (slope_sqr: UnreducedBigInt3) = unreduced_sqr(slope); | ||
|
|
||
| %{ | ||
| from starkware.cairo.common.cairo_secp.secp_utils import SECP_P, pack | ||
| SECP_P = 2**255-19 | ||
| slope = pack(ids.slope, PRIME) | ||
| x = pack(ids.point.x, PRIME) | ||
| y = pack(ids.point.y, PRIME) | ||
| value = new_x = (pow(slope, 2, SECP_P) - 2 * x) % SECP_P | ||
| %} | ||
|
|
||
| let (new_x: BigInt3) = nondet_bigint3(); | ||
|
|
||
| %{ value = new_y = (slope * (x - new_x) - y) % SECP_P %} | ||
| let (new_y: BigInt3) = nondet_bigint3(); | ||
|
|
||
| verify_zero( | ||
| UnreducedBigInt3( | ||
| d0=slope_sqr.d0 - new_x.d0 - 2 * point.x.d0, | ||
| d1=slope_sqr.d1 - new_x.d1 - 2 * point.x.d1, | ||
| d2=slope_sqr.d2 - new_x.d2 - 2 * point.x.d2, | ||
| ), | ||
| ); | ||
|
|
||
| let (x_diff_slope: UnreducedBigInt3) = unreduced_mul( | ||
| BigInt3(d0=point.x.d0 - new_x.d0, d1=point.x.d1 - new_x.d1, d2=point.x.d2 - new_x.d2), slope | ||
| ); | ||
|
|
||
| verify_zero( | ||
| UnreducedBigInt3( | ||
| d0=x_diff_slope.d0 - point.y.d0 - new_y.d0, | ||
| d1=x_diff_slope.d1 - point.y.d1 - new_y.d1, | ||
| d2=x_diff_slope.d2 - point.y.d2 - new_y.d2, | ||
| ), | ||
| ); | ||
|
|
||
| return (res=EcPoint(new_x, new_y)); | ||
| } | ||
|
|
||
| func main{range_check_ptr}() { | ||
| let x = BigInt3(1,2,3); | ||
| let y = BigInt3(4,5,6); | ||
| let p = EcPoint(x, y); | ||
|
|
||
| let (r) = ec_double(p); | ||
|
|
||
| assert r.x.d0 = 57832968898037685942927716; | ||
| assert r.x.d1 = 27957507593122495312333579; | ||
| assert r.x.d2 = 876486538158111111042155; | ||
|
|
||
| assert r.y.d0 = 76653617457582133477854326; | ||
| assert r.y.d1 = 906421522066442687720656; | ||
| assert r.y.d2 = 11165193544924531831122323; | ||
|
|
||
| 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
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.