@@ -428,10 +428,13 @@ function isBase10NumStr(x) {
428
428
429
429
// Ensure a param is represented by a buffer
430
430
// TODO: Remove circular dependency in util.js so that we can put this function there
431
- function ensureHexBuffer ( x ) {
431
+ function ensureHexBuffer ( x , zeroIsNull = true ) {
432
432
try {
433
- // For null values, return a 0-sized buffer
434
- if ( x === null ) return Buffer . alloc ( 0 ) ;
433
+ // For null values, return a 0-sized buffer. For most situations we assume
434
+ // 0 should be represented with a zero-length buffer (e.g. for RLP-building
435
+ // txs), but it can also be treated as a 1-byte buffer (`00`) if needed
436
+ if ( x === null || ( x === 0 && zeroIsNull === true ) )
437
+ return Buffer . alloc ( 0 ) ;
435
438
const isNumber = typeof x === 'number' || isBase10NumStr ( x ) ;
436
439
// Otherwise try to get this converted to a hex string
437
440
if ( isNumber ) {
@@ -646,7 +649,8 @@ function parseEIP712Item(data, type, isEthers=false) {
646
649
data = `0x${ data . toString ( 'hex' ) } `
647
650
}
648
651
} else if ( type === 'uint8' || type === 'uint16' || type === 'uint32' || type === 'uint64' ) {
649
- data = parseInt ( ensureHexBuffer ( data ) . toString ( 'hex' ) , 16 )
652
+ // In this case we want the hex buffer to represent `0` as a 1-byte buffer (`00`)
653
+ data = parseInt ( ensureHexBuffer ( data , false ) . toString ( 'hex' ) , 16 )
650
654
} else if ( type === 'uint256' ) {
651
655
let b = ensureHexBuffer ( data ) ;
652
656
// Edge case to handle 0-value bignums
0 commit comments