Skip to content

Commit 7680b82

Browse files
authored
Merge pull request ethereumjs#479 from ethereumjs/v4
V4 tracker
2 parents 068db32 + 00f99c2 commit 7680b82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+4055
-3562
lines changed

.babelrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"presets": [
33
[
4-
"env"
4+
"@babel/preset-env",
55
]
6-
]
7-
}
6+
],
7+
"plugins": ["@babel/plugin-transform-runtime"]
8+
}

.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
.vscode
3+
package.json
4+
dist
5+
.nyc_output
6+
*.json
7+
docs

CHANGELOG.md

Lines changed: 119 additions & 117 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# SYNOPSIS
22

33
[![NPM Package](https://img.shields.io/npm/v/ethereumjs-vm.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-vm)
4-
[![Build Status](
5-
https://img.shields.io/circleci/project/github/ethereumjs/ethereumjs-vm/master.svg
6-
)](https://circleci.com/gh/ethereumjs/ethereumjs-vm)
4+
[![Build Status](https://img.shields.io/circleci/project/github/ethereumjs/ethereumjs-vm/master.svg)](https://circleci.com/gh/ethereumjs/ethereumjs-vm)
75
[![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-vm.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-vm)
86
[![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs)
97

@@ -19,27 +17,35 @@ The VM currently supports the following hardfork rules:
1917
- `Constantinople`
2018
- `Petersburg` (default)
2119

22-
If you are still looking for a [Spurious Dragon](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-607.md) compatible version of this library install the latest of the ``2.2.x`` series (see [Changelog](./CHANGELOG.md)).
20+
If you are still looking for a [Spurious Dragon](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-607.md) compatible version of this library install the latest of the `2.2.x` series (see [Changelog](./CHANGELOG.md)).
2321

2422
# INSTALL
23+
2524
`npm install ethereumjs-vm`
2625

2726
# USAGE
27+
2828
```javascript
2929
var VM = require('ethereumjs-vm')
3030

3131
//create a new VM instance
3232
var vm = new VM()
33-
var code = '7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3'
34-
35-
vm.runCode({
36-
code: Buffer.from(code, 'hex'), // code needs to be a Buffer
37-
gasLimit: Buffer.from('ffffffff', 'hex')
38-
}, function(err, results){
39-
console.log('returned: ' + results.return.toString('hex'));
40-
})
33+
var code =
34+
'7f4e616d65526567000000000000000000000000000000000000000000000000003055307f4e616d6552656700000000000000000000000000000000000000000000000000557f436f6e666967000000000000000000000000000000000000000000000000000073661005d2720d855f1d9976f88bb10c1a3398c77f5573661005d2720d855f1d9976f88bb10c1a3398c77f7f436f6e6669670000000000000000000000000000000000000000000000000000553360455560df806100c56000396000f3007f726567697374657200000000000000000000000000000000000000000000000060003514156053576020355415603257005b335415603e5760003354555b6020353360006000a233602035556020353355005b60007f756e72656769737465720000000000000000000000000000000000000000000060003514156082575033545b1560995733335460006000a2600033545560003355005b60007f6b696c6c00000000000000000000000000000000000000000000000000000000600035141560cb575060455433145b1560d25733ff5b6000355460005260206000f3'
35+
36+
vm.runCode(
37+
{
38+
code: Buffer.from(code, 'hex'), // code needs to be a Buffer
39+
gasLimit: Buffer.from('ffffffff', 'hex'),
40+
},
41+
function(err, results) {
42+
console.log('returned: ' + results.return.toString('hex'))
43+
},
44+
)
4145
```
46+
4247
Also more examples can be found here
48+
4349
- [examples](./examples)
4450
- [old blog post](https://wanderer.github.io/ethereum/nodejs/code/2014/08/12/running-contracts-with-vm/)
4551

@@ -51,48 +57,48 @@ To build for standalone use in the browser, install `browserify` and check [run-
5157

5258
## VM
5359

54-
For documentation on ``VM`` instantiation, exposed API and emitted ``events`` see generated [API docs](./docs/index.md).
60+
For documentation on `VM` instantiation, exposed API and emitted `events` see generated [API docs](./docs/index.md).
5561

5662
## StateManger
5763

58-
The API for the ``StateManager`` is currently in ``Beta``, separate documentation can be found [here](./docs/stateManager.md), see also [release notes](https://github.com/ethereumjs/ethereumjs-vm/releases/tag/v2.5.0) from the ``v2.5.0`` VM release for details on the ``StateManager`` rewrite.
64+
The API for the `StateManager` is currently in `Beta`, separate documentation can be found [here](./docs/stateManager.md), see also [release notes](https://github.com/ethereumjs/ethereumjs-vm/releases/tag/v2.5.0) from the `v2.5.0` VM release for details on the `StateManager` rewrite.
5965

6066
# Internal Structure
67+
6168
The VM processes state changes at many levels.
6269

63-
* **runBlockchain**
64-
* for every block, runBlock
65-
* **runBlock**
66-
* for every tx, runTx
67-
* pay miner and uncles
68-
* **runTx**
69-
* check sender balance
70-
* check sender nonce
71-
* runCall
72-
* transfer gas charges
73-
* **runCall**
74-
* checkpoint state
75-
* transfer value
76-
* load code
77-
* runCode
78-
* materialize created contracts
79-
* revert or commit checkpoint
80-
* **runCode**
81-
* iterate over code
82-
* run op codes
83-
* track gas usage
84-
* **OpFns**
85-
* run individual op code
86-
* modify stack
87-
* modify memory
88-
* calculate fee
70+
- **runBlockchain**
71+
- for every block, runBlock
72+
- **runBlock**
73+
- for every tx, runTx
74+
- pay miner and uncles
75+
- **runTx**
76+
- check sender balance
77+
- check sender nonce
78+
- runCall
79+
- transfer gas charges
80+
- **runCall**
81+
- checkpoint state
82+
- transfer value
83+
- load code
84+
- runCode
85+
- materialize created contracts
86+
- revert or commit checkpoint
87+
- **runCode**
88+
- iterate over code
89+
- run op codes
90+
- track gas usage
91+
- **OpFns**
92+
- run individual op code
93+
- modify stack
94+
- modify memory
95+
- calculate fee
8996

9097
The opFns for `CREATE`, `CALL`, and `CALLCODE` call back up to `runCall`.
9198

92-
9399
# DEVELOPMENT
94100

95-
Developer documentation - currently mainly with information on testing and debugging - can be found [here](./docs/developer.md).
101+
Developer documentation - currently mainly with information on testing and debugging - can be found [here](./docs/developer.md).
96102

97103
# EthereumJS
98104

@@ -101,4 +107,5 @@ See our organizational [documentation](https://ethereumjs.readthedocs.io) for an
101107
If you want to join for work or do improvements on the libraries have a look at our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html).
102108

103109
# LICENSE
110+
104111
[MPL-2.0](https://www.mozilla.org/MPL/2.0/)

examples/run-blockchain/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const BlockHeader = require('ethereumjs-block/header.js')
77
const VM = require('../../')
88
const level = require('level')
99
const levelMem = require('level-mem')
10-
const Account = require('ethereumjs-account')
10+
const Account = require('ethereumjs-account').default
1111
const utils = require('ethereumjs-util')
1212
const BN = utils.BN
1313
const rlp = utils.rlp

examples/run-transactions-complete/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var Buffer = require('safe-buffer').Buffer // use for Node.js <4.5.0
99
var async = require('async')
1010
var VM = require('./../../index.js')
11-
var Account = require('ethereumjs-account')
11+
var Account = require('ethereumjs-account').default
1212
var Transaction = require('ethereumjs-tx')
1313
var Trie = require('merkle-patricia-tree')
1414
var rlp = require('rlp')

examples/run-transactions-simple/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Run command
1212
$ browserify index.js -o bundle.js
1313
```
1414

15-
Then host this folder in a web server
15+
Then host this folder in a web server
1616

1717
```
1818
$ http-server

index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/bloom/index.js renamed to lib/bloom/index.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
const assert = require('assert')
2-
const utils = require('ethereumjs-util')
1+
import * as assert from 'assert'
2+
import { zeros, keccak256 } from 'ethereumjs-util'
33

44
const BYTE_SIZE = 256
55

6-
module.exports = class Bloom {
6+
export default class Bloom {
7+
bitvector: Buffer
8+
79
/**
810
* Represents a Bloom
911
* @constructor
1012
* @param {Buffer} bitvector
1113
*/
12-
constructor (bitvector) {
14+
constructor(bitvector?: Buffer) {
1315
if (!bitvector) {
14-
this.bitvector = utils.zeros(BYTE_SIZE)
16+
this.bitvector = zeros(BYTE_SIZE)
1517
} else {
1618
assert(bitvector.length === BYTE_SIZE, 'bitvectors must be 2048 bits long')
1719
this.bitvector = bitvector
@@ -21,10 +23,11 @@ module.exports = class Bloom {
2123
/**
2224
* adds an element to a bit vector of a 64 byte bloom filter
2325
* @method add
24-
* @param {Buffer|Array|String|Number} e the element to add
26+
* @param {Buffer} e the element to add
2527
*/
26-
add (e) {
27-
e = utils.keccak256(e)
28+
add(e: Buffer) {
29+
assert(Buffer.isBuffer(e), 'Element should be buffer')
30+
e = keccak256(e)
2831
const mask = 2047 // binary 11111111111
2932

3033
for (let i = 0; i < 3; i++) {
@@ -39,11 +42,12 @@ module.exports = class Bloom {
3942
/**
4043
* checks if an element is in the bloom
4144
* @method check
42-
* @param {Buffer|Array|String|Number} e the element to check
45+
* @param {Buffer} e the element to check
4346
* @returns {boolean} Returns {@code true} if the element is in the bloom
4447
*/
45-
check (e) {
46-
e = utils.keccak256(e)
48+
check(e: Buffer): boolean {
49+
assert(Buffer.isBuffer(e), 'Element should be Buffer')
50+
e = keccak256(e)
4751
const mask = 2047 // binary 11111111111
4852
let match = true
4953

@@ -52,7 +56,7 @@ module.exports = class Bloom {
5256
const loc = mask & first2bytes
5357
const byteLoc = loc >> 3
5458
const bitLoc = 1 << loc % 8
55-
match = (this.bitvector[BYTE_SIZE - byteLoc - 1] & bitLoc)
59+
match = (this.bitvector[BYTE_SIZE - byteLoc - 1] & bitLoc) !== 0
5660
}
5761

5862
return Boolean(match)
@@ -61,19 +65,19 @@ module.exports = class Bloom {
6165
/**
6266
* checks if multiple topics are in a bloom
6367
* @method multiCheck
64-
* @param {Buffer[]|Array[]|String[]|Number[]} topics
68+
* @param {Buffer[]} topics
6569
* @returns {boolean} Returns {@code true} if every topic is in the bloom
6670
*/
67-
multiCheck (topics) {
68-
return topics.every((t) => this.check(t))
71+
multiCheck(topics: Buffer[]): boolean {
72+
return topics.every((t: Buffer) => this.check(t))
6973
}
7074

7175
/**
7276
* bitwise or blooms together
7377
* @method or
7478
* @param {Bloom} bloom
7579
*/
76-
or (bloom) {
80+
or(bloom: Bloom) {
7781
if (bloom) {
7882
for (let i = 0; i <= BYTE_SIZE; i++) {
7983
this.bitvector[i] = this.bitvector[i] | bloom.bitvector[i]

0 commit comments

Comments
 (0)