From 76851911bcfba0f8f263e5ba60edab3addfe87a8 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Fri, 2 Feb 2018 09:55:35 +0100 Subject: [PATCH] Updated isPrecomile according to Byzantium precompile-used address space --- index.js | 4 ++-- test/index.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 55d112b1..fa9a584a 100644 --- a/index.js +++ b/index.js @@ -510,13 +510,13 @@ exports.generateAddress = function (from, nonce) { } /** - * Returns true if the supplied address belongs to a precompiled account + * Returns true if the supplied address belongs to a precompiled account (Byzantium) * @param {Buffer|String} address * @return {Boolean} */ exports.isPrecompiled = function (address) { const a = exports.unpad(address) - return a.length === 1 && a[0] > 0 && a[0] < 5 + return a.length === 1 && a[0] >= 1 && a[0] <= 8 } /** diff --git a/test/index.js b/test/index.js index 1b22a886..72650b81 100644 --- a/test/index.js +++ b/test/index.js @@ -411,11 +411,17 @@ describe('isPrecompiled', function () { assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000002'), true) assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000003'), true) assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000004'), true) + assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000005'), true) + assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000006'), true) + assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000007'), true) + assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000008'), true) + assert.equal(ethUtils.isPrecompiled(Buffer.from('0000000000000000000000000000000000000001', 'hex')), true) }) it('should return false', function () { assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000000'), false) - assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000005'), false) + assert.equal(ethUtils.isPrecompiled('0000000000000000000000000000000000000009'), false) assert.equal(ethUtils.isPrecompiled('1000000000000000000000000000000000000000'), false) + assert.equal(ethUtils.isPrecompiled(Buffer.from('0000000000000000000000000000000000000000', 'hex')), false) }) })