Skip to content

fix: validate proposal calldata before decoding selectors - #901

Open
msbanky wants to merge 1 commit into
DigiNodes:mainfrom
msbanky:fix/issue-888-prewave-be-187-validate-proposal-calldata
Open

msbanky wants to merge 1 commit into
DigiNodes:mainfrom
msbanky:fix/issue-888-prewave-be-187-validate-proposal-calldata

Conversation

@msbanky

@msbanky msbanky commented Nov 19, 2026

Copy link
Copy Markdown

Overview

This PR hardens the proposal decoder so that malformed calldata is structurally validated before any selector slicing or ABI decoding occurs. Malformed, non-hex, odd-length, missing-prefix, or oversized calldata now returns the documented fail-closed unknown-selector representation instead of throwing out of decodeCall(), and a single bad call no longer breaks the containing proposal response.

Related Issue

Changes

🛡️ Proposal Decoder Hardening

  • [MODIFY] src/v2/governance/proposal-decoder.service.ts

    • Validate calldata as a 0x-prefixed, even-length hex byte string before calling dataSlice().
    • Bound calldata length prior to decoding to prevent memory/CPU abuse from oversized payloads.
    • Treat empty calldata as the valid plain-transfer case, and short-selector calldata as an unknown-selector result without throwing.
    • Return the documented selectorUnknown: true representation with no fabricated decoded arguments for malformed hex, missing prefix, odd length, oversized payloads, and ABI-decode failures.
    • Preserve exact raw calldata and checksum only after successful structural validation.
    • Add error-safe logging that does not dump arbitrarily large calldata.
  • [MODIFY] src/v2/governance/proposal-decoder.service.spec.ts

    • Empty calldata remains a valid plain transfer case.
    • Valid selector and ABI payload decode normally.
    • Short selector payload returns unknown without throwing.
    • Odd-length, non-hex, missing-prefix, and oversized calldata return a safe unknown/error result.
    • Malformed ABI arguments return unknown without breaking the containing proposal response.
    • A proposal with one malformed call does not prevent other calls from being decoded safely.

Verification Results

npm test -- src/v2/governance/proposal-decoder.service.spec.ts
✅ All decoder spec cases passed (valid, empty, short-selector, malformed, oversized, mixed-call proposal)
Acceptance Criteria Status
Calldata is structurally validated before dataSlice() ✅ Hex/prefix/length checks run before slicing
Malformed calldata never escapes as an uncaught decoder exception ✅ All malformed cases return fail-closed unknown result
Unknown/malformed calls do not produce fabricated arguments ✅ No decoded args emitted for unknown selectors
Payload size is bounded ✅ Oversized calldata rejected before decoding
Golden valid and malformed fixtures pass ✅ Covered in proposal-decoder.service.spec.ts

Closes #888

@msbanky
msbanky requested a review from dDevAhmed as a code owner November 19, 2026 18:49
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@msbanky
msbanky force-pushed the fix/issue-888-prewave-be-187-validate-proposal-calldata branch from c5cb5f5 to d771eae Compare November 24, 2026 04:36
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.

PREWAVE-BE-187 — Validate proposal calldata before decoding selectors

1 participant