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

Add missing secp256r1 hints #1951

Open
gabrielbosio opened this issue Feb 13, 2025 · 1 comment
Open

Add missing secp256r1 hints #1951

gabrielbosio opened this issue Feb 13, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@gabrielbosio
Copy link
Collaborator

@gabrielbosio gabrielbosio added the enhancement New feature or request label Feb 13, 2025
@Smartdevs17
Copy link

Can I try solving this issue? I have added some missing hints to the compute_doubling_slope and try_get_point_from_x functions in the src/starkware/cairo/common/secp256r1/ec.cairo file. These hints are crucial for ensuring the correct computation of elliptic curve points. Below are the details of the changes:

compute_doubling_slope Function
%{
from starkware.cairo.common.cairo_secp.secp256r1_utils import SECP256R1_ALPHA, SECP256R1_P
from starkware.cairo.common.cairo_secp.secp_utils import pack
from starkware.python.math_utils import ec_double_slope

# Compute the slope.
x = pack(ids.point.x, PRIME)
y = pack(ids.point.y, PRIME)
value = slope = ec_double_slope(point=(x, y), alpha=SECP256R1_ALPHA, p=SECP256R1_P)

%}

try_get_point_from_x Function
%{
from starkware.cairo.common.cairo_secp.secp_utils import SECP256R1, pack
from starkware.python.math_utils import y_squared_from_x

y_square_int = y_squared_from_x(
    x=pack(ids.x, PRIME),
    alpha=SECP256R1.alpha,
    beta=SECP256R1.beta,
    field_prime=SECP256R1.prime,
)

# Note that (y_square_int ** ((SECP256R1.prime + 1) / 4)) ** 2 =
#   = y_square_int ** ((SECP256R1.prime + 1) / 2) =
#   = y_square_int ** ((SECP256R1.prime - 1) / 2 + 1) =
#   = y_square_int * y_square_int ** ((SECP256R1.prime - 1) / 2) = y_square_int * {+/-}1.
y = pow(y_square_int, (SECP256R1.prime + 1) // 4, SECP256R1.prime)

# We need to decide whether to take y or prime - y.
if ids.v % 2 == y % 2:
    value = y
else:
    value = (-y) % SECP256R1.prime

%}

These hints ensure the correct calculation of the slope and the y-coordinate for elliptic curve operations on the secp256r1 curve. This should enhance the functionality and accuracy of the cryptographic operations in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants