Skip to content

Comments

fix(bridge): prevent invalid initia/evm balance queries on chain switch#161

Open
tansawit wants to merge 2 commits intomainfrom
fix/bridge-initia-bech32-validation
Open

fix(bridge): prevent invalid initia/evm balance queries on chain switch#161
tansawit wants to merge 2 commits intomainfrom
fix/bridge-initia-bech32-validation

Conversation

@tansawit
Copy link
Contributor

@tansawit tansawit commented Feb 18, 2026

Summary

This PR fixes address-format handling issues in the bridge flow for Initia/EVM chain pairs.

Users could trigger a transient state where the bridge queried balances with a mismatched address format during source/destination chain transitions:

  • querying an EVM chain with an Initia bech32 address, or
  • querying an Initia chain with a hex address.

That first request failed, then a second request succeeded after form state settled.

Root Cause

Bridge form updates were not fully atomic across chain and address fields. During chain switching, query hooks could execute with new chain IDs but stale sender/recipient values from the previous chain context.

In addition, route query keys included full form values, which introduced unnecessary refetches from fields unrelated to route computation.

Changes

  1. Strict Initia address validation

    • Enforce bech32+prefix validation for Initia chains.
    • Keep explicit EVM hex validation and prefix-based Cosmos validation.
    • File: packages/interwovenkit-react/src/pages/bridge/data/address.ts
  2. Prevent invalid balance requests during chain/address transitions

    • Gate balance queries with chain-aware address validation (enabled now requires a valid address for the selected chain).
    • This suppresses the invalid first /balances call.
    • File: packages/interwovenkit-react/src/pages/bridge/data/balance.ts
  3. Tighten route query key inputs

    • Scope route query keys to route-defining params only: srcChainId, srcDenom, dstChainId, dstDenom, quantity.
    • Align queryFn with the same routeParams object used by queryKey for clarity and exhaustive-deps correctness.
    • Files:
      • packages/interwovenkit-react/src/pages/bridge/data/skip.ts
      • packages/interwovenkit-react/src/pages/bridge/data/simulate.ts

User Impact

  • Eliminates transient failed balance requests for Initia/EVM pair switching.
  • Reduces noisy duplicate querying around chain/address transitions.
  • Keeps route simulation cache behavior focused on real route inputs.

Validation

  • pnpm --filter @initia/interwovenkit-react exec eslint src/pages/bridge/data/address.ts src/pages/bridge/data/balance.ts src/pages/bridge/data/skip.ts src/pages/bridge/data/simulate.ts
  • pnpm --filter @initia/interwovenkit-react typecheck
  • pnpm --filter @initia/interwovenkit-react test

Summary by CodeRabbit

  • New Features

    • Added a helper to fetch a specific token balance for a given address, chain and denom.
  • Bug Fixes

    • Improved address validation across networks to prevent invalid addresses from triggering balance queries.
    • Balance and simulation flows now reliably skip or disable requests when inputs are invalid or incomplete, reducing erroneous results.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

No actionable comments were generated in the recent review. 🎉


Walkthrough

Introduces a bech32-prefix address helper and tightens address checks; adds address validation gating to balance queries and a helper to fetch a single denom; consolidates simulated-route params into a single object; and narrows skip query key typing to a RouteParams subset.

Changes

Cohort / File(s) Summary
Address validation
packages/interwovenkit-react/src/pages/bridge/data/address.ts
Adds isBech32WithPrefix() and switches "initia"/"cosmos" validation to explicit bech32-prefix checks; preserves "evm" checks via isAddress().
Balances & helpers
packages/interwovenkit-react/src/pages/bridge/data/balance.ts
Adds address validation to useSkipBalancesQuery (disables query/select when invalid) and exports useSkipBalance(address, chainId, denom) to read a single denom.
Simulation params consolidation
packages/interwovenkit-react/src/pages/bridge/data/simulate.ts
Replaces debounced-values aggregation with a single routeParams object used for disabled logic, query keys/fn, parsing, and tracking payload.
Skip query keys typing
packages/interwovenkit-react/src/pages/bridge/data/skip.ts
Introduces internal RouteParams type and updates skipQueryKeys.route signature to accept RouteParams (runtime behavior unchanged).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through code with careful paws,
Counting bech32 bits and checking clause,
I bundled params in one neat sack,
Pulled balances only when valid—no flack,
A tiny hop, a tidy bridge, applause! 🎉

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title references preventing invalid balance queries on chain switch, but the main focus is enforcing strict bech32 validation for Initia addresses and consolidating validation logic. Update the title to reflect the primary change: e.g., 'fix(bridge): enforce strict initia bech32 validation and consolidate address checks'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/bridge-initia-bech32-validation

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying interwovenkit-staging with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2063910
Status: ✅  Deploy successful!
Preview URL: https://229175bb.interwovenkit-staging.pages.dev
Branch Preview URL: https://fix-bridge-initia-bech32-val.interwovenkit-staging.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying interwovenkit with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2063910
Status: ✅  Deploy successful!
Preview URL: https://09d7ef80.interwovenkit.pages.dev
Branch Preview URL: https://fix-bridge-initia-bech32-val.interwovenkit.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying interwovenkit-testnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2063910
Status: ✅  Deploy successful!
Preview URL: https://3bc3fab9.interwovenkit-testnet.pages.dev
Branch Preview URL: https://fix-bridge-initia-bech32-val.interwovenkit-testnet.pages.dev

View logs

@linear
Copy link

linear bot commented Feb 18, 2026

@tansawit tansawit marked this pull request as ready for review February 18, 2026 02:02
@tansawit tansawit changed the title fix(bridge): enforce strict initia bech32 validation fix(bridge): prevent invalid initia/evm balance queries on chain switch Feb 18, 2026
@tansawit tansawit self-assigned this Feb 18, 2026
@tansawit tansawit added priority:high type:bug Something isn't working labels Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:high type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant