Skip to content

Commit

Permalink
fix padRight validation failure on large uint (#7265)
Browse files Browse the repository at this point in the history
* fix padRight validation failure on large uint

* update CHANGELOG.md
  • Loading branch information
Muhammad-Altabba authored Sep 24, 2024
1 parent 61babcc commit aa471e7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/web3-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,7 @@ Documentation:
- `_sendPendingRequests` will catch unhandled errors from `_sendToSocket` (#6968)

## [Unreleased]

### Fixed

- fix `padRight` validation failure on large `uint` (#7265)
6 changes: 3 additions & 3 deletions packages/web3-utils/src/string_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export const padRight = (value: Numbers, characterAmount: number, sign = '0'): s
return value.padEnd(characterAmount, sign);
}

validator.validate(['int'], [value]);

const hexString = typeof value === 'string' && isHexStrict(value) ? value : numberToHex(value);

const prefixLength = hexString.startsWith('-') ? 3 : 2;

validator.validate([hexString.startsWith('-') ? 'int' : 'uint'], [value]);

return hexString.padEnd(characterAmount + prefixLength, sign);
};

Expand Down
8 changes: 8 additions & 0 deletions packages/web3-utils/test/fixtures/string_manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export const padRightData: [[Numbers, number, string], HexString][] = [
[[BigInt(10000), 8, '0'], '0x27100000'],
[[BigInt(-14), 8, '0'], '-0xe0000000'],
[['15.5', 8, '0'], '15.50000'],
[
['0x05e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2', 64, '0'],
'0x05e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2',
],
[
['0xb5e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2', 64, '0'],
'0xb5e2e7de3cd95eb48fa9ff77e7860cf249fe05f726abea45a0a44e62b4bf52b2',
],
];

export const toTwosComplementData: [[Numbers, number | undefined], HexString][] = [
Expand Down

1 comment on commit aa471e7

@github-actions
Copy link

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: aa471e7 Previous: 61babcc Ratio
processingTx 21158 ops/sec (±9.13%) 21257 ops/sec (±6.74%) 1.00
processingContractDeploy 39080 ops/sec (±6.04%) 39869 ops/sec (±7.27%) 1.02
processingContractMethodSend 15073 ops/sec (±10.51%) 15648 ops/sec (±7.56%) 1.04
processingContractMethodCall 27542 ops/sec (±6.80%) 27272 ops/sec (±8.03%) 0.99
abiEncode 41986 ops/sec (±6.88%) 43420 ops/sec (±6.60%) 1.03
abiDecode 29298 ops/sec (±7.95%) 29805 ops/sec (±7.97%) 1.02
sign 1506 ops/sec (±0.77%) 1521 ops/sec (±0.83%) 1.01
verify 357 ops/sec (±3.31%) 360 ops/sec (±0.50%) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.