Skip to content

fix: accept RTC faucet wallet addresses#4893

Merged
Scottcjn merged 2 commits into
Scottcjn:mainfrom
ethever:ethever/fix-faucet-rtc-wallet-4890
May 14, 2026
Merged

fix: accept RTC faucet wallet addresses#4893
Scottcjn merged 2 commits into
Scottcjn:mainfrom
ethever:ethever/fix-faucet-rtc-wallet-4890

Conversation

@ethever
Copy link
Copy Markdown
Contributor

@ethever ethever commented May 12, 2026

Summary

  • fixes Bug: Faucet rejects valid RTC wallet addresses #4890 by accepting native RTC-prefixed wallet addresses in the live root faucet.py endpoint
  • keeps invalid wallet prefixes rejected
  • adds legacy faucet regressions for native RTC acceptance and invalid-prefix rejection

Validation

  • git diff --check origin/main...HEAD
  • python3 -m py_compile faucet.py tests/test_legacy_faucet_json_validation.py
  • uv run --no-project --with pytest --with flask --with flask-cors --with requests python -m pytest tests/test_legacy_faucet_json_validation.py tests/test_faucet.py -q -> 9 passed
  • python3 tools/bcos_spdx_check.py --base-ref origin/main -> OK

Wallet/miner ID for bounty payout: b3a58f80a97bae5e2b438894aa85600cb0c066RTC

No live faucet or production wallet mutation was performed.

 - allow native RTC-prefixed wallet addresses in the legacy faucet

 - add regression coverage for native RTC wallets and invalid prefixes
@github-actions
Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Your PR has a BCOS-L1 or BCOS-L2 label
  • New code files include an SPDX license header
  • You've tested your changes against the live node

Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150)

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) tests Test suite changes size/S PR: 11-50 lines labels May 12, 2026
@ethever
Copy link
Copy Markdown
Contributor Author

ethever commented May 12, 2026

Checklist note: I do not have permission to apply repository labels from this fork. This is a small live-path faucet compatibility fix for #4890; I would classify it as BCOS-L1 unless maintainers prefer another tier. Local validation and BCOS SPDX check are listed in the PR body.

Copy link
Copy Markdown
Contributor

@saim256 saim256 left a comment

Choose a reason for hiding this comment

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

Requesting changes because the new RTC branch accepts malformed native-wallet strings, not just native RTC addresses.

The current predicate is:

if not wallet.startswith(('0x', 'RTC')) or len(wallet) < 10:

That fixes the specific happy-path example from #4890, but it also accepts values like RTCnotvalid, RTCzzzzzzzzzz, or any other arbitrary string with the RTC prefix and length >= 10. Native RustChain wallet examples in the issue and bounty claims use RTC plus a 40-character hex payload, so the validator should either enforce that shape for the RTC branch or add an intentionally documented reason for accepting loose aliases.

Suggested tightening:

RTC_WALLET_RE = re.compile(r"^RTC[0-9a-fA-F]{40}$")
...
valid_wallet = (wallet.startswith("0x") and len(wallet) >= 10) or RTC_WALLET_RE.fullmatch(wallet)

Please also add a regression such as RTCnot-a-native-wallet or RTCzzzzzzzzzz returning 400, alongside the existing valid RTC acceptance test.

Validation run locally:

  • python -m pytest tests\test_legacy_faucet_json_validation.py tests\test_faucet.py -q -> 9 passed
  • python -m py_compile faucet.py tests\test_legacy_faucet_json_validation.py -> passed
  • git diff --check origin/main...HEAD -> passed
  • python tools\bcos_spdx_check.py --base-ref origin/main -> OK

No live faucet or production wallet testing was performed.

Copy link
Copy Markdown
Contributor

@508704820 508704820 left a comment

Choose a reason for hiding this comment

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

Code Review: Accept RTC Faucet Wallet Addresses

Summary

Updates faucet validation to accept both Ethereum-style (0x...) and native RTC (RTC...) wallet addresses. Previously only 0x-prefix was accepted, blocking native RTC wallets.

What Works Well

  1. Dual format support: Accepts both 0x and RTC prefixes
  2. Test coverage: Tests both unknown prefix rejection and valid RTC addresses
  3. Important for our team: Our canonical wallet RTC15e1241... was previously rejected by the faucet

Verdict: Approve

Important fix — native RTC wallets should be first-class citizens in the ecosystem.

Copy link
Copy Markdown

@TJCurnutte TJCurnutte left a comment

Choose a reason for hiding this comment

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

Reviewed the focused faucet validation change. It matches the issue's requested live-path fix: native RTC-prefixed addresses are now accepted while unrelated prefixes are still rejected, and the regression tests cover both cases.\n\nValidation run:\n- python3 -m py_compile faucet.py tests/test_legacy_faucet_json_validation.py\n- python3 -m pytest tests/test_legacy_faucet_json_validation.py -q\n- git diff --check\n\nOne non-blocking follow-up: if the project wants to prevent typoed faucet destinations, consider tightening both accepted formats later (for example + 40 hex chars and + 40 hex chars) instead of prefix + length only. I would not block this PR on that because it preserves the existing loose validation style and fixes the reported RTC rejection.

@TJCurnutte
Copy link
Copy Markdown

Small correction to my previous review text: the intended non-blocking follow-up examples were RTC + 40 hex chars and 0x + 40 hex chars. The PR comment renderer lost those backticked fragments from my shell invocation, but the validation result and review position are unchanged.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Security Fix

Good security fix. Atomic rate limiting / fail-closed patterns are correct.

Verdict: Approve.

Copy link
Copy Markdown
Contributor

@loganoe loganoe left a comment

Choose a reason for hiding this comment

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

The included tests pass locally, but the new validation is too broad for native RustChain wallets. The route now accepts any string starting with RTC and length >= 10, so malformed addresses such as RTCnot-a-native-wallet receive a successful drip and are recorded.

Local repro on this branch:

  • POST /faucet/drip with {"wallet": "RTCnot-a-native-wallet"} returns 200 with ok: true.

Please validate the canonical native wallet shape, e.g. RTC plus the expected 40 hex characters, and add a regression for malformed RTC... input. The legacy 0x... behavior can stay as-is if that compatibility is intentional.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix. Addresses the issue correctly.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix. Addresses the issue correctly.

**Verdict: Approve.

@508704820
Copy link
Copy Markdown
Contributor

Code Review: Accept RTC faucet wallet addresses

Summary

Same fix as #4892 (saim256) and our #4890 — faucet rejects native RTC wallet addresses because validation only accepts 0x prefix.

Comparison

Aspect #4890 (Xeophon) #4892 (saim256) #4893 (ethever)
Approach Issue report only Fix + tests Fix + tests
Prefix check 0x or RTC 0x or RTC 0x or RTC
Test coverage None 2 tests 3 tests (includes unknown prefix test ✅)
Uses tuple Yes Yes Yes

Positive ✅

  1. Unknown prefix test — adds test for BAD prefix, ensuring the validation properly rejects non-0x/non-RTC addresses
  2. Same correct fix as fix: accept native RTC faucet wallets #4892

Note

All three PRs fix the same bug. #4893 has the most comprehensive test coverage with the unknown prefix rejection test.

LGTM

Review quality: Comparative review

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

**Verdict: Approve.

Copy link
Copy Markdown

@shuibui shuibui left a comment

Choose a reason for hiding this comment

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

Code Review: Approve

Good fix.

**Verdict: Approve.

 - require native RTC faucet wallets to match RTC plus 40 hex chars

 - add a regression for malformed RTC-prefixed wallet strings
@ethever
Copy link
Copy Markdown
Contributor Author

ethever commented May 13, 2026

Addressed the requested RTC validation tightening in commit 541c784.

Changes:

  • Added RTC_WALLET_RE = re.compile(r'^RTC[0-9a-fA-F]{40}$').
  • Kept the existing legacy 0x branch behavior.
  • Replaced the loose wallet.startswith(('0x', 'RTC')) check with is_valid_wallet_address().
  • Added a regression that rejects RTCzzzzzzzzzz with 400 Invalid wallet address.

Validation run:

  • git diff --check origin/main...HEAD -> passed
  • python3 -m py_compile faucet.py tests/test_legacy_faucet_json_validation.py -> passed
  • uv run --no-project --with pytest --with flask --with flask-cors --with requests python -m pytest tests/test_legacy_faucet_json_validation.py tests/test_faucet.py -q -> 10 passed
  • python3 tools/bcos_spdx_check.py --base-ref origin/main -> OK

Copy link
Copy Markdown
Contributor

@saim256 saim256 left a comment

Choose a reason for hiding this comment

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

Reviewed current head 541c784ce97b0b6aa7fc9ded1bfbffa9a9dff85f after the RTC validation follow-up.

The blocker from my prior review is fixed. The PR no longer accepts arbitrary RTC... strings: native RTC wallets now must match ^RTC[0-9a-fA-F]{40}$, while the existing legacy 0x branch behavior is preserved. The added malformed-wallet regression covers RTCzzzzzzzzzz returning 400 Invalid wallet address, and valid native RTC wallets are accepted.

Validation performed locally:

  • python -m pytest tests\test_legacy_faucet_json_validation.py tests\test_faucet.py -q -> 10 passed
  • python -m py_compile faucet.py tests\test_legacy_faucet_json_validation.py -> passed
  • python -m ruff check faucet.py tests\test_legacy_faucet_json_validation.py --select E9,F821,F811 --output-format=concise -> passed
  • git diff --check origin/main...HEAD -> passed
  • python tools\bcos_spdx_check.py --base-ref origin/main -> OK

No live faucet, production wallet, or destructive testing was used.

Copy link
Copy Markdown
Contributor

@himanalot himanalot left a comment

Choose a reason for hiding this comment

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

Reviewed the live faucet.py endpoint and the legacy faucet tests. The PR accepts native RTC wallet addresses with a strict RTC[0-9a-fA-F]{40} check, keeps the existing Ethereum-style fallback behavior unchanged, and adds regressions for accepted native wallets plus malformed/unknown prefixes.

I do not see a blocking issue in this patch. Approved.

@guangningsun
Copy link
Copy Markdown
Contributor

PR Review — Standard Quality ✓

PR: #4893 — Fix: accept RTC faucet wallet addresses

What I reviewed

  • faucet.py
  • tests/test_legacy_faucet_json_validation.py

Observations

  1. Adding import re for regex-based wallet address validation — proper regex validation ensures only valid RTC wallet addresses can request faucet drips, preventing abuse.

  2. New test test_legacy_faucet_rejects_non_string_wallet validates that non-string wallet addresses are rejected with 400 Bad Request.

  3. Faucet spam prevention — without proper validation, attackers could request unlimited drips using malformed addresses.

LGTM.

Bounty: #2782
Disclosure: I received RTC compensation for this review.

@Scottcjn Scottcjn merged commit 403a116 into Scottcjn:main May 14, 2026
2 checks passed
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) size/S PR: 11-50 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Faucet rejects valid RTC wallet addresses

9 participants