Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ABI encoding large negative ints #6239

Merged
merged 11 commits into from
Jun 29, 2023
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
Loading