test: add parser fuzzing and discriminator injectivity checks - #324
Merged
Merged
Conversation
senzenn
force-pushed
the
test/parser-robustness
branch
from
September 13, 2026 11:46
e8b2d4c to
6ec3380
Compare
senzenn
marked this pull request as ready for review
September 13, 2026 12:08
senzenn
force-pushed
the
ci/pin-codama-version
branch
from
September 14, 2026 11:22
3a41ab1 to
86f44ab
Compare
senzenn
force-pushed
the
test/parser-robustness
branch
from
September 14, 2026 11:22
6ec3380 to
562a47f
Compare
senzenn
force-pushed
the
ci/pin-codama-version
branch
from
September 14, 2026 11:34
86f44ab to
d6670fa
Compare
senzenn
force-pushed
the
test/parser-robustness
branch
from
September 14, 2026 11:34
562a47f to
cb10ae7
Compare
senzenn
force-pushed
the
ci/pin-codama-version
branch
from
September 14, 2026 16:49
d6670fa to
908e025
Compare
senzenn
force-pushed
the
test/parser-robustness
branch
2 times, most recently
from
September 14, 2026 16:55
a4bf29b to
cb2052e
Compare
senzenn
force-pushed
the
ci/pin-codama-version
branch
from
September 14, 2026 18:04
908e025 to
e2ef2e4
Compare
senzenn
force-pushed
the
test/parser-robustness
branch
from
September 14, 2026 18:04
cb2052e to
02abaca
Compare
kespinola
approved these changes
Sep 15, 2026
Two properties the generated parsers already have, with nothing asserting them. No production code changes. parser_robustness.rs drives every parse entry point with buffers the IDL never described: every prefix of a valid one including empty, and valid ones with bytes appended. The contract is return Ok or Err, never panic, which in Rust also rules out an over-read since a slice past the end aborts. Truncation is the shape that slips through, because a guard that checks data.len() == N and then slices data[..M] only fails between M and N. It drives two IDLs. discriminator_guards alone is not enough: its zero-width account arm matches data.get(0..0) for every buffer and returns before any later arm is tried, so the one arm behind it that slices a real window is unreachable and the account side is never truncated at all. truncation_guards has no zero-width arm, and its windows, 8 bytes at offset 0 and 4 at offset 8, are what exercise that path. Reverting the account renderer's data.get(offset..end) to an unchecked index fails only the test that drives the second fixture; the other five pass, which is the reason it exists. Random buffers come from a seeded xorshift64* so a CI failure replays from the seed. Half the random corpus is primed with a valid discriminator, because uniformly random bytes satisfy a 4-byte one with probability 2^-32, so an unprimed corpus never reaches the body decoder and the tally proves only that the first compare rejected everything. The tally records which account arms were reached rather than counting successes, since a count cannot separate real coverage from every buffer tripping one unconditional arm. pump_fun.rs gets the same loop against a real Anchor IDL. That binary already expands pump_fun.json, so it adds no compile time, and it reaches what the synthetic fixtures cannot: six accounts with a real 8-byte discriminator and no zero-width or size-only arm, and instructions declaring real account lists, so a short account vector reaches a generated accessor. discriminator_injectivity_tests proves no two differently-keyed instructions can both match one buffer. Equal keys are already handled: the renderer groups them and disambiguates on account count. Unequal keys get one arm each, tried in order, so an overlap there is decided by emission order rather than by anything the IDL states. The check runs over the whole corpus. joint_satisfiability_detects_real_overlap pins the helper on hand-built keys, since one that always answered no would make the corpus check pass on any input, and same_key_collision_groups_are_accounted_for pins the four IDLs that do rely on account-count disambiguation so a fifth arrives as a deliberate change. Both corpus walks now report a fixture that stops loading instead of skipping it. They read every IDL in tests/idls, so a silent skip would let most of the corpus fall out while the tests stayed green. They also share one helper: the directory walk, the extension filter, the load and the key extraction were duplicated verbatim between them, and only what each does with the keys differs. Neither check depends on the codama bump; both hold on 0.9.1.
senzenn
force-pushed
the
test/parser-robustness
branch
from
September 16, 2026 16:51
02abaca to
c485108
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two properties the generated parsers already have, with nothing asserting them. No
production code changes.
parser_robustness.rs drives every parse entry point with buffers the IDL never described:
every prefix of a valid one including empty, and valid ones with bytes appended. The
contract is return Ok or Err, never panic, which in Rust also rules out an over-read since
a slice past the end aborts. Truncation is the shape that slips through, because a guard
that checks data.len() == N and then slices data[..M] only fails between M and N, which a
happy-path test misses. Random buffers come from a seeded xorshift64* so a CI failure
replays from the seed, and drive returns a tally of outcomes, since "never panicked" is
also true of a corpus that bounced off the first length check every time.
discriminator_injectivity_tests proves no two differently-keyed instructions can both match
one buffer. Equal keys are already handled: the renderer groups them and disambiguates on
account count. Unequal keys get one arm each, tried in order, so an overlap there is decided
by emission order rather than by anything the IDL states. jointly_satisfiable compares two
keys byte-wise over the intersection of their windows, and treats non-overlapping windows as
satisfiable, which is the case that matters. The check runs over the whole corpus rather than
up to a bound.
joint_satisfiability_detects_real_overlap pins the helper on hand-built keys (same window
different bytes, disjoint windows, overlapping and agreeing, overlapping and disagreeing, a
size discriminator against a window past its end), since a helper that always answered no
would make the corpus check pass on any input.
same_key_collision_groups_are_accounted_for pins the four IDLs that do rely on account-count
disambiguation:
so a fifth arrives as a deliberate change.
Neither check depends on the codama bump; both hold on 0.9.1. It sits on #323 to keep the
stack linear.
Tested: 378 passed, 0 failed. clippy -Dwarnings and fmt --check clean.