Skip to content

feat(ckb): add malformed-witness and type-script fuzz corpus - #285

Merged
truthixify merged 2 commits into
wraith-protocol:developfrom
khoap1220-hue:feat/ckb-malformed-witness-type-fuzz-corpus
Nov 23, 2026
Merged

truthixify merged 2 commits into
wraith-protocol:developfrom
khoap1220-hue:feat/ckb-malformed-witness-type-fuzz-corpus

Conversation

@khoap1220-hue

@khoap1220-hue khoap1220-hue commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

In ckb/contracts/wraith-names-type/src/main.rs (validate(), validate_output_data(), count_cells_with_type_hash()) and ckb/contracts/wraith-stealth-lock/src/main.rs (auth(), From<SysError>), malformed transactions and duplicate .wraith name cells previously had three unguarded paths discovered while building the fuzz corpus:

  1. Duplicate .wraith Name Outputs/Inputs (wraith-names-type): has_cell_with_type_hash() collapsed matching cell counts to booleans (has_input, has_output), allowing a single transaction to mint duplicate .wraith name cells (0 -> 2, 1 -> 2) or coalesce duplicate inputs (2 -> 1). Replaced with count_cells_with_type_hash() enforcing singleton cell uniqueness (<= 1 matching input and <= 1 matching output) and returning Error::DuplicateNameCell (7).
  2. Unchecked wraith-names-type Args Length & Non-Matching Invocation Trap: Added NAME_ARGS_LEN = 32 validation (Error::InvalidArgsLength = 6), replaced QueryIter::new(load_cell_data, Source::Output) with load_cell_type_hash pre-filtering so unrelated outputs are not loaded into heap memory, and replaced (false, false) => panic!(...) with Error::NoMatchingCells (8).
  3. Panic-Free From<SysError> & CString Construction: Replaced panic! arms in From<SysError> and .unwrap() calls in ckb/contracts/wraith-stealth-lock/src/main.rs and ckb/contracts/wraith-names-type/src/main.rs with deterministic exit codes (Error::UnexpectedSysError, Error::Encoding) while keeping existing exit codes (1..=7 on wraith-stealth-lock, 1..=5 on wraith-names-type) unchanged. Updated AUTHORIZATION_MATRIX.md with the new error codes.

Fuzz Targets & Retained Corpus (ckb/fuzz/)

Added a standalone host fuzz crate at ckb/fuzz/ ([workspace], detached from ckb/Cargo.toml so ckb/Cargo.lock remains untouched for supply-chain.yml) with 5 targets and 40 minimized seed/regression inputs under ckb/fuzz/corpus/<target>/:

Target Surface & Acceptance Coverage
lock_witness_and_args Molecule WitnessArgs total-size header, 3-field monotonic offsets, BytesOpt inner length prefix, field-boundary truncation, trailing excess bytes, u32::MAX offset overflow, and 53-byte wraith-stealth-lock args (ephemeral_pubkey[33] || pubkey_hash[20]).
names_type_script 32-byte blake2b(name) type args, 66-byte output cell data (spending_pk[33] || viewing_pk[33]), singleton cell uniqueness (0 -> 2, 1 -> 2, 2 -> 1 regressions), and zero-match lock invocation (NoMatchingCells).
ckb_auth_inputs ckb-auth IPC argv slices (algorithm_id, signature, message, pubkey_hash), rejecting unsupported algorithm IDs (0x01..=0xFF), interior NUL bytes, non-hex/odd-length strings, recovery IDs >= 4, and zero r/s scalars.
cell_deps_and_announcement CellDep resolution (CKB_AUTH_CODE_HASH, Data2 vs Type, unresolved DepGroup, wrong dep/type hashes, duplicate out-points) and canonical 61-byte + metadata stealth announcement args wire codec with round-trip fixed-point checks.
ckb_tx_layout Multi-cell CKB transaction invariants: u64::checked_add capacity overflow guards (u64::MAX), 61-CKB occupied-capacity floor, output_index bounds, duplicated outputs, lock-group witness mapping, and cross-script dispatch.

RISC-V CKB VM Integration Suite & CI (ckb/integration-tests/, ckb/Makefile, .github/workflows/ci.yml)

  • Extended ckb/integration-tests/src/lib.rs with NamesTypeHarness and LockHarness::build_unlock_with_raw_witnesses().
  • Added ckb/integration-tests/tests/fuzz_corpus_regressions.rs executing both compiled riscv64imac-unknown-none-elf binaries inside ckb-testtool across all 6 corpus categories plus a bounded deterministic SplitMix64 VM fuzz loop (WRAITH_CKB_VM_FUZZ_ITERS=256).
  • Updated ckb/Makefile so make test-ci builds both wraith-stealth-lock and wraith-names-type, runs the RISC-V VM regression suite (WRAITH_CKB_VM_FUZZ_ITERS=256), and replays all 40 corpus seeds plus a bounded deterministic sample (WRAITH_CKB_FUZZ_CASES=4096) in CI, alongside make fuzz-sample and make fuzz-scheduled (FUZZ_SCHEDULED_SECONDS=180) targets for scheduled cargo-fuzz sweeps.
  • Updated .github/workflows/ci.yml so the ckb PR job installs pinned cargo-fuzz (=0.12.0 --locked) and runs a bounded deterministic cargo-fuzz sample (-seed=281 -runs=512) across all 5 targets, and added the scheduled/manual fuzz-ckb workflow job (-max_total_time=180 per target with crash artifact upload).

Closes #281

Add deterministic fuzz targets, minimized regression seeds, and RISC-V CKB VM integration coverage for `wraith-stealth-lock` and `wraith-names-type`, hardening both scripts against panics, duplicate `.wraith` name cells, and malformed args/witnesses.

Closes wraith-protocol#281
@drips-wave

drips-wave Bot commented Nov 18, 2026

Copy link
Copy Markdown

@khoap1220-hue 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

Wire cargo-fuzz 0.12.0 (--locked) into the ckb CI job (-seed=281 -runs=512 across all five CKB targets) and add the scheduled/manual fuzz-ckb workflow job (180s per target with crash artifact upload).
@truthixify
truthixify merged commit 9beea81 into wraith-protocol:develop Nov 23, 2026
21 checks passed
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.

[Wave 11] Add a malformed-witness and type-script fuzz corpus for CKB

2 participants