Skip to content

Add proptest feature with arb module for IDL type strategies#1

Draft
shahan-khatchadourian-anchorage wants to merge 6 commits into
add-ci-workflowfrom
solana-parser-add-arbitrary
Draft

Add proptest feature with arb module for IDL type strategies#1
shahan-khatchadourian-anchorage wants to merge 6 commits into
add-ci-workflowfrom
solana-parser-add-arbitrary

Conversation

@shahan-khatchadourian-anchorage
Copy link
Copy Markdown

@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage commented Mar 13, 2026

Summary

Adds a proptest feature flag to solana_parser exposing solana_parser::arb, a collection of proptest strategies for generating arbitrary IDL types and valid borsh-encoded instruction bytes.

  • arb_primitive_idl_type / arb_idl_type — leaf and recursive IdlType strategies; the recursive case uses prop_recursive to depth-bound generation of Vec/Option/Array containers without infinite recursion at strategy-construction time
  • arb_idl_instruction / arb_idl / arb_idl_json — instruction and full IDL strategies; arb_idl guarantees unique discriminators by deriving them from unique instruction names via the Anchor formula
  • arb_bytes_for_type / arb_valid_instruction_bytes — generates borsh-encoded bytes that are exactly consumed by parse_data_into_args, enabling roundtrip Ok assertions in property tests

Zero impact on consumers who don't opt in — proptest is an optional dependency, only activated via features = ["proptest"].

Merge order

Step 1: Merge #2 first (custom IDL support and parse_instruction_with_idl from @prasincs).

Step 2: Merge this PR.

Test plan

  • cargo test passes on this repo
  • Consumer repo (visualsign-parser #203) fuzz and pipeline integration tests pass with features = ["proptest"] enabled

🤖 Generated with Claude Code

@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage changed the base branch from main to prasincs/custom-idl-support March 13, 2026 23:16
@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage changed the base branch from prasincs/custom-idl-support to add-ci-workflow March 14, 2026 01:40
@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage marked this pull request as draft March 14, 2026 01:40
@shahan-khatchadourian-anchorage shahan-khatchadourian-anchorage force-pushed the solana-parser-add-arbitrary branch 2 times, most recently from e419d5c to cbd53ea Compare March 14, 2026 02:16
Adds a `proptest` feature flag that exposes `solana_parser::arb`, a
collection of proptest strategies for generating arbitrary IDL types and
valid borsh-encoded instruction bytes.

Key additions:
- `arb_primitive_idl_type` / `arb_idl_type` — leaf and recursive IdlType
  strategies; the recursive case uses `prop_recursive` to depth-bound
  generation of Vec/Option/Array containers
- `arb_idl_instruction` / `arb_idl` / `arb_idl_json` — instruction and
  full IDL strategies; `arb_idl` guarantees unique discriminators by
  deriving them from unique instruction names via the Anchor formula
- `arb_bytes_for_type` / `arb_valid_instruction_bytes` — generates
  borsh-encoded bytes that are exactly consumed by `parse_data_into_args`,
  enabling roundtrip Ok assertions in property tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tions

Three libFuzzer targets:
- fuzz_idl_json: arbitrary bytes as IDL JSON into decode_idl_data
- fuzz_instruction_data: arbitrary bytes as instruction data into parse_instruction_with_idl
- fuzz_transaction: arbitrary bytes as encoded transaction into parse_transaction

Run with: cargo +nightly fuzz run <target>

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move proptest strategies from src/arb.rs into fuzz-core/src/proptest.rs
and add arbitrary::Arbitrary implementation for IDL types in
fuzz-core/src/arbitrary.rs (ArbIdl wrapper). This separates fuzz
infrastructure from the core library into a dedicated crate that can be
depended on by both libfuzzer targets and proptest consumers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace hardcoded IDL with ArbIdl-based dynamic generation, fixing the
wrong discriminator bug where the hardcoded value didn't match the
Anchor-computed SHA256("global:transfer") discriminator. The fuzz target
now generates random IDL shapes and exercises parse_instruction_with_idl
across varying instruction schemas.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move fuzz_idl_parsing.rs and its proptest regressions here where the IDL
parsing code lives. Add embedded_idls_never_panic and
embedded_idls_valid_data_always_parses_ok tests that replace the
fuzz_all_idls.sh shell script with Rust test code iterating over all 13
embedded IDLs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The proptest feature was removed from solana_parser when arb.rs moved to
fuzz-core. The workspace-level cargo test already runs fuzz-core tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant