Skip to content

fix(security): verify input token decimals on-chain before building transactions - #1492

Merged
matheus1lva merged 1 commit into
mainfrom
matheus1lva/sec-onchain-decimals
Nov 24, 2026
Merged

matheus1lva merged 1 commit into
mainfrom
matheus1lva/sec-onchain-decimals

Conversation

@matheus1lva

Copy link
Copy Markdown
Collaborator

Summary

Hardening: in the vault deposit widget, the decimals used to parse the typed amount and to build approve/deposit/zap transactions can come from off-chain metadata (token lists, Kong, Enso balances). In the multicall balance path, a non-zero listed value takes precedence over decimals() (useBalances.multichains.ts), and the widget fell back to 18 when nothing was known.

This PR makes the deposit widget confirm the input token's decimals on-chain before it builds any transaction:

  • New useVerifiedTokenDecimals hook reads decimals() for the input token with wagmi's useReadContract. Reads go through the existing JSON-RPC batch transport and are cached for the session (staleTime/gcTime = ∞). It only runs inside the deposit widget, so pages that build no transaction make no extra calls. Native tokens are checked against 18 without a read.
  • New pure getVerifiedTokenDecimals (utils/verifiedTokenDecimals.ts) returns verified decimals only when the off-chain value equals the on-chain one. If they differ, or if either value is missing or the read fails, it returns an error.
  • deposit/index.tsx: useDepositFlow receives an amount only once decimals are verified, so no route, approval or deposit gets prepared before that. The inputToken?.decimals ?? 18 default on the flow and on the approval overlay (custom approve amount) is removed. The overlay only renders once decimals are verified. A mismatch shows "Token decimals do not match on-chain value" and a failed read shows "Unable to verify token decimals", through the existing input error slot.

Scope notes:

  • Withdraw, stake and migrate inputs (vault share, asset) already take their decimals from decimals() via useTokens, not from lists, so they are unchanged.
  • Pinning or self-hosting the token-list URLs is out of scope here.

How to verify

  • Unit tests: bun run --cwd packages/vault-widget test -- src/utils/verifiedTokenDecimals.test.ts. They cover matching, mismatching, missing listed decimals, failed or missing read, pending read, and native token.
  • Preview: open a vault page (for example an Ethereum USDC vault) and deposit with the vault asset (6 decimals). Then pick an 18-decimals token (DAI or ETH) and a 6-decimals token (USDT) in the selector to zap. Amounts, balances, quotes and approvals should behave as before, with a short initial wait for the one decimals() read.

Checks run

  • bun run tslint, tslint:widget, tslint:4626, tslint:ybold
  • bun run lint:fix
  • Tests: widget 394, yearn 1132, 4626 36, ybold 39, all passing

🤖 Generated with Claude Code

…eposit transactions

The deposit widget parsed the typed amount and built approve/deposit/zap
transactions with decimals taken from off-chain metadata (token lists, Kong,
Enso balances), falling back to 18 when unknown. Read decimals() on-chain for
the input token (cached for the session) and only hand the flow an amount once
the off-chain value matches; otherwise show an error and build no transaction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
yearnfi Ready Ready Preview Nov 24, 2026 1:58pm UTC

Request Review

@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown

Deploy preview for yearn-bold ready!

Project:yearn-bold
Status: ✅  Deploy successful!
Preview URL:https://yearn-bold-d98nzyex3-yearn.vercel.app
Latest Commit:cec0e54

Deployed with vercel-action

@github-actions

Copy link
Copy Markdown

Deploy preview for yearn-4626 ready!

Project:yearn-4626
Status: ✅  Deploy successful!
Preview URL:https://yearn-4626-6t8ipdbry-yearn.vercel.app
Latest Commit:cec0e54

Deployed with vercel-action

@github-actions

Copy link
Copy Markdown

Deploy preview for yearn-fi ready!

Project:yearn-fi
Status: ✅  Deploy successful!
Preview URL:https://yearnfi-rhgkqm8bs-yearn.vercel.app
Latest Commit:cec0e54

Deployed with vercel-action

@matheus1lva
matheus1lva merged commit 43f778a into main Nov 24, 2026
14 checks passed
@matheus1lva
matheus1lva deleted the matheus1lva/sec-onchain-decimals branch November 24, 2026 14:06

This branch was successfully deployed

1 active deployment
preview — cec0e54e Deployed Nov 24, 2026 by github-actions[bot]
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.

1 participant