From 9ea16e5172928962792ba4c0273e23db373409e0 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 17 Mar 2020 13:55:45 -0400 Subject: [PATCH] Throw errors when trying to RLP encode integers. --- packages/bytes/src.ts/index.ts | 2 +- packages/rlp/src.ts/index.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/bytes/src.ts/index.ts b/packages/bytes/src.ts/index.ts index 1872e15cff..f291c5191a 100644 --- a/packages/bytes/src.ts/index.ts +++ b/packages/bytes/src.ts/index.ts @@ -97,7 +97,7 @@ export function arrayify(value: BytesLike | Hexable | number, options?: DataOpti const result = []; while (value) { result.unshift(value & 0xff); - value /= 256; + value = parseInt(String(value / 256)); } if (result.length === 0) { result.push(0); } diff --git a/packages/rlp/src.ts/index.ts b/packages/rlp/src.ts/index.ts index 6fd0dfad6e..1f00f1033c 100644 --- a/packages/rlp/src.ts/index.ts +++ b/packages/rlp/src.ts/index.ts @@ -2,8 +2,7 @@ //See: https://github.com/ethereum/wiki/wiki/RLP - -import { arrayify, BytesLike, hexlify } from "@ethersproject/bytes"; +import { arrayify, BytesLike, hexlify, isBytesLike } from "@ethersproject/bytes"; function arrayifyInteger(value: number): Array { const result = []; @@ -41,6 +40,10 @@ function _encode(object: Array | string): Array { } + if (!isBytesLike(object)) { + throw new Error("RLP object must be BytesLike"); + } + const data: Array = Array.prototype.slice.call(arrayify(object)); if (data.length === 1 && data[0] <= 0x7f) {