@@ -133,6 +133,9 @@ type EVM struct {
133133 // jumpDests stores results of JUMPDEST analysis.
134134 jumpDests JumpDestCache
135135
136+ hasher crypto.KeccakState // Keccak256 hasher instance shared across opcodes
137+ hasherBuf common.Hash // Keccak256 hasher result array shared across opcodes
138+
136139 readOnly bool // Whether to throw on stateful modifications
137140 returnData []byte // Last CALL's return data for subsequent reuse
138141}
@@ -149,6 +152,7 @@ func NewEVM(blockCtx BlockContext, statedb StateDB, chainConfig *params.ChainCon
149152 chainConfig : chainConfig ,
150153 chainRules : chainConfig .Rules (blockCtx .BlockNumber , blockCtx .Random != nil , blockCtx .Time , blockCtx .ArbOSVersion ),
151154 jumpDests : newMapJumpDests (),
155+ hasher : crypto .NewKeccakState (),
152156 }
153157 evm .ProcessingHook = DefaultTxProcessor {evm : evm }
154158 evm .precompiles = activePrecompiledContracts (evm .chainRules )
@@ -699,7 +703,7 @@ func (evm *EVM) Create(caller common.Address, code []byte, gas uint64, value *ui
699703// The different between Create2 with Create is Create2 uses keccak256(0xff ++ msg.sender ++ salt ++ keccak256(init_code))[12:]
700704// instead of the usual sender-and-nonce-hash as the address where the contract is initialized at.
701705func (evm * EVM ) Create2 (caller common.Address , code []byte , gas uint64 , endowment * uint256.Int , salt * uint256.Int ) (ret []byte , contractAddr common.Address , leftOverGas uint64 , usedMultiGas multigas.MultiGas , err error ) {
702- inithash := crypto .Keccak256Hash ( code )
706+ inithash := crypto .HashData ( evm . hasher , code )
703707 contractAddr = crypto .CreateAddress2 (caller , salt .Bytes32 (), inithash [:])
704708 return evm .create (caller , code , gas , endowment , contractAddr , CREATE2 )
705709}
0 commit comments