Repository navigation
fix(security): verify input token decimals on-chain before building transactions - #1492
Merged
Merged
Conversation
…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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
Deploy preview for yearn-bold ready!
Deployed with vercel-action |
|
Deploy preview for yearn-4626 ready!
Deployed with vercel-action |
|
Deploy preview for yearn-fi ready!
Deployed with vercel-action |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 to18when nothing was known.This PR makes the deposit widget confirm the input token's decimals on-chain before it builds any transaction:
useVerifiedTokenDecimalshook readsdecimals()for the input token with wagmi'suseReadContract. 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.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:useDepositFlowreceives an amount only once decimals are verified, so no route, approval or deposit gets prepared before that. TheinputToken?.decimals ?? 18default 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:
decimals()viauseTokens, not from lists, so they are unchanged.How to verify
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.decimals()read.Checks run
bun run tslint,tslint:widget,tslint:4626,tslint:yboldbun run lint:fix🤖 Generated with Claude Code