Skip to content

Commit

Permalink
[VM] add Berlin state tests, add empty input test
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Sep 6, 2020
1 parent c39856d commit 2f24bf9
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 1,970 deletions.
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/vm/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ module.exports = function(config) {
'./tests/api/**/*.js': ['browserify'],
},

proxies: {
'/mcl_c384_256.wasm': '../../node_modules/mcl-wasm/mcl_c384_256.wasm'
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://www.npmjs.com/browse/keyword/karma-reporter
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/evm/precompiles/0c-bls12-g1multiexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function (opts: PrecompileInput): Promise<ExecResult> {
let inputData = opts.data

if (inputData.length == 0) {
return VmErrorResult(new VmError(ERROR.BLS_12_381_INPUT_EMPTY), new BN(0)) // follow Geths implementation
return VmErrorResult(new VmError(ERROR.BLS_12_381_INPUT_EMPTY), opts.gasLimit) // follow Geths implementation
}

const numPairs = Math.floor(inputData.length / 160)
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/evm/precompiles/0f-bls12-g2multiexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function (opts: PrecompileInput): Promise<ExecResult> {
let inputData = opts.data

if (inputData.length == 0) {
return VmErrorResult(new VmError(ERROR.BLS_12_381_INPUT_EMPTY), new BN(0)) // follow Geths implementation
return VmErrorResult(new VmError(ERROR.BLS_12_381_INPUT_EMPTY), opts.gasLimit) // follow Geths implementation
}

const numPairs = Math.floor(inputData.length / 288)
Expand Down
6 changes: 5 additions & 1 deletion packages/vm/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { precompiles } from './evm/precompiles'
import runBlockchain from './runBlockchain'
const AsyncEventEmitter = require('async-eventemitter')
const promisify = require('util.promisify')
const mcl = require('mcl-wasm')
let mcl = require('mcl-wasm')
if (Object.keys(mcl).length == 0) {
mcl = (<any>globalThis).window.mcl
}

const mclInitPromise = mcl.init(mcl.BLS12_381) // We can use the same instance of mcl for all VMs. The methods are static.

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"safe-buffer": "^5.1.1",
"util.promisify": "^1.0.1",
"util-callbackify": "^1.0.0",
"mcl-wasm": "^0.4.3"
"mcl-wasm": "^0.4.5"
},
"devDependencies": {
"@ethereumjs/config-nyc": "^1.1.1",
Expand Down
Loading

0 comments on commit 2f24bf9

Please sign in to comment.