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

Residual ECIP in Rust cleaning #159

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions hydra/garaga/hints/ecip.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ def zk_ecip_hint(
dss = construct_digit_vectors(scalars)
Q, Ds = ecip_functions(Bs, dss)
dlogs = [dlog(D) for D in Ds]
for i, dd in enumerate(dlogs):
dd: FunctionFelt
sum_dlog = dlogs[0]
field = get_base_field(Q.curve_id.value, PyFelt)
for i in range(1, len(dlogs)):
Expand Down Expand Up @@ -671,3 +669,18 @@ def build_cairo1_tests_derive_ec_point_from_X(x: int, curve_id: CurveID, idx: in
# print(f"Max number of roots: {max_n_roots}")

# verify_ecip([G1Point.gen_random_point(CurveID.SECP256K1)], scalars=[-1])

import time

order = CURVES[CurveID.BN254.value].n
n = 50
Bs = [G1Point.gen_random_point(CurveID.BN254) for _ in range(n)]
ss = [random.randint(1, order) for _ in range(n)]

t0 = time.time()
ZZ = zk_ecip_hint(Bs, ss, use_rust=False)
print(f"Time taken py : {time.time()-t0}")

t0 = time.time()
ZZ = zk_ecip_hint(Bs, ss, use_rust=True)
print(f"Time taken rs : {time.time()-t0}")
11 changes: 1 addition & 10 deletions tools/garaga_rs/src/ecip/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,14 @@ where
{
// println!("Running ecip");
let (q, divisors) = ecip_functions(points, dss);
q.print();
// println!("Calculating dlogs");
let dlogs: Vec<_> = divisors.iter().map(|d| dlog(d.clone())).collect();

for (i, dlog) in dlogs.clone().iter().enumerate() {
println!("DLOG_{} : {}", i, dlog.print_as_sage_poly());
}
let mut sum_dlog = dlogs[0].clone();
let minus_three = FieldElement::<F>::zero() - FieldElement::<F>::from(3);
let mut neg_3_power = FieldElement::<F>::one();
for (i, dlog) in dlogs.iter().enumerate().skip(1) {
for dlog in dlogs.iter().skip(1) {
neg_3_power *= minus_three.clone();
println!(
"neg_3_pow_{}: {:?}",
i,
neg_3_power.representative().to_string()
);
sum_dlog = sum_dlog + dlog.clone().scale_by_coeff(neg_3_power.clone());
}

Expand Down
4 changes: 0 additions & 4 deletions tools/garaga_rs/src/ecip/g1point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ impl<F: IsPrimeField + CurveParamsProvider<F>> G1Point<F> {
let curve_params = F::get_curve_params();
let a = curve_params.a;
let b = curve_params.b;

println!("a: {:?}", a.representative().to_string());
println!("b: {:?}", b.representative().to_string());

self.y.square() == self.x.clone().square() * self.x.clone() + a * self.x.clone() + b
}

Expand Down
Loading