Skip to content

Commit

Permalink
Fix blockchain tests
Browse files Browse the repository at this point in the history
This fixes the last set of blockchain tests:

* RPC_API_Test
* randomStatetest224BC
* randomStatetest234BC
* randomStatetest529BC
* ExtraData32
* log1_correct
* timeDiff0
* timeDiff12
* timeDiff13
* timeDiff14

These were mostly caused by missing block validation and the intentional disparity between the bloom filter implementation and the yellow paper introduced in #295.
  • Loading branch information
mattdean-digicatapult committed Nov 7, 2018
1 parent 84db45e commit 45390ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
18 changes: 2 additions & 16 deletions lib/bloom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ const assert = require('assert')
const utils = require('ethereumjs-util')
const byteSize = 256

/**
* Drops leading zeroes from a buffer
* @function dropLeadingZeroes
* @param {Buffer} buff
* @returns {Buffer} a slice of the given buffer starting at the first non-zero entry
*/
function dropLeadingZeroes (buff) {
for (var i = 0; i < buff.length; i++) {
if (buff[i] !== 0) {
return buff.slice(i)
}
}
}

/**
* Represents a Bloom
* @constructor
Expand All @@ -36,7 +22,7 @@ var Bloom = module.exports = function (bitvector) {
* @param {Buffer} e the element to add
*/
Bloom.prototype.add = function (e) {
e = utils.keccak256(dropLeadingZeroes(e))
e = utils.keccak256(e)
var mask = 2047 // binary 11111111111

for (var i = 0; i < 3; i++) {
Expand All @@ -55,7 +41,7 @@ Bloom.prototype.add = function (e) {
* @returns {boolean} Returns {@code true} if the element is in the bloom
*/
Bloom.prototype.check = function (e) {
e = utils.keccak256(dropLeadingZeroes(e))
e = utils.keccak256(e)
var mask = 2047 // binary 11111111111
var match = true

Expand Down
11 changes: 8 additions & 3 deletions lib/runBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports = function (opts, cb) {

// parse options
const block = opts.block
const skipBlockValidation = opts.skipBlockValidation || false
const generateStateRoot = !!opts.generate
const validateStateRoot = !generateStateRoot
const bloom = new Bloom()
Expand Down Expand Up @@ -80,10 +81,14 @@ module.exports = function (opts, cb) {
}

function validateBlock (cb) {
if (new BN(block.header.gasLimit).gte(new BN('8000000000000000', 16))) {
cb(new Error('Invalid block with gas limit greater than (2^63 - 1)'))
} else {
if (skipBlockValidation) {
cb()
} else {
if (new BN(block.header.gasLimit).gte(new BN('8000000000000000', 16))) {
cb(new Error('Invalid block with gas limit greater than (2^63 - 1)'))
} else {
block.validate(self.blockchain, cb)
}
}
}

Expand Down

0 comments on commit 45390ac

Please sign in to comment.