evm.go 20 KB

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