Skip to content

Commit

Permalink
Fix address creation. Add precompiles resolution to EVM.
Browse files Browse the repository at this point in the history
  • Loading branch information
rumkin committed Feb 22, 2020
1 parent 938dfd7 commit e995b39
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/evm/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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')]
}

/**
Expand Down
3 changes: 1 addition & 2 deletions lib/evm/opFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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())
}
}

Expand Down

0 comments on commit e995b39

Please sign in to comment.