Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 658118b

Browse files
committed
Added elliptic curve pairing tests
1 parent c4fb10a commit 658118b

File tree

4 files changed

+12188
-6
lines changed

4 files changed

+12188
-6
lines changed

ethereum/specials.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def proc_ecpairing(ext, msg):
151151
# Data must be an exact multiple of 192 byte
152152
if msg.data.size % 192:
153153
return 0, 0, []
154-
gascost = opcodes.GPAIRINGBASE + msg.data.size / 192 * opcodes.GPAIRINGPERPOINT
154+
gascost = opcodes.GPAIRINGBASE + msg.data.size // 192 * opcodes.GPAIRINGPERPOINT
155155
if msg.gas < gascost:
156156
return 0, 0, []
157157
zero = (py_pairing.FQ2.one(), py_pairing.FQ2.one(), py_pairing.FQ2.zero())
@@ -169,18 +169,18 @@ def proc_ecpairing(ext, msg):
169169
for v in (x2_i, x2_r, y2_i, y2_r):
170170
if v >= py_pairing.field_modulus:
171171
return 0, 0, []
172-
fq2_x = py_pairing.FQ2([py_pairing.FQ(x2_r), py_pairing.FQ(x2_i)])
173-
fq2_y = py_pairing.FQ2([py_pairing.FQ(y2_r), py_pairing.FQ(y2_i)])
172+
fq2_x = py_pairing.FQ2([x2_r, x2_i])
173+
fq2_y = py_pairing.FQ2([y2_r, y2_i])
174174
if (fq2_x, fq2_y) != (py_pairing.FQ2.zero(), py_pairing.FQ2.zero()):
175175
p2 = (fq2_x, fq2_y, py_pairing.FQ2.one())
176176
if not py_pairing.is_on_curve(p2, py_pairing.b2):
177177
return 0, 0, []
178178
else:
179179
p2 = zero
180-
if py_pairing.multiply(p2, py_pairing.curve_order) != zero:
180+
if py_pairing.multiply(p2, py_pairing.curve_order)[-1] != py_pairing.FQ2.zero():
181181
return 0, 0, []
182-
exponent *= py_pairing.pairing(p1, p2, final_exponentiate=False)
183-
result = py_pairing.final_exponentiate(exponent) == FQ12.one()
182+
exponent *= py_pairing.pairing(p2, p1, final_exponentiate=False)
183+
result = py_pairing.final_exponentiate(exponent) == py_pairing.FQ12.one()
184184
return 1, msg.gas - gascost, [0] * 31 + [1 if result else 0]
185185

186186
specials = {

0 commit comments

Comments
 (0)