Skip to content

Commit 02157f6

Browse files
sevkett12Hakkush-07just-erray
authored
Fix failing tests (BitVM#196)
* fix test_hinted_quad_miller * fixed generate_f * fix stable_script in chunk_scalar_mul by changing names to run1 and run2 * use script macro in pairing * use script macro in fq12 * use script macro in fq6 * use script macro in fq2, verifier, chunk_evaluate_lines * uncomment message in winternitz test * remove unused hint variables, remove P_POW3, add new constants --------- Co-authored-by: Hakkush-07 <hakan.karakus@std.bogazici.edu.tr> Co-authored-by: just-erray <c.e.aslan37@gmail.com>
1 parent dbbc60f commit 02157f6

File tree

12 files changed

+716
-850
lines changed

12 files changed

+716
-850
lines changed

bitvm/src/bn254/fq12.rs

Lines changed: 60 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,23 @@ impl Fq12 {
9090
let (hinted_script2, hint2) = Fq6::hinted_mul(6, a.c1, 0, b.c1);
9191
let (hinted_script3, hint3) = Fq6::hinted_mul(6, a.c0 + a.c1, 0, b.c0 + b.c1);
9292

93-
let mut script = script! {};
94-
let script_lines = [
95-
Fq6::copy(a_depth + 6),
96-
Fq6::copy(b_depth + 12),
97-
hinted_script1,
98-
Fq6::copy(a_depth + 6),
99-
Fq6::copy(b_depth + 12),
100-
hinted_script2,
101-
Fq6::add(a_depth + 12, a_depth + 18),
102-
Fq6::add(b_depth + 18, b_depth + 24),
103-
hinted_script3,
104-
Fq6::copy(12),
105-
Fq6::copy(12),
106-
Fq12::mul_fq6_by_nonresidue(),
107-
Fq6::add(6, 0),
108-
Fq6::add(18, 12),
109-
Fq6::sub(12, 0),
110-
];
111-
for script_line in script_lines {
112-
script = script.push_script(script_line.compile());
113-
}
93+
let script = script! {
94+
{ Fq6::copy(a_depth + 6) }
95+
{ Fq6::copy(b_depth + 12) }
96+
{ hinted_script1 }
97+
{ Fq6::copy(a_depth + 6) }
98+
{ Fq6::copy(b_depth + 12) }
99+
{ hinted_script2 }
100+
{ Fq6::add(a_depth + 12, a_depth + 18) }
101+
{ Fq6::add(b_depth + 18, b_depth + 24) }
102+
{ hinted_script3 }
103+
{ Fq6::copy(12) }
104+
{ Fq6::copy(12) }
105+
{ Fq12::mul_fq6_by_nonresidue() }
106+
{ Fq6::add(6, 0) }
107+
{ Fq6::add(18, 12) }
108+
{ Fq6::sub(12, 0) }
109+
};
114110

115111
hints.extend(hint1);
116112
hints.extend(hint2);
@@ -135,59 +131,54 @@ impl Fq12 {
135131
let (hinted_script2, hint2) =
136132
Fq6::hinted_mul_by_01(p.c0 + p.c1, c3 + ark_bn254::Fq2::ONE, c4);
137133

138-
let mut script = script! {};
139-
140-
let script_lines = [
134+
let script = script! {
141135
// copy p.c1, c3, c4
142-
Fq6::copy(4),
143-
Fq2::copy(8),
144-
Fq2::copy(8),
136+
{ Fq6::copy(4) }
137+
{ Fq2::copy(8) }
138+
{ Fq2::copy(8) }
145139
// [p, c3, c4, p.c1, c3, c4]
146140

147141
// compute b = p.c1 * (c3, c4)
148-
hinted_script1,
142+
{ hinted_script1 }
149143
// [p, c3, c4, b]
150144

151145
// a = p.c0 * c0, where c0 = 1
152-
Fq6::copy(16),
146+
{ Fq6::copy(16) }
153147
// [p, c3, c4, b, a]
154148

155149
// compute beta * b
156-
Fq6::copy(6),
157-
Fq12::mul_fq6_by_nonresidue(),
150+
{ Fq6::copy(6) }
151+
{ Fq12::mul_fq6_by_nonresidue() }
158152
// [p, c3, c4, b, a, beta * b]
159153

160154
// compute final c0 = a + beta * b
161-
Fq6::copy(6),
162-
Fq6::add(6, 0),
155+
{ Fq6::copy(6) }
156+
{ Fq6::add(6, 0) }
163157
// [p, c3, c4, b, a, c0]
164158

165159
// compute e = p.c0 + p.c1
166-
Fq6::add(28, 22),
160+
{ Fq6::add(28, 22) }
167161
// [c3, c4, b, a, c0, e]
168162

169163
// compute c0 + c3, where c0 = 1
170-
Fq2::roll(26),
171-
Fq2::push_one(),
172-
Fq2::add(2, 0),
164+
{ Fq2::roll(26) }
165+
{ Fq2::push_one() }
166+
{ Fq2::add(2, 0) }
173167
// [c4, b, a, c0, e, 1 + c3]
174168

175169
// update e = e * (c0 + c3, c4), where c0 = 1
176-
Fq2::roll(26),
177-
hinted_script2,
170+
{ Fq2::roll(26) }
171+
{ hinted_script2 }
178172
// [b, a, c0, e]
179173

180174
// sum a and b
181-
Fq6::add(18, 12),
175+
{ Fq6::add(18, 12) }
182176
// [c0, e, a + b]
183177

184178
// compute final c1 = e - (a + b)
185-
Fq6::sub(6, 0),
186-
];
179+
{ Fq6::sub(6, 0) }
180+
};
187181

188-
for script_line in script_lines {
189-
script = script.push_script(script_line.compile());
190-
}
191182
hints.extend(hint1);
192183
hints.extend(hint2);
193184

@@ -216,35 +207,29 @@ impl Fq12 {
216207
ark_bn254::Fq12Config::mul_fp6_by_nonresidue_in_place(&mut beta_ac1);
217208
let (hinted_script2, hints2) = Fq6::hinted_mul(12, a.c0 + a.c1, 6, a.c0 + beta_ac1);
218209

219-
let mut script = script! {};
220-
221-
let script_lines = [
210+
let script = script! {
222211
// v0 = c0 + c1
223-
Fq6::copy(6),
224-
Fq6::copy(6),
225-
Fq6::add(6, 0),
212+
{ Fq6::copy(6) }
213+
{ Fq6::copy(6) }
214+
{ Fq6::add(6, 0) }
226215
// v3 = c0 + beta * c1
227-
Fq6::copy(6),
228-
Fq12::mul_fq6_by_nonresidue(),
229-
Fq6::copy(18),
230-
Fq6::add(0, 6),
216+
{ Fq6::copy(6) }
217+
{ Fq12::mul_fq6_by_nonresidue() }
218+
{ Fq6::copy(18) }
219+
{ Fq6::add(0, 6) }
231220
// v2 = c0 * c1
232-
hinted_script1,
221+
{ hinted_script1 }
233222
// v0 = v0 * v3
234-
hinted_script2,
223+
{ hinted_script2 }
235224
// final c0 = v0 - (beta + 1) * v2
236-
Fq6::copy(6),
237-
Fq12::mul_fq6_by_nonresidue(),
238-
Fq6::copy(12),
239-
Fq6::add(6, 0),
240-
Fq6::sub(6, 0),
225+
{ Fq6::copy(6) }
226+
{ Fq12::mul_fq6_by_nonresidue() }
227+
{ Fq6::copy(12) }
228+
{ Fq6::add(6, 0) }
229+
{ Fq6::sub(6, 0) }
241230
// final c1 = 2 * v2
242-
Fq6::double(6),
243-
];
244-
245-
for script_line in script_lines {
246-
script = script.push_script(script_line.compile());
247-
}
231+
{ Fq6::double(6) }
232+
};
248233

249234
hints.extend(hints1);
250235
hints.extend(hints2);
@@ -349,17 +334,13 @@ impl Fq12 {
349334
[i % ark_bn254::Fq12Config::FROBENIUS_COEFF_FP12_C1.len()],
350335
);
351336

352-
let mut script = script! {};
353-
let script_lines = [
354-
Fq6::roll(6),
355-
hinted_script1,
356-
Fq6::roll(6),
357-
hinted_script2,
358-
hinted_script3,
359-
];
360-
for script_line in script_lines {
361-
script = script.push_script(script_line.compile());
362-
}
337+
let script = script! {
338+
{ Fq6::roll(6) }
339+
{ hinted_script1 }
340+
{ Fq6::roll(6) }
341+
{ hinted_script2 }
342+
{ hinted_script3 }
343+
};
363344

364345
hints.extend(hint1);
365346
hints.extend(hint2);

bitvm/src/bn254/fq2.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,23 @@ impl Fq2 {
4646
let (hinted_script1, hint1) = Fq::hinted_mul_keep_element(1, a.c0, 0, a.c1);
4747
let (hinted_script2, hint2) = Fq::hinted_mul(1, a.c0 - a.c1, 0, a.c0 + a.c1);
4848

49-
let mut script = script! {};
50-
let script_lines = [
49+
let script = script! {
5150
// a0, a1
52-
Fq::copy(1),
53-
Fq::copy(1),
51+
{ Fq::copy(1) }
52+
{ Fq::copy(1) }
5453
// a0, a1, a0, a1
55-
hinted_script1,
54+
{ hinted_script1 }
5655
// a0, a1, a0, a1, a0*a1
57-
Fq::double(0),
56+
{ Fq::double(0) }
5857
// a0, a1, a0, a1, 2*a0*a1
59-
Fq::sub(2, 1),
60-
Fq::add(3, 2),
58+
{ Fq::sub(2, 1) }
59+
{ Fq::add(3, 2) }
6160
// 2*a0*a1, a0-a1, a0+a1
62-
hinted_script2,
61+
{ hinted_script2 }
6362
// 2*a0*a1, a0^2-a1^2
64-
Fq::roll(1),
63+
{ Fq::roll(1) }
6564
// a0^2-a1^2, 2*a0*a1
66-
];
67-
for script_line in script_lines {
68-
script = script.push_script(script_line.compile());
69-
}
65+
};
7066

7167
hints.extend(hint1);
7268
hints.extend(hint2);
@@ -267,24 +263,20 @@ impl Fq2 {
267263
let (hinted_script2, hint2) = Fq::hinted_mul_by_constant(a.c1, &constant.c1);
268264
let (hinted_script3, hint3) = Fq::hinted_mul_by_constant(a.c0+a.c1, &(constant.c0+constant.c1));
269265

270-
let mut script = script! {};
271-
let script_lines = [
272-
Fq::copy(1),
273-
hinted_script1,
274-
Fq::copy(1),
275-
hinted_script2,
276-
Fq::add(3, 2),
277-
hinted_script3,
278-
Fq::copy(2),
279-
Fq::copy(2),
280-
Fq::add(1, 0),
281-
Fq::sub(1, 0),
282-
Fq::sub(2, 1),
283-
Fq::roll(1),
284-
];
285-
for script_line in script_lines {
286-
script = script.push_script(script_line.compile());
287-
}
266+
let script = script! {
267+
{ Fq::copy(1) }
268+
{ hinted_script1 }
269+
{ Fq::copy(1) }
270+
{ hinted_script2 }
271+
{ Fq::add(3, 2) }
272+
{ hinted_script3 }
273+
{ Fq::copy(2) }
274+
{ Fq::copy(2) }
275+
{ Fq::add(1, 0) }
276+
{ Fq::sub(1, 0) }
277+
{ Fq::sub(2, 1) }
278+
{ Fq::roll(1) }
279+
};
288280

289281
hints.extend(hint1);
290282
hints.extend(hint2);

0 commit comments

Comments
 (0)