Skip to content

fix(hyperliquid-composer): validate evmExtraWeiDecimals before requestEvmContract#1940

Open
imfeng wants to merge 2 commits intoLayerZero-Labs:mainfrom
imfeng:feat/hyper-check-evm-decimals
Open

fix(hyperliquid-composer): validate evmExtraWeiDecimals before requestEvmContract#1940
imfeng wants to merge 2 commits intoLayerZero-Labs:mainfrom
imfeng:feat/hyper-check-evm-decimals

Conversation

@imfeng
Copy link

@imfeng imfeng commented Mar 23, 2026

Motivation

request-evm-contract reads txData.weiDiff from the local deployment JSON and submits it as evmExtraWeiDecimals without any validation. If the deployment file is stale, manually edited, or generated by an older CLI version, the wrong value gets submitted. Once finalize-evm-contract is called, this value is permanently locked on-chain.

This has already caused real-world damage: token index 1825 on Hyperliquid testnet was permanently locked with evm_extra_wei_decimals=0 instead of the correct value 11 (ERC20 decimals(18) - weiDecimals(7)). The token had to be abandoned and redeployed.

Additionally, writeUpdatedCoreSpotDeployment silently falls back to 0 when weiDiff is null/undefined, masking configuration errors.

Changes

1. On-chain cross-validation in requestEvmContract (link-evm-core.ts)

Before submitting, the CLI now:

  • Fetches decimals() from the ERC20 contract on-chain
  • Computes the expected value: onChainDecimals - coreSpot.weiDecimals
  • If the stored txData.weiDiff does not match, warns the user with full details and prompts to use the on-chain derived value
  • If accepted, persists the corrected value to the deployment JSON so finalize-evm-contract also uses it

2. Display evmExtraWeiDecimals in confirmation prompt (link-evm-core.ts)

The confirmation prompt now shows the exact evmExtraWeiDecimals value being submitted and warns that it becomes irreversible after finalization:

Connect HyperCore-EVM {index} to {address} with evmExtraWeiDecimals={value}. This value is IRREVERSIBLE after finalization. Continue?

3. Remove silent fallback to 0 (parser.ts)

writeUpdatedCoreSpotDeployment previously used txData.weiDiff ?? 0, silently writing evm_extra_wei_decimals: 0 when weiDiff was missing. This is now replaced with an explicit error:

Error: weiDiff is not set in txData. Run core-spot-deployment create first to calculate the correct value.

Files Changed

File Change
packages/hyperliquid-composer/src/commands/link-evm-core.ts On-chain validation, updated prompt, persist corrected value
packages/hyperliquid-composer/src/io/parser.ts Replace ?? 0 fallback with explicit null-check error

…n EVM connection process

- Added retrieval of ERC20 ABI and on-chain decimals to validate weiDiff.
- Introduced user prompt to confirm using on-chain derived weiDiff if discrepancies are found.
- Updated writeUpdatedCoreSpotDeployment to ensure weiDiff is set before proceeding.
@cursor
Copy link

cursor bot commented Mar 23, 2026

PR Summary

Medium Risk
Affects token-linking CLI flows and the persisted deployment JSON; mistakes here could lead to incorrect irreversible on-chain parameters, though the change is additive validation and safer failure modes.

Overview
Adds on-chain validation to requestEvmContract by fetching ERC20 decimals() and cross-checking the stored txData.weiDiff against decimals - weiDecimals, prompting the user to optionally persist the corrected value before submitting.

Updates the confirmation prompt to explicitly display the evmExtraWeiDecimals being sent and warn about irreversibility, and changes writeUpdatedCoreSpotDeployment to throw when weiDiff is missing instead of silently writing 0.

Written by Cursor Bugbot for commit cea8e56. This will update automatically on new commits. Configure here.

…maintain weiDiff integrity

- Wrapped the on-chain decimals retrieval in a try-catch block to handle potential errors gracefully.
- Added logging to warn when on-chain decimals fetching fails, ensuring the process continues with the stored weiDiff value.
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.

2 participants