diff --git a/common/hexutil/hexutil.go b/common/hexutil/hexutil.go index 29e6de3335155b6cc990e8c5c6117ec357a55294..4ec0ee8e625368db6105b007daafe4e0b6630012 100644 --- a/common/hexutil/hexutil.go +++ b/common/hexutil/hexutil.go @@ -169,12 +169,7 @@ func EncodeBig(bigint *big.Int) string { if nbits == 0 { return "0x0" } - enc := make([]byte, 2, (nbits/8)*2+2) - copy(enc, "0x") - for i := len(bigint.Bits()) - 1; i >= 0; i-- { - enc = strconv.AppendUint(enc, uint64(bigint.Bits()[i]), 16) - } - return string(enc) + return fmt.Sprintf("0x%x", bigint) } func has0xPrefix(input string) bool { diff --git a/common/hexutil/hexutil_test.go b/common/hexutil/hexutil_test.go index b58b4745c5109a2f4bf3ea1be98a1c97a5bfd0b8..324e9d34817abcc8455b9b96f02422dd8264df81 100644 --- a/common/hexutil/hexutil_test.go +++ b/common/hexutil/hexutil_test.go @@ -46,6 +46,7 @@ var ( {referenceBig("1"), "0x1"}, {referenceBig("ff"), "0xff"}, {referenceBig("112233445566778899aabbccddeeff"), "0x112233445566778899aabbccddeeff"}, + {referenceBig("80a7f2c1bcc396c00"), "0x80a7f2c1bcc396c00"}, } encodeUint64Tests = []marshalTest{ diff --git a/common/hexutil/json.go b/common/hexutil/json.go index c36d862b5ec272679934e499947c3c21cde59b8c..7e4736dd68e58536c1d203cee013b4e0d1875129 100644 --- a/common/hexutil/json.go +++ b/common/hexutil/json.go @@ -109,13 +109,8 @@ func (b *Big) MarshalJSON() ([]byte, error) { if nbits == 0 { return jsonZero, nil } - enc := make([]byte, 3, (nbits/8)*2+4) - copy(enc, `"0x`) - for i := len(bigint.Bits()) - 1; i >= 0; i-- { - enc = strconv.AppendUint(enc, uint64(bigint.Bits()[i]), 16) - } - enc = append(enc, '"') - return enc, nil + enc := fmt.Sprintf(`"0x%x"`, bigint) + return []byte(enc), nil } // UnmarshalJSON implements json.Unmarshaler.