Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c053761
block -> refactor: reworked header class with static factory instanti…
holgerd77 Sep 21, 2020
ff46c55
block -> refactoring: added new static factory helpers to block class
holgerd77 Sep 21, 2020
dd228bc
block -> refactor: fix build errors, remove unused imports, unpad num…
jochem-brouwer Sep 24, 2020
608d804
block -> rename Header to BlockHeader
jochem-brouwer Sep 28, 2020
17a33a8
block/tx -> fix block tests
jochem-brouwer Sep 28, 2020
72b5b78
block -> enforce BNs on fields which are interpreted as numbers
jochem-brouwer Sep 28, 2020
8adcdf9
block -> edge case in toBN
jochem-brouwer Sep 29, 2020
8987003
ethash -> make ethash compatible with block
jochem-brouwer Sep 29, 2020
5f5e9f2
Merge branch 'master' into refactor-block-library
ryanio Oct 7, 2020
5351fb8
have validateTransactions return a string[] (https://github.com/ether…
ryanio Oct 7, 2020
ce1dac1
let => const
ryanio Oct 7, 2020
526f986
set default param to resolve js runtime check
ryanio Oct 7, 2020
75689e6
continue refactoring and simplifying methods
ryanio Oct 8, 2020
8923f71
api updates
ryanio Oct 8, 2020
6a2c193
continuing work
ryanio Oct 8, 2020
381f5e1
inline buffer validations. add checks for extraData, mixHash and nonce
ryanio Oct 8, 2020
7eecf80
various fixups
ryanio Oct 8, 2020
395c6f8
continuing various work
ryanio Oct 9, 2020
be5c8d2
continuing work and refactoring
ryanio Oct 9, 2020
7fa486d
Merge branch 'master' into refactor-block-library
ryanio Oct 9, 2020
91d45d7
re-add timestamp to genesis (for rinkeby)
ryanio Oct 9, 2020
7e788c3
last fixups
ryanio Oct 9, 2020
bc459e8
update readme, benchmarks
ryanio Oct 9, 2020
ea8a401
update vm readme, simplify validate
ryanio Oct 10, 2020
b694010
fix timestamp validation
ryanio Oct 10, 2020
1f66378
use native eq
ryanio Oct 10, 2020
9f9bab0
make blockchain optional in block.validate()
ryanio Oct 10, 2020
7ce9132
fixups
ryanio Oct 10, 2020
a5d3d14
remove BLOCK_difficulty_GivenAsList from skip list (https://github.co…
ryanio Oct 12, 2020
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
Prev Previous commit
Next Next commit
last fixups
  • Loading branch information
ryanio committed Oct 9, 2020
commit 7e788c35dc938374380c94876684b901d1981843
10 changes: 5 additions & 5 deletions packages/vm/lib/evm/eei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,35 +245,35 @@ export default class EEI {
* Returns the block’s number.
*/
getBlockNumber(): BN {
return new BN(this._env.block.header.number)
return this._env.block.header.number
}

/**
* Returns the block's beneficiary address.
*/
getBlockCoinbase(): BN {
return new BN(this._env.block.header.coinbase)
return new BN(this._env.block.header.coinbase.buf)
}

/**
* Returns the block's timestamp.
*/
getBlockTimestamp(): BN {
return new BN(this._env.block.header.timestamp)
return this._env.block.header.timestamp
}

/**
* Returns the block's difficulty.
*/
getBlockDifficulty(): BN {
return new BN(this._env.block.header.difficulty)
return this._env.block.header.difficulty
}

/**
* Returns the block's gas limit.
*/
getBlockGasLimit(): BN {
return new BN(this._env.block.header.gasLimit)
return this._env.block.header.gasLimit
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/evm/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export default class EVM {
depth: message.depth || 0,
gasPrice: this._tx.gasPrice,
origin: this._tx.origin || message.caller || zeros(32),
block: this._block || Block.fromBlockData(),
block: this._block || new Block(),
contract: await this._state.getAccount(message.to || zeros(32)),
codeAddress: message.codeAddress,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/runCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface RunCallOpts {
* @ignore
*/
export default function runCall(this: VM, opts: RunCallOpts): Promise<EVMResult> {
const block = opts.block || Block.fromBlockData()
const block = opts.block || new Block()

const txContext = new TxContext(
opts.gasPrice || new BN(0),
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/lib/runCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface RunCodeOpts {
*/
export default function runCode(this: VM, opts: RunCodeOpts): Promise<ExecResult> {
if (!opts.block) {
opts.block = Block.fromBlockData()
opts.block = new Block()
}

// Backwards compatibility
Expand Down
9 changes: 5 additions & 4 deletions packages/vm/lib/runTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default async function runTx(this: VM, opts: RunTxOpts): Promise<RunTxRes

async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
const state = this.stateManager
const { block, tx } = opts
const { tx, block } = opts

/**
* The `beforeTx` event
Expand Down Expand Up @@ -152,7 +152,7 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
results.gasUsed.iadd(basefee)
// Process any gas refund
const gasRefund = evm._refund
if (gasRefund) {
if (gasRefund.gtn(0)) {
if (gasRefund.lt(results.gasUsed.divn(2))) {
results.gasUsed.isub(gasRefund)
} else {
Expand All @@ -171,14 +171,15 @@ async function _runTx(this: VM, opts: RunTxOpts): Promise<RunTxResult> {
await state.putAccount(caller, fromAccount)

// Update miner's balance
const minerAccount = await state.getAccount(block!.header.coinbase.buf)
const minerBuf = block!.header.coinbase.buf
const minerAccount = await state.getAccount(minerBuf)
// add the amount spent on gas to the miner's account
minerAccount.balance = new BN(minerAccount.balance).add(results.amountSpent).toArrayLike(Buffer)

// Put the miner account into the state. If the balance of the miner account remains zero, note that
// the state.putAccount function puts this into the "touched" accounts. This will thus be removed when
// we clean the touched accounts below in case we are in a fork >= SpuriousDragon
await state.putAccount(block!.header.coinbase.buf, minerAccount)
await state.putAccount(minerBuf, minerAccount)

/*
* Cleanup accounts
Expand Down
9 changes: 3 additions & 6 deletions packages/vm/tests/GeneralStateTestsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,17 @@ async function runTestCase(options: any, testData: any, t: tape.Test) {

const common = new Common({ chain: 'mainnet', hardfork, eips })

const vm = new VM({
state,
common: common,
})
const vm = new VM({ state, common })

await setupPreConditions(vm.stateManager._trie, testData)

const tx = makeTx(testData.transaction, common)
const tx = makeTx(testData.transaction, { common })

if (!tx.validate()) {
throw new Error('Transaction is invalid')
}

const block = makeBlockFromEnv(testData.env)
const block = makeBlockFromEnv(testData.env, { common })

if (options.jsontrace) {
vm.on('step', function (e: any) {
Expand Down
32 changes: 10 additions & 22 deletions packages/vm/tests/util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as tape from 'tape'
import { BN, rlp, keccak256, stripHexPrefix, setLengthLeft, toBuffer } from 'ethereumjs-util'
import Account from '@ethereumjs/account'
import { Transaction } from '@ethereumjs/tx'
import { Block, BlockHeader } from '@ethereumjs/block'
import { Transaction, TxOptions } from '@ethereumjs/tx'
import { Block, BlockHeader, BlockOptions } from '@ethereumjs/block'
import Common from '@ethereumjs/common'

export function dumpState(state: any, cb: Function) {
Expand Down Expand Up @@ -87,11 +87,11 @@ const format = (exports.format = function (
/**
* Make a tx using JSON from tests repo
* @param {Object} txData The tx object from tests repo
* @param {Common} common An @ethereumjs/common object
* @param {TxOptions} opts Tx opts that can include an @ethereumjs/common object
* @returns {Transaction} Transaction to be passed to VM.runTx function
*/
export function makeTx(txData: any, common: Common) {
const tx = Transaction.fromTxData(txData, { common })
export function makeTx(txData: any, opts: TxOptions = {}) {
const tx = Transaction.fromTxData(txData, opts)

if (txData.secretKey) {
const privKey = toBuffer(txData.secretKey)
Expand Down Expand Up @@ -249,7 +249,7 @@ export function verifyLogs(logs: any, testData: any, t: tape.Test) {
}
}

export function makeBlockHeader(data: any) {
export function makeBlockHeader(data: any, opts: BlockOptions = {}) {
const {
currentTimestamp,
currentGasLimit,
Expand All @@ -266,15 +266,7 @@ export function makeBlockHeader(data: any) {
gasLimit: currentGasLimit,
timestamp: currentTimestamp,
}
return BlockHeader.fromHeaderData(headerData)
// const headerData = {
// number: format(currentNumber),
// coinbase: setLengthLeft(format(currentCoinbase, false, true), 20),
// parentHash: format(previousHash),
// difficulty: format(currentDifficulty),
// gasLimit: format(currentGasLimit),
// timestamp: format(currentTimestamp),
// }
return BlockHeader.fromHeaderData(headerData, opts)
}

/**
Expand All @@ -284,13 +276,9 @@ export function makeBlockHeader(data: any) {
* @param uncleHeaders uncle headers for the block (optional)
* @returns the block
*/
export function makeBlockFromEnv(
env: any,
transactions: Transaction[] = [],
uncleHeaders: BlockHeader[] = [],
): Block {
const header = makeBlockHeader(env)
return new Block(header, transactions, uncleHeaders)
export function makeBlockFromEnv(env: any, opts: BlockOptions = {}): Block {
const header = makeBlockHeader(env, opts)
return new Block(header)
}

/**
Expand Down