A parser fed by a raw feed reads bytes it has never validated, so fuzz it before live traffic does. Use cargo fuzz with seeds taken from real legacy, v0 and v1 transactions, and assert three things: it never panics, it never trusts an unchecked length field, and every index it returns points inside the account list.
Why a parser behind a raw feed needs fuzzing#
When you read transactions through an RPC node, the node has already parsed and checked them. When you decode them yourself from shreds, your parser is the first code to interpret those bytes. Most of what arrives is well formed, but a parser runs on every transaction, all day, and only needs one bad input to panic.
The risky parts of a Solana transaction are the length fields. In legacy and v0 messages, signature counts, account key counts, instruction counts and instruction data lengths are all compact encoded (v1 uses fixed width counts instead), and a parser that reads a count and then allocates or loops that many times can be made to do enormous work by a single byte. The account indexes inside each instruction are another trap: they must point into the key list, and a parser that indexes without checking will panic on the first one that does not.
Three formats raise the stakes. Legacy and v0 messages share one layout family; v1 starts with a version byte of 129, puts the signatures after the message and allows up to 4096 bytes. A parser that guesses the format wrongly reads one layout with the rules of the other.
Setting up cargo fuzz#
cargo fuzz drives libFuzzer from a Rust crate. It needs a nightly toolchain.
- Install the tool with
cargo install cargo-fuzz. - In your parser crate, run
cargo fuzz init. It creates afuzzdirectory with its ownCargo.tomlthat depends on your crate. - Add a target with
cargo fuzz add parse_transaction. It appears asfuzz/fuzz_targets/parse_transaction.rs. - Put seed inputs in
fuzz/corpus/parse_transaction/, one raw transaction per file. - Run it with
cargo +nightly fuzz run parse_transaction. Inputs that crash are saved underfuzz/artifacts/parse_transaction/. - When a crash appears,
cargo fuzz tminshrinks the input to the smallest bytes that still reproduce it.
A fuzz target with invariants#
The target below calls your own parser. my_decoder::parse_transaction stands for whatever function in your crate turns bytes into a parsed transaction; the checks are what matter.
#![no_main]use libfuzzer_sys::fuzz_target;fuzz_target!(|data: &[u8]| {// Invariant 1: never panic. Errors are fine; a panic fails the run.let Ok(tx) = my_decoder::parse_transaction(data) else { return };// Invariant 2: nothing parsed can be larger than the input that produced it.assert!(tx.signatures.len() * 64 <= data.len());assert!(tx.account_keys.len() * 32 <= data.len());// Invariant 3: every index points inside the account list your parser built.let total_keys = tx.account_keys.len() + tx.lookup_writable.len() + tx.lookup_readonly.len();for ix in &tx.instructions {assert!((ix.program_id_index as usize) < tx.account_keys.len());for &i in &ix.accounts {assert!((i as usize) < total_keys);}}// Invariant 4: if your parser can serialize, a round trip returns the same bytes.if let Ok(bytes) = my_decoder::serialize_transaction(&tx) {assert!(data.starts_with(&bytes));}});
The program index is checked against the static keys only, because a valid v0 message never loads a program from a lookup table. If your parser accepts one that does, the fuzzer has found a validation gap, not just a crash.
Seeds worth starting from#
libFuzzer mutates what you give it, so seeds that already reach deep into the parser find bugs faster than random bytes.
- Real transactions in each format. Fetch a few legacy, v0 and v1 transactions through
getBlockwithmaxSupportedTransactionVersionset to 1 and save their raw bytes. - Edge shapes. A transaction with one signature and one instruction; one with many accounts; one with long instruction data; a v0 transaction with several lookup tables; a v1 transaction with its fee fields set.
- Boundaries. Each seed truncated by one byte, and each seed with one extra byte appended.
- Format confusion. A v1 body behind a v0 prefix byte, and the reverse.
Keep the seed set small and varied. libFuzzer grows its own corpus as it finds new paths, and cargo fuzz cmin trims that corpus back to the inputs that still add coverage.
Turning crashes into regression fixtures#
Each crash is a test you did not have. Copy the minimized input into your test fixtures, write a test that asserts the parser now returns an error instead of panicking, and keep it forever. Over time those files become the most valuable part of your test suite, because each one is an input that once broke you. Regression fixtures describes how to store and run them in CI alongside your decoded-output tests.
What fuzzing will not tell you#
Fuzzing proves your parser survives strange input. It does not prove the parser decodes valid input correctly: a parser that rejects every transaction passes all four invariants. Pair it with fixtures whose decoded output you have checked against an RPC node. Fuzzing also stops at your parser's edge. Program-level layouts, lookup table resolution and everything that depends on execution need their own tests.
Related reading#
The Rust decoder guide shows the parser this target would exercise, and decoder tests cover the correctness side. Zero copy parsing is worth reading before you fuzz, because borrowed views over a buffer make the bounds checks above even more important. The transaction layout page has the field order the seeds exercise. Once the fuzzer runs quietly, the quickstart puts the same parser in front of live traffic.
Many fuzz findings turn out to be familiar Borsh decoding mistakes, so compare a new crash against that list before you write a fix.
Sources#
- Rust Fuzz Book: cargo fuzz (checked 2026-11-18)
- Solana docs: transactions (compact length prefixes, message layout) (checked 2026-11-18)
- Solana improvement document 0385, the v1 transaction layout (checked 2026-11-18)
- solana-sdk v0 message sanitize rules (checked 2026-11-18)
Raw shreds on your own server
Ultra Low Latency Shreds is $200 and Standard Shreds is $100. You pay in crypto, tell us which IPv4 address and UDP port should receive the stream, and we wire it up by hand.