feat(fuzzer): add version-byte swap mutator - #304
Conversation
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.
|
@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! 🚀 |
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
📝 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)
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. Comment |
…s-291 feat(rust-fuzzer): implement truncate and pad length mutators + fix broken test data
|
@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.
…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.
Implements swap_version_byte(addr, rng) in src/mutators/version.rs.
closes #290
Summary by CodeRabbit
New Features
Tests