-
Notifications
You must be signed in to change notification settings - Fork 211
Newhint#20 and Newhint#16: add COMPUTE_SLOPE_SECP256R1 and IMPORT_SECP256R1_P #1014
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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6341a0f
add newhint#20
mfachal 3b7e691
add slope_compute program
mfachal bfbef42
format
mfachal c90295f
fix hint#16 string
mfachal d57bf5f
WIP
mfachal 0fcf061
WIP add SECP_P to exec_scopes
mfachal 6a5fb1f
WIP add SECP_P to exec_scope
mfachal c38ec64
add newhint#16 and newhint#20
mfachal e4f1b21
update changelog
mfachal 946890e
Merge branch 'main' into newhint20-slope_secp_p
mfachal cfd3331
use BigUint for SECP256R1_N and SECP256R1_ALPHA
mfachal e7b7b47
Merge branch 'main' into newhint20-slope_secp_p
mfachal 1831377
refactor compute_slope
mfachal 3e41963
Merge branch 'main' into newhint20-slope_secp_p
mfachal c0a0c85
Merge branch 'main' into newhint20-slope_secp_p
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/myBraavos/efficient-secp256r1/blob/main/src/secp256r1/ec.cairo | ||
|
|
||
| from starkware.cairo.common.serialize import serialize_word | ||
| from starkware.cairo.common.cairo_secp.bigint import BigInt3, UnreducedBigInt3, nondet_bigint3 | ||
| from starkware.cairo.common.cairo_secp.field import ( | ||
| is_zero, | ||
| unreduced_mul, | ||
| unreduced_sqr, | ||
| verify_zero, | ||
| ) | ||
| from starkware.cairo.common.cairo_secp.ec import EcPoint | ||
|
|
||
|
|
||
| // Returns the slope of the line connecting the two given points. | ||
| // The slope is used to compute pt0 + pt1. | ||
| // Assumption: pt0.x != pt1.x (mod secp256k1_prime). | ||
| func compute_slope{range_check_ptr: felt}(point0: EcPoint, point1: EcPoint) -> (slope: BigInt3) { | ||
| %{ from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_P as SECP_P %} | ||
| %{ | ||
| from starkware.cairo.common.cairo_secp.secp_utils import pack | ||
| from starkware.python.math_utils import line_slope | ||
|
|
||
| # Compute the slope. | ||
| x0 = pack(ids.point0.x, PRIME) | ||
| y0 = pack(ids.point0.y, PRIME) | ||
| x1 = pack(ids.point1.x, PRIME) | ||
| y1 = pack(ids.point1.y, PRIME) | ||
| value = slope = line_slope(point1=(x0, y0), point2=(x1, y1), p=SECP_P) | ||
| %} | ||
| let (slope) = nondet_bigint3(); | ||
|
|
||
| return (slope=slope); | ||
| } | ||
|
|
||
|
|
||
| func test_compute_slope{range_check_ptr: felt}() { | ||
| let x0 = BigInt3(d0=1, d1=5, d2=10); | ||
| let y0 = BigInt3(d0=2, d1=4, d2=20); | ||
|
|
||
| let pt0 = EcPoint(x=x0, y=y0); | ||
|
|
||
| let x1 = BigInt3(d0=3, d1=3, d2=3); | ||
| let y1 = BigInt3(d0=3, d1=5, d2=22); | ||
|
|
||
| let pt1 = EcPoint(x=x1, y=y1); | ||
|
|
||
| // Compute slope | ||
| let (slope) = compute_slope(pt0, pt1); | ||
|
|
||
| assert slope = slope; | ||
| return (); | ||
| } | ||
|
|
||
| func main{range_check_ptr: felt}(){ | ||
| test_compute_slope(); | ||
|
|
||
| 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.