diff --git a/packages/vm/.eslintrc.js b/packages/vm/.eslintrc.js index d6d2bcc51d..db658abe8e 100644 --- a/packages/vm/.eslintrc.js +++ b/packages/vm/.eslintrc.js @@ -4,9 +4,10 @@ module.exports = { rules: { '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/no-unnecessary-condition': 'off', + '@typescript-eslint/no-unused-vars': ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }], + 'no-unused-vars': ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }], 'no-invalid-this': 'off', 'no-restricted-syntax': 'off', - 'no-unused-vars': ["error", { "argsIgnorePattern": "^_" }] }, overrides: [ { diff --git a/packages/vm/src/evm/interpreter.ts b/packages/vm/src/evm/interpreter.ts index e9d456a468..e2a525dca0 100644 --- a/packages/vm/src/evm/interpreter.ts +++ b/packages/vm/src/evm/interpreter.ts @@ -143,12 +143,13 @@ export default class Interpreter { const opInfo = this.lookupOpInfo(this._runState.opCode) const gas = new BN(opInfo.fee) - // clone the gas limit; call opcodes can add stipend, which makes it seem like the gas left increases + // clone the gas limit; call opcodes can add stipend, + // which makes it seem like the gas left increases const gasLimitClone = this._eei.getGasLeft() if (opInfo.dynamicGas) { const dynamicGasHandler = dynamicGasHandlers.get(this._runState.opCode)! - // This function updates the gas BN by using `i*` methods + // This function updates the gas BN in-place using `i*` methods // It needs the base fee, for correct gas limit calculation for the CALL opcodes await dynamicGasHandler(this._runState, gas) } diff --git a/packages/vm/src/evm/opcodes/gas.ts b/packages/vm/src/evm/opcodes/gas.ts index aa631f2a13..0762f5820e 100644 --- a/packages/vm/src/evm/opcodes/gas.ts +++ b/packages/vm/src/evm/opcodes/gas.ts @@ -53,7 +53,7 @@ export const dynamicGasHandlers: Map = new Map([ /* CALLDATACOPY */ 0x37, async function (runState: RunState, gas: BN): Promise { - const [memOffset /*dataOffset*/, , dataLength] = runState.stack.peek(3) + const [memOffset, _dataOffset, dataLength] = runState.stack.peek(3) gas.iadd(subMemUsage(runState, memOffset, dataLength)) if (!dataLength.eqn(0)) { @@ -67,7 +67,7 @@ export const dynamicGasHandlers: Map = new Map([ /* CODECOPY */ 0x39, async function (runState: RunState, gas: BN): Promise { - const [memOffset /*codeOffset*/, , dataLength] = runState.stack.peek(3) + const [memOffset, _codeOffset, dataLength] = runState.stack.peek(3) gas.iadd(subMemUsage(runState, memOffset, dataLength)) if (!dataLength.eqn(0)) { @@ -90,7 +90,7 @@ export const dynamicGasHandlers: Map = new Map([ /* EXTCODECOPY */ 0x3c, async function (runState: RunState, gas: BN): Promise { - const [addressBN, memOffset /*codeOffset*/, , dataLength] = runState.stack.peek(4) + const [addressBN, memOffset, _codeOffset, dataLength] = runState.stack.peek(4) gas.iadd(subMemUsage(runState, memOffset, dataLength)) const address = new Address(addressToBuffer(addressBN)) @@ -194,7 +194,8 @@ export const dynamicGasHandlers: Map = new Map([ } // We have to do this after the Istanbul (EIP2200) checks. - // Otherwise, we might run out of gas, due to "sentry check" of 2300 gas, if we deduct extra gas first. + // Otherwise, we might run out of gas, due to "sentry check" of 2300 gas, + // if we deduct extra gas first. gas.iadd(accessStorageEIP2929(runState, keyBuf, true)) }, ], @@ -229,7 +230,7 @@ export const dynamicGasHandlers: Map = new Map([ if (runState.eei.isStatic()) { trap(ERROR.STATIC_STATE_CHANGE) } - const [, /*value*/ offset, length] = runState.stack.peek(3) + const [_value, offset, length] = runState.stack.peek(3) gas.iadd(accessAddressEIP2929(runState, runState.eei.getAddress(), false)) @@ -268,7 +269,8 @@ export const dynamicGasHandlers: Map = new Map([ } } else if (!(await runState.eei.accountExists(toAddress))) { // We are before Spurious Dragon and the account does not exist. - // Call new account gas: account does not exist (it is not in the state trie, not even as an "empty" account) + // Call new account gas: account does not exist + // (it is not in the state trie, not even as an "empty" account) gas.iadd(new BN(runState._common.param('gasPrices', 'callNewAccount'))) } @@ -277,7 +279,8 @@ export const dynamicGasHandlers: Map = new Map([ runState.eei.getGasLeft().isub(gas), runState ) - // note that TangerineWhistle or later this cannot happen (it could have ran out of gas prior to getting here though) + // note that TangerineWhistle or later this cannot happen + // (it could have ran out of gas prior to getting here though) if (gasLimit.gt(runState.eei.getGasLeft().isub(gas))) { trap(ERROR.OUT_OF_GAS) } @@ -315,7 +318,8 @@ export const dynamicGasHandlers: Map = new Map([ runState.eei.getGasLeft().isub(gas), runState ) - // note that TangerineWhistle or later this cannot happen (it could have ran out of gas prior to getting here though) + // note that TangerineWhistle or later this cannot happen + // (it could have ran out of gas prior to getting here though) if (gasLimit.gt(runState.eei.getGasLeft().isub(gas))) { trap(ERROR.OUT_OF_GAS) } @@ -355,7 +359,8 @@ export const dynamicGasHandlers: Map = new Map([ runState.eei.getGasLeft().isub(gas), runState ) - // note that TangerineWhistle or later this cannot happen (it could have ran out of gas prior to getting here though) + // note that TangerineWhistle or later this cannot happen + // (it could have ran out of gas prior to getting here though) if (gasLimit.gt(runState.eei.getGasLeft().isub(gas))) { trap(ERROR.OUT_OF_GAS) } @@ -371,7 +376,7 @@ export const dynamicGasHandlers: Map = new Map([ trap(ERROR.STATIC_STATE_CHANGE) } - const [, /*value*/ offset, length /*salt*/] = runState.stack.peek(4) + const [_value, offset, length, _salt] = runState.stack.peek(4) gas.iadd(subMemUsage(runState, offset, length)) gas.iadd(accessAddressEIP2929(runState, runState.eei.getAddress(), false)) diff --git a/packages/vm/src/evm/stack.ts b/packages/vm/src/evm/stack.ts index d2d601df06..6b3613a12b 100644 --- a/packages/vm/src/evm/stack.ts +++ b/packages/vm/src/evm/stack.ts @@ -1,5 +1,5 @@ import { BN, MAX_INTEGER } from 'ethereumjs-util' -const { ERROR, VmError } = require('../exceptions') +import { ERROR, VmError } from '../exceptions' /** * Implementation of the stack used in evm. @@ -59,6 +59,11 @@ export default class Stack { return this._store.splice(-1 * num).reverse() } + /** + * Return items from the stack + * @param num Number of items to return + * @throws {@link ERROR.STACK_UNDERFLOW} + */ peek(num: number = 1): BN[] { const peekArray: BN[] = []