Skip to content

Commit

Permalink
Fix for ABI encoding large negative ints (#6239)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
spacesailor24 authored Jun 29, 2023
1 parent 512aba7 commit 47b9769
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,4 @@ Released with 1.0.0-beta.37 code base.
### Fixed

- Builds fixed by updating all typescript versions to 4.9.5 (#6238)
- ABI encoding for large negative `int`s (#6239)
7 changes: 5 additions & 2 deletions packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,11 @@ ABICoder.prototype.formatParam = function (type, param) {
if (match) {
let size = parseInt(match[2] || "256");
if (size / 8 < param.length) {
// pad to correct bit width
param = utils.leftPad(param, size);
param = param.startsWith("-")
// pad to correct bit width, with - at the beginning
? `-${utils.leftPad(param.substring(1), size)}`
// pad to correct bit width
: utils.leftPad(param, size);
}
}

Expand Down
3 changes: 3 additions & 0 deletions test/eth.abi.encodeParameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var tests = [{
},{
params: ['bytes32[]', ['0xdf3234', '0xfdfd']],
result: '0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000'
},{
params: ['int128', '-170141183460469231731687303715884105727'],
result: '0xffffffffffffffffffffffffffffffff80000000000000000000000000000001'
}];

describe('encodeParameter', function () {
Expand Down

0 comments on commit 47b9769

Please sign in to comment.