feat(fuzzer): add version-byte swap mutator - #304
Conversation
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.
|
@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! 🚀 |
📝 WalkthroughWalkthroughThe 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 ChangesVersion-byte mutator
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@Promzy204-bad fix conflicts in your PR |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
examples/rust-address-fuzzer/src/mutators/version.rs (1)
131-198: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFactor out the StrKey codec into shared helpers
examples/rust-address-fuzzer/src/mutators/version.rsduplicates the same base32/CRC logic already present inexamples/prism-core/src/address.rs. If these paths are meant to stay aligned, move the codec into a shared helper or expose reusable primitives fromprism_coreinstead 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
📒 Files selected for processing (4)
examples/rust-address-fuzzer/src/main.rsexamples/rust-address-fuzzer/src/mutators/mod.rsexamples/rust-address-fuzzer/src/mutators/version.rsexamples/rust-address-fuzzer/src/report.rs
| use rand::Rng; | ||
|
|
||
| use prism_core::address::{parse, AddressKind, ParseError}; |
There was a problem hiding this comment.
📐 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.
| 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.
Implements swap_version_byte(addr, rng) in src/mutators/version.rs.
closes #290
Summary by CodeRabbit
New Features
Tests