Skip to content

Commit 81c80a8

Browse files
committed
feat: integration of parallel.Processor with EVM.Create
1 parent 686cd69 commit 81c80a8

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

core/vm/evm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ func (c *codeAndHash) Hash() common.Hash {
433433
return c.hash
434434
}
435435

436-
// create creates a new contract using code as deployment code.
437-
func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *uint256.Int, address common.Address, typ OpCode) ([]byte, common.Address, uint64, error) {
436+
// createCommon creates a new contract using code as deployment code.
437+
func (evm *EVM) createCommon(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *uint256.Int, address common.Address, typ OpCode) ([]byte, common.Address, uint64, error) {
438438
// Depth check execution. Fail if we're trying to execute above the
439439
// limit.
440440
if evm.depth > int(params.CallCreateDepth) {

core/vm/evm.libevm.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
package vm
1818

1919
import (
20+
"github.com/holiman/uint256"
21+
2022
"github.com/ava-labs/libevm/common"
2123
"github.com/ava-labs/libevm/libevm"
2224
"github.com/ava-labs/libevm/log"
23-
"github.com/holiman/uint256"
2425
)
2526

2627
// canCreateContract is a convenience wrapper for calling the
@@ -65,6 +66,16 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
6566
return evm.call(caller, addr, input, gas, value)
6667
}
6768

69+
// create wraps the original geth method of the same name, now name
70+
// [EVM.createCommon], first spending preprocessing gas.
71+
func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *uint256.Int, address common.Address, typ OpCode) ([]byte, common.Address, uint64, error) {
72+
gas, err := evm.spendPreprocessingGas(gas)
73+
if err != nil {
74+
return nil, common.Address{}, gas, err
75+
}
76+
return evm.createCommon(caller, codeAndHash, gas, value, address, typ)
77+
}
78+
6879
func (evm *EVM) spendPreprocessingGas(gas uint64) (uint64, error) {
6980
if evm.depth > 0 || !libevmHooks.Registered() {
7081
return gas, nil

core/vm/hooks.libevm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Hooks interface {
4646

4747
// A Preprocessor performs computation on a transaction before the
4848
// [EVMInterpreter] is invoked and reports its gas charge for spending at the
49-
// beginning of [EVM.Call].
49+
// beginning of [EVM.Call] or [EVM.Create].
5050
type Preprocessor interface {
5151
PreprocessingGasCharge(tx common.Hash) uint64
5252
}

libevm/precompiles/parallel/parallel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func TestIntegration(t *testing.T) {
248248
{'o', 't', 'h', 'e', 'r'},
249249
handler.addr,
250250
} {
251-
ui := uint(i) //nolint:gosec // Known value that won't overflow
251+
ui := uint(i)
252252
data := []byte("hello, world")
253253

254254
// Having all arguments `false` is equivalent to what

0 commit comments

Comments
 (0)