Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta.2 Releases #946

Merged
merged 7 commits into from
Nov 12, 2020
9 changes: 7 additions & 2 deletions packages/vm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## 5.0.0-beta.2 - 2020-11-12

This is the second beta release towards a final library release, see [beta.1 release notes](https://github.com/ethereumjs/ethereumjs-vm/releases/tag/%40ethereumjs%2Fvm%405.0.0-beta.1) for an overview on the full changes since the last publicly released version.

- Fixed `SSTORE` gas calculation on `constantinople`, PR [#931](https://github.com/ethereumjs/ethereumjs-vm/pull/931)
- Visibility cleanup (Renaming and/or code docs additions) for class members not being part of the API, PR [#925](https://github.com/ethereumjs/ethereumjs-vm/pull/925)

Expand Down Expand Up @@ -91,8 +93,11 @@ PR [#872](https://github.com/ethereumjs/ethereumjs-vm/pull/872).
This API can be used as follows:

```typescript
import VM from 'ethereumjs-vm'
const vm = new VM({ eips: [2537] })
import Common from '@ethereumjs/common'
import VM from '@ethereumjs/vm'

const common = new Common({ chain: 'mainnet', eips: [2537] })
const vm = new VM({ common })
```

### API Change: New Major Library Versions
Expand Down
188 changes: 95 additions & 93 deletions packages/vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,22 @@
[![Code Coverage][vm-coverage-badge]][vm-coverage-link]
[![Discord][discord-badge]][discord-link]

Implements Ethereum's VM in Javascript.
Implements Ethereum's VM in `TypeScript`.

#### Fork Support

The VM currently supports the following hardfork rules:

- `Chainstart` (a.k.a. Frontier) (v5, UNRELEASED)
- `Homestead` (v5, UNRELEASED)
- `TangerineWhistle` (v5, UNRELEASED)
- `SpuriousDragon` (v5, UNRELEASED)
- `Byzantium`
- `Constantinople`
- `Petersburg` (default)
- `Istanbul`
- `MuirGlacier` (only `mainnet` and `ropsten`)

##### MuirGlacier Hardfork Support

An Ethereum test suite compliant `MuirGlacier` HF implementation is available
since the `v4.1.3` VM release. You can activate a `MuirGlacier` VM by using the
`muirGlacier` `hardfork` option flag.

**Note:** The original `v4.1.2` release contains a critical bug preventing the
`MuirGlacier` VM to work properly and there is the need to update.

##### Istanbul Harfork Support

An Ethereum test suite compliant `Istanbul` HF implementation is available
since the `v4.1.1` VM release. You can activate an `Istanbul` VM by using the
`istanbul` `hardfork` option flag.

Supported `Istanbul` EIPs:

- [EIP-152](https://eips.ethereum.org/EIPS/eip-152): Blake 2b `F` precompile,
PR [#584](https://github.com/ethereumjs/ethereumjs-vm/pull/584)
- [EIP-1108](https://eips.ethereum.org/EIPS/eip-1108): Reduce `alt_bn128`
precompile gas costs,
PR [#540](https://github.com/ethereumjs/ethereumjs-vm/pull/540)
(already released in `v4.0.0`)
- [EIP-1344](https://eips.ethereum.org/EIPS/eip-1344): Add ChainID Opcode,
PR [#572](https://github.com/ethereumjs/ethereumjs-vm/pull/572)
- [EIP-1884](https://eips.ethereum.org/EIPS/eip-1884): Trie-size-dependent
Opcode Repricing,
PR [#581](https://github.com/ethereumjs/ethereumjs-vm/pull/581)
- [EIP-2200](https://eips.ethereum.org/EIPS/eip-2200): Rebalance net-metered
SSTORE gas costs,
PR [#590](https://github.com/ethereumjs/ethereumjs-vm/pull/590)

#### EIP Support

It is possible to individually activate EIP support in the VM. In order to do so, pass an array to the `eips` field of the VMs options, such as `new VM({ eips: [ 2537 ]})`.

Currently supported EIPs are:

- [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537): BLS precompiles
Note: this `README` reflects the state of the library from `v5.0.0` onwards. See `README` from the [standalone repository](https://github.com/ethereumjs/ethereumjs-vm) for an introduction on the last preceeding release.

# INSTALL

`npm install ethereumjs-vm`
`npm install @ethereumjs/vm`

# USAGE

```javascript
```typescript
import { BN } from 'ethereumjs-util'
import Common from '@ethereumjs/common'
import VM from '@ethereumjs/vm'

const common = new Common({ chain: 'mainnet', hardfork: 'istanbul' })
const common = new Common({ chain: 'mainnet' })
const vm = new VM({ common })

const STOP = '00'
Expand Down Expand Up @@ -110,10 +58,6 @@ This projects contain the following examples:

All of the examples have their own `README.md` explaining how to run them.

# BROWSER

To build the VM for standalone use in the browser, see: [Running the VM in a browser](https://github.com/ethereumjs/ethereumjs-vm/tree/master/examples/run-code-browser).

# API

## VM
Expand All @@ -122,44 +66,67 @@ For documentation on `VM` instantiation, exposed API and emitted `events` see ge

## StateManager

The API for the `StateManager` is currently in `Beta`, separate documentation can be found [here](./docs/classes/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.
Documentation on the `StateManager` can be found [here](./docs/classes/_state_statemanager_.defaultstatemanager.md). If you want to provide your own `StateManager` you can implement the dedicated [interface](./docs/interfaces/_state_interface_.statemanager.md) to ensure that your implementation conforms with the current API.

# Internal Structure
# BROWSER

The VM processes state changes at many levels.
To build the VM for standalone use in the browser, see: [Running the VM in a browser](https://github.com/ethereumjs/ethereumjs-vm/tree/master/examples/run-code-browser).

- **runBlockchain**
- for every block, runBlock
- **runBlock**
- for every tx, runTx
- pay miner and uncles
- **runTx**
- check sender balance
- check sender nonce
- runCall
- transfer gas charges
- **runCall**
- checkpoint state
- transfer value
- load code
- runCode
- materialize created contracts
- revert or commit checkpoint
- **runCode**
- iterate over code
- run op codes
- track gas usage
- **OpFns**
- run individual op code
- modify stack
- modify memory
- calculate fee
# SETUP

The opFns for `CREATE`, `CALL`, and `CALLCODE` call back up to `runCall`.
## Hardfork Support

Starting with the `v5` release series all hardforks from `Frontier` (`chainstart`) up to the latest active mainnet hardfork are supported.

The VM currently supports the following hardfork rules:

- `chainstart` (a.k.a. Frontier) (`v5.0.0`+)
- `homestead` (`v5.0.0`+)
- `tangerineWhistle` (`v5.0.0`+)
- `spuriousDragon` (`v5.0.0`+)
- `byzantium`
- `constantinople`
- `petersburg`
- `istanbul` (`v4.1.1`+)
- `muirGlacier` (only `mainnet` and `ropsten`) (`v4.1.3`+)
- `berlin` (`DRAFT`, only `EIP-2315`)
holgerd77 marked this conversation as resolved.
Show resolved Hide resolved

## VM's tracing events
Default: `istanbul` (taken from `Common.DEFAULT_HARDFORK`)

You can subscribe to the following events of the VM:
A specific hardfork VM ruleset can be activated by passing in the hardfork
along the `Common` instance:

```typescript
import Common from '@ethereumjs/common'
import VM from '@ethereumjs/vm'

const common = new Common({ chain: 'mainnet', hardfork: 'byzantium' })
const vm = new VM({ common })
```

## EIP Support

It is possible to individually activate EIP support in the VM by instantiate the `Common` instance passed
with the respective EIPs, e.g.:

```typescript
import Common from '@ethereumjs/common'
import VM from '@ethereumjs/vm'

const common = new Common({ chain: 'mainnet', eips: [2537] })
const vm = new VM({ common })
```

Currently supported EIPs:

- [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537): BLS precompiles
- [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929): gas cost increases for state access opcodes

## Tracing Events

Our `TypeScript` VM is implemented as an [AsyncEventEmitter](https://github.com/ahultgren/async-eventemitter) and events are submitted along major execution steps which you can listen to.

You can subscribe to the following events:

- `beforeBlock`: Emits a `Block` right before running it.
- `afterBlock`: Emits `RunBlockResult` right after running a block.
Expand All @@ -170,6 +137,8 @@ You can subscribe to the following events of the VM:
- `step`: Emits an `InterpreterStep` right before running an EVM step.
- `newContract`: Emits a `NewContractEvent` right before creating a contract. This event contains the deployment code, not the deployed code, as the creation message may not return such a code.

An example for the `step` event can be found in the initial usage example in this `README`.

### Asynchronous event handlers

You can perform asynchronous operations from within an event handler
Expand Down Expand Up @@ -197,6 +166,39 @@ by it, the exception will bubble into the VM and interrupt it, possibly
corrupting its state. It's strongly recommended not to throw from withing
event handlers.

# Internal Structure

The VM processes state changes at many levels.

- **runBlockchain**
- for every block, runBlock
- **runBlock**
- for every tx, runTx
- pay miner and uncles
- **runTx**
- check sender balance
- check sender nonce
- runCall
- transfer gas charges
- **runCall**
- checkpoint state
- transfer value
- load code
- runCode
- materialize created contracts
- revert or commit checkpoint
- **runCode**
- iterate over code
- run op codes
- track gas usage
- **OpFns**
- run individual op code
- modify stack
- modify memory
- calculate fee

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

# DEVELOPMENT

Developer documentation - currently mainly with information on testing and debugging - can be found [here](./developer.md).
Expand Down
12 changes: 6 additions & 6 deletions packages/vm/docs/classes/_index_.vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ___

▸ **copy**(): *[VM](_index_.vm.md)*

*Defined in [index.ts:324](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L324)*
*Defined in [index.ts:326](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L326)*

Returns a copy of the [VM](_index_.vm.md) instance.

Expand All @@ -121,7 +121,7 @@ ___

▸ **runBlock**(`opts`: [RunBlockOpts](../interfaces/_runblock_.runblockopts.md)): *Promise‹[RunBlockResult](../interfaces/_runblock_.runblockresult.md)›*

*Defined in [index.ts:278](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L278)*
*Defined in [index.ts:280](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L280)*

Processes the `block` running all of the transactions it contains and updating the miner's account

Expand All @@ -143,7 +143,7 @@ ___

▸ **runBlockchain**(`blockchain?`: Blockchain): *Promise‹void›*

*Defined in [index.ts:263](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L263)*
*Defined in [index.ts:265](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L265)*

Processes blocks and adds them to the blockchain.

Expand All @@ -163,7 +163,7 @@ ___

▸ **runCall**(`opts`: [RunCallOpts](../interfaces/_runcall_.runcallopts.md)): *Promise‹[EVMResult](../interfaces/_evm_evm_.evmresult.md)›*

*Defined in [index.ts:304](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L304)*
*Defined in [index.ts:306](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L306)*

runs a call (or create) operation.

Expand All @@ -183,7 +183,7 @@ ___

▸ **runCode**(`opts`: [RunCodeOpts](../interfaces/_runcode_.runcodeopts.md)): *Promise‹[ExecResult](../interfaces/_evm_evm_.execresult.md)›*

*Defined in [index.ts:316](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L316)*
*Defined in [index.ts:318](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L318)*

Runs EVM code.

Expand All @@ -203,7 +203,7 @@ ___

▸ **runTx**(`opts`: [RunTxOpts](../interfaces/_runtx_.runtxopts.md)): *Promise‹[RunTxResult](../interfaces/_runtx_.runtxresult.md)›*

*Defined in [index.ts:292](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L292)*
*Defined in [index.ts:294](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L294)*

Process a transaction. Run the vm. Transfers eth. Checks balances.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

▸ (`runState`: RunState): *Promise‹void›*

*Defined in [evm/opcodes/functions.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L34)*
*Defined in [evm/opcodes/functions.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L35)*

**Parameters:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

▸ (`runState`: RunState): *void*

*Defined in [evm/opcodes/functions.ts:30](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L30)*
*Defined in [evm/opcodes/functions.ts:31](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L31)*

**Parameters:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

▸ (`runState`: RunState): *Promise‹void›*

*Defined in [evm/opcodes/functions.ts:34](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L34)*
*Defined in [evm/opcodes/functions.ts:35](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L35)*

**Parameters:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

▸ (`runState`: RunState): *void*

*Defined in [evm/opcodes/functions.ts:30](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L30)*
*Defined in [evm/opcodes/functions.ts:31](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L31)*

**Parameters:**

Expand Down
15 changes: 11 additions & 4 deletions packages/vm/docs/modules/_evm_opcodes_functions_.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

Ƭ **OpHandler**: *[SyncOpHandler](../interfaces/_evm_opcodes_functions_.syncophandler.md) | [AsyncOpHandler](../interfaces/_evm_opcodes_functions_.asyncophandler.md)*

*Defined in [evm/opcodes/functions.ts:38](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L38)*
*Defined in [evm/opcodes/functions.ts:39](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L39)*

## Variables

Expand Down Expand Up @@ -736,8 +736,15 @@
// TODO: Replace getContractStorage with EEI method
const found = await getContractStorage(runState, runState.eei.getAddress(), keyBuf)
accessStorageEIP2929(runState, keyBuf, true)
updateSstoreGasEIP1283(runState, found, setLengthLeftStorage(value))
updateSstoreGasEIP2200(runState, found, setLengthLeftStorage(value), keyBuf)

if (runState._common.hardfork() === 'constantinople') {
updateSstoreGasEIP1283(runState, found, setLengthLeftStorage(value))
} else if (runState._common.gteHardfork('istanbul')) {
updateSstoreGasEIP2200(runState, found, setLengthLeftStorage(value), keyBuf)
} else {
updateSstoreGas(runState, found, setLengthLeftStorage(value), keyBuf)
}

await runState.eei.storageStore(keyBuf, value)
},
],
Expand Down Expand Up @@ -1199,4 +1206,4 @@
],
])

*Defined in [evm/opcodes/functions.ts:41](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L41)*
*Defined in [evm/opcodes/functions.ts:42](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/evm/opcodes/functions.ts#L42)*
Loading