def mk_test(p1, m, execgas, datarestrict=96): encoded = mk_ecmul_data(p1, m)[:datarestrict] + \ b'\x00' * max(datarestrict - 96, 0) pre = tester.mk_state_test_prefill(c) try: o = x1.foo( encoded, startgas=21000 + intrinsic_gas_of_data( x1.translator.encode( 'foo', [encoded])) + execgas) x, y = big_endian_to_int(o[:32]), big_endian_to_int(o[32:]) if py_pairing.normalize(py_pairing.multiply(p1, m)) != ( py_pairing.FQ(x), py_pairing.FQ(y)): raise Exception("Mismatch! %r %r %d, expected %r computed %r" % (p1, m, datarestrict, py_pairing.normalize(py_pairing.multiply(p1, m)), (x, y))) print('Succeeded! %r %d %d %r' % (p1, m, datarestrict, (x, y))) except tester.TransactionFailed: print('OOG %r %d %d %d' % (p1, m, datarestrict, execgas)) o = tester.mk_state_test_postfill(c, pre) o2 = tester.mk_state_test_postfill(c, pre, filler_mode=True) assert new_statetest_utils.verify_state_test(o) return o, o2
raise Exception("Mismatch! %r %r %d, expected %r computed %r" % (p1, p2, datarestrict, py_pairing.normalize(py_pairing.add(p1, p2)), (x, y))) print('Succeeded! %r %r %d %r' % (p1, p2, datarestrict, (x, y))) except tester.TransactionFailed: print('OOG %r %r %d %d' % (p1, p2, datarestrict, execgas)) o = tester.mk_state_test_postfill(c, pre) o2 = tester.mk_state_test_postfill(c, pre, filler_mode=True) assert new_statetest_utils.verify_state_test(o) return o, o2 gaslimits = [21000, 25000] zero = (py_pairing.FQ(1), py_pairing.FQ(1), py_pairing.FQ(0)) wrong1 = (py_pairing.FQ(1), py_pairing.FQ(3), py_pairing.FQ(1)) wrong2 = (py_pairing.FQ(0), py_pairing.FQ(3), py_pairing.FQ(1)) wrong3 = (py_pairing.FQ(6), py_pairing.FQ(9), py_pairing.FQ(1)) wrong4 = (py_pairing.FQ(19274124), py_pairing.FQ(124124), py_pairing.FQ(1)) tests = [] for g in gaslimits: tests.append((zero, zero, g, 128)) tests.append((zero, zero, g, 64)) tests.append((zero, zero, g, 80)) tests.append((zero, zero, g, 0)) tests.append((zero, zero, g, 192)) tests.append((zero, py_pairing.G1, g, 128)) tests.append((zero, py_pairing.G1, g, 192))
execgas) x, y = big_endian_to_int(o[:32]), big_endian_to_int(o[32:]) if py_pairing.normalize(py_pairing.multiply(p1, m)) != ( py_pairing.FQ(x), py_pairing.FQ(y)): raise Exception("Mismatch! %r %r %d, expected %r computed %r" % (p1, m, datarestrict, py_pairing.normalize(py_pairing.multiply(p1, m)), (x, y))) print('Succeeded! %r %d %d %r' % (p1, m, datarestrict, (x, y))) except tester.TransactionFailed: print('OOG %r %d %d %d' % (p1, m, datarestrict, execgas)) o = tester.mk_state_test_postfill(c, pre) o2 = tester.mk_state_test_postfill(c, pre, filler_mode=True) assert new_statetest_utils.verify_state_test(o) return o, o2 zero = (py_pairing.FQ(1), py_pairing.FQ(1), py_pairing.FQ(0)) wrong1 = (py_pairing.FQ(1), py_pairing.FQ(3), py_pairing.FQ(1)) wrong2 = (py_pairing.FQ(0), py_pairing.FQ(3), py_pairing.FQ(1)) gaslimits = [21000, 28000] mults = [ 0, 1, 2, 9, 2**128, py_pairing.curve_order - 1, py_pairing.curve_order, 2**256 -