43
43
modulus :: < SF > ( ) ,
44
44
) ;
45
45
let n = scalar_chip. load_constant ( ctx, scalar_chip. p . to_biguint ( ) . unwrap ( ) ) ;
46
- println ! ( "n of scalar_chip {:?}" , n) ;
47
46
48
47
// check whether the pubkey is (0, 0), i.e. in the case of ecrecover, no pubkey could be
49
48
// recovered.
80
79
. gate ( )
81
80
. or ( ctx, Existing ( s_is_zero) , Existing ( s_in_range) ) ;
82
81
83
- println ! ( "r {:?}" , r) ;
84
- println ! ( "s {:?}" , s) ;
85
- println ! ( "pub_key {:?}" , pubkey) ;
86
- println ! ( "msg_hash {:?}" , msghash) ;
87
- println ! ( "r_is_valid {:?}" , r_is_valid) ;
88
- println ! ( "s_is_valid {:?}" , s_is_valid) ;
89
82
// load required constants
90
83
let zero = scalar_chip. load_constant ( ctx, FpConfig :: < F , SF > :: fe_to_constant ( SF :: ZERO ) ) ;
91
84
let one = scalar_chip. load_constant ( ctx, FpConfig :: < F , SF > :: fe_to_constant ( SF :: ONE ) ) ;
@@ -103,12 +96,9 @@ where
103
96
let u1 = scalar_chip. divide ( ctx, msghash, & s_prime) ;
104
97
let u1 = scalar_chip. select ( ctx, & zero, & u1, & s_is_zero) ;
105
98
106
- println ! ( "u1 after: {:?}" , u1) ;
107
-
108
99
// compute u2 = r * s^{-1} mod n
109
100
let u2 = scalar_chip. divide ( ctx, r, & s_prime) ;
110
101
let u2 = scalar_chip. select ( ctx, & zero, & u2, & s_is_zero) ;
111
- println ! ( "u2 after: {:?}" , u2) ;
112
102
113
103
// we want to compute u1*G + u2*PK, there are two edge cases
114
104
// 1. either u1 or u2 is 0; we use binary selections to handle the this case
@@ -127,17 +117,13 @@ where
127
117
base_chip. limb_bits ,
128
118
fixed_window_bits,
129
119
) ;
130
- println ! ( "u1_mul point {:?}" , u1_mul_affine) ;
131
- println ! ( "u1_is_zero {:?}" , u1_is_zero) ;
132
120
133
121
let u1_mul = ecc_chip. select ( ctx, & point_at_infinity, & u1_mul_affine, & u1_is_zero) ;
134
122
135
123
// compute u2 * pubkey
136
124
let u2_prime = scalar_chip. select ( ctx, & one, & u2, & s_is_zero) ;
137
125
let pubkey_prime = ecc_chip. load_random_point :: < GA > ( ctx) ;
138
126
let pubkey_prime = ecc_chip. select ( ctx, & pubkey_prime, pubkey, & is_pubkey_zero) ;
139
- println ! ( "u2_prime {:?}" , u2_prime) ;
140
- println ! ( "pubkey_prime {:?}" , pubkey_prime) ;
141
127
142
128
let u2_mul_affine = scalar_multiply :: < F , _ , GA > (
143
129
base_chip,
@@ -148,15 +134,12 @@ where
148
134
var_window_bits,
149
135
) ;
150
136
151
- println ! ( "u2_mul_affine point {:?}" , u2_mul_affine) ;
152
-
153
137
let u2_is_zero =
154
138
base_chip
155
139
. range ( )
156
140
. gate ( )
157
141
. or ( ctx, Existing ( s_is_zero) , Existing ( is_pubkey_zero) ) ;
158
142
let u2_mul = ecc_chip. select ( ctx, & point_at_infinity, & u2_mul_affine, & u2_is_zero) ;
159
- println ! ( "u2_is_zero {:?}" , u2_is_zero) ;
160
143
161
144
// =================================
162
145
// case 2:
@@ -173,7 +156,6 @@ where
173
156
. and ( ctx, Existing ( u1_is_zero) , Existing ( u2_is_zero) ) ;
174
157
let u1_u2_x_eq = base_chip. is_equal ( ctx, u1_mul. x ( ) , u2_mul. x ( ) ) ;
175
158
176
- println ! ( "u1_u2_x_eq {:?}" , u1_u2_x_eq) ;
177
159
let u1_u2_y_neg = {
178
160
let u2_y_neg = base_chip. negate ( ctx, u2_mul. y ( ) ) ;
179
161
base_chip. is_equal ( ctx, u1_mul. y ( ) , & u2_y_neg)
@@ -185,13 +167,10 @@ where
185
167
Existing ( u1_u2_y_neg) ,
186
168
) ;
187
169
188
- println ! ( "sum_is_infinity {:?}" , sum_is_infinity) ;
189
-
190
170
let sum_is_not_infinity = base_chip
191
171
. gate ( )
192
172
. not ( ctx, QuantumCell :: Existing ( sum_is_infinity) ) ;
193
173
194
- println ! ( "sum_is_not_infinity {:?}" , sum_is_not_infinity) ;
195
174
// For a valid ECDSA signature, the x co-ordinate of u1.G + u2.Pk, i.e. x_3, MUST EQUAL r
196
175
//
197
176
// For ec_add:
@@ -221,8 +200,7 @@ where
221
200
let x_3 = base_chip. carry_mod ( ctx, & x_3_no_carry) ;
222
201
let dx_13 = base_chip. sub_no_carry ( ctx, u1_mul. x ( ) , & x_3) ;
223
202
let lambda_dx_13 = base_chip. mul_no_carry ( ctx, & lambda, & dx_13) ;
224
- //let y_3_no_carry = base_chip.sub_no_carry(ctx, &lambda_dx_13, u1_mul.y());
225
- let y_3_no_carry = base_chip. add_no_carry ( ctx, & lambda_dx_13, u1_mul. y ( ) ) ;
203
+ let y_3_no_carry = base_chip. sub_no_carry ( ctx, & lambda_dx_13, u1_mul. y ( ) ) ;
226
204
227
205
let y_3 = base_chip. carry_mod ( ctx, & y_3_no_carry) ;
228
206
@@ -280,9 +258,6 @@ where
280
258
) ;
281
259
282
260
println ! ( "equal_check {:?}" , equal_check) ;
283
- println ! ( "x_3 {:?}" , x_3) ;
284
- println ! ( "y_3 {:?}" , y_3) ;
285
- println ! ( "res {:?}" , res) ;
286
261
287
262
( res, is_pubkey_zero, y_3)
288
263
}
0 commit comments