From d16ee274e3c9888542563079d1c0d4b4ce648a5e Mon Sep 17 00:00:00 2001 From: Emanuele Cesena Date: Tue, 28 May 2024 18:41:27 +0000 Subject: [PATCH] syscall: add harness ctx --- generators/all.sh | 10 + generators/ed25519.py | 1 - generators/secp256k1.py | 5 +- generators/syscalls_alt_bn128.py | 898 ++++++++++++++++++++++++++ generators/syscalls_hash.py | 208 ++++++ generators/syscalls_poseidon.py | 224 +++++++ generators/syscalls_secp256k1.py | 206 ++++++ invoke.proto | 110 +++- src/test_suite/fuzz_context.py | 7 + src/test_suite/invoke_pb2.py | 445 ++++++++++++- src/test_suite/syscall/codec_utils.py | 13 + src/test_suite/test_suite.py | 3 +- 12 files changed, 2123 insertions(+), 7 deletions(-) create mode 100755 generators/all.sh create mode 100644 generators/syscalls_alt_bn128.py create mode 100644 generators/syscalls_hash.py create mode 100644 generators/syscalls_poseidon.py create mode 100644 generators/syscalls_secp256k1.py create mode 100644 src/test_suite/syscall/codec_utils.py diff --git a/generators/all.sh b/generators/all.sh new file mode 100755 index 0000000..4c11c6b --- /dev/null +++ b/generators/all.sh @@ -0,0 +1,10 @@ +#!/bin/bash +TESTS_PATH=./test-vectors/instr/inputs/20240425 +rm ${TESTS_PATH}/ed25519/* ; python3 generators/ed25519.py +rm ${TESTS_PATH}/secp256k1/* ; python3 generators/secp256k1.py +rm ${TESTS_PATH}/syscalls/keccak256/* +rm ${TESTS_PATH}/syscalls/blake3/* +rm ${TESTS_PATH}/syscalls/sha256/* ; python3 generators/syscalls_hash.py +rm ${TESTS_PATH}/syscalls/secp256k1/* ; python3 generators/syscalls_secp256k1.py +rm ${TESTS_PATH}/syscalls/poseidon/* ; python3 generators/syscalls_poseidon.py +rm ${TESTS_PATH}/syscalls/alt_bn128/* ; python3 generators/syscalls_alt_bn128.py diff --git a/generators/ed25519.py b/generators/ed25519.py index 650c64d..52da49c 100644 --- a/generators/ed25519.py +++ b/generators/ed25519.py @@ -2,7 +2,6 @@ import hashlib import test_suite.invoke_pb2 as pb from dataclasses import dataclass -import datetime import requests OUTPUT_DIR = "./test-vectors/instr/inputs/20240425/ed25519" diff --git a/generators/secp256k1.py b/generators/secp256k1.py index f825762..9201cce 100644 --- a/generators/secp256k1.py +++ b/generators/secp256k1.py @@ -3,7 +3,6 @@ from eth_hash.auto import keccak import test_suite.invoke_pb2 as pb from dataclasses import dataclass -import datetime import requests OUTPUT_DIR = "./test-vectors/instr/inputs/20240425/secp256k1" @@ -78,8 +77,8 @@ # tested above # https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L975-L978 # signature fails to decode - [1, 32, 0, 0, 12, 0, 0, 97, 0, 5, 0, 0, 129, 246, 169, 169, 105, 76, 208, 128, 223, 135, 27, 68, 249, 42, 201, 69, 55, 2, 173, 101, 255, 196, 198, 193, 237, 0, 14, 83, 87, 183, 25, 69, 136, 43, 251, 73, 44, 194, 141, 230, 102, 16, 220, 6, 46, 214, 214, 125, 120, 16, 103, 254, 39, 121, 88, 223, 156, 229, 186, 211, 38, 101, 196, 233, 125, 150, 136, 177, 123, 197, 48, 219, 28, 26, 10, 76, 198, 127, 91, 80, 88, 191, 6, 3, 255, 104, 101, 108, 108, 111], - # \--- pubkey (eth) ---/ \--- sig ---/ \--- msg ---/ + [1, 32, 0, 0, 12, 0, 0, 97, 0, 5, 0, 0, 129, 246, 169, 169, 105, 76, 208, 128, 223, 135, 27, 68, 249, 42, 201, 69, 55, 2, 173, 101, 255, 196, 198, 193, 237, 0, 14, 83, 87, 183, 25, 69, 136, 43, 251, 73, 44, 194, 141, 230, 102, 16, 220, 6, 46, 214, 214, 125, 120, 16, 103, 254, 39, 121, 88, 223, 156, 229, 186, 211, 38, 101, 196, 233, 125, 150, 136, 177, 123, 197, 48, 219, 28, 26, 10, 76, 198, 127, 91, 80, 88, 191, 6, 3, 1, 104, 101, 108, 108, 111], + # \--- pubkey (eth) ---/ \--- sig ---/ \--- msg ---/ # InvalidRecoveryId (result: 2) # https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L981C43-L981C60 diff --git a/generators/syscalls_alt_bn128.py b/generators/syscalls_alt_bn128.py new file mode 100644 index 0000000..11b0593 --- /dev/null +++ b/generators/syscalls_alt_bn128.py @@ -0,0 +1,898 @@ +import base64 +import hashlib +import test_suite.invoke_pb2 as pb + +OUTPUT_DIR = "./test-vectors/instr/inputs/20240425/syscalls/alt_bn128" +HEAP_START = 0x300000000 +CU_BASE = 542 +CU_PER_ELEM = 61 +CU_MEM_OP = 10 + +ADD_OP = 0 +ADD_SZ = 64+64 +ADD_CU = 334 + +MUL_OP = 2 +MUL_SZ = 64+32 +MUL_CU = 3840 + +PAIRING_OP = 3 +PAIRING_SZ = (64+128)*2 +PAIRING_CU = 36364 + 12121 + PAIRING_SZ + 85 + 32 # wtf!? + +COMP_G1_OP = 0 +COMP_G1_SZ = 64 +COMP_G1_CU = 30 + 100 + +DECOMP_G1_OP = 1 +DECOMP_G1_SZ = 32 +DECOMP_G1_CU = 398 + 100 + +COMP_G2_OP = 2 +COMP_G2_SZ = 128 +COMP_G2_CU = 86 + 100 + +DECOMP_G2_OP = 3 +DECOMP_G2_SZ = 64 +DECOMP_G2_CU = 13610 + 100 + +def exact_cu_cost(data_vec): + return CU_BASE + CU_PER_ELEM * len(data_vec) * len(data_vec) + +def _into_key_data(key_prefix, test_vectors): + return [(key_prefix + str(j), data) for j, data in enumerate(test_vectors)] + +test_vectors_add = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1547 + # invalid op + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": 1, # sub not implemented + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": 4, + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1551 + # cost + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": ADD_OP, + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1553-L1565 + # i/o + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": ADD_OP, + "input_addr": HEAP_START + 1, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": ADD_OP, + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START + 100, + "cu_avail": ADD_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1580-L1589 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": ADD_OP, + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L164 + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d700", True), + "op": ADD_OP, + "input_addr": HEAP_START, + "input_size": ADD_SZ + 1, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L173 + # this can never happen + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L175 + { + "heap_prefix": base64.b16decode("ffb18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", True), + "op": ADD_OP, + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L179 + # this can never happen + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L181 + { + "heap_prefix": base64.b16decode("18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17ff", True), + "op": ADD_OP, + "input_addr": HEAP_START, + "input_size": ADD_SZ, + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L191 + # this can never happen + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L195 + # this can never happen + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1594 + # this can never happen +] +# from src/ballet/bn254/test_bn254.c +add_inputs = [ + "18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f3726607c2b7f58a84bd6145f00c9c2bc0bb1a187f20ff2c92963a88019e7c6a014eed06614e20c147e940f2d70da3f74c9a17df361706a4485c742bd6788478fa17d7", + "2243525c5efd4b9c3d3c45ac0ca3fe4dd85e830a4ce6b65fa1eeaee202839703301d1d33be6da8e509df21cc35964723180eed7532537db9ae5e7d48f195c91518b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9063c909c4720840cb5134cb9f59fa749755796819658d32efc0d288198f37266", + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "", + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98", +] +for test in add_inputs: + input = base64.b16decode(test, True) + test_vectors_add.append({ + "heap_prefix": bytes([0] * 64) + input, + "op": ADD_OP, + "input_addr": HEAP_START + 64, + "input_size": len(input), + "result_addr": HEAP_START, + "cu_avail": ADD_CU, + }) + + +test_vectors_mul = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1551 + # cost + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", True), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ, + "result_addr": HEAP_START, + "cu_avail": MUL_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1553-L1565 + # i/o + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", True), + "op": MUL_OP, + "input_addr": HEAP_START + 1, + "input_size": MUL_SZ, + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }, + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", True), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ, + "result_addr": HEAP_START + 100, + "cu_avail": MUL_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1580-L1589 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", True), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ, + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L202 + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c200", True), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ + 1, # implementation bug + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }, + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c200", True) + bytes([0]*32), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ + 33, + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L211 + # this can never happen + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L213 + { + "heap_prefix": base64.b16decode("ffd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", True), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ, + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L217 + { + "heap_prefix": base64.b16decode("2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb204ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", True), + "op": MUL_OP, + "input_addr": HEAP_START, + "input_size": MUL_SZ, + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }, +] +# from src/ballet/bn254/test_bn254.c +mul_inputs = [ + "2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb721611ce0a6af85915e2f1d70300909ce2e49dfad4a4619c8390cae66cefdb20400000000000000000000000000000000000000000000000011138ce750fa15c2", + "070a8d6a982153cae4be29d434e8faef8a47b274a053f5a4ee2a6c9c13c31e5c031b8ce914eba3a9ffb989f9cdd5b0f01943074bf4f0f315690ec3cec6981afc30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd46", + "025a6f4181d2b4ea8b724290ffb40156eb0adb514c688556eb79cdea0752c2bb2eff3f31dea215f1eb86023a133a996eb6300b44da664d64251d05381bb8a02e183227397098d014dc2822db40c0ac2ecbc0b548b438e5469e10460b6c3e7ea3", + "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f6ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f630644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000", + "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f60000000000000000000000000000000100000000000000000000000000000000", + "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f60000000000000000000000000000000000000000000000000000000000000009", + "1a87b0584ce92f4593d161480614f2989035225609f08058ccfa3d0f940febe31a2f3c951f6dadcc7ee9007dff81504b0fcd6d7cf59996efdc33d92bf7f9f8f60000000000000000000000000000000000000000000000000000000000000001", + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000", + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c0000000000000000000000000000000100000000000000000000000000000000", + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c0000000000000000000000000000000000000000000000000000000000000009", + "17c139df0efee0f766bc0204762b774362e4ded88953a39ce849a8a7fa163fa901e0559bacb160664764a357af8a9fe70baa9258e0b959273ffc5718c6d4cc7c0000000000000000000000000000000000000000000000000000000000000001", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d9830644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000000", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d980000000000000000000000000000000100000000000000000000000000000000", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d980000000000000000000000000000000000000000000000000000000000000009", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d980000000000000000000000000000000000000000000000000000000000000001", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98", + "039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d9800000000000000000000000000000001", +] +for test in mul_inputs: + input = base64.b16decode(test, True) + test_vectors_mul.append({ + "heap_prefix": bytes([0] * 64) + input, + "op": MUL_OP, + "input_addr": HEAP_START + 64, + "input_size": len(input), + "result_addr": HEAP_START, + "cu_avail": MUL_CU, + }) + + +test_vectors_pairing = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1551 + # cost + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": PAIRING_SZ, + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1553-L1565 + # i/o + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START + 1, + "input_size": PAIRING_SZ, + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": PAIRING_SZ, + "result_addr": HEAP_START + 360, + "cu_avail": PAIRING_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1580-L1589 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": PAIRING_SZ, + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, + { + "heap_prefix": [0] * 32, + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": 0, + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L244 + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": PAIRING_SZ - 1, # implementation bug + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": 191, # implementation bug + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L261 + { + "heap_prefix": base64.b16decode("ff76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": PAIRING_SZ, + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, + # https://github.com/anza-xyz/agave/blob/master/sdk/program/src/alt_bn128/mod.rs#L273 + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7dff", True), + "op": PAIRING_OP, + "input_addr": HEAP_START, + "input_size": PAIRING_SZ, + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU, + }, +] +# from src/ballet/bn254/test_bn254.c +pairing_inputs = [ + "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "2eca0c7238bf16e83e7a1e6c5d49540685ff51380f309842a98561558019fc0203d3260361bb8451de5ff5ecd17f010ff22f5c31cdf184e9020b06fa5997db841213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f06967a1237ebfeca9aaae0d6d0bab8e28c198c5a339ef8a2407e31cdac516db922160fa257a5fd5b280642ff47b65eca77e626cb685c84fa6d3b6882a283ddd1198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "0f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd216da2f5cb6be7a0aa72c440c53c9bbdfec6c36c7d515536431b3a865468acbba2e89718ad33c8bed92e210e81d1853435399a271913a6520736a4729cf0d51eb01a9e2ffa2e92599b68e44de5bcf354fa2642bd4f26b259daa6f7ce3ed57aeb314a9a87b789a58af499b314e13c3d65bede56c07ea2d418d6874857b70763713178fb49a2d6cd347dc58973ff49613a20757d0fcc22079f9abd10c3baee245901b9e027bd5cfc2cb5db82d4dc9677ac795ec500ecd47deee3b5da006d6d049b811d7511c78158de484232fc68daf8a45cf217d1c2fae693ff5871e8752d73b21198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "2f2ea0b3da1e8ef11914acf8b2e1b32d99df51f5f4f206fc6b947eae860eddb6068134ddb33dc888ef446b648d72338684d678d2eb2371c61a50734d78da4b7225f83c8b6ab9de74e7da488ef02645c5a16a6652c3c71a15dc37fe3a5dcb7cb122acdedd6308e3bb230d226d16a105295f523a8a02bfc5e8bd2da135ac4c245d065bbad92e7c4e31bf3757f1fe7362a63fbfee50e7dc68da116e67d600d9bf6806d302580dc0661002994e7cd3a7f224e7ddc27802777486bf80f40e4ca3cfdb186bac5188a98c45e6016873d107f5cd131f3a3e339d0375e58bd6219347b008122ae2b09e539e152ec5364e7e2204b03d11d3caa038bfc7cd499f8176aacbee1f39e4e4afc4bc74790a4a028aff2c3d2538731fb755edefd8cb48d6ea589b5e283f150794b6736f670d6a1033f9b46c6f5204f50813eb85c8dc4b59db1c5d39140d97ee4d2b36d99bc49974d18ecca3e7ad51011956051b464d9e27d46cc25e0764bb98575bd466d32db7b15f582b2d5c452b36aa394b789366e5e3ca5aabd415794ab061441e51d01e94640b7e3084a07e02c78cf3103c542bc5b298669f211b88da1679b0b64a63b7e0e7bfe52aae524f73a55be7fe70c7e9bfc94b4cf0da1213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f", + "20a754d2071d4d53903e3b31a7e98ad6882d58aec240ef981fdf0a9d22c5926a29c853fcea789887315916bbeb89ca37edb355b4f980c9a12a94f30deeed30211213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f1abb4a25eb9379ae96c84fff9f0540abcfc0a0d11aeda02d4f37e4baf74cb0c11073b3ff2cdbb38755f8691ea59e9606696b3ff278acfc098fa8226470d03869217cee0a9ad79a4493b5253e2e4e3a39fc2df38419f230d341f60cb064a0ac290a3d76f140db8418ba512272381446eb73958670f00cf46f1d9e64cba057b53c26f64a8ec70387a13e41430ed3ee4a7db2059cc5fc13c067194bcc0cb49a98552fd72bd9edb657346127da132e5b82ab908f5816c826acb499e22f2412d1a2d70f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd2198a1f162a73261f112401aa2db79c7dab1533c9935c77290a6ce3b191f2318d198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c103188585e2364128fe25c70558f1560f4f9350baf3959e603cc91486e110936198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "105456a333e6d636854f987ea7bb713dfd0ae8371a72aea313ae0c32c0bf10160cf031d41b41557f3e7e3ba0c51bebe5da8e6ecd855ec50fc87efcdeac168bcc0476be093a6d2b4bbf907172049874af11e1b6267606e00804d3ff0037ec57fd3010c68cb50161b7d1d96bb71edfec9880171954e56871abf3d93cc94d745fa114c059d74e5b6c4ec14ae5864ebe23a71781d86c29fb8fb6cce94f70d3de7a2101b33461f39d9e887dbb100f170a2345dde3c07e256d1dfa2b657ba5cd030427000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021a2c3013d2ea92e13c800cde68ef56a294b883f6ac35d25f587c09b1b3c635f7290158a80cd3d66530f74dc94c94adb88f5cdb481acca997b6e60071f08a115f2f997f3dbd66a7afe07fe7862ce239edba9e05c5afff7f8a1259c9733b2dfbb929d1691530ca701b4a106054688728c9972c8512e9789e9567aae23e302ccd75", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed275dc4a288d1afb3cbb1ac09187524c7db36395df7be3b99e673b13a075a65ec1d9befcd05a5323e6da4d435f3b617cdb3af83285c2df711ef39c01571827f9d", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002203e205db4f19b37b60121b83a7333706db86431c6d835849957ed8c3928ad7927dc7234fd11d3e8c36c59277c3e6f149d5cd3cfa9a62aee49f8130962b4b3b9195e8aa5b7827463722b8c153931579d3505566b4edf48d498e185f0509de15204bb53b8977e5f92a0bc372742c4830944a59b4fe6b1c0466e2a6dad122b5d2e030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd31a76dae6d3272396d0cbe61fced2bc532edac647851e3ac53ce1cc9c7e645a83198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", + "105456a333e6d636854f987ea7bb713dfd0ae8371a72aea313ae0c32c0bf10160cf031d41b41557f3e7e3ba0c51bebe5da8e6ecd855ec50fc87efcdeac168bcc0476be093a6d2b4bbf907172049874af11e1b6267606e00804d3ff0037ec57fd3010c68cb50161b7d1d96bb71edfec9880171954e56871abf3d93cc94d745fa114c059d74e5b6c4ec14ae5864ebe23a71781d86c29fb8fb6cce94f70d3de7a2101b33461f39d9e887dbb100f170a2345dde3c07e256d1dfa2b657ba5cd030427000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021a2c3013d2ea92e13c800cde68ef56a294b883f6ac35d25f587c09b1b3c635f7290158a80cd3d66530f74dc94c94adb88f5cdb481acca997b6e60071f08a115f2f997f3dbd66a7afe07fe7862ce239edba9e05c5afff7f8a1259c9733b2dfbb929d1691530ca701b4a106054688728c9972c8512e9789e9567aae23e302ccd75", + "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa000000000000000000000000000000000000000000000000000000000000000130644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd45198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", +] +for test in pairing_inputs: + input = base64.b16decode(test, True) + test_vectors_pairing.append({ + "heap_prefix": bytes([0] * 64) + input, + "op": PAIRING_OP, + "input_addr": HEAP_START + 32, + "input_size": len(input), + "result_addr": HEAP_START, + "cu_avail": PAIRING_CU + 12121 * 20, # enough CUs for all tests + }) + + +test_vectors_compress_g1 = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1890 + # invalid op + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": 4, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1813 + # cost + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1815-L1827 + # i/o + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START + 1, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START + 33, + "cu_avail": COMP_G1_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1834-L1847 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59002f7149c03b2c47b35163356519d1179affcf3b9487f7f857c3f11331120e06", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + + # firedancer + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L17 + # - https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254_g1.c#L263 + # - https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254_g1.c#L267 + # - https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254_g1.c#L272 + # - https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254_g1.c#L274 + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L27 + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L34 + { + "heap_prefix": bytes([0] * 64), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([8] + [0] * 63), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([4] + [0] * 63), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([12] + [0] * 63), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([0xff] * 32 + [0] * 32), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([0] * 32 + [0xff] * 32), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([0] * 32 + [8] + [0] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([0] * 32 + [4] + [0] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([0] * 32 + [12] + [0] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("9c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("9c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59002f7149c03b2c47b35163356519d1179affcf3b9487f7f857c3f11331120e06", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("5c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("5c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59002f7149c03b2c47b35163356519d1179affcf3b9487f7f857c3f11331120e06", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + + { # 19 + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59b034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59802f7149c03b2c47b35163356519d1179affcf3b9487f7f857c3f11331120e06", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f597034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { # 22 + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59402f7149c03b2c47b35163356519d1179affcf3b9487f7f857c3f11331120e06", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59f034dd2920f673e204fee2811c678745fc819b55d3e9d294e45c9b03a76aef41", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59c02f7149c03b2c47b35163356519d1179affcf3b9487f7f857c3f11331120e06", True), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, +] +test_vectors_decompress_g1 = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1813 + # cost + { + "heap_prefix": base64.b16decode("9c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59", True) + bytes([0]*32), + "op": DECOMP_G1_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G1_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1815-L1827 + # i/o + { + "heap_prefix": base64.b16decode("9c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59", True) + bytes([0]*32), + "op": DECOMP_G1_OP, + "input_addr": HEAP_START + 33, + "input_size": DECOMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("9c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59", True) + bytes([0]*32), + "op": DECOMP_G1_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G1_SZ, + "result_addr": HEAP_START + 1, + "cu_avail": DECOMP_G1_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1834-L1847 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("9c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59", True) + bytes([0]*32), + "op": DECOMP_G1_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59", True) + bytes([0]*32), + "op": DECOMP_G1_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G1_CU, + }, + + # firedancer + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L43 + # - https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254_field.c#78 + # - https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254_field.c#90 + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L52 + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L62 + # - ... + # https://github.com/firedancer-io/firedancer/blob/a8c2e27b/src/ballet/bn254/fd_bn254.c#L67 + # tested above (success cases) + { + "heap_prefix": bytes([0] * 32), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([8] + [0] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([4] + [0] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": bytes([12] + [0] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, + { + "heap_prefix": base64.b16decode("dc76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59", True) + bytes([0]*32), + "op": DECOMP_G1_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G1_CU, + }, + { + "heap_prefix": bytes([0x3f] + [0xff] * 31), + "op": COMP_G1_OP, + "input_addr": HEAP_START, + "input_size": COMP_G1_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G1_CU, + }, +] +test_vectors_compress_g2 = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1813 + # cost + { + "heap_prefix": base64.b16decode("209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550", True), + "op": COMP_G2_OP, + "input_addr": HEAP_START, + "input_size": COMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G2_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1815-L1827 + # i/o + { + "heap_prefix": base64.b16decode("209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550", True), + "op": COMP_G2_OP, + "input_addr": HEAP_START + 1, + "input_size": COMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G2_CU, + }, + { + "heap_prefix": base64.b16decode("209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550", True), + "op": COMP_G2_OP, + "input_addr": HEAP_START, + "input_size": COMP_G2_SZ, + "result_addr": HEAP_START + 65, + "cu_avail": COMP_G2_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1834-L1847 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cfc93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce61f0c9bb048165fe5e4de877550", True), + "op": COMP_G2_OP, + "input_addr": HEAP_START, + "input_size": COMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G2_CU, + }, + { + "heap_prefix": base64.b16decode("209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a4167804ac1c27ea61d6f480ad989c3d245b50f4da4fc3edadaadf7c8d4fec86bec8fa1e5a2425ee25843033f124ef834777def4b484725bd61a4525c0a631f9f587f7", True), + "op": COMP_G2_OP, + "input_addr": HEAP_START, + "input_size": COMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": COMP_G2_CU, + }, +] +test_vectors_decompress_g2 = [ + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1813 + # cost + { + "heap_prefix": base64.b16decode("a09dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678", True) + bytes([0]*64), + "op": DECOMP_G2_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G2_CU - 1, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1815-L1827 + # i/o + { + "heap_prefix": base64.b16decode("a09dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678", True) + bytes([0]*64), + "op": DECOMP_G2_OP, + "input_addr": HEAP_START + 65, + "input_size": DECOMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G2_CU, + }, + { + "heap_prefix": base64.b16decode("a09dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678", True) + bytes([0]*64), + "op": DECOMP_G2_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G2_SZ, + "result_addr": HEAP_START + 1, + "cu_avail": DECOMP_G2_CU, + }, + + # https://github.com/anza-xyz/agave/blob/v1.18.12/programs/bpf_loader/src/syscalls/mod.rs#L1834-L1847 + # actual op - all these tests either return Ok(0) or Ok(1) + { + "heap_prefix": base64.b16decode("a09dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678", True) + bytes([0]*64), + "op": DECOMP_G2_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G2_CU, + }, + { + "heap_prefix": base64.b16decode("209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a41678", True) + bytes([0]*64), + "op": DECOMP_G2_OP, + "input_addr": HEAP_START, + "input_size": DECOMP_G2_SZ, + "result_addr": HEAP_START, + "cu_avail": DECOMP_G2_CU, + }, +] + +test_vectors_group = \ + _into_key_data("a", test_vectors_add) + \ + _into_key_data("m", test_vectors_mul) + \ + _into_key_data("p", test_vectors_pairing) +test_vectors_group = [] + +test_vectors_compression = \ + _into_key_data("c1", test_vectors_compress_g1) + \ + _into_key_data("d1", test_vectors_decompress_g1) + \ + _into_key_data("c2", test_vectors_compress_g2) + \ + _into_key_data("d2", test_vectors_decompress_g2) + +features = [ + 0xaaef1edeb6c5bf85, # enable_alt_bn128_syscall + 0x9bb55b5df1c396c5, # enable_alt_bn128_compression_syscall + # 0x8ba9e9038d9fdcff, # simplify_alt_bn128_syscall_error_codes +] + +if __name__ == "__main__": + print("Generating syscall alt_bn128 tests...") + + for (key, test) in test_vectors_group: + heap_prefix = test.get("heap_prefix", []) + syscall_ctx = pb.SyscallContext() + syscall_ctx.syscall_invocation.function_name = b"sol_alt_bn128_group_op" + syscall_ctx.syscall_invocation.heap_prefix = bytes(heap_prefix) + syscall_ctx.vm_ctx.heap_max = len(heap_prefix) + syscall_ctx.vm_ctx.r1 = test.get("op", 0) + syscall_ctx.vm_ctx.r2 = test.get("input_addr", 0) + syscall_ctx.vm_ctx.r3 = test.get("input_size", 0) + syscall_ctx.vm_ctx.r4 = test.get("result_addr", 0) + syscall_ctx.instr_ctx.cu_avail = test.get("cu_avail", 0) + syscall_ctx.instr_ctx.program_id = bytes([0]*32) # solfuzz-agave expectes a program_id + syscall_ctx.vm_ctx.rodata = b"x" # fd expects some bytes + + syscall_ctx.instr_ctx.epoch_context.features.features.extend(features) + + filename = str(key) + "_" + hashlib.sha3_256(syscall_ctx.instr_ctx.data).hexdigest()[:16] + + serialized_instr = syscall_ctx.SerializeToString(deterministic=True) + with open(f"{OUTPUT_DIR}/{filename}.bin", "wb") as f: + f.write(serialized_instr) + + print("done!") + print("Generating syscall alt_bn128_compression tests...") + + for (key, test) in test_vectors_compression: + heap_prefix = test.get("heap_prefix", []) + syscall_ctx = pb.SyscallContext() + syscall_ctx.syscall_invocation.function_name = b"sol_alt_bn128_compression" + syscall_ctx.syscall_invocation.heap_prefix = bytes(heap_prefix) + syscall_ctx.vm_ctx.heap_max = len(heap_prefix) + syscall_ctx.vm_ctx.r1 = test.get("op", 0) + syscall_ctx.vm_ctx.r2 = test.get("input_addr", 0) + syscall_ctx.vm_ctx.r3 = test.get("input_size", 0) + syscall_ctx.vm_ctx.r4 = test.get("result_addr", 0) + syscall_ctx.instr_ctx.cu_avail = test.get("cu_avail", 0) + syscall_ctx.instr_ctx.program_id = bytes([0]*32) # solfuzz-agave expectes a program_id + syscall_ctx.vm_ctx.rodata = b"x" # fd expects some bytes + + syscall_ctx.instr_ctx.epoch_context.features.features.extend(features) + + filename = str(key) + "_" + hashlib.sha3_256(syscall_ctx.instr_ctx.data).hexdigest()[:16] + + serialized_instr = syscall_ctx.SerializeToString(deterministic=True) + with open(f"{OUTPUT_DIR}/{filename}.bin", "wb") as f: + f.write(serialized_instr) + + print("done!") diff --git a/generators/syscalls_hash.py b/generators/syscalls_hash.py new file mode 100644 index 0000000..e25b56a --- /dev/null +++ b/generators/syscalls_hash.py @@ -0,0 +1,208 @@ +import hashlib +import test_suite.invoke_pb2 as pb +import struct + +OUTPUT_DIR = "./test-vectors/instr/inputs/20240425/syscalls" +HEAP_START = 0x300000000 +CU_BASE = 85 +CU_PER_BYTE = 1 # this is actually every 2 bytes... +CU_MEM_OP = 10 + +def heap_vec(data_vec, start): + res = [] + last = start + len(data_vec) * 16 + for data in data_vec: + res += struct.pack('