Skip to content

Add rule B011: target chain address format validation - #893

Merged
mijinummi merged 2 commits into
MDTechLabs:mainfrom
ThatCodeBabe:feat/b011-address-format-rule-867
Jul 31, 2026
Merged

Add rule B011: target chain address format validation#893
mijinummi merged 2 commits into
MDTechLabs:mainfrom
ThatCodeBabe:feat/b011-address-format-rule-867

Conversation

@ThatCodeBabe

Copy link
Copy Markdown
Contributor

Closes #867

Summary

Greenfield — no rules/ crate exists in this fork (a similar-but-unrelated rule was built independently in a different contributor's fork; not present here). Standalone Rust crate at rules/, using solang-parser, following the same "independent crate, no shared workspace" convention as contracts/soroban/*.

  • Flags a function as in-scope when its name suggests a cross-chain transfer (bridge/transfer/send/deposit/dispatch) AND it has both a recipient-like param and a separate chain-ID-like param — then flags address/address payable recipient params (always 20 bytes, too narrow for e.g. a 32-byte Solana pubkey), passing bytes/bytes32
  • This codebase's own real contracts/router/BatchBridgeRouter.sol/NativeBridgeRouter.sol already use bytes32 recipient for exactly this reason — used as grounding for a realistic fixture rather than an artificial one
  • Fixture includes a case proving the rule does NOT over-flag: a withdraw(address recipient, ...) function with no chain-ID param and a non-cross-chain name is correctly left unflagged

Acceptance criteria

  • Flags cross-chain transfer signatures restricting recipient address lengths for non-EVM routes
  • Passes on functions accepting dynamic bytes or bytes32 recipient parameters

Test plan

  • cargo test — 6/6 passing (fixture parses; violation flagged with correct line; both safe-type cases pass; non-cross-chain case not over-flagged; exact violation count == 1)
  • cargo build --release — clean
  • cargo clippy --all-targets — no warnings on new code

Adds a standalone Rust crate (rules/) that parses Solidity with
solang-parser and flags cross-chain outbound transfer functions that
restrict their recipient parameter to a 20-byte address/address payable
type instead of bytes or bytes32, which cannot safely represent non-EVM
recipient addresses (Solana, Bitcoin, Cosmos, etc.).

The crate is standalone, not part of any Cargo workspace, matching the
existing contracts/soroban/*/Cargo.toml convention. A function is
considered in-scope for the rule when its name suggests a cross-chain
transfer (bridge/transfer/send/deposit/dispatch) and it has both a
recipient-like parameter and a narrow uint chain-ID-like parameter,
which keeps ordinary domestic functions with a "recipient" argument
from being flagged.

Includes test/fixtures/b011_samples.sol covering the violation case,
the bytes32/bytes passing cases, and a non-cross-chain function with an
address recipient param that must not be flagged, plus unit tests in
rules/src/b011_address_format.rs that parse the fixture from disk and
assert an exact violation count.
@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

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

@mijinummi

Copy link
Copy Markdown
Collaborator

Hi, please kindly resolve conflict @ThatCodeBabe

@mijinummi
mijinummi merged commit acbfdd1 into MDTechLabs:main Jul 31, 2026
1 check failed
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.

[RULE] Rule B011: Enforce Target Chain Address Format Validation

2 participants