Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Block fuzzing target #107

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ $ solana-test-suite create-env [OPTIONS]

**Options**:

* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: /data/mjain/repos/solfuzz-agave/target/release/libsolfuzz_agave.so]
* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: impl/lib/libsolfuzz_agave_v2.0.so]
* `-h, --default-harness-type TEXT`: Harness type to use for Context protobufs [default: InstrHarness]
* `-t, --target PATH`: Shared object (.so) target file paths (pairs with --keep-passing). Targets must have required function entrypoints defined [default: /data/mjain/repos/firedancer/build/native/clang/lib/libfd_exec_sol_compat.so]
* `-t, --target PATH`: Shared object (.so) target file paths (pairs with --keep-passing). Targets must have required function entrypoints defined [default: impl/lib/libsolfuzz_firedancer.so]
* `-o, --output-dir PATH`: Output directory for messages [default: debug_mismatch]
* `-u, --repro-urls TEXT`: Comma-delimited list of FuzzCorp mismatch links
* `-n, --section-names TEXT`: Comma-delimited list of FuzzCorp section names
Expand Down Expand Up @@ -72,7 +72,7 @@ $ solana-test-suite create-fixtures [OPTIONS]

* `-i, --input PATH`: Input protobuf file or directory of protobuf files [default: corpus8]
* `-h, --default-harness-type TEXT`: Harness type to use for Context protobufs [default: InstrHarness]
* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: /data/mjain/repos/solfuzz-agave/target/release/libsolfuzz_agave.so]
* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: impl/lib/libsolfuzz_agave_v2.0.so]
* `-t, --target PATH`: Shared object (.so) target file paths (pairs with --keep-passing). Targets must have required function entrypoints defined
* `-o, --output-dir PATH`: Output directory for fixtures [default: test_fixtures]
* `-p, --num-processes INTEGER`: Number of processes to use [default: 4]
Expand All @@ -96,9 +96,9 @@ $ solana-test-suite debug-mismatches [OPTIONS]

**Options**:

* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: /data/mjain/repos/solfuzz-agave/target/release/libsolfuzz_agave.so]
* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: impl/lib/libsolfuzz_agave_v2.0.so]
* `-h, --default-harness-type TEXT`: Harness type to use for Context protobufs [default: InstrHarness]
* `-t, --target PATH`: Shared object (.so) target file paths (pairs with --keep-passing). Targets must have required function entrypoints defined [default: /data/mjain/repos/firedancer/build/native/clang/lib/libfd_exec_sol_compat.so]
* `-t, --target PATH`: Shared object (.so) target file paths (pairs with --keep-passing). Targets must have required function entrypoints defined [default: impl/lib/libsolfuzz_firedancer.so]
* `-o, --output-dir PATH`: Output directory for messages [default: debug_mismatch]
* `-u, --repro-urls TEXT`: Comma-delimited list of FuzzCorp mismatch links
* `-n, --section-names TEXT`: Comma-delimited list of FuzzCorp section names
Expand Down Expand Up @@ -211,8 +211,8 @@ $ solana-test-suite mass-regenerate-fixtures [OPTIONS]

* `-i, --input PATH`: Input test-vectors directory [default: corpus8]
* `-o, --output-dir PATH`: Output directory for regenerated fixtures [default: /tmp/regenerated_fixtures]
* `-t, --target PATH`: Shared object (.so) target file path to execute [default: /data/mjain/repos/solfuzz-agave/target/release/libsolfuzz_agave.so]
* `-s, --stubbed-target PATH`: Stubbed shared object (.so) target file path to execute [default: /data/mjain/repos/solfuzz-agave/target/debug/libsolfuzz_agave_stubbed.so]
* `-t, --target PATH`: Shared object (.so) target file path to execute [default: impl/lib/libsolfuzz_agave_v2.0.so]
* `-s, --stubbed-target PATH`: Stubbed shared object (.so) target file path to execute [default: impl/lib/libsolfuzz_firedancer.so]
* `-f, --add-feature TEXT`: List of feature pubkeys to force add to the fixtures.
* `-r, --remove-feature TEXT`: List of feature pubkeys to force remove from the fixtures.
* `-k, --rekey-feature TEXT`: List of feature pubkeys to rekey in the fixtures, formatted 'old/new' (e.g. `--rekey-feature old/new`).
Expand All @@ -233,7 +233,7 @@ $ solana-test-suite regenerate-fixtures [OPTIONS]
**Options**:

* `-i, --input PATH`: Either a file or directory containing messages [default: corpus8]
* `-t, --target PATH`: Shared object (.so) target file path to execute [default: /data/mjain/repos/solfuzz-agave/target/release/libsolfuzz_agave.so]
* `-t, --target PATH`: Shared object (.so) target file path to execute [default: impl/lib/libsolfuzz_agave_v2.0.so]
* `-o, --output-dir PATH`: Output directory for regenerated fixtures [default: regenerated_fixtures]
* `-d, --dry-run`: Only print the fixtures that would be regenerated
* `-f, --add-feature TEXT`: List of feature pubkeys to force add to the fixtures.
Expand All @@ -260,8 +260,8 @@ $ solana-test-suite run-tests [OPTIONS]

* `-i, --input PATH`: Input protobuf file or directory of protobuf files [default: corpus8]
* `-h, --default-harness-type TEXT`: Harness type to use for Context protobufs [default: InstrHarness]
* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: /data/mjain/repos/solfuzz-agave/target/release/libsolfuzz_agave.so]
* `-t, --target PATH`: Shared object (.so) target file paths [default: /data/mjain/repos/firedancer/build/native/clang/lib/libfd_exec_sol_compat.so]
* `-s, --solana-target PATH`: Solana (or ground truth) shared object (.so) target file path [default: impl/lib/libsolfuzz_agave_v2.0.so]
* `-t, --target PATH`: Shared object (.so) target file paths [default: impl/lib/libsolfuzz_firedancer.so]
* `-o, --output-dir PATH`: Output directory for test results [default: test_results]
* `-p, --num-processes INTEGER`: Number of processes to use [default: 4]
* `-r, --randomize-output-buffer`: Randomizes bytes in output buffer before shared library execution
Expand Down
81 changes: 81 additions & 0 deletions src/test_suite/block/codec_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import fd58
import test_suite.block_pb2 as block_pb
from test_suite.context.codec_utils import decode_acct_state, encode_acct_state
from test_suite.txn.codec_utils import decode_sanitized_tx, encode_sanitized_tx


def decode_input(context: block_pb.BlockContext):
"""
Decode BlockContext fields in-place into human-readable format.
Addresses are decoded from base58, data from base64.

Args:
- context (block_pb.BlockContext): Instruction context (will be modified).
"""
if context.program_id:
context.program_id = fd58.dec32(context.program_id)

for i in range(len(context.microblocks)):
for j in range(len(context.microblocks[i].txns)):
decode_sanitized_tx(context.microblocks[i].txns[j])

for i in range(len(context.acct_states)):
decode_acct_state(context.acct_states[i])

# POH hash
context.slot_ctx.poh = fd58.dec32(context.slot_ctx.poh)

# Vote accounts
for i in range(len(context.epoch_ctx.vote_accounts)):
context.epoch_ctx.vote_accounts[i].pubkey = fd58.dec32(
context.epoch_ctx.vote_accounts[i].pubkey
)

# Blockhash queue
for i in range(len(context.blockhash_queue)):
context.blockhash_queue[i] = fd58.dec32(context.blockhash_queue[i])


def encode_input(context: block_pb.BlockContext):
"""
Encode BlockContext fields in-place into binary, digestable format.
Addresses are encoded in base58, data in base64.

Args:
- context (block_pb.BlockContext): Instruction context (will be modified).
"""
for i in range(len(context.microblocks)):
for j in range(len(context.microblocks[i].txns)):
encode_sanitized_tx(context.microblocks[i].txns[j])

for i in range(len(context.acct_states)):
encode_acct_state(context.acct_states[i])

# POH hash
context.slot_ctx.poh = fd58.enc32(context.slot_ctx.poh)

# Vote accounts
for i in range(len(context.epoch_ctx.vote_accounts)):
context.epoch_ctx.vote_accounts[i].pubkey = fd58.enc32(
context.epoch_ctx.vote_accounts[i].pubkey
)

# Blockhash queue
for i in range(len(context.blockhash_queue)):
context.blockhash_queue[i] = fd58.enc32(context.blockhash_queue[i])


def encode_output(effects: block_pb.BlockEffects):
"""
Encode BlockEffects fields in-place into human-readable format.
Addresses are encoded in base58, data in base64.

Args:
- effects (block_pb.BlockEffects): Instruction effects (will be modified).
"""
for i in range(len(effects.acct_states)):
encode_acct_state(effects.acct_states[i])

effects.bank_hash = fd58.enc32(effects.bank_hash)
effects.lt_hash = fd58.enc32(effects.lt_hash)
effects.account_delta_hash = fd58.enc32(effects.account_delta_hash)
Loading
Loading