Skip to content

Fix strict Base address validation - #5480

Closed
kekehanshujun wants to merge 2 commits into
Scottcjn:mainfrom
kekehanshujun:fix-strict-base-address-validation-5432-5434-5436
Closed

kekehanshujun wants to merge 2 commits into
Scottcjn:mainfrom
kekehanshujun:fix-strict-base-address-validation-5432-5434-5436

Conversation

@kekehanshujun

Copy link
Copy Markdown
Contributor

Summary

  • add a shared-style strict Base/EVM address validator for bridge locks and x402 wallet endpoints
  • require 0x plus exactly 40 hex characters instead of only checking prefix or length
  • add regressions for short and non-hex Base addresses across bridge, RustChain x402, and Beacon x402 flows

Fixes #5432
Fixes #5434
Fixes #5436

Validation

  • python -m py_compile bridge/bridge_api.py bridge/test_bridge_api.py node/rustchain_x402.py node/beacon_x402.py node/tests/test_base_evm_address_validation.py
  • python -m pytest bridge/test_bridge_api.py node/tests/test_base_evm_address_validation.py -q --tb=short -> 45 passed
  • git diff --check -- bridge/bridge_api.py bridge/test_bridge_api.py node/rustchain_x402.py node/beacon_x402.py node/tests/test_base_evm_address_validation.py

RTC wallet: RTC02811ff5e2bb4bb4b95eee44c5429cd9525496e7

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related tests Test suite changes size/M PR: 51-200 lines labels May 16, 2026

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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

Verified this locally. The strict Base/EVM address validation looks good to me.

Validation run on detached head a7717c36b581:

  • git diff --check origin/main...HEAD -- bridge/bridge_api.py bridge/test_bridge_api.py node/beacon_x402.py node/rustchain_x402.py node/tests/test_base_evm_address_validation.py — passed.
  • python3 -B -m py_compile bridge/bridge_api.py bridge/test_bridge_api.py node/beacon_x402.py node/rustchain_x402.py node/tests/test_base_evm_address_validation.py — passed.
  • uv run --no-project --with pytest --with flask python -B -m pytest -q bridge/test_bridge_api.py node/tests/test_base_evm_address_validation.py --noconftest — 45 passed in 0.33s.
  • Runtime probe: bridge_api._is_base_evm_address() accepted canonical 0x + 40-hex addresses including mixed-case hex, and rejected 0X..., short, non-hex, and non-string values. A Flask test-client probe for /wallet/link-coinbase accepted a valid mixed-case Base address and rejected short/non-hex/non-string addresses with HTTP 400 before the bad values could be written.

The important path is covered: /bridge/lock now rejects Base target_wallet values unless they are exactly 0x plus 40 hex characters before receipt verification/ledger insert, while the RustChain and Beacon x402 wallet-link routes enforce the same shape before persistence. Existing signed receipt and Solana bridge cases still pass in the focused bridge suite.

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

Reviewed PR #5480 at head a7717c3.

Blocking finding:

This PR says it fixes #5434, but the #5434 path remains vulnerable on the PR head. Issue #5434 specifically points to node/bridge_api.py::validate_chain_address_format(chain="base", address=...), and that function still only checks the 0x prefix and length 42. It does not verify that the remaining 40 characters are hexadecimal.

Reproduction on this PR head:

python import bridge_api bad = "0x" + "Z" * 40 ok, msg = bridge_api.validate_chain_address_format("base", bad) assert ok is True

Observed output:

ext {'ok': True, 'msg': '', 'bad': '0xZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'}

The standalone bridge lock endpoint and x402 wallet endpoints look covered, but #5434 remains open until node/bridge_api.py also enforces exactly 0x plus 40 hex characters.

Validation performed:

  • git fetch origin pull/5480/head:review-pr-5480 --force
  • git diff --check origin/main...review-pr-5480 -- bridge/bridge_api.py bridge/test_bridge_api.py node/rustchain_x402.py node/beacon_x402.py node/tests/test_base_evm_address_validation.py -> passed.
  • python -m py_compile bridge/bridge_api.py bridge/test_bridge_api.py node/rustchain_x402.py node/beacon_x402.py node/tests/test_base_evm_address_validation.py on extracted PR-head files -> passed.
  • python -m pytest bridge/test_bridge_api.py node/tests/test_base_evm_address_validation.py -q --confcutdir= -> 45 passed.
  • Checked issues #5432, #5434, and #5436.
  • Ran the node/bridge_api.py validator probe above and confirmed #5434 still reproduces.

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@508704820 508704820 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix strict Base address validation. Verify: (1) Address validation rejects both invalid checksum and wrong network prefix. (2) Validation is applied consistently across all Base chain endpoints. (3) Error message does not reveal expected address format to assist attackers. - Xeophon (security review)

@LubuSeb LubuSeb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the updated head 7d3b100 after the earlier #5434 blocker.

Validation performed:

  • git diff --check origin/main...HEAD -- bridge/bridge_api.py bridge/test_bridge_api.py node/bridge_api.py node/beacon_x402.py node/rustchain_x402.py node/tests/test_base_evm_address_validation.py -> passed
  • python -B -m py_compile bridge/bridge_api.py bridge/test_bridge_api.py node/bridge_api.py node/beacon_x402.py node/rustchain_x402.py node/tests/test_base_evm_address_validation.py -> passed
  • isolated venv with pytest + flask, then PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTHONPATH=node:. python -B -m pytest -q bridge/test_bridge_api.py node/tests/test_base_evm_address_validation.py --noconftest --tb=short -> 46 passed
  • direct node bridge validator probe: validate_chain_address_format("base", "0x" + "Z" * 40) now returns (False, "Invalid Base address format"); canonical 0x + 40 hex still returns (True, ""); uppercase 0X remains rejected.

The follow-up commit applies strict 40-hex validation to node/bridge_api.py, so the issue called out in the previous review no longer reproduces. The standalone bridge route, node bridge validator, and x402 wallet-link paths are covered by the focused tests. Approving the current head.

Reviewer wallet/miner ID for bounty #73: RTC4a92ce8abb537f827b8b0dac456242f8697c1ad6

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@508704820

Copy link
Copy Markdown
Contributor

Security Review ✅

Strict Base/EVM address validation requiring 0x + exactly 40 hex chars. Previous loose validation (prefix or length only) could allow crafted addresses that bypass checks — e.g. 0xGGGG... with non-hex chars, or truncated addresses that match unintended accounts. Fix applies consistently across bridge locks and x402 wallet endpoints.

Reviewed by Xeophon - Solana: Lt9nERv6VHsojw15LpFeiaabuphAggzfLF9sM9UXRrZ

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jaxint jaxint left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work on this PR. 🚀

@HCIE2054 HCIE2054 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Scottcjn

Copy link
Copy Markdown
Owner

Closing as stale branch — would cause destructive deletions if merged.

Your branch was filed roughly 155 commits behind current main. Since then, many overlapping fixes from other contributors have landed via parallel PRs. GitHub's mergeable=clean indicator only catches text-level conflicts — it doesn't detect "this branch is so old that merging would silently delete code that landed after it was filed."

Bounty credit acknowledged

If your fix addressed a real bug, the canonical version has very likely already shipped via a parallel contributor's PR over the past two weeks. Specific cases covered by today's audit:

If you want fresh review

Rebase against current main and verify your diff shows roughly the size of the changes you originally made:

git fetch upstream main
git rebase upstream/main
git diff main..HEAD --shortstat

If the deletion count is significantly higher than what you added, the branch is still picking up stale assumptions — recreate from a fresh main.

Thanks for the contribution work this week.

@Scottcjn Scottcjn closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

8 participants