Skip to content

Commit

Permalink
Merge branch 'master' into block-consecutive-difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio authored Oct 29, 2020
2 parents 34fa3ea + 2828988 commit 411658b
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 138 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/vm-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
fork: ['Berlin', 'MuirGlacier', 'Petersburg', 'Istanbul', 'Byzantium', 'SpuriousDragon', 'TangerineWhistle', 'Homestead', 'Chainstart']
fork: [
'Berlin',
'MuirGlacier',
'Istanbul',
'Petersburg',
'Constantinople',
'Byzantium',
'SpuriousDragon',
'TangerineWhistle',
'Homestead',
'Chainstart'
]
fail-fast: false
steps:
- uses: actions/setup-node@v1
Expand Down Expand Up @@ -83,7 +94,17 @@ jobs:
strategy:
matrix:
# Args to pass to the tester. Note that some have splitted the slow tests and only running those: these are only on forks where that is applicable (see PR #489 for numbers on these)
args: ['--fork=Chainstart --expected-test-amount=4385', '--fork=Homestead --expected-test-amount=6997', '--fork=Petersburg --excludeDir=stTimeConsuming --expected-test-amount=17174', '--fork=Petersburg --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561', '--fork=Istanbul --excludeDir=stTimeConsuming --expected-test-amount=19817', '--fork=Istanbul --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561', '--fork=Berlin --expected-test-amount=33']
args: [
'--fork=Chainstart --expected-test-amount=4385',
'--fork=Homestead --expected-test-amount=6997',
'--fork=Petersburg --excludeDir=stTimeConsuming --expected-test-amount=17174',
'--fork=Petersburg --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561',
'--fork=Constantinople --excludeDir=stTimeConsuming --expected-test-amount=17193',
'--fork=Constantinople --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561',
'--fork=Istanbul --excludeDir=stTimeConsuming --expected-test-amount=19817',
'--fork=Istanbul --dir=GeneralStateTests/stTimeConsuming --expected-test-amount=15561',
'--fork=Berlin --expected-test-amount=33'
]
fail-fast: false
steps:
- uses: actions/setup-node@v1
Expand Down Expand Up @@ -159,4 +180,4 @@ jobs:

# Re-apply git stash to prepare for saving back to cache.
# Avoids exit code 1 by checking if there are changes to be stashed first
- run: STASH_LIST=`git stash list` && [ ! -z $STASH_LIST ] && git stash apply || echo "No files to stash-apply. Skipping…"
- run: STASH_LIST=`git stash list` && [ ! -z $STASH_LIST ] && git stash apply || echo "No files to stash-apply. Skipping…"
22 changes: 11 additions & 11 deletions packages/block/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ updated.

There are three new factory methods to create a new `BlockHeader`:

1. Pass in a Header-attribute named dictionary to `BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts: BlockOptions = {})`:
1. Pass in a Header-attribute named dictionary to `BlockHeader.fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions)`:

```typescript
const headerData = {
Expand All @@ -75,24 +75,24 @@ const headerData = {
gasLimit: 8000000,
timestamp: 1562422144,
}
const header = BlockHeader.fromHeaderData(headerData, {})
const header = BlockHeader.fromHeaderData(headerData)
```

2. Create a `BlockHeader` from an RLP-serialized header `Buffer` with `BlockHeader.fromRLPSerializedHeader(serialized: Buffer, opts: BlockOptions)`.

```typescript
const serialized = Buffer.from(
'f901f7a06bfee7294bf44572b7266358e627f3c35105e1c3851f3de09e6d646f955725a7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000f837a120080845d20ab8080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000',
'hex',
'hex'
)
const header = BlockHeader.fromRLPSerializedHeader(serialized, {})
const header = BlockHeader.fromRLPSerializedHeader(serialized)
```

3. Create a `BlockHeader` from an array of `Buffer` values, you can do a first short roundtrip test with:

```typescript
const valuesArray = header.raw()
BlockHeader.fromValuesArray(valuesArray, {})
BlockHeader.fromValuesArray(valuesArray)
```

Generally internal types representing block header values are now closer to their domain representation
Expand All @@ -102,9 +102,9 @@ Generally internal types representing block header values are now closer to thei

There are analogue new static factories for the `Block` class:

- `Block.fromBlockData(blockData: BlockData = {}, opts: BlockOptions = {})`
- `Block.fromRLPSerializedBlock(serialized: Buffer, opts: BlockOptions = {})`
- `Block.fromValuesArray(values: BlockBuffer, opts: BlockOptions = {})`
- `Block.fromBlockData(blockData: BlockData = {}, opts?: BlockOptions)`
- `Block.fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions)`
- `Block.fromValuesArray(values: BlockBuffer, opts?: BlockOptions)`

Learn more about the full API in the [docs](./docs/README.md).

Expand Down Expand Up @@ -143,7 +143,7 @@ try {

### Header Validation Methods > Signature Changes

**Breaking**: The signatures of the following header validation methods have been updated to take a `parentBlockHeader` instead of a
**Breaking**: The signatures of the following header validation methods have been updated to take a `parentBlockHeader` instead of a
`parentBlock` input parameter for consistency and removing a circling dependency with `Block`:

- `BlockHeader.canonicalDifficulty(parentBlockHeader: BlockHeader): BN`
Expand All @@ -161,8 +161,8 @@ see PR [#863](https://github.com/ethereumjs/ethereumjs-vm/pull/863).

### Dual ES5 and ES2017 Builds

We significantly updated our internal tool and CI setup along the work on
PR [#913](https://github.com/ethereumjs/ethereumjs-vm/pull/913) with an update to `ESLint` from `TSLint`
We significantly updated our internal tool and CI setup along the work on
PR [#913](https://github.com/ethereumjs/ethereumjs-vm/pull/913) with an update to `ESLint` from `TSLint`
for code linting and formatting and the introduction of a new build setup.

Packages now target `ES2017` for Node.js builds (the `main` entrypoint from `package.json`) and introduce
Expand Down
8 changes: 4 additions & 4 deletions packages/block/src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Block {
public readonly txTrie = new Trie()
public readonly _common: Common

public static fromBlockData(blockData: BlockData = {}, opts: BlockOptions = {}) {
public static fromBlockData(blockData: BlockData = {}, opts?: BlockOptions) {
const { header: headerData, transactions: txsData, uncleHeaders: uhsData } = blockData

const header = BlockHeader.fromHeaderData(headerData, opts)
Expand All @@ -39,7 +39,7 @@ export class Block {
return new Block(header, transactions, uncleHeaders)
}

public static fromRLPSerializedBlock(serialized: Buffer, opts: BlockOptions = {}) {
public static fromRLPSerializedBlock(serialized: Buffer, opts?: BlockOptions) {
const values = (rlp.decode(serialized) as any) as BlockBuffer

if (!Array.isArray(values)) {
Expand All @@ -49,7 +49,7 @@ export class Block {
return Block.fromValuesArray(values, opts)
}

public static fromValuesArray(values: BlockBuffer, opts: BlockOptions = {}) {
public static fromValuesArray(values: BlockBuffer, opts?: BlockOptions) {
if (values.length > 3) {
throw new Error('invalid block. More values than expected were received')
}
Expand All @@ -76,7 +76,7 @@ export class Block {
/**
* Alias for Block.fromBlockData() with initWithGenesisHeader set to true.
*/
public static genesis(blockData: BlockData = {}, opts: BlockOptions = {}) {
public static genesis(blockData: BlockData = {}, opts?: BlockOptions) {
opts = { ...opts, initWithGenesisHeader: true }
return Block.fromBlockData(blockData, opts)
}
Expand Down
8 changes: 4 additions & 4 deletions packages/block/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class BlockHeader {

public readonly _common: Common

public static fromHeaderData(headerData: HeaderData = {}, opts: BlockOptions = {}) {
public static fromHeaderData(headerData: HeaderData = {}, opts?: BlockOptions) {
const {
parentHash,
uncleHash,
Expand Down Expand Up @@ -76,7 +76,7 @@ export class BlockHeader {
)
}

public static fromRLPSerializedHeader(serialized: Buffer, opts: BlockOptions) {
public static fromRLPSerializedHeader(serialized: Buffer, opts?: BlockOptions) {
const values = rlp.decode(serialized)

if (!Array.isArray(values)) {
Expand All @@ -86,7 +86,7 @@ export class BlockHeader {
return BlockHeader.fromValuesArray(values, opts)
}

public static fromValuesArray(values: BlockHeaderBuffer, opts: BlockOptions) {
public static fromValuesArray(values: BlockHeaderBuffer, opts?: BlockOptions) {
if (values.length > 15) {
throw new Error('invalid header. More values than expected were received')
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export class BlockHeader {
/**
* Alias for Header.fromHeaderData() with initWithGenesisHeader set to true.
*/
public static genesis(headerData: HeaderData = {}, opts: BlockOptions = {}) {
public static genesis(headerData: HeaderData = {}, opts?: BlockOptions) {
opts = { ...opts, initWithGenesisHeader: true }
return BlockHeader.fromHeaderData(headerData, opts)
}
Expand Down
81 changes: 39 additions & 42 deletions packages/vm/lib/evm/opcodes/EIP1283.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,48 @@ import { RunState } from './../interpreter'
* @param {Buffer} value
*/
export function updateSstoreGasEIP1283(runState: RunState, found: any, value: Buffer) {
if (runState._common.hardfork() === 'constantinople') {
const original = found.original
const current = found.current
if (current.equals(value)) {
// If current value equals new value (this is a no-op), 200 gas is deducted.
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreNoopGas')))
return
const { original, current } = found
if (current.equals(value)) {
// If current value equals new value (this is a no-op), 200 gas is deducted.
runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreNoopGas')))
return
}
// If current value does not equal new value
if (original.equals(current)) {
// If original value equals current value (this storage slot has not been changed by the current execution context)
if (original.length === 0) {
// If original value is 0, 20000 gas is deducted.
return runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreInitGas')))
}
// If current value does not equal new value
if (original.equals(current)) {
// If original value equals current value (this storage slot has not been changed by the current execution context)
if (original.length === 0) {
// If original value is 0, 20000 gas is deducted.
return runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreInitGas')))
}
if (value.length === 0) {
// If new value is 0, add 15000 gas to refund counter.
runState.eei.refundGas(new BN(runState._common.param('gasPrices', 'netSstoreClearRefund')))
}
// Otherwise, 5000 gas is deducted.
return runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreCleanGas')))
if (value.length === 0) {
// If new value is 0, add 15000 gas to refund counter.
runState.eei.refundGas(new BN(runState._common.param('gasPrices', 'netSstoreClearRefund')))
}
// If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
if (original.length !== 0) {
// If original value is not 0
if (current.length === 0) {
// If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
runState.eei.subRefund(new BN(runState._common.param('gasPrices', 'netSstoreClearRefund')))
} else if (value.length === 0) {
// If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
runState.eei.refundGas(new BN(runState._common.param('gasPrices', 'netSstoreClearRefund')))
}
// Otherwise, 5000 gas is deducted.
return runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreCleanGas')))
}
// If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
if (original.length !== 0) {
// If original value is not 0
if (current.length === 0) {
// If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
runState.eei.subRefund(new BN(runState._common.param('gasPrices', 'netSstoreClearRefund')))
} else if (value.length === 0) {
// If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
runState.eei.refundGas(new BN(runState._common.param('gasPrices', 'netSstoreClearRefund')))
}
if (original.equals(value)) {
// If original value equals new value (this storage slot is reset)
if (original.length === 0) {
// If original value is 0, add 19800 gas to refund counter.
runState.eei.refundGas(
new BN(runState._common.param('gasPrices', 'netSstoreResetClearRefund'))
)
} else {
// Otherwise, add 4800 gas to refund counter.
runState.eei.refundGas(new BN(runState._common.param('gasPrices', 'netSstoreResetRefund')))
}
}
if (original.equals(value)) {
// If original value equals new value (this storage slot is reset)
if (original.length === 0) {
// If original value is 0, add 19800 gas to refund counter.
runState.eei.refundGas(
new BN(runState._common.param('gasPrices', 'netSstoreResetClearRefund'))
)
} else {
// Otherwise, add 4800 gas to refund counter.
runState.eei.refundGas(new BN(runState._common.param('gasPrices', 'netSstoreResetRefund')))
}
return runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreDirtyGas')))
}
return runState.eei.useGas(new BN(runState._common.param('gasPrices', 'netSstoreDirtyGas')))
}
Loading

0 comments on commit 411658b

Please sign in to comment.