Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 67e0ba5

Browse files
authored
fix tob-wave3-week3 (#904)
1 parent a88264d commit 67e0ba5

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

zkevm-circuits/src/sig_circuit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<F: Field> SigCircuit<F> {
424424
ecc_chip
425425
.field_chip
426426
.range
427-
.range_check(ctx, &assigned_y_tmp, 88);
427+
.range_check(ctx, &assigned_y_tmp, 87);
428428

429429
Ok(AssignedECDSA {
430430
pk: pk_assigned,

zkevm-circuits/src/sig_circuit/ecdsa.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -100,36 +100,9 @@ where
100100
// - (u1 + u3) * G
101101
// - u2 * pubkey + u3 * G
102102
// are not equal
103-
//
104-
// TODO: Technically they could be equal for a valid signature, but this happens with
105-
// vanishing probability for an ECDSA signature constructed in a standard way
106-
// coordinates of u1_mul and u2_mul are in proper bigint form, and lie in but are not
107-
// constrained to [0, n) we therefore need hard inequality here
108103
let u1_u2_x_eq = ecc_chip.is_equal(ctx, &u1u3_mul, &u2_pk_u3_g);
109104
let u1_u2_not_eq = base_chip.range.gate().not(ctx, Existing(u1_u2_x_eq));
110105

111-
// check u1*G and u2*pubkey are not negate of each other
112-
// that means the sum of
113-
// - (u1 + u3) * G
114-
// - u2 * pubkey + u3 * G
115-
// should not equal to 2u3 * G
116-
let u1_u2_not_neg = {
117-
// again we get 2u3*G from constant to avoid scalar_multiply
118-
let two_generator = GA::generator();
119-
let neg_two_generator = -two_generator;
120-
let two_generator = ecc_chip.assign_constant_point(ctx, two_generator);
121-
let neg_two_generator = ecc_chip.assign_constant_point(ctx, neg_two_generator);
122-
let two_u3_g = ecc_chip.select(ctx, &neg_two_generator, &two_generator, &u1_is_one);
123-
124-
base_chip.enforce_less_than_p(ctx, u1u3_mul.x());
125-
base_chip.enforce_less_than_p(ctx, u2_pk_u3_g.x());
126-
// safe: we have already checked (u1 + u3) * G != u2 * pubkey + u3 * G
127-
let sum = ec_add_unequal(base_chip, ctx, &u1u3_mul, &u2_pk_u3_g, false);
128-
129-
let is_equal = ecc_chip.is_equal(ctx, &sum, &two_u3_g);
130-
base_chip.range.gate().not(ctx, Existing(is_equal))
131-
};
132-
133106
// compute (x1, y1) = u1 * G + u2 * pubkey and check (r mod n) == x1 as integers
134107
// which is basically u1u3_mul + u2_mul - u3_mul
135108
// WARNING: For optimization reasons, does not reduce x1 mod n, which is
@@ -184,12 +157,8 @@ where
184157
let res5 = base_chip
185158
.range
186159
.gate()
187-
.and(ctx, Existing(res4), Existing(u1_u2_not_neg));
188-
let res6 = base_chip
189-
.range
190-
.gate()
191-
.and(ctx, Existing(res5), Existing(equal_check));
192-
(res6, sum.y)
160+
.and(ctx, Existing(res4), Existing(equal_check));
161+
(res5, sum.y)
193162
}
194163

195164
fn scalar_field_element_is_one<F: PrimeField, SF: PrimeField>(

zkevm-circuits/src/sig_circuit/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use halo2_proofs::{
1313
// Hard coded parameters.
1414
// FIXME: allow for a configurable param.
1515
pub(super) const MAX_NUM_SIG: usize = 128;
16-
// Each ecdsa signature requires 462274 cells
17-
pub(super) const CELLS_PER_SIG: usize = 462274;
18-
// Each ecdsa signature requires 62994 lookup cells
19-
pub(super) const LOOKUP_CELLS_PER_SIG: usize = 62994;
16+
// Each ecdsa signature requires 460605 cells
17+
pub(super) const CELLS_PER_SIG: usize = 460605;
18+
// Each ecdsa signature requires 63012 lookup cells
19+
pub(super) const LOOKUP_CELLS_PER_SIG: usize = 63012;
2020
// Total number of rows allocated for ecdsa chip
2121
pub(super) const LOG_TOTAL_NUM_ROWS: usize = 20;
2222
// Max number of columns allowed

0 commit comments

Comments
 (0)