Skip to content

feat(fuzzer): add valid-address generator for G, M, and C kinds - #301

Open
Legit003 wants to merge 1 commit into
Boxkit-Labs:mainfrom
Legit003:feat/rust-fuzzer-valid-address-generator
Open

feat(fuzzer): add valid-address generator for G, M, and C kinds#301
Legit003 wants to merge 1 commit into
Boxkit-Labs:mainfrom
Legit003:feat/rust-fuzzer-valid-address-generator

Conversation

@Legit003

@Legit003 Legit003 commented Jul 27, 2026

Copy link
Copy Markdown

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.
closes #288

Summary by CodeRabbit

  • Bug Fixes

    • Updated address validation tests with corrected valid and invalid examples.
    • Improved coverage for lowercase normalization and muxed-address parsing.
  • Tests

    • Added generation and round-trip validation for correctly checksummed G, M, and C addresses.
    • Enhanced fuzz testing by mixing valid generated addresses with random inputs.
    • Added coverage for muxed identifiers, including boundary values.

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

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Valid address fuzzing

Layer / File(s) Summary
Checksummed address generator
examples/rust-address-fuzzer/src/generate.rs
Generates G, M, and C strkeys with CRC-16 checksums, validates round-trip parsing, and tests lengths, prefixes, randomness, and muxed IDs.
Valid seeds in random fuzzing
examples/rust-address-fuzzer/src/main.rs
Adds the generator module and periodically inserts valid addresses into random fuzzing inputs while retaining random strings.
Parser test vector updates
examples/prism-core/src/address.rs, examples/rust-address-fuzzer/src/parse.rs
Replaces invalid, valid, and normalization address fixtures with updated strings.

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

Possibly related PRs

Suggested reviewers: codeze-us

🚥 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 clearly matches the main change: adding a valid-address generator for G, M, and C kinds.
Linked Issues check ✅ Passed The PR implements random_valid_address for G/M/C, uses random 64-bit M ids, and panics on parse validation failure.
Out of Scope Changes check ✅ Passed The test-vector updates and fuzzer support changes align with the stated objectives and do not introduce unrelated scope.
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.

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

🧹 Nitpick comments (2)
examples/rust-address-fuzzer/src/main.rs (1)

79-93: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Fragile coupling between i % 4 and i % 12.

The kind-selection match i % 12 { 0 => G, 4 => M, _ => C } is only correct because the outer i % 4 == 0 guard guarantees i % 12 ∈ {0, 4, 8}. If either modulus is changed independently in the future (e.g. adjusting the valid-seed frequency), the _ => C arm 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 win

Replace the hand-rolled CRC/Base32 helpers with crates. data-encoding::BASE32_NOPAD covers 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

📥 Commits

Reviewing files that changed from the base of the PR and between d2898d4 and bf74f36.

📒 Files selected for processing (4)
  • 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/parse.rs

@codeZe-us
codeZe-us self-requested a review July 27, 2026 17:57
@codeZe-us

Copy link
Copy Markdown
Contributor

@Legit003 fix conflicts in your PR

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.

Build a valid-address generator as the mutation seed source.

2 participants