Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 47b9769

Browse files
Fix for ABI encoding large negative ints (#6239)
* Bump typescript version to 4.9.5 * Update CHANGELOG * Bump ts-node to 10.9.1 * Fix issue with encoding large negative numbers * Correct test cases for check-address-checksum-test * dtslint debug * Convert if/else to ternary * Update CHANGELOG
1 parent 512aba7 commit 47b9769

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,4 @@ Released with 1.0.0-beta.37 code base.
685685
### Fixed
686686

687687
- Builds fixed by updating all typescript versions to 4.9.5 (#6238)
688+
- ABI encoding for large negative `int`s (#6239)

packages/web3-eth-abi/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,11 @@ ABICoder.prototype.formatParam = function (type, param) {
268268
if (match) {
269269
let size = parseInt(match[2] || "256");
270270
if (size / 8 < param.length) {
271-
// pad to correct bit width
272-
param = utils.leftPad(param, size);
271+
param = param.startsWith("-")
272+
// pad to correct bit width, with - at the beginning
273+
? `-${utils.leftPad(param.substring(1), size)}`
274+
// pad to correct bit width
275+
: utils.leftPad(param, size);
273276
}
274277
}
275278

test/eth.abi.encodeParameter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ var tests = [{
1111
},{
1212
params: ['bytes32[]', ['0xdf3234', '0xfdfd']],
1313
result: '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000'
14+
},{
15+
params: ['int128', '-170141183460469231731687303715884105727'],
16+
result: '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001'
1417
}];
1518

1619
describe('encodeParameter', function () {

0 commit comments

Comments
 (0)