Skip to content

BWS/BWC: Fix - tx proposal amount precision loss - #4247

Open
gabrielbazan7 wants to merge 2 commits into
bitpay:masterfrom
gabrielbazan7:fix/formatnumbers1
Open

gabrielbazan7 wants to merge 2 commits into
bitpay:masterfrom
gabrielbazan7:fix/formatnumbers1

Conversation

@gabrielbazan7

Copy link
Copy Markdown
Contributor

Description

Fixes "Server response could not be verified" when sending an amount that a JavaScript number cannot
round-trip (e.g. 0.07 of an 18-decimal token). BWS no longer converts amount types, and BWC no longer
asks it to.

Changelog

  • Preserve stored proposal amounts across BWS/BWC.
  • Reject signing when the requested numberFormat rebuilds a different transaction.
  • Bind the prePublishRaw verification fallback to proposals with mutable tx data.
  • Add exact BigInt totals for balance and allowance checks.
  • Prevent BTC amount mutation and string concatenation.
  • Stop BWC from requesting number formatting by default.
  • Correct invalid numberFormat request handling.
  • Add precision regression tests.

Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The signature fallback trusts unauthenticated mutability flags, allowing altered transaction outputs to pass verification.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Preserves transaction amount precision across BWS/BWC while maintaining transaction verification and accurate balance checks.

Changes:

  • Stops default number-format conversion and validates explicit formats.
  • Uses exact totals and avoids amount mutation/string concatenation.
  • Adds precision, signing, routing, allowance, and escrow regressions.
File summaries
File Description
packages/bitcore-wallet-service/test/numberformat-routes.test.ts Tests route format validation.
packages/bitcore-wallet-service/test/model/txproposal.test.ts Tests exact totals and formatting.
packages/bitcore-wallet-service/test/integration/server.test.ts Tests exact token allowance checks.
packages/bitcore-wallet-service/test/chain/xrp.test.ts Tests XRP precision handling.
packages/bitcore-wallet-service/test/chain/sol.test.ts Tests SOL precision handling.
packages/bitcore-wallet-service/test/chain/eth.test.ts Tests ETH precision handling.
packages/bitcore-wallet-service/test/chain/btc.test.ts Tests BTC string amounts.
packages/bitcore-wallet-service/src/types/expressapp.d.ts Updates validation return type.
packages/bitcore-wallet-service/src/lib/server.ts Uses exact allowance totals.
packages/bitcore-wallet-service/src/lib/routes/wallets.ts Stops invalid-format requests.
packages/bitcore-wallet-service/src/lib/routes/transactions.ts Stops invalid-format requests.
packages/bitcore-wallet-service/src/lib/routes/helpers/error.ts Handles absent request context.
packages/bitcore-wallet-service/src/lib/routes/context.ts Returns format-validation status.
packages/bitcore-wallet-service/src/lib/model/txproposal.ts Preserves amounts and verifies rebuilt transactions.
packages/bitcore-wallet-service/src/lib/chain/xrp/index.ts Uses exact XRP totals.
packages/bitcore-wallet-service/src/lib/chain/sol/index.ts Uses exact SOL totals.
packages/bitcore-wallet-service/src/lib/chain/eth/index.ts Uses exact ETH totals.
packages/bitcore-wallet-service/src/lib/chain/btc/index.ts Avoids BTC amount mutation and concatenation.
packages/bitcore-wallet-client/test/numberformat.test.ts Tests client format behavior.
packages/bitcore-wallet-client/test/numberformat-signing.test.ts Tests precision-safe signing flows.
packages/bitcore-wallet-client/test/escrow-amount-types.test.ts Tests BCH escrow amount types.
packages/bitcore-wallet-client/test/amount-type-divergence.test.ts Documents EVM numeric divergence.
packages/bitcore-wallet-client/src/lib/verifier.ts Restricts raw-signature fallback.
packages/bitcore-wallet-client/src/lib/common/utils.ts Normalizes escrow arithmetic.
packages/bitcore-wallet-client/src/lib/bulkclient.ts Removes default bulk formatting.
packages/bitcore-wallet-client/src/lib/api.ts Omits number formatting by default.
Review details
  • Files reviewed: 25/26 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/bitcore-wallet-client/src/lib/verifier.ts Outdated
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