Skip to content

fix(#5549): harden Beacon x402 wallet/export fallbacks#5554

Closed
weilixiong wants to merge 1 commit into
Scottcjn:mainfrom
weilixiong:fix-5549-beacon-x402-wallet
Closed

fix(#5549): harden Beacon x402 wallet/export fallbacks#5554
weilixiong wants to merge 1 commit into
Scottcjn:mainfrom
weilixiong:fix-5549-beacon-x402-wallet

Conversation

@weilixiong
Copy link
Copy Markdown
Contributor

Closes #5549

  • Fix relay wallet lookup when relay_agents.coinbase_address is present
  • Make contracts export tolerate uninitialized contracts table
  • Use dict() wrapper for sqlite3.Row access

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/S PR: 11-50 lines labels May 17, 2026
Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

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 ✅

Expanded Beacon x402 hardening: dict() wrapper for sqlite3.Row access, contracts export tolerates uninitialized table, relay wallet lookup with coinbase_address. More robust than #5549.

Reviewed by Xeophon - Solana: Lt9nERv6VHsojw15LpFeiaabuphAggzfLF9sM9UXRrZ

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the contribution.

Copy link
Copy Markdown
Contributor

@kekehanshujun kekehanshujun left a comment

Choose a reason for hiding this comment

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

I reviewed this as part of the #73 code review bounty.

Findings:

  1. The PR body uses Closes #5549, but #5549 is an open PR, not the underlying bounty/bug issue. If this merges, the cross-reference is misleading and may confuse review/payment tracking. Please link the actual bug/bounty issue, or use Refs #5549 if the intent is only to reference the prior PR.
  2. premium_contracts_export() now catches every exception from the contracts query and returns an empty successful export. That hides real database corruption/permission errors as “no contracts”, which makes operational failures silent. Please narrow the catch to the expected missing-table/missing-schema case, or return a generic 5xx for unexpected DB errors while still avoiding public exception disclosure.
  3. This PR also modifies node/server_proxy.py and otc-bridge/otc_bridge.py, which are unrelated to the Beacon x402 export/wallet fallback described in the title. Splitting those hunks would reduce conflicts with #5555/#5556 and keep the Beacon fix reviewable.

I received RTC compensation for this review.

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Requesting changes because the relay wallet fallback still 500s on the same sqlite3.Row access pattern this PR is trying to harden.

Validated head 2a5af2101828ccc0fa105110f267ecea94e736d8 locally:

git diff --check origin/main...HEAD -- node/beacon_x402.py node/server_proxy.py otc-bridge/otc_bridge.py
python3 -B -m py_compile node/beacon_x402.py node/server_proxy.py otc-bridge/otc_bridge.py

Then I ran a focused Flask/temp-SQLite probe with conn.row_factory = sqlite3.Row, no native beacon_wallets row, and a matching relay_agents.coinbase_address row. The contracts export fallback added here worked, but the relay wallet lookup did not:

GET /api/agents/relay1/wallet -> 500
AttributeError: 'sqlite3.Row' object has no attribute 'get'
node/beacon_x402.py:257: if relay and relay.get("coinbase_address"):

GET /api/premium/contracts/export with no contracts table -> 200
{"contracts":[],"exported_at":...,"total":0}

So /api/agents/<id>/wallet still cannot return the relay wallet path whenever the DB returns sqlite3.Row. Please convert relay to a dict before .get(...) or use relay["coinbase_address"] after checking the column exists, and add a regression for the relay-agent fallback path.

Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

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. 🚀

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

@weilixiong
Copy link
Copy Markdown
Contributor Author

Hi @TJCurnutte, could you take a look at this PR when you have a moment? Thanks!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Copy Markdown
Contributor

@HCIE2054 HCIE2054 left a comment

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

Duplicate of #5549 with scope-explosion. Adds unrelated changes to node/server_proxy.py and otc-bridge/otc_bridge.py and broadens the catch to except Exception. Per Codex forensic audit (2026-05-18), this is one of three near-identical duplicates of the same root cause. First-poster #5549 is the canonical fix.

@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/S PR: 11-50 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants