Skip to content

Commit 3e66cca

Browse files
committed
encoding fixed size variables > 32 bytes"
1 parent e3a8734 commit 3e66cca

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

lib/solidity/formatters.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ var SolidityParam = require('./param');
3636
* @returns {SolidityParam}
3737
*/
3838
var formatInputInt = function (value) {
39-
var padding = c.ETH_PADDING * 2;
4039
BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
41-
var result = utils.padLeft(utils.toTwosComplement(value).round().toString(16), padding);
40+
var result = utils.padLeft(utils.toTwosComplement(value).round().toString(16), 64);
4241
return new SolidityParam(result);
4342
};
4443

@@ -50,7 +49,9 @@ var formatInputInt = function (value) {
5049
* @returns {SolidityParam}
5150
*/
5251
var formatInputBytes = function (value) {
53-
var result = utils.padRight(utils.toHex(value).substr(2), 64);
52+
var result = utils.toHex(value).substr(2);
53+
var l = Math.floor((result.length + 63) / 64);
54+
result = utils.padRight(result, l * 64);
5455
return new SolidityParam(result);
5556
};
5657

lib/solidity/param.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ SolidityParam.prototype.combine = function (param) {
7272
* @returns {Boolean}
7373
*/
7474
SolidityParam.prototype.isDynamic = function () {
75-
return this.value.length > 64 || this.offset !== undefined;
75+
return this.offset !== undefined;
7676
};
7777

7878
/**

test/coder.encodeParam.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ describe('lib/solidity/coder', function () {
4343
'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
4444
test({ type: 'bytes32', value: '0xc3a40000c3a4',
4545
expected: 'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
46+
test({ type: 'bytes64', value: '0xc3a40000c3a40000000000000000000000000000000000000000000000000000' +
47+
'c3a40000c3a40000000000000000000000000000000000000000000000000000',
48+
expected: 'c3a40000c3a40000000000000000000000000000000000000000000000000000' +
49+
'c3a40000c3a40000000000000000000000000000000000000000000000000000'});
4650
test({ type: 'string', value: 'ää',
4751
expected: '0000000000000000000000000000000000000000000000000000000000000020' +
4852
'0000000000000000000000000000000000000000000000000000000000000008' +

0 commit comments

Comments
 (0)