feat(fuzzer): add valid-address generator for G, M, and C kinds - #301
feat(fuzzer): add valid-address generator for G, M, and C kinds#301Legit003 wants to merge 1 commit into
Conversation
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.
|
@Legit003 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 gains a checksummed generator for G, M, and C addresses, injects valid seeds into random runs, and validates generated addresses through parsing. Parser test vectors are also updated. ChangesValid address fuzzing
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
examples/rust-address-fuzzer/src/main.rs (1)
79-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winFragile coupling between
i % 4andi % 12.The kind-selection
match i % 12 { 0 => G, 4 => M, _ => C }is only correct because the outeri % 4 == 0guard guaranteesi % 12 ∈ {0, 4, 8}. If either modulus is changed independently in the future (e.g. adjusting the valid-seed frequency), the_ => Carm would silently swallow unexpected residues instead of failing loudly, skewing the G/M/C distribution without any compiler or runtime signal.Deriving the kind directly from the seed-slot index removes the implicit coupling:
♻️ Proposed refactor
- let input = if i % 4 == 0 { - let kind = match i % 12 { - 0 => AddressKind::G, - 4 => AddressKind::M, - _ => AddressKind::C, - }; - generate::random_valid_address(kind, rng) - } else { - random_string(rng) - }; + let input = if i % 4 == 0 { + let kind = match (i / 4) % 3 { + 0 => AddressKind::G, + 1 => AddressKind::M, + _ => AddressKind::C, + }; + generate::random_valid_address(kind, rng) + } else { + random_string(rng) + };🤖 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/main.rs` around lines 79 - 93, Update the valid-seed branch in the loop around random_valid_address so kind selection derives from the seed-slot index rather than coupling i % 4 with i % 12. Use an explicit exhaustive mapping for the intended G, M, and C sequence, and avoid a catch-all arm that can silently accept unexpected residues; preserve random_string for non-seed iterations.examples/rust-address-fuzzer/src/generate.rs (1)
28-36: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace the hand-rolled CRC/Base32 helpers with crates.
data-encoding::BASE32_NOPADcovers the Base32 path, and a CRC crate can replace the checksum helper; this keeps the fuzzer seed generator smaller and avoids maintaining protocol primitives locally.🤖 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/generate.rs` around lines 28 - 36, Replace the local crc16 helper and the corresponding hand-rolled Base32 logic in the seed generator with established crate implementations: use data-encoding::BASE32_NOPAD for Base32 encoding and a suitable CRC crate for the checksum, updating dependencies and call sites while preserving the current output format and behavior.
🤖 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.
Nitpick comments:
In `@examples/rust-address-fuzzer/src/generate.rs`:
- Around line 28-36: Replace the local crc16 helper and the corresponding
hand-rolled Base32 logic in the seed generator with established crate
implementations: use data-encoding::BASE32_NOPAD for Base32 encoding and a
suitable CRC crate for the checksum, updating dependencies and call sites while
preserving the current output format and behavior.
In `@examples/rust-address-fuzzer/src/main.rs`:
- Around line 79-93: Update the valid-seed branch in the loop around
random_valid_address so kind selection derives from the seed-slot index rather
than coupling i % 4 with i % 12. Use an explicit exhaustive mapping for the
intended G, M, and C sequence, and avoid a catch-all arm that can silently
accept unexpected residues; preserve random_string for non-seed iterations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fa7cc5c6-1bfd-4cd8-8e01-62d2acea3b35
📒 Files selected for processing (4)
examples/prism-core/src/address.rsexamples/rust-address-fuzzer/src/generate.rsexamples/rust-address-fuzzer/src/main.rsexamples/rust-address-fuzzer/src/parse.rs
|
@Legit003 fix conflicts in your PR |
Implements random_valid_address(kind, rng) in src/generate.rs that produces correctly checksummed strkey for all three address types:
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.
closes #288
Summary by CodeRabbit
Bug Fixes
Tests