@@ -23,11 +23,12 @@ import type { InterpreterStep } from "@ethereumjs/evm";
2323import { decode } from "@ganache/rlp" ;
2424import { KECCAK256_RLP } from "@ethereumjs/util" ;
2525import { Common } from "@ethereumjs/common" ;
26- import { VM } from "@ethereumjs/vm" ;
26+ import { EEI , VM } from "@ethereumjs/vm" ;
2727import {
2828 EvmError as VmError ,
2929 EvmErrorMessage as ERROR ,
30- EVMResult
30+ EVMResult ,
31+ EVM
3132} from "@ethereumjs/evm" ;
3233import { EthereumInternalOptions , Hardfork } from "@ganache/ethereum-options" ;
3334import {
@@ -684,26 +685,27 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
684685 } ;
685686
686687 common = common || this . common ;
687-
688- // @ts -ignore
689- const vm = new VM ( {
688+ const stateManager = this . fallback
689+ ? // TODO: prefixCodeHashes should eventually be conditional
690+ // https://github.com/trufflesuite/ganache/issues/3701
691+ new ForkStateManager ( {
692+ trie : stateTrie as ForkTrie ,
693+ prefixCodeHashes : false
694+ } )
695+ : // TODO: prefixCodeHashes should eventually be conditional
696+ // https://github.com/trufflesuite/ganache/issues/3701
697+ new DefaultStateManager ( { trie : stateTrie , prefixCodeHashes : false } ) ;
698+
699+ const eei = new EEI ( stateManager , common , blockchain ) ;
700+ const evm = new EVM ( { common, allowUnlimitedContractSize, eei } ) ;
701+ const vm = await VM . create ( {
690702 activatePrecompiles : false ,
691703 common,
692- allowUnlimitedContractSize,
693704 blockchain,
694- stateManager : this . fallback
695- ? // TODO: prefixCodeHashes should eventually be conditional
696- // https://github.com/trufflesuite/ganache/issues/3701
697- new ForkStateManager ( {
698- trie : stateTrie as ForkTrie ,
699- prefixCodeHashes : false
700- } )
701- : // TODO: prefixCodeHashes should eventually be conditional
702- // https://github.com/trufflesuite/ganache/issues/3701
703- new DefaultStateManager ( { trie : stateTrie , prefixCodeHashes : false } )
704- } ) as VM ;
705- // @ts -ignore
706- vm . evm . _allowUnlimitedContractSize = allowUnlimitedContractSize ;
705+ stateManager,
706+ evm
707+ } ) ;
708+
707709 if ( activatePrecompile ) {
708710 await activatePrecompiles ( vm . eei ) ;
709711
@@ -1166,7 +1168,6 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
11661168 await vm . eei . putAccount ( callerAddress , fromAccount ) ;
11671169
11681170 // finally, run the call
1169- // @ts -ignore types are dumbs
11701171 result = await vm . evm . runCall ( {
11711172 caller : callerAddress ,
11721173 data : transaction . data && transaction . data . toBuffer ( ) ,
@@ -1189,7 +1190,6 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
11891190 context : transactionContext
11901191 } ) ;
11911192 if ( result . execResult . exceptionError ) {
1192- // @ts -ignore types are dumbs
11931193 throw new CallError ( result ) ;
11941194 } else {
11951195 return Data . from ( result . execResult . returnValue || "0x" ) ;
@@ -1225,23 +1225,31 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
12251225 )
12261226 : this . common ;
12271227
1228+ const stateManager = this . fallback
1229+ ? // TODO: prefixCodeHashes should eventually be conditional
1230+ // https://github.com/trufflesuite/ganache/issues/3701
1231+ new ForkStateManager ( {
1232+ trie : trie as ForkTrie ,
1233+ prefixCodeHashes : false
1234+ } )
1235+ : // TODO: prefixCodeHashes should eventually be conditional
1236+ // https://github.com/trufflesuite/ganache/issues/3701
1237+ new DefaultStateManager ( { trie, prefixCodeHashes : false } ) ;
1238+
1239+ const eei = new EEI ( stateManager , common , blockchain ) ;
1240+ const evm = new EVM ( {
1241+ common,
1242+ allowUnlimitedContractSize :
1243+ this . #options. chain . allowUnlimitedContractSize ,
1244+ eei
1245+ } ) ;
12281246 const vm = await VM . create ( {
12291247 activatePrecompiles : false ,
12301248 common,
12311249 blockchain,
1232- stateManager : this . fallback
1233- ? // TODO: prefixCodeHashes should eventually be conditional
1234- // https://github.com/trufflesuite/ganache/issues/3701
1235- new ForkStateManager ( {
1236- trie : trie as ForkTrie ,
1237- prefixCodeHashes : false
1238- } )
1239- : // TODO: prefixCodeHashes should eventually be conditional
1240- // https://github.com/trufflesuite/ganache/issues/3701
1241- new DefaultStateManager ( { trie : trie , prefixCodeHashes : false } )
1250+ stateManager,
1251+ evm
12421252 } ) ;
1243- //@ts -ignore
1244- vm . _allowUnlimitedContractSize = this . vm . evm . _allowUnlimitedContractSize ;
12451253
12461254 const storage : StorageRecords = { } ;
12471255
@@ -1641,7 +1649,7 @@ export default class Blockchain extends Emittery<BlockchainTypedEvents> {
16411649 } ;
16421650
16431651 const rs = storageTrie . createReadStream ( ) ;
1644- // @ts -ignore
1652+ // @ts -ignore TODO: remove once https://github.com/ethereumjs/ethereumjs-monorepo/pull/2318 is released
16451653 rs . on ( "data" , handleData ) . on ( "error" , reject ) . on ( "end" , handleEnd ) ;
16461654 } ) ;
16471655 } ;
0 commit comments