Example #1
0
def ecrecover_substitute(z, v, r, s):
    P, A, B, N, Gx, Gy = b.P, b.A, b.B, b.N, b.Gx, b.Gy
    x = r
    beta = pow(x*x*x+A*x+B, (P + 1) / 4, P)
    BETA_PREMIUM = modexp_substitute(x, (P + 1) / 4, P)["gas"]
    y = beta if v % 2 ^ beta % 2 else (P - beta)
    Gz = b.jordan_multiply(((Gx, 1), (Gy, 1)), (N - z) % N)
    GZ_PREMIUM = jacobian_mul_substitute(Gx, 1, Gy, 1, (N - z) % N)["gas"]
    XY = b.jordan_multiply(((x, 1), (y, 1)), s)
    XY_PREMIUM = jacobian_mul_substitute(x, 1, y, 1, s % N)["gas"]
    Qr = b.jordan_add(Gz, XY)
    QR_PREMIUM = jacobian_add_substitute(Gz[0][0], Gz[0][1], Gz[1][0], Gz[1][1],
                                         XY[0][0], XY[0][1], XY[1][0], XY[1][1]
                                         )["gas"]
    Q = b.jordan_multiply(Qr, pow(r, N - 2, N))
    Q_PREMIUM = jacobian_mul_substitute(Qr[0][0], Qr[0][1], Qr[1][0], Qr[1][1],
                                        pow(r, N - 2, N))["gas"]
    R_PREMIUM = modexp_substitute(r, N - 2, N)["gas"]
    OX_PREMIUM = modexp_substitute(Q[0][1], P - 2, P)["gas"]
    OY_PREMIUM = modexp_substitute(Q[1][1], P - 2, P)["gas"]
    Q = b.from_jordan(Q)
    return {
        "gas": 993 + BETA_PREMIUM + GZ_PREMIUM + XY_PREMIUM + QR_PREMIUM +
        Q_PREMIUM + R_PREMIUM + OX_PREMIUM + OY_PREMIUM,
        "output": signed(Q)
    }
Example #2
0
def ecrecover_substitute(z, v, r, s):
    P, A, B, N, Gx, Gy = b.P, b.A, b.B, b.N, b.Gx, b.Gy
    x = r
    beta = pow(x * x * x + A * x + B, (P + 1) / 4, P)
    BETA_PREMIUM = modexp_substitute(x, (P + 1) / 4, P)["gas"]
    y = beta if v % 2 ^ beta % 2 else (P - beta)
    Gz = b.jordan_multiply(((Gx, 1), (Gy, 1)), (N - z) % N)
    GZ_PREMIUM = jacobian_mul_substitute(Gx, 1, Gy, 1, (N - z) % N)["gas"]
    XY = b.jordan_multiply(((x, 1), (y, 1)), s)
    XY_PREMIUM = jacobian_mul_substitute(x, 1, y, 1, s % N)["gas"]
    Qr = b.jordan_add(Gz, XY)
    QR_PREMIUM = jacobian_add_substitute(Gz[0][0], Gz[0][1], Gz[1][0],
                                         Gz[1][1], XY[0][0], XY[0][1],
                                         XY[1][0], XY[1][1])["gas"]
    Q = b.jordan_multiply(Qr, pow(r, N - 2, N))
    Q_PREMIUM = jacobian_mul_substitute(Qr[0][0], Qr[0][1], Qr[1][0], Qr[1][1],
                                        pow(r, N - 2, N))["gas"]
    R_PREMIUM = modexp_substitute(r, N - 2, N)["gas"]
    OX_PREMIUM = modexp_substitute(Q[0][1], P - 2, P)["gas"]
    OY_PREMIUM = modexp_substitute(Q[1][1], P - 2, P)["gas"]
    Q = b.from_jordan(Q)
    return {
        "gas":
        993 + BETA_PREMIUM + GZ_PREMIUM + XY_PREMIUM + QR_PREMIUM + Q_PREMIUM +
        R_PREMIUM + OX_PREMIUM + OY_PREMIUM,
        "output":
        signed(Q)
    }
Example #3
0
def jacobian_add_substitute(A, B, C, D, E, F, G, H):
    if A == 0 or E == 0:
        gas = 144
    elif (A * F - B * E) % b.P == 0:
        if (C * H - D * G) % b.P == 0:
            gas = 434
        else:
            gas = 177
    else:
        gas = 294
    output = b.jordan_add(((A, B), (C, D)), ((E, F), (G, H)))
    return {"gas": gas, "output": signed(list(output[0]) + list(output[1]))}
Example #4
0
def jacobian_add_substitute(A, B, C, D, E, F, G, H):
    if A == 0 or E == 0:
        gas = 144
    elif (A * F - B * E) % b.P == 0:
        if (C * H - D * G) % b.P == 0:
            gas = 434
        else:
            gas = 177
    else:
        gas = 294
    output = b.jordan_add(((A, B), (C, D)), ((E, F), (G, H)))
    return {
        "gas": gas,
        "output": signed(list(output[0]) + list(output[1]))
    }