From 540f30cbec0e745df1a38d51286f2c6326829581 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 19 Aug 2025 01:47:44 -0400 Subject: [PATCH 1/3] Allow zero-width big-endian data for toBeHex and allow widths fo toBeArray (#5025). --- src.ts/utils/maths.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src.ts/utils/maths.ts b/src.ts/utils/maths.ts index 0200c27a3b..37ee55328c 100644 --- a/src.ts/utils/maths.ts +++ b/src.ts/utils/maths.ts @@ -191,6 +191,10 @@ export function toBeHex(_value: BigNumberish, _width?: Numeric): string { if (result.length % 2) { result = "0" + result; } } else { const width = getNumber(_width, "width"); + + // Special case when both value and width are 0 (see: #5025) + if (width === 0 && value === BN_0) { return "0x"; } + assert(width * 2 >= result.length, `value exceeds width (${ width } bytes)`, "NUMERIC_FAULT", { operation: "toBeHex", fault: "overflow", @@ -208,14 +212,29 @@ export function toBeHex(_value: BigNumberish, _width?: Numeric): string { /** * Converts %%value%% to a Big Endian Uint8Array. */ -export function toBeArray(_value: BigNumberish): Uint8Array { +export function toBeArray(_value: BigNumberish, _width?: Numeric): Uint8Array { const value = getUint(_value, "value"); - if (value === BN_0) { return new Uint8Array([ ]); } + if (value === BN_0) { + const width = (_width != null) ? getNumber(_width, "width"): 0; + return new Uint8Array(width); + } let hex = value.toString(16); if (hex.length % 2) { hex = "0" + hex; } + if (_width != null) { + const width = getNumber(_width, "width"); + + while (hex.length < (width * 2)) { hex = "00" + hex; } + + assert((width * 2) === hex.length, `value exceeds width (${ width } bytes)`, "NUMERIC_FAULT", { + operation: "toBeArray", + fault: "overflow", + value: _value + }); + } + const result = new Uint8Array(hex.length / 2); for (let i = 0; i < result.length; i++) { const offset = i * 2; From 0f16aa29419801b50407994e21f8d191074a76b4 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Wed, 20 Aug 2025 03:15:43 -0400 Subject: [PATCH 2/3] docs: random small fixes (#4990, #4991, #5000, #5003, #5010, #5024) --- CHANGELOG.md | 6 +++--- README.md | 2 +- docs.wrm/getting-started.wrm | 4 ++-- docs.wrm/migrating.wrm | 22 +++++++++++++++++++++ src.ts/contract/contract.ts | 8 ++++---- src.ts/wordlists/generation/encode-latin.ts | 6 +++--- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77f5ad371c..1aca9e64a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,7 +63,7 @@ ethers/v6.13.6 (2025-03-21 18:21) - tests: added browser tests for sending ([afd613a](https://github.com/ethers-io/ethers.js/commit/afd613a2a0c9fb548805ed36e23ad9a5d4bcc239)). - tests: debugging browser tests failing to launch ([d1baa74](https://github.com/ethers-io/ethers.js/commit/d1baa741f6b272ba692e0e78787cacb1bd42a8b4)). - tests: fix assert call for browser assert ([1806bbd](https://github.com/ethers-io/ethers.js/commit/1806bbde27523933fb140ad985426f94e0286faf)). - - tests: inlcude more node tests in the browser tests ([92fd5d1](https://github.com/ethers-io/ethers.js/commit/92fd5d1f47c640caa7100bcccf0b133e866989e6)). + - tests: include more node tests in the browser tests ([92fd5d1](https://github.com/ethers-io/ethers.js/commit/92fd5d1f47c640caa7100bcccf0b133e866989e6)). - tests: move more tests to dev network ([996f30c](https://github.com/ethers-io/ethers.js/commit/996f30c674002cea316fa7aa3929f43409f934bc)). - tests: debugging CI browser failure ([ce7212d](https://github.com/ethers-io/ethers.js/commit/ce7212d03d6867081603794f0480f31d053823c4)). - tests: debugging CI browser failure ([f1821a6](https://github.com/ethers-io/ethers.js/commit/f1821a696763938ca9d44815bdcd5cc043eb3900)). @@ -316,7 +316,7 @@ ethers/v6.5.0 (2023-06-06 22:41) - Fixed type guard for non-Typed instances ([#4087](https://github.com/ethers-io/ethers.js/issues/4087); [20c3d1b](https://github.com/ethers-io/ethers.js/commit/20c3d1b109743e33ab60a75d69bf7ede73b15ce2)). - Add confirmations to TransactionResponse ([#4094](https://github.com/ethers-io/ethers.js/issues/4094); [bb8685b](https://github.com/ethers-io/ethers.js/commit/bb8685b112ce1c689c740d4dbcb358c16fb9b22d)). - Fix stray promises when a node returns invalid results ([#4118](https://github.com/ethers-io/ethers.js/issues/4118); [3c1bad2](https://github.com/ethers-io/ethers.js/commit/3c1bad2fb7ad4a6ff90ff11f3e382fd18e41c800)). - - Added support to detect and stop providers spinning on intitial network detection ([#4015](https://github.com/ethers-io/ethers.js/issues/4015); [f37a52d](https://github.com/ethers-io/ethers.js/commit/f37a52da28ac130b7f4de52901618320994ea87a)). + - Added support to detect and stop providers spinning on initial network detection ([#4015](https://github.com/ethers-io/ethers.js/issues/4015); [f37a52d](https://github.com/ethers-io/ethers.js/commit/f37a52da28ac130b7f4de52901618320994ea87a)). ethers/v6.4.2 (2023-06-05 22:41) -------------------------------- @@ -344,7 +344,7 @@ ethers/v6.4.0 (2023-05-18 17:28) - Fix receipt gas price when effectiveGasPrice is 0 on testnets ([#4014](https://github.com/ethers-io/ethers.js/issues/4014); [2b0fe61](https://github.com/ethers-io/ethers.js/commit/2b0fe611335432aee334d777a64d8c7827881618)). - Added error event to provider ([#3970](https://github.com/ethers-io/ethers.js/issues/3970), [#3982](https://github.com/ethers-io/ethers.js/issues/3982); [af0291c](https://github.com/ethers-io/ethers.js/commit/af0291c01639674658f5049343da88a84da763a1)). - Removed superfluous parameters for internal transaction functions ([e848978](https://github.com/ethers-io/ethers.js/commit/e8489787585c2e69a23f6cdec6901f22b096aebe)). - - More aggresive tree-shaking ([076edad](https://github.com/ethers-io/ethers.js/commit/076edad81ef62474f48f2b4c8af0edc6e4fd64f2)). + - More aggressive tree-shaking ([076edad](https://github.com/ethers-io/ethers.js/commit/076edad81ef62474f48f2b4c8af0edc6e4fd64f2)). - More flexible static network checking ([#3834](https://github.com/ethers-io/ethers.js/issues/3834); [7c0465c](https://github.com/ethers-io/ethers.js/commit/7c0465c5fb834eba18d4e5535072685bdc1029f0)). - Support transitive dependants that use non-node16 moduleResolution ([#3920](https://github.com/ethers-io/ethers.js/issues/3920); [df685b1](https://github.com/ethers-io/ethers.js/commit/df685b1bd9ad346ee7863beb6c3ca3f4e94932a2)). - Populate any missing log.removed with false ([#3959](https://github.com/ethers-io/ethers.js/issues/3959); [4e478e6](https://github.com/ethers-io/ethers.js/commit/4e478e625d5648f2172631eef5fda5776ee776b0)). diff --git a/README.md b/README.md index 5db1fbf947..5af8510217 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ in [TypeScript](https://www.typescriptlang.org). - Import and export **JSON wallets** (Geth, Parity and crowdsale) - Import and export BIP 39 **mnemonic phrases** (12 word backup phrases) and **HD Wallets** (English as well as Czech, French, Italian, Japanese, Korean, Simplified Chinese, Spanish, Traditional Chinese) - Meta-classes create JavaScript objects from any contract ABI, including **ABIv2** and **Human-Readable ABI** -- Connect to Ethereum nodes over [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC), [INFURA](https://infura.io), [Etherscan](https://etherscan.io), [Alchemy](https://alchemyapi.io), [Ankr](https://ankr.com) or [MetaMask](https://metamask.io) +- Connect to Ethereum nodes over [JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/), [INFURA](https://infura.io), [Etherscan](https://etherscan.io), [Alchemy](https://alchemyapi.io), [Ankr](https://ankr.com) or [MetaMask](https://metamask.io) - **ENS names** are first-class citizens; they can be used anywhere an Ethereum addresses can be used - **Small** (~144kb compressed; 460kb uncompressed) - **Tree-shaking** focused; include only what you need during bundling diff --git a/docs.wrm/getting-started.wrm b/docs.wrm/getting-started.wrm index f89e879b28..0a9febe211 100644 --- a/docs.wrm/getting-started.wrm +++ b/docs.wrm/getting-started.wrm @@ -419,7 +419,7 @@ _code: listen for ERC-20 events @lang