Skip to content

Commit

Permalink
precompiles: improve tests (#36)
Browse files Browse the repository at this point in the history
* precompiles: improve tests

* add verbose option
  • Loading branch information
0x0ece authored May 17, 2024
1 parent 65f805a commit 4d21da2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion generators/ed25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# Ok() (result: 0)
# valid signature
[1, 0, 48, 0, 255, 255, 16, 0, 255, 255, 112, 0, 5, 0, 255, 255, 75, 214, 129, 151, 244, 149, 70, 192, 102, 135, 224, 99, 199, 172, 238, 204, 3, 67, 253, 92, 104, 212, 24, 116, 243, 199, 49, 42, 20, 156, 143, 83, 1, 148, 145, 203, 46, 109, 182, 75, 135, 218, 65, 3, 176, 77, 9, 53, 33, 86, 42, 178, 80, 169, 11, 169, 251, 61, 180, 51, 167, 39, 34, 189, 140, 51, 151, 209, 50, 76, 167, 90, 205, 1, 57, 197, 149, 97, 99, 241, 191, 66, 222, 90, 0, 251, 220, 145, 101, 24, 220, 32, 183, 0, 19, 5, 104, 101, 108, 108, 111],
# InvalidSignature (result: 3)
# InvalidPublicKey (result: 1)
[1, 0, 48, 0, 255, 255, 16, 0, 255, 255, 112, 0, 5, 0, 255, 255, 75, 214, 129, 151, 0, 149, 70, 192, 102, 135, 224, 99, 199, 172, 238, 204, 3, 67, 253, 92, 104, 212, 24, 116, 243, 199, 49, 42, 20, 156, 143, 83, 1, 148, 145, 203, 46, 109, 182, 75, 135, 218, 65, 3, 176, 77, 9, 53, 33, 86, 42, 178, 80, 169, 11, 169, 251, 61, 180, 51, 167, 39, 34, 189, 140, 51, 151, 209, 50, 76, 167, 90, 205, 1, 57, 197, 149, 97, 99, 241, 191, 66, 222, 90, 0, 251, 220, 145, 101, 24, 220, 32, 183, 0, 19, 5, 104, 101, 108, 108, 111]
]

Expand All @@ -41,6 +41,7 @@
# inconsistent between ed25519 and secp256k1
[ 0 ], # ed25519: err, secp256k1: ok
[ 0, 0 ], # ed25519: ok, secp256k1: err
[ 0, 2 ], # ed25519: ok, secp256k1: err
# InvalidInstructionDataSize (result: 5)
# https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L90-L92
[ 1 ],
Expand Down
17 changes: 15 additions & 2 deletions generators/secp256k1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,23 @@
[2, 23, 0, 0, 88, 0, 0, 108, 0, 5, 0, 0, 113, 0, 0, 178, 0, 0, 198, 0, 5, 0, 0, 8, 106, 2, 17, 228, 135, 168, 210, 219, 113, 75, 102, 239, 51, 218, 230, 218, 125, 149, 73, 201, 61, 102, 253, 170, 115, 201, 14, 162, 243, 11, 22, 90, 90, 242, 118, 196, 38, 97, 5, 74, 132, 110, 172, 168, 204, 248, 224, 162, 249, 64, 95, 48, 88, 72, 56, 157, 16, 4, 2, 165, 47, 207, 113, 0, 45, 237, 4, 121, 189, 201, 77, 37, 225, 171, 23, 82, 196, 28, 174, 59, 124, 136, 139, 245, 104, 101, 108, 108, 111, 8, 106, 2, 17, 228, 135, 168, 210, 219, 113, 75, 102, 239, 51, 218, 230, 218, 125, 149, 73, 201, 61, 102, 253, 170, 115, 201, 14, 162, 243, 11, 22, 165, 165, 13, 137, 59, 217, 158, 250, 181, 123, 145, 83, 87, 51, 7, 30, 23, 181, 156, 135, 126, 240, 88, 3, 34, 194, 90, 138, 43, 6, 113, 208, 1, 45, 237, 4, 121, 189, 201, 77, 37, 225, 171, 23, 82, 196, 28, 174, 59, 124, 136, 139, 245, 104, 101, 108, 108, 111],
]

prefix = [1, 32, 0, 0, 12, 0, 0, 97, 0, 5, 0, 0]
prefix_alt = [1, 37, 0, 0, 12, 0, 0, 32, 0, 5, 0, 0] ## swap sig, msg
pubkey = [129, 246, 169, 169, 105, 76, 208, 128, 223, 135, 27, 68, 249, 42, 201, 69, 55, 2, 173, 101]
pubkey_err = [111, 246, 169, 169, 105, 76, 208, 128, 223, 135, 27, 68, 249, 42, 201, 69, 55, 2, 173, 101]
sig = [14, 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]
sig_invalid = [255]*64
sig_err = [14, 196, 198, 193, 237, 0, 14, 255, 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]
# ^^^ modified byte
recid = 1
msg = [104, 101, 108, 108, 111] # hello

# manual code cov
test_vectors_manual = [
# inconsistent between ed25519 and secp256k1
[ 0 ], # ed25519: err, secp256k1: ok
[ 0, 0 ], # ed25519: ok, secp256k1: err
[ 0, 2 ], # ed25519: ok, secp256k1: err
# InvalidInstructionDataSize (result: 5)
# https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L937-L947
# note: this is different behavior than ed25519
Expand Down Expand Up @@ -72,8 +84,9 @@

# InvalidRecoveryId (result: 2)
# https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L981C43-L981C60
[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, 14, 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, 4, 104, 101, 108, 108, 111],
# \--- pubkey (eth) ---/ \--- sig ---/ \--- msg ---/
prefix + pubkey + sig + [4] + msg,
prefix_alt + pubkey + msg + sig + [4],
prefix_alt + pubkey + msg + sig,

# InvalidDataOffsets (result: 4)
# https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L984-L989
Expand Down
10 changes: 10 additions & 0 deletions src/test_suite/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ def run_tests(
log_chunk_size: int = typer.Option(
10000, "--chunk-size", "-c", help="Number of test results per file"
),
verbose: bool = typer.Option(
False,
"--verbose",
"-v",
help="Verbose output: log failed test cases",
),
):
# Add Solana library to shared libraries
shared_libraries = [solana_shared_library] + shared_libraries
Expand Down Expand Up @@ -516,6 +522,7 @@ def run_tests(
passed = 0
failed = 0
skipped = 0
failed_tests = []
target_log_files = {target: None for target in shared_libraries}
for file_stem, status, stringified_results in test_case_results:
if stringified_results is None:
Expand Down Expand Up @@ -543,6 +550,7 @@ def run_tests(
passed += 1
elif status == -1:
failed += 1
failed_tests.append(file_stem)

print("Cleaning up...")
for target in shared_libraries:
Expand All @@ -555,6 +563,8 @@ def run_tests(

print(f"Total test cases: {passed + failed + skipped}")
print(f"Passed: {passed}, Failed: {failed}, Skipped: {skipped}")
if verbose:
print(f"Failed tests: {failed_tests}")


@app.command()
Expand Down

0 comments on commit 4d21da2

Please sign in to comment.