Skip to content

feat(fuzzer): add version-byte swap mutator - #304

Merged
Emrys02 merged 13 commits into
Boxkit-Labs:mainfrom
Promzy204-bad:feat/version-byte-swap-mutator
Aug 14, 2026
Merged

feat(fuzzer): add version-byte swap mutator#304
Emrys02 merged 13 commits into
Boxkit-Labs:mainfrom
Promzy204-bad:feat/version-byte-swap-mutator

Conversation

@Promzy204-bad

@Promzy204-bad Promzy204-bad commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Implements swap_version_byte(addr, rng) in src/mutators/version.rs.

  • Decodes any valid G/M/C address, replaces the version byte with a randomly-chosen value, and re-encodes with a fresh CRC-16 checksum.
  • Two distinct sub-cases: Known (one of the four protocol-defined bytes: Account=48, Muxed=96, Contract=16, Seed=144) and Invalid (any byte not mapped to a strkey type), selected with 50/50 probability.
  • SwapResult.is_misclassification() detects silent misclassifications: parser returns Ok but the reported kind doesn't match the leading prefix character of the re-encoded string.
  • assert_no_misclassification() panics with a full diagnostic if one is detected, ensuring misreads are never silent.
  • Full sweep test covers all 256 version bytes: invalid bytes are always rejected; known bytes are never misclassified.
  • 18/18 tests pass.

closes #290

Summary by CodeRabbit

  • New Features

    • Added a version-byte mutation tool for testing Stellar address parsing.
    • Supports known and invalid version-byte substitutions, with detailed mutation outcomes.
    • Added checks for parser misclassification and rejection behavior.
  • Tests

    • Added extensive round-trip, exhaustive, and randomized validation for address mutations.
    • Added default initialization support for test reports.

Yinklekay and others added 4 commits July 27, 2026 14:55
Add length-mutation helpers for the rust-address-fuzzer:
- truncate(addr, rng): removes 1 to len/2 trailing characters
- pad(addr, rng): appends 1-16 random base32 characters

Both produce strings guaranteed to fail parsing with no panics
and no partial-parse Ok results.

Also fixes pre-existing test data: 3 tests in prism-core and
1 test in parse.rs used 53-char phantom addresses that could
never pass the LEN_G=56 check. Replaced with valid 56-char
addresses from spec/vectors.json.

Closes Boxkit-Labs#291
Implements random_valid_address(kind, rng) in src/generate.rs that
produces correctly checksummed strkey for all three address types:

- G: version(0x30) + 32 random bytes + CRC-16 LE → 56 chars
- M: version(0x60) + random u64 muxed id (BE) + 32 random bytes
     + CRC-16 LE → 69 chars (exercises the full u64 decoder path)
- C: version(0x10) + 32 random bytes + CRC-16 LE → 56 chars

Every generated address is round-tripped through prism_core::address::parse
immediately; a parse failure panics so a broken generator is caught at
seed-generation time rather than producing silent bad corpus entries.

run_random in main.rs now emits one valid seed per three random strings
(every 4th input), cycling G → M → C, so the fuzzer explores the
boundary of validity rather than spending all budget on obvious garbage.

Also fixes two pre-existing broken test fixtures (53-char G addresses)
in parse.rs and prism-core/src/address.rs — both now use the correct
56-char all-zero-key address GAAAAAA...AWHF.
Implements swap_version_byte(addr, rng) in src/mutators/version.rs.

- Decodes any valid G/M/C address, replaces the version byte with a
  randomly-chosen value, and re-encodes with a fresh CRC-16 checksum.
- Two distinct sub-cases: Known (one of the four protocol-defined bytes:
  Account=48, Muxed=96, Contract=16, Seed=144) and Invalid (any byte
  not mapped to a strkey type), selected with 50/50 probability.
- SwapResult.is_misclassification() detects silent misclassifications:
  parser returns Ok but the reported kind doesn't match the leading
  prefix character of the re-encoded string.
- assert_no_misclassification() panics with a full diagnostic if one
  is detected, ensuring misreads are never silent.
- Full sweep test covers all 256 version bytes: invalid bytes are
  always rejected; known bytes are never misclassified.
- 18/18 tests pass.
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Promzy204-bad Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Emrys02, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ec45306d-d4bd-4ff8-975e-adc19dcc4e00

📥 Commits

Reviewing files that changed from the base of the PR and between 20a4366 and d88951f.

📒 Files selected for processing (8)
  • README.md
  • examples/prism-core/src/address.rs
  • examples/rust-address-fuzzer/src/generate.rs
  • examples/rust-address-fuzzer/src/main.rs
  • examples/rust-address-fuzzer/src/mutators/length.rs
  • examples/rust-address-fuzzer/src/mutators/mod.rs
  • examples/rust-address-fuzzer/src/parse.rs
  • spec/vectors.json
📝 Walkthrough

Walkthrough

The fuzzer adds a public version-byte mutator that decodes and re-encodes StrKey addresses, parses mutation results, detects misclassification, and tests known and invalid version-byte injections. The binary exposes the module, and Report derives Default.

Changes

Version-byte mutator

Layer / File(s) Summary
Module wiring and report initialization
examples/rust-address-fuzzer/src/main.rs, examples/rust-address-fuzzer/src/mutators/mod.rs, examples/rust-address-fuzzer/src/report.rs
The fuzzer includes and exports the mutator module, while Report gains a derived Default implementation.
Mutation result and encoding contract
examples/rust-address-fuzzer/src/mutators/version.rs
Defines known and invalid injection categories, mutation results, misclassification checks, and local StrKey base-32/CRC16 re-encoding helpers.
Mutation execution and validation
examples/rust-address-fuzzer/src/mutators/version.rs
Implements randomized version-byte swapping and diagnostic assertions, with unit tests covering round-trips, exhaustive inputs, transitions, and randomized cases.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Fuzzer
  participant swap_version_byte
  participant AddressParser
  Fuzzer->>swap_version_byte: provide address and RNG
  swap_version_byte->>AddressParser: parse original address
  swap_version_byte->>swap_version_byte: inject version byte and re-encode checksum
  swap_version_byte->>AddressParser: parse mutated address
  AddressParser-->>swap_version_byte: return AddressKind or ParseError
  swap_version_byte-->>Fuzzer: return SwapResult
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the main change: adding a version-byte swap mutator.
Linked Issues check ✅ Passed The mutator, misclassification detection, invalid-byte handling, and exhaustive tests match issue #290's requirements.
Out of Scope Changes check ✅ Passed The added module wiring and Report::default derive support the new mutator and tests, and do not appear unrelated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…s-291

feat(rust-fuzzer): implement truncate and pad length mutators + fix broken test data
@codeZe-us

Copy link
Copy Markdown
Contributor

@Promzy204-bad fix conflicts in your PR

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/rust-address-fuzzer/src/mutators/version.rs (1)

131-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Factor out the StrKey codec into shared helpers

examples/rust-address-fuzzer/src/mutators/version.rs duplicates the same base32/CRC logic already present in examples/prism-core/src/address.rs. If these paths are meant to stay aligned, move the codec into a shared helper or expose reusable primitives from prism_core instead of maintaining two copies.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/rust-address-fuzzer/src/mutators/version.rs` around lines 131 - 198,
Replace the duplicated strkey_decode, strkey_encode, and crc16 implementations
in version.rs with reusable StrKey codec primitives from prism_core or a shared
helper, and update reencode_with_version to use them while preserving the
existing byte layout and CRC behavior. Ensure both address paths use the same
codec implementation rather than maintaining parallel logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/rust-address-fuzzer/src/mutators/version.rs`:
- Around line 21-23: Update the imports in the version mutator to use the
crate-local parse wrapper from examples/rust-address-fuzzer/src/parse.rs instead
of importing parse directly from prism_core::address; keep AddressKind and
ParseError sourced from prism_core::address.

---

Nitpick comments:
In `@examples/rust-address-fuzzer/src/mutators/version.rs`:
- Around line 131-198: Replace the duplicated strkey_decode, strkey_encode, and
crc16 implementations in version.rs with reusable StrKey codec primitives from
prism_core or a shared helper, and update reencode_with_version to use them
while preserving the existing byte layout and CRC behavior. Ensure both address
paths use the same codec implementation rather than maintaining parallel logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c3c74f1b-5c7f-48f4-8f99-6bf194eee6a1

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf9b64 and 20a4366.

📒 Files selected for processing (4)
  • examples/rust-address-fuzzer/src/main.rs
  • examples/rust-address-fuzzer/src/mutators/mod.rs
  • examples/rust-address-fuzzer/src/mutators/version.rs
  • examples/rust-address-fuzzer/src/report.rs

Comment on lines +21 to +23
use rand::Rng;

use prism_core::address::{parse, AddressKind, ParseError};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Bypasses the crate's own parse wrapper.

examples/rust-address-fuzzer/src/parse.rs already re-exports prism_core::address::parse as the shared entry point for mutators (per the upstream-contract relationship in the codebase graph). This file imports parse straight from prism_core::address instead, creating a second, independent path into the same external crate.

♻️ Proposed fix
-use prism_core::address::{parse, AddressKind, ParseError};
+use crate::parse::parse;
+use prism_core::address::{AddressKind, ParseError};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use rand::Rng;
use prism_core::address::{parse, AddressKind, ParseError};
use rand::Rng;
use crate::parse::parse;
use prism_core::address::{AddressKind, ParseError};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/rust-address-fuzzer/src/mutators/version.rs` around lines 21 - 23,
Update the imports in the version mutator to use the crate-local parse wrapper
from examples/rust-address-fuzzer/src/parse.rs instead of importing parse
directly from prism_core::address; keep AddressKind and ParseError sourced from
prism_core::address.

DrSa7ag3 and others added 8 commits July 30, 2026 06:00
…non-base32-strkeys

test: add non-base32 and null-byte rejection vectors (partial Boxkit-Labs#292)
Implements random_valid_address(kind, rng) in src/generate.rs that
produces correctly checksummed strkey for all three address types:

- G: version(0x30) + 32 random bytes + CRC-16 LE → 56 chars
- M: version(0x60) + random u64 muxed id (BE) + 32 random bytes
     + CRC-16 LE → 69 chars (exercises the full u64 decoder path)
- C: version(0x10) + 32 random bytes + CRC-16 LE → 56 chars

Every generated address is round-tripped through prism_core::address::parse
immediately; a parse failure panics so a broken generator is caught at
seed-generation time rather than producing silent bad corpus entries.

run_random in main.rs now emits one valid seed per three random strings
(every 4th input), cycling G → M → C, so the fuzzer explores the
boundary of validity rather than spending all budget on obvious garbage.

Also fixes two pre-existing broken test fixtures (53-char G addresses)
in parse.rs and prism-core/src/address.rs — both now use the correct
56-char all-zero-key address GAAAAAA...AWHF.
…id-address-generator

feat(fuzzer): add valid-address generator for G, M, and C kinds
Implements swap_version_byte(addr, rng) in src/mutators/version.rs.

- Decodes any valid G/M/C address, replaces the version byte with a
  randomly-chosen value, and re-encodes with a fresh CRC-16 checksum.
- Two distinct sub-cases: Known (one of the four protocol-defined bytes:
  Account=48, Muxed=96, Contract=16, Seed=144) and Invalid (any byte
  not mapped to a strkey type), selected with 50/50 probability.
- SwapResult.is_misclassification() detects silent misclassifications:
  parser returns Ok but the reported kind doesn't match the leading
  prefix character of the re-encoded string.
- assert_no_misclassification() panics with a full diagnostic if one
  is detected, ensuring misreads are never silent.
- Full sweep test covers all 256 version bytes: invalid bytes are
  always rejected; known bytes are never misclassified.
- 18/18 tests pass.
@Emrys02
Emrys02 self-requested a review August 14, 2026 11:06
@Emrys02
Emrys02 merged commit 24a9d0c into Boxkit-Labs:main Aug 14, 2026
4 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the version-byte mutator.

5 participants