From e995b390f0a81f09115b62793642fddb1e688e60 Mon Sep 17 00:00:00 2001 From: Pavel Rumkin Date: Sat, 22 Feb 2020 14:08:23 +0300 Subject: [PATCH] Fix address creation. Add precompiles resolution to EVM. --- lib/evm/evm.ts | 4 ++-- lib/evm/opFns.ts | 3 +-- lib/index.ts | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/evm/evm.ts b/lib/evm/evm.ts index 49507b7f78..c4610e2a31 100644 --- a/lib/evm/evm.ts +++ b/lib/evm/evm.ts @@ -10,7 +10,7 @@ import { import Account from 'ethereumjs-account' import { ERROR, VmError } from '../exceptions' import PStateManager from '../state/promisified' -import { getPrecompile, PrecompileFunc, Precompiles, ripemdPrecompileAddress } from './precompiles' +import { PrecompileFunc, Precompiles } from './precompiles' import TxContext from './txContext' import Message from './message' import EEI from './eei' @@ -331,7 +331,7 @@ export default class EVM { * if no such precompile exists. */ getPrecompile(address: Buffer): PrecompileFunc { - return getPrecompile(address.toString('hex')) + return this._precompiledContracts[address.toString('hex')] } /** diff --git a/lib/evm/opFns.ts b/lib/evm/opFns.ts index bbbaf7f788..2458d4d9c3 100644 --- a/lib/evm/opFns.ts +++ b/lib/evm/opFns.ts @@ -702,8 +702,7 @@ export const handlers: { [k: string]: OpHandler } = { const empty = await runState.eei.isAccountEmpty(toAddressBuf) if (empty) { - const precompiledContracts = runState.eei._evm._precompiledContracts - if (!precompiledContracts[toAddressBuf.toString('hex')] && !value.isZero()) { + if (!value.isZero()) { runState.eei.useGas(new BN(runState._common.param('gasPrices', 'callNewAccount'))) } } diff --git a/lib/index.ts b/lib/index.ts index 31b0f2378a..d647a01053 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -50,7 +50,6 @@ export interface VMOpts { * * Setting this to true has the effect of precompiled contracts' gas costs matching mainnet's from * the very first call, which is intended for testing networks. - * @deprecated */ activatePrecompiles?: boolean /** @@ -155,7 +154,7 @@ export default class VM extends AsyncEventEmitter { if (opts.activatePrecompiles && !opts.stateManager) { for (const address of Object.keys(this.precompiledContracts)) { - await state.putAccount(new BN(address).toArrayLike(Buffer, 'be', 20), new Account()) + await state.putAccount(Buffer.from(address, 'hex'), new Account()) } }