Skip to content

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

Open
Promzy204-bad wants to merge 1 commit into
Boxkit-Labs:mainfrom
Promzy204-bad:feat/version-byte-swap-mutator
Open

feat(fuzzer): add version-byte swap mutator#304
Promzy204-bad wants to merge 1 commit 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

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.

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

📝 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

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

@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.

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.

2 participants