Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Updated isPrecomile according to Byzantium precompile-used address space #115

Merged
merged 1 commit into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add isValidAddress?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, normally your are right. I wouldn't want this here, since the IsPrecompiled method is removed anyhow (citing @axic) on next major release. Adding isValidAddress would change the behavior here and would cause extra/unnecessary problems for people already have this in use.

return a.length === 1 && a[0] > 0 && a[0] < 5
return a.length === 1 && a[0] >= 1 && a[0] <= 8
}

/**
Expand Down
8 changes: 7 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

@fanatid fanatid Feb 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (let i = 1; i < 9; ++i) {
  assert.true(ethUtils.isPrecompiled(new BN(i).toString(10, 40)))
  assert.true(ethUtils.isPrecompiled(new BN(i).toBuffer('be', 20)))
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely more elegant, thanks for the suggestion. Unfortunately it kills the browser tests somehow due to Buffer usage, just tested it, and I didn't want to go deeper in debugging here, think this would be not worth it in this case. Is it ok to leave it as is?

Also, can you approve, If you are ok with both explanations?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this is ok let it as is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks.

})
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)
})
})

Expand Down