Skip to content

Commit

Permalink
multi G1
Browse files Browse the repository at this point in the history
  • Loading branch information
asanso committed Mar 11, 2024
1 parent 90fad48 commit a329dd3
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def hex_to_int(x: str) -> int:
BLS12_G2MUL_GAS = 55000
BLS12_MAP_FP_TO_G1_GAS = 5500
BLS12_MAP_FP2_TO_G2_GAS = 110000
BLS12_MAP_FP2_TO_G2_GAS = 110000
BLS12_MULTIEXP_DISCOUNT_TABLE = [[1, 1200], [2, 888], [3, 764], [4, 641], [5, 594], [6, 547], [7, 500], [8, 453], [9, 438], [10, 423], [11, 408], [12, 394], [13, 379], [14, 364], [15, 349], [16, 334], [17, 330], [18, 326], [19, 322], [20, 318], [21, 314], [22, 310], [23, 306], [24, 302], [25, 298], [26, 294], [27, 289], [28, 285], [29, 281], [30, 277], [31, 273], [32, 269], [33, 268], [34, 266], [35, 265], [36, 263], [37, 262], [38, 260], [39, 259], [40, 257], [41, 256], [42, 254], [43, 253], [44, 251], [45, 250], [46, 248], [47, 247], [48, 245], [49, 244], [50, 242], [51, 241], [52, 239], [53, 238], [54, 236], [55, 235], [56, 233], [57, 232], [58, 231], [59, 229], [60, 228], [61, 226], [62, 225], [63, 223], [64, 222], [65, 221], [66, 220], [67, 219], [68, 219], [69, 218], [70, 217], [71, 216], [72, 216], [73, 215], [74, 214], [75, 213], [76, 213], [77, 212], [78, 211], [79, 211], [80, 210], [81, 209], [82, 208], [83, 208], [84, 207], [85, 206], [86, 205], [87, 205], [88, 204], [89, 203], [90, 202], [91, 202], [92, 201], [93, 200], [94, 199], [95, 199], [96, 198], [97, 197], [98, 196], [99, 196], [100, 195], [101, 194], [102, 193], [103, 193], [104, 192], [105, 191], [106, 191], [107, 190], [108, 189], [109, 188], [110, 188], [111, 187], [112, 186], [113, 185], [114, 185], [115, 184], [116, 183], [117, 182], [118, 182], [119, 181], [120, 180], [121, 179], [122, 179], [123, 178], [124, 177], [125, 176], [126, 176], [127, 175], [128, 174]]


# random point in G1
P1 = (
Expand Down Expand Up @@ -442,7 +445,6 @@ def case04_mul_G2():
# test vectors taken from
# /~https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve/blob/main/poc/vectors/BLS12381G1_XMD%3ASHA-256_SSWU_NU_.json
def case05_map_fp_to_G1():

yield 'map_fp_to_G1_bls', [
{
"Input": HASH_G1_MESSAGES[0][1],
Expand Down Expand Up @@ -526,7 +528,26 @@ def case06_map_fp2_to_G2():


def case07_multiexp_G1():
# Doubling
result_doubling_G1 = add(G1, G1)
assert result_doubling_G1 == multiply(G1, 2)
result_doubling_P1 = add(P1, P1)
assert result_doubling_P1 == multiply(P1, 2)
yield 'multiexp_G1_bls', [
{
"Input": int_to_hex(int(G1[0]), 64) + (int_to_hex(int(G1[1]), 64)) + int_to_hex(int(2), 32),
"Name": "bls_g1multiexp_(g1+g1=2*g1)",
"Expected": int_to_hex(int(result_doubling_G1[0]), 64) + (int_to_hex(int(result_doubling_G1[1]), 64)),
"Gas": BLS12_G1MUL_GAS,
"NoBenchmark": False
},
{
"Input": int_to_hex(int(P1[0]), 64) + (int_to_hex(int(P1[1]), 64)) + int_to_hex(int(2), 32),
"Name": "bls_g1multiexp_(p1+p1=2*p1)",
"Expected": int_to_hex(int(result_doubling_P1[0]), 64) + (int_to_hex(int(result_doubling_P1[1]), 64)),
"Gas": BLS12_G1MUL_GAS,
"NoBenchmark": False
}
]


Expand Down

0 comments on commit a329dd3

Please sign in to comment.