From b109b393f84b31fc61e29f1550b0d53e9f5c1d7c Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 11 Dec 2021 23:19:23 -0500 Subject: [PATCH 01/20] tx: throw on negative bn txdata --- packages/tx/src/baseTransaction.ts | 26 ++++++++++++++++++++- packages/tx/src/eip1559Transaction.ts | 5 ++++ packages/tx/test/base.spec.ts | 11 +++++++++ packages/tx/test/eip1559.spec.ts | 4 +++- packages/tx/test/legacy.spec.ts | 4 +++- packages/tx/test/transactionFactory.spec.ts | 5 ++++ packages/tx/test/typedTxsAndEIP2930.spec.ts | 2 ++ 7 files changed, 54 insertions(+), 3 deletions(-) diff --git a/packages/tx/src/baseTransaction.ts b/packages/tx/src/baseTransaction.ts index 6917a6068b..889197ec2d 100644 --- a/packages/tx/src/baseTransaction.ts +++ b/packages/tx/src/baseTransaction.ts @@ -83,7 +83,17 @@ export abstract class BaseTransaction { protected DEFAULT_HARDFORK: string | Hardfork = Hardfork.Istanbul constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData) { - const { nonce, gasLimit, to, value, data, v, r, s, type } = txData + const { data, nonce, gasLimit, gasPrice, r, s, to, type, v, value } = txData + this._validateCannotHaveNegativeBN({ + gasLimit, + gasPrice, + nonce, + v, + r, + s, + type, + value, + }) this._type = new BN(toBuffer(type)).toNumber() const toB = toBuffer(to === '' ? '0x' : to) @@ -338,6 +348,7 @@ export abstract class BaseTransaction { * @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx) */ protected _getCommon(common?: Common, chainId?: BNLike) { + this._validateCannotHaveNegativeBN({ chainId }) // Chain ID provided if (chainId) { const chainIdBN = new BN(toBuffer(chainId)) @@ -430,6 +441,19 @@ export abstract class BaseTransaction { } } + /** + * Validates that an object with BN values has no negative BN values + * @param values Object containing string keys and BN values + */ + protected _validateCannotHaveNegativeBN(values: { [key: string]: BNLike | undefined }) { + for (const [key, value] of Object.entries(values)) { + if (value && BN.isBN(value) && value.isNeg()) { + const msg = this._errorMsg(`${key} cannot be negative, given ${value}`) + throw new Error(msg) + } + } + } + /** * Return a compact error string representation of the object */ diff --git a/packages/tx/src/eip1559Transaction.ts b/packages/tx/src/eip1559Transaction.ts index 032acebce5..53ce8be329 100644 --- a/packages/tx/src/eip1559Transaction.ts +++ b/packages/tx/src/eip1559Transaction.ts @@ -201,6 +201,11 @@ export default class FeeMarketEIP1559Transaction extends BaseTransaction { + t.test('cannot input decimal or negative values', (st) => { const values = [ 'maxFeePerGas', 'maxPriorityFeePerGas', @@ -33,6 +33,8 @@ tape('[FeeMarketEIP1559Transaction]', function (t) { '0xaa.1', -10.1, -1, + new BN(-10), + '-100', '-10.1', '-0xaa', Infinity, diff --git a/packages/tx/test/legacy.spec.ts b/packages/tx/test/legacy.spec.ts index 776f96b85a..739a2fd330 100644 --- a/packages/tx/test/legacy.spec.ts +++ b/packages/tx/test/legacy.spec.ts @@ -11,7 +11,7 @@ const txFixturesEip155: VitaliksTestsDataEntry[] = require('./json/ttTransaction tape('[Transaction]', function (t) { const transactions: Transaction[] = [] - t.test('cannot input decimal values', (st) => { + t.test('cannot input decimal or negative values', (st) => { const values = ['gasPrice', 'gasLimit', 'nonce', 'value', 'v', 'r', 's'] const cases = [ 10.1, @@ -19,6 +19,8 @@ tape('[Transaction]', function (t) { '0xaa.1', -10.1, -1, + new BN(-10), + '-100', '-10.1', '-0xaa', Infinity, diff --git a/packages/tx/test/transactionFactory.spec.ts b/packages/tx/test/transactionFactory.spec.ts index 58f65da4ff..5a429a479f 100644 --- a/packages/tx/test/transactionFactory.spec.ts +++ b/packages/tx/test/transactionFactory.spec.ts @@ -140,6 +140,11 @@ tape('[TransactionFactory]: Basic functions', function (t) { st.throws(() => { TransactionFactory.fromTxData({ type: 999 }) }) + + st.throws(() => { + TransactionFactory.fromTxData({ value: new BN('-100') }) + }) + st.end() }) diff --git a/packages/tx/test/typedTxsAndEIP2930.spec.ts b/packages/tx/test/typedTxsAndEIP2930.spec.ts index cbc8139014..17663b7a12 100644 --- a/packages/tx/test/typedTxsAndEIP2930.spec.ts +++ b/packages/tx/test/typedTxsAndEIP2930.spec.ts @@ -103,6 +103,8 @@ tape( '0xaa.1', -10.1, -1, + new BN(-10), + '-100', '-10.1', '-0xaa', Infinity, From fc2942770da918ed118048c8b4116376f640ab37 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 11 Dec 2021 23:31:08 -0500 Subject: [PATCH 02/20] util: remove negative bn support in toBuffer method --- packages/util/src/bytes.ts | 3 +++ packages/util/test/bytes.spec.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/util/src/bytes.ts b/packages/util/src/bytes.ts index a9e88d0afb..5940f41d71 100644 --- a/packages/util/src/bytes.ts +++ b/packages/util/src/bytes.ts @@ -172,6 +172,9 @@ export const toBuffer = function (v: ToBufferInputTypes): Buffer { } if (BN.isBN(v)) { + if (v.isNeg()) { + throw new Error(`Cannot convert negative BN to buffer. Given: ${v}`) + } return v.toArrayLike(Buffer) } diff --git a/packages/util/test/bytes.spec.ts b/packages/util/test/bytes.spec.ts index 80f094518b..75dc2961c3 100644 --- a/packages/util/test/bytes.spec.ts +++ b/packages/util/test/bytes.spec.ts @@ -279,6 +279,9 @@ tape('toBuffer', function (t) { st.throws(function () { toBuffer({ test: 1 } as any) }) + st.throws(function () { + toBuffer(new BN(-10)) + }) st.end() }) From 5c69fc7d322f33b848a5f54f5781b51a3b734534 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 11 Dec 2021 23:40:40 -0500 Subject: [PATCH 03/20] vm: throw on negative message value field --- packages/vm/src/evm/message.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/vm/src/evm/message.ts b/packages/vm/src/evm/message.ts index bb7a3a11aa..5f951438cc 100644 --- a/packages/vm/src/evm/message.ts +++ b/packages/vm/src/evm/message.ts @@ -17,6 +17,9 @@ export default class Message { delegatecall: boolean constructor(opts: any) { + if (opts.value && BN.isBN(opts.value) && !new BN(opts.value).isNeg()) { + throw new Error('invalid negative value field') + } this.to = opts.to this.value = opts.value ? opts.value : new BN(0) this.caller = opts.caller From 5741479f651668fcd6636d6dab8bfc1e137056a1 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sat, 11 Dec 2021 23:55:02 -0500 Subject: [PATCH 04/20] vm: fix boolean check --- packages/vm/src/evm/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/src/evm/message.ts b/packages/vm/src/evm/message.ts index 5f951438cc..052883780c 100644 --- a/packages/vm/src/evm/message.ts +++ b/packages/vm/src/evm/message.ts @@ -17,7 +17,7 @@ export default class Message { delegatecall: boolean constructor(opts: any) { - if (opts.value && BN.isBN(opts.value) && !new BN(opts.value).isNeg()) { + if (opts.value && BN.isBN(opts.value) && new BN(opts.value).isNeg()) { throw new Error('invalid negative value field') } this.to = opts.to From a006183b5034cf14914a5ee280d68b3341d7ba95 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 12 Dec 2021 00:07:20 -0500 Subject: [PATCH 05/20] vm: add runCall test for negative BN value --- packages/vm/tests/api/runCall.spec.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/vm/tests/api/runCall.spec.ts b/packages/vm/tests/api/runCall.spec.ts index f021a145f0..ac7c7b29f8 100644 --- a/packages/vm/tests/api/runCall.spec.ts +++ b/packages/vm/tests/api/runCall.spec.ts @@ -262,3 +262,28 @@ tape('Ensure that IDENTITY precompile copies the memory', async (t) => { t.end() }) + +tape('Throws on negative call value', async (t) => { + // setup the accounts for this test + const caller = new Address(Buffer.from('00000000000000000000000000000000000000ee', 'hex')) // caller addres + const address = new Address(Buffer.from('00000000000000000000000000000000000000ff', 'hex')) + // setup the vm + const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) + const vm = new VM({ common: common }) + + // setup the call arguments + const runCallArgs = { + caller: caller, // call address + to: address, + value: new BN(-10), + } + + try { + await vm.runCall(runCallArgs) + t.notOk('should not accept a negative call value') + } catch { + t.ok('throws on negative call value') + } + + t.end() +}) From 7061f77fcb2b412b30c993265e7c3a676ef06957 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 12 Dec 2021 09:04:13 -0500 Subject: [PATCH 06/20] vm: more specific runCall test --- packages/vm/src/evm/message.ts | 2 +- packages/vm/tests/api/runCall.spec.ts | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/vm/src/evm/message.ts b/packages/vm/src/evm/message.ts index 052883780c..9928e6b71f 100644 --- a/packages/vm/src/evm/message.ts +++ b/packages/vm/src/evm/message.ts @@ -18,7 +18,7 @@ export default class Message { constructor(opts: any) { if (opts.value && BN.isBN(opts.value) && new BN(opts.value).isNeg()) { - throw new Error('invalid negative value field') + throw new Error('value field can not be negative') } this.to = opts.to this.value = opts.value ? opts.value : new BN(0) diff --git a/packages/vm/tests/api/runCall.spec.ts b/packages/vm/tests/api/runCall.spec.ts index ac7c7b29f8..9f1920e305 100644 --- a/packages/vm/tests/api/runCall.spec.ts +++ b/packages/vm/tests/api/runCall.spec.ts @@ -264,25 +264,20 @@ tape('Ensure that IDENTITY precompile copies the memory', async (t) => { }) tape('Throws on negative call value', async (t) => { - // setup the accounts for this test - const caller = new Address(Buffer.from('00000000000000000000000000000000000000ee', 'hex')) // caller addres - const address = new Address(Buffer.from('00000000000000000000000000000000000000ff', 'hex')) // setup the vm const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.Istanbul }) const vm = new VM({ common: common }) // setup the call arguments const runCallArgs = { - caller: caller, // call address - to: address, value: new BN(-10), } try { await vm.runCall(runCallArgs) t.notOk('should not accept a negative call value') - } catch { - t.ok('throws on negative call value') + } catch (err: any) { + t.ok(err.message.includes('value field can not be negative'), 'throws on negative call value') } t.end() From 7c349bad45cfc34feb4552452cdce3a9afd769a1 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Sun, 12 Dec 2021 15:17:15 -0500 Subject: [PATCH 07/20] vm: address ryan's review --- packages/tx/src/baseTransaction.ts | 26 +------------------------- packages/tx/src/eip1559Transaction.ts | 5 ----- packages/tx/test/base.spec.ts | 11 ----------- packages/vm/src/evm/message.ts | 7 ++++--- 4 files changed, 5 insertions(+), 44 deletions(-) diff --git a/packages/tx/src/baseTransaction.ts b/packages/tx/src/baseTransaction.ts index 889197ec2d..e814b1a5a5 100644 --- a/packages/tx/src/baseTransaction.ts +++ b/packages/tx/src/baseTransaction.ts @@ -83,17 +83,7 @@ export abstract class BaseTransaction { protected DEFAULT_HARDFORK: string | Hardfork = Hardfork.Istanbul constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData) { - const { data, nonce, gasLimit, gasPrice, r, s, to, type, v, value } = txData - this._validateCannotHaveNegativeBN({ - gasLimit, - gasPrice, - nonce, - v, - r, - s, - type, - value, - }) + const { data, nonce, gasLimit, r, s, to, type, v, value } = txData this._type = new BN(toBuffer(type)).toNumber() const toB = toBuffer(to === '' ? '0x' : to) @@ -348,7 +338,6 @@ export abstract class BaseTransaction { * @param chainId - Chain ID from tx options (typed txs) or signature (legacy tx) */ protected _getCommon(common?: Common, chainId?: BNLike) { - this._validateCannotHaveNegativeBN({ chainId }) // Chain ID provided if (chainId) { const chainIdBN = new BN(toBuffer(chainId)) @@ -441,19 +430,6 @@ export abstract class BaseTransaction { } } - /** - * Validates that an object with BN values has no negative BN values - * @param values Object containing string keys and BN values - */ - protected _validateCannotHaveNegativeBN(values: { [key: string]: BNLike | undefined }) { - for (const [key, value] of Object.entries(values)) { - if (value && BN.isBN(value) && value.isNeg()) { - const msg = this._errorMsg(`${key} cannot be negative, given ${value}`) - throw new Error(msg) - } - } - } - /** * Return a compact error string representation of the object */ diff --git a/packages/tx/src/eip1559Transaction.ts b/packages/tx/src/eip1559Transaction.ts index 53ce8be329..032acebce5 100644 --- a/packages/tx/src/eip1559Transaction.ts +++ b/packages/tx/src/eip1559Transaction.ts @@ -201,11 +201,6 @@ export default class FeeMarketEIP1559Transaction extends BaseTransaction Date: Tue, 14 Dec 2021 22:21:31 -0500 Subject: [PATCH 08/20] chore: can not -> cannot and undo reordering --- packages/tx/src/baseTransaction.ts | 2 +- packages/vm/src/evm/message.ts | 2 +- packages/vm/tests/api/runCall.spec.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tx/src/baseTransaction.ts b/packages/tx/src/baseTransaction.ts index e814b1a5a5..6917a6068b 100644 --- a/packages/tx/src/baseTransaction.ts +++ b/packages/tx/src/baseTransaction.ts @@ -83,7 +83,7 @@ export abstract class BaseTransaction { protected DEFAULT_HARDFORK: string | Hardfork = Hardfork.Istanbul constructor(txData: TxData | AccessListEIP2930TxData | FeeMarketEIP1559TxData) { - const { data, nonce, gasLimit, r, s, to, type, v, value } = txData + const { nonce, gasLimit, to, value, data, v, r, s, type } = txData this._type = new BN(toBuffer(type)).toNumber() const toB = toBuffer(to === '' ? '0x' : to) diff --git a/packages/vm/src/evm/message.ts b/packages/vm/src/evm/message.ts index 9703f862e2..85da7f5f04 100644 --- a/packages/vm/src/evm/message.ts +++ b/packages/vm/src/evm/message.ts @@ -32,7 +32,7 @@ export default class Message { this.delegatecall = opts.delegatecall || false if (this.value.isNeg()) { - throw new Error(`value field can not be negative, received ${this.value}`) + throw new Error(`value field cannot be negative, received ${this.value}`) } } diff --git a/packages/vm/tests/api/runCall.spec.ts b/packages/vm/tests/api/runCall.spec.ts index 9f1920e305..9a8388ae70 100644 --- a/packages/vm/tests/api/runCall.spec.ts +++ b/packages/vm/tests/api/runCall.spec.ts @@ -277,7 +277,7 @@ tape('Throws on negative call value', async (t) => { await vm.runCall(runCallArgs) t.notOk('should not accept a negative call value') } catch (err: any) { - t.ok(err.message.includes('value field can not be negative'), 'throws on negative call value') + t.ok(err.message.includes('value field cannot be negative'), 'throws on negative call value') } t.end() From 49f91963bda220bb63f05a523a7cdafd550fd1f1 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Tue, 14 Dec 2021 23:50:27 -0500 Subject: [PATCH 09/20] vm: runCode test case for negative value --- packages/vm/tests/api/runCode.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/vm/tests/api/runCode.spec.ts b/packages/vm/tests/api/runCode.spec.ts index 718c9c4554..e0d4791b33 100644 --- a/packages/vm/tests/api/runCode.spec.ts +++ b/packages/vm/tests/api/runCode.spec.ts @@ -95,3 +95,22 @@ tape('VM.runCode: interpreter', (t) => { st.end() }) }) + +tape('VM.runCode: RunCodeOptions', (t) => { + t.test('should throw on negative value args', async (st) => { + const vm = new VM() + + const runCodeArgs = { + value: new BN('-10'), + } + + try { + await vm.runCode(runCodeArgs) + st.notOk('should not accept a negative call value') + } catch (err: any) { + st.ok(err.message.includes('value field cannot be negative'), 'throws on negative call value') + } + + st.end() + }) +}) From bb67bc55cf2444981156b91e0b4042a14c3d8874 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 14:38:19 -0500 Subject: [PATCH 10/20] vm: add runTx negative value test --- packages/vm/tests/api/runTx.spec.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/vm/tests/api/runTx.spec.ts b/packages/vm/tests/api/runTx.spec.ts index bc820a7e47..baf9ab07ac 100644 --- a/packages/vm/tests/api/runTx.spec.ts +++ b/packages/vm/tests/api/runTx.spec.ts @@ -20,6 +20,7 @@ const TRANSACTION_TYPES = [ name: 'EIP1559 tx', }, ] + const common = new Common({ chain: Chain.Mainnet, hardfork: Hardfork.London }) common.setMaxListeners(100) @@ -328,7 +329,7 @@ tape('runTx() -> runtime behavior', async (t) => { 'e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex' ) - /* Code which is deployed here: + /* Code which is deployed here: PUSH1 01 PUSH1 00 SSTORE @@ -559,3 +560,29 @@ tape('runTx() -> consensus bugs', async (t) => { t.end() }) }) + +tape('runTx: RunTxOptions', (t) => { + t.test('should throw on negative value args', async (t) => { + for (const txType of TRANSACTION_TYPES) { + const vm = new VM({ common }) + + const tx = getTransaction(vm._common, txType.type, true) + tx.value.isubn(1) + + try { + await vm.runTx({ + tx, + skipBalance: true, + }) + t.notOk('should not accept a negative call value') + } catch (err: any) { + console.log(err) + t.ok( + err.message.includes('value field cannot be negative'), + 'throws on negative call value' + ) + } + } + t.end() + }) +}) From 8bada8aadead4c37722e680909f523171070592a Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 14:54:07 -0500 Subject: [PATCH 11/20] vm: remove lint no console override --- packages/vm/.eslintrc.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/vm/.eslintrc.js b/packages/vm/.eslintrc.js index f145af7138..9a851285ec 100644 --- a/packages/vm/.eslintrc.js +++ b/packages/vm/.eslintrc.js @@ -1,17 +1,9 @@ -module.exports = { - extends: '../../config/eslint.js', - ignorePatterns: ['scripts', 'benchmarks', 'examples', 'karma.conf.js'], - rules: { - '@typescript-eslint/no-use-before-define': 'off', - 'no-invalid-this': 'off', - 'no-restricted-syntax': 'off', - }, - overrides: [ - { - files: ['tests/**/*.ts'], - rules: { - 'no-console': 'off', - }, - }, - ], -} +module.exports = { + extends: '../../config/eslint.js', + ignorePatterns: ['scripts', 'benchmarks', 'examples', 'karma.conf.js'], + rules: { + '@typescript-eslint/no-use-before-define': 'off', + 'no-invalid-this': 'off', + 'no-restricted-syntax': 'off', + }, +} From c44c55580e8cebac1cdec87077b689b22ae230f3 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 14:55:03 -0500 Subject: [PATCH 12/20] Update packages/vm/tests/api/runTx.spec.ts Co-authored-by: Ryan Ghods --- packages/vm/tests/api/runTx.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/tests/api/runTx.spec.ts b/packages/vm/tests/api/runTx.spec.ts index baf9ab07ac..435f23ecaa 100644 --- a/packages/vm/tests/api/runTx.spec.ts +++ b/packages/vm/tests/api/runTx.spec.ts @@ -561,7 +561,7 @@ tape('runTx() -> consensus bugs', async (t) => { }) }) -tape('runTx: RunTxOptions', (t) => { +tape('runTx() -> RunTxOptions', (t) => { t.test('should throw on negative value args', async (t) => { for (const txType of TRANSACTION_TYPES) { const vm = new VM({ common }) From d8496edbfefa56e1384f6d1ad1cbf75818896ee8 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 14:55:22 -0500 Subject: [PATCH 13/20] vm: remove console log --- packages/vm/tests/api/runTx.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vm/tests/api/runTx.spec.ts b/packages/vm/tests/api/runTx.spec.ts index baf9ab07ac..150c02664e 100644 --- a/packages/vm/tests/api/runTx.spec.ts +++ b/packages/vm/tests/api/runTx.spec.ts @@ -576,7 +576,6 @@ tape('runTx: RunTxOptions', (t) => { }) t.notOk('should not accept a negative call value') } catch (err: any) { - console.log(err) t.ok( err.message.includes('value field cannot be negative'), 'throws on negative call value' From 9b04c11a6ec4f1c113b93da1224d6ca6bfe21e8a Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:04:36 -0500 Subject: [PATCH 14/20] vm: remove console logs --- packages/vm/src/evm/opcodes/EIP2929.ts | 4 ++-- packages/vm/tests/api/EIPs/eip-2565-modexp-gas-cost.spec.ts | 1 - packages/vm/tests/api/EIPs/eip-3541.spec.ts | 2 -- packages/vm/tests/api/runCall.spec.ts | 1 - packages/vm/tests/tester/index.ts | 1 + packages/vm/tests/tester/runners/BlockchainTestsRunner.ts | 1 - packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts | 3 +-- packages/vm/tests/util.ts | 1 + 8 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/vm/src/evm/opcodes/EIP2929.ts b/packages/vm/src/evm/opcodes/EIP2929.ts index 2f8ae3ecc5..24b1a40b61 100644 --- a/packages/vm/src/evm/opcodes/EIP2929.ts +++ b/packages/vm/src/evm/opcodes/EIP2929.ts @@ -27,7 +27,7 @@ export function accessAddressEIP2929( // Cold if (!(runState.stateManager).isWarmedAddress(addressStr)) { // eslint-disable-next-line prettier/prettier - (runState.stateManager).addWarmedAddress(addressStr) + (runState.stateManager).addWarmedAddress(addressStr) // CREATE, CREATE2 opcodes have the address warmed for free. // selfdestruct beneficiary address reads are charged an *additional* cold access @@ -69,7 +69,7 @@ export function accessStorageEIP2929( // Cold (SLOAD and SSTORE) if (slotIsCold) { // eslint-disable-next-line prettier/prettier - (runState.stateManager).addWarmedStorage(address, key) + (runState.stateManager).addWarmedStorage(address, key) runState.eei.useGas(new BN(common.param('gasPrices', 'coldsload')), 'EIP-2929 -> coldsload') } else if (!isSstore) { runState.eei.useGas( diff --git a/packages/vm/tests/api/EIPs/eip-2565-modexp-gas-cost.spec.ts b/packages/vm/tests/api/EIPs/eip-2565-modexp-gas-cost.spec.ts index 92e171e552..0e8f8fdcde 100644 --- a/packages/vm/tests/api/EIPs/eip-2565-modexp-gas-cost.spec.ts +++ b/packages/vm/tests/api/EIPs/eip-2565-modexp-gas-cost.spec.ts @@ -35,7 +35,6 @@ tape('EIP-2565 ModExp gas cost tests', (t) => { } if (!result.execResult.returnValue.equals(Buffer.from(test.Expected, 'hex'))) { - console.log(result.execResult.returnValue.toString('hex')) st.fail(`[${testName}]: Return value not the expected value`) continue } diff --git a/packages/vm/tests/api/EIPs/eip-3541.spec.ts b/packages/vm/tests/api/EIPs/eip-3541.spec.ts index 7affa9f5f3..8b39c8024b 100644 --- a/packages/vm/tests/api/EIPs/eip-3541.spec.ts +++ b/packages/vm/tests/api/EIPs/eip-3541.spec.ts @@ -90,8 +90,6 @@ tape('EIP 3541 tests', (t) => { nonce: 1, }).sign(pkey) - console.log('tx1') - await vm.runTx({ tx: tx1 }) code = await vm.stateManager.getContractCode(address!) diff --git a/packages/vm/tests/api/runCall.spec.ts b/packages/vm/tests/api/runCall.spec.ts index 93544fe5a3..408285b038 100644 --- a/packages/vm/tests/api/runCall.spec.ts +++ b/packages/vm/tests/api/runCall.spec.ts @@ -217,7 +217,6 @@ tape('Ensure that Istanbul sstoreCleanRefundEIP2200 gas is applied correctly', a } const result = await vm.runCall(runCallArgs) - console.log(result.gasUsed, result.execResult.gasRefund) t.equal(result.gasUsed.toNumber(), 5812, 'gas used incorrect') t.equal(result.execResult.gasRefund!.toNumber(), 4200, 'gas refund incorrect') diff --git a/packages/vm/tests/tester/index.ts b/packages/vm/tests/tester/index.ts index d850e5d062..2982c3927c 100755 --- a/packages/vm/tests/tester/index.ts +++ b/packages/vm/tests/tester/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { exit } from 'process' import path from 'path' import tape from 'tape' diff --git a/packages/vm/tests/tester/runners/BlockchainTestsRunner.ts b/packages/vm/tests/tester/runners/BlockchainTestsRunner.ts index b1c4f864c8..09bfa917c4 100644 --- a/packages/vm/tests/tester/runners/BlockchainTestsRunner.ts +++ b/packages/vm/tests/tester/runners/BlockchainTestsRunner.ts @@ -89,7 +89,6 @@ export default async function runBlockchainTest(options: any, testData: any, t: if (expectException) { t.pass(`Expected exception ${expectException}`) } else { - console.log(error) t.fail(error) } } diff --git a/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts b/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts index aef9312e81..9af08a0d5c 100644 --- a/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts +++ b/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts @@ -154,8 +154,7 @@ export default async function runStateTest(options: any, testData: any, t: tape. for (const testCase of testCases) { await runTestCase(options, testCase, t) } - } catch (e: any) { - console.log(e) + } catch { t.fail('error running test case for fork: ' + options.forkConfigTestSuite) } } diff --git a/packages/vm/tests/util.ts b/packages/vm/tests/util.ts index 39f96dcf2a..d83f0775d6 100644 --- a/packages/vm/tests/util.ts +++ b/packages/vm/tests/util.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import tape from 'tape' import { Block, BlockHeader, BlockOptions } from '@ethereumjs/block' import Common, { Chain, Hardfork } from '@ethereumjs/common' From a1c98f93de0deef7d5f34c8d80c77f818c545e0f Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:08:19 -0500 Subject: [PATCH 15/20] vm: eslintrc exception instead of per-file --- packages/vm/.eslintrc.js | 8 ++++++++ packages/vm/tests/tester/index.ts | 1 - packages/vm/tests/util.ts | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/vm/.eslintrc.js b/packages/vm/.eslintrc.js index 9a851285ec..5c1e55e8ea 100644 --- a/packages/vm/.eslintrc.js +++ b/packages/vm/.eslintrc.js @@ -6,4 +6,12 @@ module.exports = { 'no-invalid-this': 'off', 'no-restricted-syntax': 'off', }, + overrides: [ + { + files: ['tests/util.ts', 'tests/tester/**/*.ts'], + rules: { + 'no-console': 'off', + }, + }, + ], } diff --git a/packages/vm/tests/tester/index.ts b/packages/vm/tests/tester/index.ts index 2982c3927c..d850e5d062 100755 --- a/packages/vm/tests/tester/index.ts +++ b/packages/vm/tests/tester/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import { exit } from 'process' import path from 'path' import tape from 'tape' diff --git a/packages/vm/tests/util.ts b/packages/vm/tests/util.ts index d83f0775d6..39f96dcf2a 100644 --- a/packages/vm/tests/util.ts +++ b/packages/vm/tests/util.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import tape from 'tape' import { Block, BlockHeader, BlockOptions } from '@ethereumjs/block' import Common, { Chain, Hardfork } from '@ethereumjs/common' From 1508db88018ae7ed75f694481f9003133ab0cef7 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:23:37 -0500 Subject: [PATCH 16/20] Update packages/vm/tests/api/runCall.spec.ts Co-authored-by: Ryan Ghods --- packages/vm/tests/api/runCall.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vm/tests/api/runCall.spec.ts b/packages/vm/tests/api/runCall.spec.ts index 408285b038..a5eca8cbe4 100644 --- a/packages/vm/tests/api/runCall.spec.ts +++ b/packages/vm/tests/api/runCall.spec.ts @@ -217,8 +217,8 @@ tape('Ensure that Istanbul sstoreCleanRefundEIP2200 gas is applied correctly', a } const result = await vm.runCall(runCallArgs) - t.equal(result.gasUsed.toNumber(), 5812, 'gas used incorrect') - t.equal(result.execResult.gasRefund!.toNumber(), 4200, 'gas refund incorrect') + t.ok(result.gasUsed.eqn(5812), 'gas used correct') + t.ok(result.execResult.gasRefund!.eqn(4200), 'gas refund correct') t.end() }) From b15319f587e266c1bc43ed1ab1112841eb2fc29f Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:42:42 -0500 Subject: [PATCH 17/20] vm: address review --- packages/vm/tests/api/runTx.spec.ts | 3 +-- packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vm/tests/api/runTx.spec.ts b/packages/vm/tests/api/runTx.spec.ts index 41d7d92f8d..f0e7b0b543 100644 --- a/packages/vm/tests/api/runTx.spec.ts +++ b/packages/vm/tests/api/runTx.spec.ts @@ -563,9 +563,8 @@ tape('runTx() -> consensus bugs', async (t) => { tape('runTx() -> RunTxOptions', (t) => { t.test('should throw on negative value args', async (t) => { + const vm = new VM({ common }) for (const txType of TRANSACTION_TYPES) { - const vm = new VM({ common }) - const tx = getTransaction(vm._common, txType.type, true) tx.value.isubn(1) diff --git a/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts b/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts index 9af08a0d5c..aef9312e81 100644 --- a/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts +++ b/packages/vm/tests/tester/runners/GeneralStateTestsRunner.ts @@ -154,7 +154,8 @@ export default async function runStateTest(options: any, testData: any, t: tape. for (const testCase of testCases) { await runTestCase(options, testCase, t) } - } catch { + } catch (e: any) { + console.log(e) t.fail('error running test case for fork: ' + options.forkConfigTestSuite) } } From 834b991a686cf7297eb389058a41dd3503cfd9c1 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:48:19 -0500 Subject: [PATCH 18/20] Update packages/vm/tests/api/runCode.spec.ts Co-authored-by: Ryan Ghods --- packages/vm/tests/api/runCode.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/tests/api/runCode.spec.ts b/packages/vm/tests/api/runCode.spec.ts index e0d4791b33..192fc6a434 100644 --- a/packages/vm/tests/api/runCode.spec.ts +++ b/packages/vm/tests/api/runCode.spec.ts @@ -106,7 +106,7 @@ tape('VM.runCode: RunCodeOptions', (t) => { try { await vm.runCode(runCodeArgs) - st.notOk('should not accept a negative call value') + st.fail('should not accept a negative call value') } catch (err: any) { st.ok(err.message.includes('value field cannot be negative'), 'throws on negative call value') } From 151f6a90b494fedd892844db4e8496ec8c2c3d72 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:48:25 -0500 Subject: [PATCH 19/20] Update packages/vm/tests/api/runTx.spec.ts Co-authored-by: Ryan Ghods --- packages/vm/tests/api/runTx.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/tests/api/runTx.spec.ts b/packages/vm/tests/api/runTx.spec.ts index f0e7b0b543..8828a1d0ef 100644 --- a/packages/vm/tests/api/runTx.spec.ts +++ b/packages/vm/tests/api/runTx.spec.ts @@ -573,7 +573,7 @@ tape('runTx() -> RunTxOptions', (t) => { tx, skipBalance: true, }) - t.notOk('should not accept a negative call value') + t.fail('should not accept a negative call value') } catch (err: any) { t.ok( err.message.includes('value field cannot be negative'), From 420328c3b2a7192cd9a762f995d96f94737550fb Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Wed, 15 Dec 2021 15:51:05 -0500 Subject: [PATCH 20/20] Update packages/vm/tests/api/runCall.spec.ts Co-authored-by: Ryan Ghods --- packages/vm/tests/api/runCall.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vm/tests/api/runCall.spec.ts b/packages/vm/tests/api/runCall.spec.ts index a5eca8cbe4..6755a41fd9 100644 --- a/packages/vm/tests/api/runCall.spec.ts +++ b/packages/vm/tests/api/runCall.spec.ts @@ -330,7 +330,7 @@ tape('Throws on negative call value', async (t) => { try { await vm.runCall(runCallArgs) - t.notOk('should not accept a negative call value') + t.fail('should not accept a negative call value') } catch (err: any) { t.ok(err.message.includes('value field cannot be negative'), 'throws on negative call value') }