-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add NewHint#27 * Update changelog * Fix changelog Some of the entries were being repeated when merging changes, and were also originally misplaced in the 0.3.0-rc1 section * Make hint codes public
- Loading branch information
1 parent
2f557b1
commit ddbeb8a
Showing
6 changed files
with
213 additions
and
139 deletions.
There are no files selected for viewing
This file contains 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 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,83 @@ | ||
%builtins range_check | ||
|
||
// Source: https://github.com/myBraavos/efficient-secp256r1/blob/73cca4d53730cb8b2dcf34e36c7b8f34b96b3230/src/secp256r1/ec.cairo#L127 | ||
|
||
from starkware.cairo.common.cairo_secp.bigint import BigInt3, UnreducedBigInt3, nondet_bigint3 | ||
from starkware.cairo.common.cairo_secp.ec import EcPoint, compute_doubling_slope | ||
from starkware.cairo.common.cairo_secp.field import ( | ||
is_zero, | ||
unreduced_mul, | ||
unreduced_sqr, | ||
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 pack | ||
|
||
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: felt}() { | ||
let x = BigInt3(235, 522, 111); | ||
let y = BigInt3(1323, 15124, 796759); | ||
|
||
let point = EcPoint(x, y); | ||
|
||
let (res) = ec_double(point); | ||
|
||
assert res = EcPoint( | ||
BigInt3(64960503569511978748964127, 74077005698377320581054215, 17246103581201827820088765), | ||
BigInt3(13476289913106792137931934, 29193128211607101710049068, 18079689234850912663169436), | ||
); | ||
|
||
return (); | ||
} |
This file contains 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 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 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 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
ddbeb8a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.30
.cairo_run(cairo_programs/benchmarks/compare_arrays_200000.json)
3051376722
ns/iter (± 35485875
)2344252332
ns/iter (± 10584452
)1.30
cairo_run(cairo_programs/benchmarks/factorial_multirun.json)
3909951002
ns/iter (± 36814944
)2961651793
ns/iter (± 6297930
)1.32
cairo_run(cairo_programs/benchmarks/integration_builtins.json)
3253451926
ns/iter (± 37280460
)2441449038
ns/iter (± 6411481
)1.33
cairo_run(cairo_programs/benchmarks/linear_search.json)
3207743529
ns/iter (± 36305177
)2448147010
ns/iter (± 12539746
)1.31
cairo_run(cairo_programs/benchmarks/keccak_integration_benchmark.json)
2987059930
ns/iter (± 30073471
)2136215824
ns/iter (± 7491326
)1.40
cairo_run(cairo_programs/benchmarks/secp_integration_benchmark.json)
2842714756
ns/iter (± 30300357
)2049877561
ns/iter (± 6004767
)1.39
cairo_run(cairo_programs/benchmarks/blake2s_integration_benchmark.json)
2777936253
ns/iter (± 31461758
)2009792624
ns/iter (± 6501229
)1.38
cairo_run(cairo_programs/benchmarks/memory_integration_benchmark.json)
2244351927
ns/iter (± 24340545
)1705233848
ns/iter (± 3245078
)1.32
cairo_run(cairo_programs/benchmarks/uint256_integration_benchmark.json)
3892905071
ns/iter (± 63059880
)2950347731
ns/iter (± 6047063
)1.32
cairo_run(cairo_programs/benchmarks/set_integration_benchmark.json)
2448893131
ns/iter (± 34828922
)1582817337
ns/iter (± 17750904
)1.55
This comment was automatically generated by workflow using github-action-benchmark.
CC: @unbalancedparentheses