evm.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. // Copyright 2014 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package vm
  17. import (
  18. "errors"
  19. "math/big"
  20. "sync/atomic"
  21. "time"
  22. "github.com/ethereum/go-ethereum/common"
  23. "github.com/ethereum/go-ethereum/crypto"
  24. "github.com/ethereum/go-ethereum/params"
  25. "github.com/holiman/uint256"
  26. )
  27. // emptyCodeHash is used by create to ensure deployment is disallowed to already
  28. // deployed contract addresses (relevant after the account abstraction).
  29. var emptyCodeHash = crypto.Keccak256Hash(nil)
  30. type (
  31. // CanTransferFunc is the signature of a transfer guard function
  32. CanTransferFunc func(StateDB, common.Address, *big.Int) bool
  33. // TransferFunc is the signature of a transfer function
  34. TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
  35. // GetHashFunc returns the n'th block hash in the blockchain
  36. // and is used by the BLOCKHASH EVM op code.
  37. GetHashFunc func(uint64) common.Hash
  38. )
  39. func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
  40. var precompiles map[common.Address]PrecompiledContract
  41. switch {
  42. case evm.chainRules.IsBerlin:
  43. precompiles = PrecompiledContractsBerlin
  44. case evm.chainRules.IsIstanbul:
  45. precompiles = PrecompiledContractsIstanbul
  46. case evm.chainRules.IsByzantium:
  47. precompiles = PrecompiledContractsByzantium
  48. default:
  49. precompiles = PrecompiledContractsHomestead
  50. }
  51. p, ok := precompiles[addr]
  52. return p, ok
  53. }
  54. // run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
  55. func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) {
  56. for _, interpreter := range evm.interpreters {
  57. if interpreter.CanRun(contract.Code) {
  58. if evm.interpreter != interpreter {
  59. // Ensure that the interpreter pointer is set back
  60. // to its current value upon return.
  61. defer func(i Interpreter) {
  62. evm.interpreter = i
  63. }(evm.interpreter)
  64. evm.interpreter = interpreter
  65. }
  66. return interpreter.Run(contract, input, readOnly)
  67. }
  68. }
  69. return nil, errors.New("no compatible interpreter")
  70. }
  71. // BlockContext provides the EVM with auxiliary information. Once provided
  72. // it shouldn't be modified.
  73. type BlockContext struct {
  74. // CanTransfer returns whether the account contains
  75. // sufficient ether to transfer the value
  76. CanTransfer CanTransferFunc
  77. // Transfer transfers ether from one account to the other
  78. Transfer TransferFunc
  79. // GetHash returns the hash corresponding to n
  80. GetHash GetHashFunc
  81. // Block information
  82. Coinbase common.Address // Provides information for COINBASE
  83. GasLimit uint64 // Provides information for GASLIMIT
  84. BlockNumber *big.Int // Provides information for NUMBER
  85. Time *big.Int // Provides information for TIME
  86. Difficulty *big.Int // Provides information for DIFFICULTY
  87. }
  88. // TxContext provides the EVM with information about a transaction.
  89. // All fields can change between transactions.
  90. type TxContext struct {
  91. // Message information
  92. Origin common.Address // Provides information for ORIGIN
  93. GasPrice *big.Int // Provides information for GASPRICE
  94. }
  95. // EVM is the Ethereum Virtual Machine base object and provides
  96. // the necessary tools to run a contract on the given state with
  97. // the provided context. It should be noted that any error
  98. // generated through any of the calls should be considered a
  99. // revert-state-and-consume-all-gas operation, no checks on
  100. // specific errors should ever be performed. The interpreter makes
  101. // sure that any errors generated are to be considered faulty code.
  102. //
  103. // The EVM should never be reused and is not thread safe.
  104. type EVM struct {
  105. // Context provides auxiliary blockchain related information
  106. Context BlockContext
  107. TxContext
  108. // StateDB gives access to the underlying state
  109. StateDB StateDB
  110. // Depth is the current call stack
  111. depth int
  112. // chainConfig contains information about the current chain
  113. chainConfig *params.ChainConfig
  114. // chain rules contains the chain rules for the current epoch
  115. chainRules params.Rules
  116. // virtual machine configuration options used to initialise the
  117. // evm.
  118. vmConfig Config
  119. // global (to this context) ethereum virtual machine
  120. // used throughout the execution of the tx.
  121. interpreters []Interpreter
  122. interpreter Interpreter
  123. // abort is used to abort the EVM calling operations
  124. // NOTE: must be set atomically
  125. abort int32
  126. // callGasTemp holds the gas available for the current call. This is needed because the
  127. // available gas is calculated in gasCall* according to the 63/64 rule and later
  128. // applied in opCall*.
  129. callGasTemp uint64
  130. }
  131. // NewEVM returns a new EVM. The returned EVM is not thread safe and should
  132. // only ever be used *once*.
  133. func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config) *EVM {
  134. evm := &EVM{
  135. Context: blockCtx,
  136. TxContext: txCtx,
  137. StateDB: statedb,
  138. vmConfig: vmConfig,
  139. chainConfig: chainConfig,
  140. chainRules: chainConfig.Rules(blockCtx.BlockNumber),
  141. interpreters: make([]Interpreter, 0, 1),
  142. }
  143. if chainConfig.IsEWASM(blockCtx.BlockNumber) {
  144. // to be implemented by EVM-C and Wagon PRs.
  145. // if vmConfig.EWASMInterpreter != "" {
  146. // extIntOpts := strings.Split(vmConfig.EWASMInterpreter, ":")
  147. // path := extIntOpts[0]
  148. // options := []string{}
  149. // if len(extIntOpts) > 1 {
  150. // options = extIntOpts[1..]
  151. // }
  152. // evm.interpreters = append(evm.interpreters, NewEVMVCInterpreter(evm, vmConfig, options))
  153. // } else {
  154. // evm.interpreters = append(evm.interpreters, NewEWASMInterpreter(evm, vmConfig))
  155. // }
  156. panic("No supported ewasm interpreter yet.")
  157. }
  158. // vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here
  159. // as we always want to have the built-in EVM as the failover option.
  160. evm.interpreters = append(evm.interpreters, NewEVMInterpreter(evm, vmConfig))
  161. evm.interpreter = evm.interpreters[0]
  162. return evm
  163. }
  164. // Reset resets the EVM with a new transaction context.Reset
  165. // This is not threadsafe and should only be done very cautiously.
  166. func (evm *EVM) Reset(txCtx TxContext, statedb StateDB) {
  167. evm.TxContext = txCtx
  168. evm.StateDB = statedb
  169. }
  170. // Cancel cancels any running EVM operation. This may be called concurrently and
  171. // it's safe to be called multiple times.
  172. func (evm *EVM) Cancel() {
  173. atomic.StoreInt32(&evm.abort, 1)
  174. }
  175. // Cancelled returns true if Cancel has been called
  176. func (evm *EVM) Cancelled() bool {
  177. return atomic.LoadInt32(&evm.abort) == 1
  178. }
  179. // Interpreter returns the current interpreter
  180. func (evm *EVM) Interpreter() Interpreter {
  181. return evm.interpreter
  182. }
  183. // Call executes the contract associated with the addr with the given input as
  184. // parameters. It also handles any necessary value transfer required and takes
  185. // the necessary steps to create accounts and reverses the state in case of an
  186. // execution error or failed value transfer.
  187. func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) {
  188. if evm.vmConfig.NoRecursion && evm.depth > 0 {
  189. return nil, gas, nil
  190. }
  191. // Fail if we're trying to execute above the call depth limit
  192. if evm.depth > int(params.CallCreateDepth) {
  193. return nil, gas, ErrDepth
  194. }
  195. // Fail if we're trying to transfer more than the available balance
  196. if value.Sign() != 0 && !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) {
  197. return nil, gas, ErrInsufficientBalance
  198. }
  199. snapshot := evm.StateDB.Snapshot()
  200. p, isPrecompile := evm.precompile(addr)
  201. if !evm.StateDB.Exist(addr) {
  202. if !isPrecompile && evm.chainRules.IsEIP158 && value.Sign() == 0 {
  203. // Calling a non existing account, don't do anything, but ping the tracer
  204. if evm.vmConfig.Debug && evm.depth == 0 {
  205. evm.vmConfig.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
  206. evm.vmConfig.Tracer.CaptureEnd(ret, 0, 0, nil)
  207. }
  208. return nil, gas, nil
  209. }
  210. evm.StateDB.CreateAccount(addr)
  211. }
  212. evm.Context.Transfer(evm.StateDB, caller.Address(), addr, value)
  213. // Capture the tracer start/end events in debug mode
  214. if evm.vmConfig.Debug && evm.depth == 0 {
  215. evm.vmConfig.Tracer.CaptureStart(evm, caller.Address(), addr, false, input, gas, value)
  216. defer func(startGas uint64, startTime time.Time) { // Lazy evaluation of the parameters
  217. evm.vmConfig.Tracer.CaptureEnd(ret, startGas-gas, time.Since(startTime), err)
  218. }(gas, time.Now())
  219. }
  220. if isPrecompile {
  221. ret, gas, err = RunPrecompiledContract(p, input, gas)
  222. } else {
  223. // Initialise a new contract and set the code that is to be used by the EVM.
  224. // The contract is a scoped environment for this execution context only.
  225. code := evm.StateDB.GetCode(addr)
  226. if len(code) == 0 {
  227. ret, err = nil, nil // gas is unchanged
  228. } else {
  229. addrCopy := addr
  230. // If the account has no code, we can abort here
  231. // The depth-check is already done, and precompiles handled above
  232. contract := NewContract(caller, AccountRef(addrCopy), value, gas)
  233. contract.SetCallCode(&addrCopy, evm.StateDB.GetCodeHash(addrCopy), code)
  234. ret, err = run(evm, contract, input, false)
  235. gas = contract.Gas
  236. }
  237. }
  238. // When an error was returned by the EVM or when setting the creation code
  239. // above we revert to the snapshot and consume any gas remaining. Additionally
  240. // when we're in homestead this also counts for code storage gas errors.
  241. if err != nil {
  242. evm.StateDB.RevertToSnapshot(snapshot)
  243. if err != ErrExecutionReverted {
  244. gas = 0
  245. }
  246. // TODO: consider clearing up unused snapshots:
  247. //} else {
  248. // evm.StateDB.DiscardSnapshot(snapshot)
  249. }
  250. return ret, gas, err
  251. }
  252. // CallCode executes the contract associated with the addr with the given input
  253. // as parameters. It also handles any necessary value transfer required and takes
  254. // the necessary steps to create accounts and reverses the state in case of an
  255. // execution error or failed value transfer.
  256. //
  257. // CallCode differs from Call in the sense that it executes the given address'
  258. // code with the caller as context.
  259. func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) {
  260. if evm.vmConfig.NoRecursion && evm.depth > 0 {
  261. return nil, gas, nil
  262. }
  263. // Fail if we're trying to execute above the call depth limit
  264. if evm.depth > int(params.CallCreateDepth) {
  265. return nil, gas, ErrDepth
  266. }
  267. // Fail if we're trying to transfer more than the available balance
  268. // Note although it's noop to transfer X ether to caller itself. But
  269. // if caller doesn't have enough balance, it would be an error to allow
  270. // over-charging itself. So the check here is necessary.
  271. if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) {
  272. return nil, gas, ErrInsufficientBalance
  273. }
  274. var snapshot = evm.StateDB.Snapshot()
  275. // It is allowed to call precompiles, even via delegatecall
  276. if p, isPrecompile := evm.precompile(addr); isPrecompile {
  277. ret, gas, err = RunPrecompiledContract(p, input, gas)
  278. } else {
  279. addrCopy := addr
  280. // Initialise a new contract and set the code that is to be used by the EVM.
  281. // The contract is a scoped environment for this execution context only.
  282. contract := NewContract(caller, AccountRef(caller.Address()), value, gas)
  283. contract.SetCallCode(&addrCopy, evm.StateDB.GetCodeHash(addrCopy), evm.StateDB.GetCode(addrCopy))
  284. ret, err = run(evm, contract, input, false)
  285. gas = contract.Gas
  286. }
  287. if err != nil {
  288. evm.StateDB.RevertToSnapshot(snapshot)
  289. if err != ErrExecutionReverted {
  290. gas = 0
  291. }
  292. }
  293. return ret, gas, err
  294. }
  295. // DelegateCall executes the contract associated with the addr with the given input
  296. // as parameters. It reverses the state in case of an execution error.
  297. //
  298. // DelegateCall differs from CallCode in the sense that it executes the given address'
  299. // code with the caller as context and the caller is set to the caller of the caller.
  300. func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) {
  301. if evm.vmConfig.NoRecursion && evm.depth > 0 {
  302. return nil, gas, nil
  303. }
  304. // Fail if we're trying to execute above the call depth limit
  305. if evm.depth > int(params.CallCreateDepth) {
  306. return nil, gas, ErrDepth
  307. }
  308. var snapshot = evm.StateDB.Snapshot()
  309. // It is allowed to call precompiles, even via delegatecall
  310. if p, isPrecompile := evm.precompile(addr); isPrecompile {
  311. ret, gas, err = RunPrecompiledContract(p, input, gas)
  312. } else {
  313. addrCopy := addr
  314. // Initialise a new contract and make initialise the delegate values
  315. contract := NewContract(caller, AccountRef(caller.Address()), nil, gas).AsDelegate()
  316. contract.SetCallCode(&addrCopy, evm.StateDB.GetCodeHash(addrCopy), evm.StateDB.GetCode(addrCopy))
  317. ret, err = run(evm, contract, input, false)
  318. gas = contract.Gas
  319. }
  320. if err != nil {
  321. evm.StateDB.RevertToSnapshot(snapshot)
  322. if err != ErrExecutionReverted {
  323. gas = 0
  324. }
  325. }
  326. return ret, gas, err
  327. }
  328. // StaticCall executes the contract associated with the addr with the given input
  329. // as parameters while disallowing any modifications to the state during the call.
  330. // Opcodes that attempt to perform such modifications will result in exceptions
  331. // instead of performing the modifications.
  332. func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte, gas uint64) (ret []byte, leftOverGas uint64, err error) {
  333. if evm.vmConfig.NoRecursion && evm.depth > 0 {
  334. return nil, gas, nil
  335. }
  336. // Fail if we're trying to execute above the call depth limit
  337. if evm.depth > int(params.CallCreateDepth) {
  338. return nil, gas, ErrDepth
  339. }
  340. // We take a snapshot here. This is a bit counter-intuitive, and could probably be skipped.
  341. // However, even a staticcall is considered a 'touch'. On mainnet, static calls were introduced
  342. // after all empty accounts were deleted, so this is not required. However, if we omit this,
  343. // then certain tests start failing; stRevertTest/RevertPrecompiledTouchExactOOG.json.
  344. // We could change this, but for now it's left for legacy reasons
  345. var snapshot = evm.StateDB.Snapshot()
  346. // We do an AddBalance of zero here, just in order to trigger a touch.
  347. // This doesn't matter on Mainnet, where all empties are gone at the time of Byzantium,
  348. // but is the correct thing to do and matters on other networks, in tests, and potential
  349. // future scenarios
  350. evm.StateDB.AddBalance(addr, big0)
  351. if p, isPrecompile := evm.precompile(addr); isPrecompile {
  352. ret, gas, err = RunPrecompiledContract(p, input, gas)
  353. } else {
  354. // At this point, we use a copy of address. If we don't, the go compiler will
  355. // leak the 'contract' to the outer scope, and make allocation for 'contract'
  356. // even if the actual execution ends on RunPrecompiled above.
  357. addrCopy := addr
  358. // Initialise a new contract and set the code that is to be used by the EVM.
  359. // The contract is a scoped environment for this execution context only.
  360. contract := NewContract(caller, AccountRef(addrCopy), new(big.Int), gas)
  361. contract.SetCallCode(&addrCopy, evm.StateDB.GetCodeHash(addrCopy), evm.StateDB.GetCode(addrCopy))
  362. // When an error was returned by the EVM or when setting the creation code
  363. // above we revert to the snapshot and consume any gas remaining. Additionally
  364. // when we're in Homestead this also counts for code storage gas errors.
  365. ret, err = run(evm, contract, input, true)
  366. gas = contract.Gas
  367. }
  368. if err != nil {
  369. evm.StateDB.RevertToSnapshot(snapshot)
  370. if err != ErrExecutionReverted {
  371. gas = 0
  372. }
  373. }
  374. return ret, gas, err
  375. }
  376. type codeAndHash struct {
  377. code []byte
  378. hash common.Hash
  379. }
  380. func (c *codeAndHash) Hash() common.Hash {
  381. if c.hash == (common.Hash{}) {
  382. c.hash = crypto.Keccak256Hash(c.code)
  383. }
  384. return c.hash
  385. }
  386. // create creates a new contract using code as deployment code.
  387. func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *big.Int, address common.Address) ([]byte, common.Address, uint64, error) {
  388. // Depth check execution. Fail if we're trying to execute above the
  389. // limit.
  390. if evm.depth > int(params.CallCreateDepth) {
  391. return nil, common.Address{}, gas, ErrDepth
  392. }
  393. if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) {
  394. return nil, common.Address{}, gas, ErrInsufficientBalance
  395. }
  396. nonce := evm.StateDB.GetNonce(caller.Address())
  397. evm.StateDB.SetNonce(caller.Address(), nonce+1)
  398. // We add this to the access list _before_ taking a snapshot. Even if the creation fails,
  399. // the access-list change should not be rolled back
  400. if evm.chainRules.IsBerlin {
  401. evm.StateDB.AddAddressToAccessList(address)
  402. }
  403. // Ensure there's no existing contract already at the designated address
  404. contractHash := evm.StateDB.GetCodeHash(address)
  405. if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != emptyCodeHash) {
  406. return nil, common.Address{}, 0, ErrContractAddressCollision
  407. }
  408. // Create a new account on the state
  409. snapshot := evm.StateDB.Snapshot()
  410. evm.StateDB.CreateAccount(address)
  411. if evm.chainRules.IsEIP158 {
  412. evm.StateDB.SetNonce(address, 1)
  413. }
  414. evm.Context.Transfer(evm.StateDB, caller.Address(), address, value)
  415. // Initialise a new contract and set the code that is to be used by the EVM.
  416. // The contract is a scoped environment for this execution context only.
  417. contract := NewContract(caller, AccountRef(address), value, gas)
  418. contract.SetCodeOptionalHash(&address, codeAndHash)
  419. if evm.vmConfig.NoRecursion && evm.depth > 0 {
  420. return nil, address, gas, nil
  421. }
  422. if evm.vmConfig.Debug && evm.depth == 0 {
  423. evm.vmConfig.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
  424. }
  425. start := time.Now()
  426. ret, err := run(evm, contract, nil, false)
  427. // check whether the max code size has been exceeded
  428. maxCodeSizeExceeded := evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize
  429. // if the contract creation ran successfully and no errors were returned
  430. // calculate the gas required to store the code. If the code could not
  431. // be stored due to not enough gas set an error and let it be handled
  432. // by the error checking condition below.
  433. if err == nil && !maxCodeSizeExceeded {
  434. createDataGas := uint64(len(ret)) * params.CreateDataGas
  435. if contract.UseGas(createDataGas) {
  436. evm.StateDB.SetCode(address, ret)
  437. } else {
  438. err = ErrCodeStoreOutOfGas
  439. }
  440. }
  441. // When an error was returned by the EVM or when setting the creation code
  442. // above we revert to the snapshot and consume any gas remaining. Additionally
  443. // when we're in homestead this also counts for code storage gas errors.
  444. if maxCodeSizeExceeded || (err != nil && (evm.chainRules.IsHomestead || err != ErrCodeStoreOutOfGas)) {
  445. evm.StateDB.RevertToSnapshot(snapshot)
  446. if err != ErrExecutionReverted {
  447. contract.UseGas(contract.Gas)
  448. }
  449. }
  450. // Assign err if contract code size exceeds the max while the err is still empty.
  451. if maxCodeSizeExceeded && err == nil {
  452. err = ErrMaxCodeSizeExceeded
  453. }
  454. if evm.vmConfig.Debug && evm.depth == 0 {
  455. evm.vmConfig.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
  456. }
  457. return ret, address, contract.Gas, err
  458. }
  459. // Create creates a new contract using code as deployment code.
  460. func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
  461. contractAddr = crypto.CreateAddress(caller.Address(), evm.StateDB.GetNonce(caller.Address()))
  462. return evm.create(caller, &codeAndHash{code: code}, gas, value, contractAddr)
  463. }
  464. // Create2 creates a new contract using code as deployment code.
  465. //
  466. // The different between Create2 with Create is Create2 uses sha3(0xff ++ msg.sender ++ salt ++ sha3(init_code))[12:]
  467. // instead of the usual sender-and-nonce-hash as the address where the contract is initialized at.
  468. func (evm *EVM) Create2(caller ContractRef, code []byte, gas uint64, endowment *big.Int, salt *uint256.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
  469. codeAndHash := &codeAndHash{code: code}
  470. contractAddr = crypto.CreateAddress2(caller.Address(), salt.Bytes32(), codeAndHash.Hash().Bytes())
  471. return evm.create(caller, codeAndHash, gas, endowment, contractAddr)
  472. }
  473. // ChainConfig returns the environment's chain configuration
  474. func (evm *EVM) ChainConfig() *params.ChainConfig { return evm.chainConfig }