Skip to content

Fix gas reserve validation for high-decimal tokens in withdraw operations#52

Closed
Copilot wants to merge 3 commits intochore/paymaster-support-fixfrom
copilot/sub-pr-49
Closed

Fix gas reserve validation for high-decimal tokens in withdraw operations#52
Copilot wants to merge 3 commits intochore/paymaster-support-fixfrom
copilot/sub-pr-49

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 23, 2026

What was the issue?

The withdraw validation in validateGasReserve() was ineffective for high-decimal tokens. When operationAmount is undefined (withdraw all scenario), the validation checked balance < gasReserve where gasReserve = max(balance * 1%, 1n). This made the check mathematically impossible to fail for any non-zero balance, allowing withdrawals that would leave insufficient tokens for gas payment.

What was fixed?

Gas reserve calculation for high-decimal tokens:

  • Changed calculateGasReserve() to return max(percentageReserve, fixedMinimum) for tokens with >6 decimals
  • fixedMinimum uses parseUnits(GAS_RESERVE_MINIMUM, decimals) (currently 0.01 tokens)
  • Ensures balance-independent minimum that makes withdraw validation meaningful

TypeScript signature fix:

  • Changed withdraw() signature from amount?: string to amount: string | undefined
  • Resolves build error where optional parameter preceded required parameter

Before:

// High-decimal token with 1 token balance
// gasReserve = max(1 token * 1%, 1n) = 0.01 tokens
// Check: 1 < 0.01 → false (validation ineffective)

After:

// gasReserve = max(0.01 tokens, 0.01 tokens) = 0.01 tokens  
// Check: 1 < 0.01 → false, but 0.005 < 0.01 → true (validation effective)

Related issues

Addresses feedback from #49


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 23, 2026 19:31
…h-decimal tokens

Co-authored-by: 0xdeval <26190360+0xdeval@users.noreply.github.com>
Co-authored-by: 0xdeval <26190360+0xdeval@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix feedback on paymaster support for protocols Fix gas reserve validation for high-decimal tokens in withdraw operations Jan 23, 2026
Copilot AI requested a review from 0xdeval January 23, 2026 19:37
@0xdeval 0xdeval closed this Jan 23, 2026
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