From a17f843f8fb4ad50740ca765f311cf6710613779 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Thu, 29 Aug 2024 11:43:39 +0200 Subject: [PATCH] core: fix rebasing issues --- core/blockchain_test.go | 3 ++- core/state_transition.go | 13 +------------ core/vm/eips.go | 10 +++++----- core/vm/eof_test.go | 8 ++++---- core/vm/evm.go | 4 ++-- 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index ef6662fb74..ad68af3f6e 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -4632,7 +4632,7 @@ func TestEOF(t *testing.T) { byte(vm.PUSH1), byte(0), byte(vm.RJUMPV), // jump over invalid op - byte(1), + byte(0), byte(0), byte(1), @@ -4658,6 +4658,7 @@ func TestEOF(t *testing.T) { gspec.Config.BerlinBlock = common.Big0 gspec.Config.LondonBlock = common.Big0 gspec.Config.ShanghaiTime = u64(0) + gspec.Config.PragueTime = u64(0) signer := types.LatestSigner(gspec.Config) container := vm.Container{ diff --git a/core/state_transition.go b/core/state_transition.go index 49375c72b1..88e6d38871 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -148,7 +148,6 @@ type Message struct { BlobGasFeeCap *big.Int BlobHashes []common.Hash AuthList types.AuthorizationList - InitCodes [][]byte // When SkipAccountChecks is true, the message nonce is not checked against the // account nonce in state. It also disables checking that the sender is an EOA. @@ -172,7 +171,6 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.In SkipAccountChecks: false, BlobHashes: tx.BlobHashes(), BlobGasFeeCap: tx.BlobGasFeeCap(), - InitCodes: tx.InitCodes(), } // If baseFee provided, set gasPrice to effectiveGasPrice. if baseFee != nil { @@ -424,17 +422,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { contractCreation = msg.To == nil ) - // Add the initcode data for calculation of the intrinsic gas - // TODO (MariusVanDerWijden): while this should work, it is very - // dirty, better to pass the initcodes directly to IntrinsicGas - // and duplicate the cost accounting logic there. - data := msg.Data - for _, initcode := range msg.InitCodes { - data = append(data, initcode...) - } - // Check clauses 4-5, subtract intrinsic gas if everything is correct - gas, err := IntrinsicGas(data, msg.AccessList, msg.AuthList, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai) + gas, err := IntrinsicGas(msg.Data, msg.AccessList, msg.AuthList, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai) if err != nil { return nil, err } diff --git a/core/vm/eips.go b/core/vm/eips.go index 69213b5d8f..6093ccf755 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -872,7 +872,7 @@ func opEOFCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ( value = scope.Stack.pop() salt = scope.Stack.pop() offset, size = scope.Stack.pop(), scope.Stack.pop() - input = scope.Memory.GetCopy(int64(offset.Uint64()), int64(size.Uint64())) + input = scope.Memory.GetCopy(offset.Uint64(), size.Uint64()) ) if int(idx) >= len(scope.Contract.Container.ContainerCode) { return nil, fmt.Errorf("invalid subcontainer") @@ -927,7 +927,7 @@ func opReturnContract(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte if int(idx) >= len(scope.Contract.Container.ContainerSections) { return nil, fmt.Errorf("invalid subcontainer") } - ret := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64())) + ret := scope.Memory.GetPtr(offset.Uint64(), size.Uint64()) containerCode := scope.Contract.Container.ContainerCode[idx] deployedCode := append(containerCode, ret...) if len(deployedCode) == 0 { @@ -1060,7 +1060,7 @@ func opExtCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([] // safe a memory alloc temp := addr // Get the arguments from the memory. - args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64())) + args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64()) if interpreter.readOnly && !value.IsZero() { return nil, ErrWriteProtection @@ -1098,7 +1098,7 @@ func opExtDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCont // safe a memory alloc temp := addr // Get arguments from the memory. - args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64())) + args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64()) // Check that we're only calling non-legacy contracts var ( @@ -1144,7 +1144,7 @@ func opExtStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContex // safe a memory alloc temp := addr // Get arguments from the memory. - args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64())) + args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64()) ret, returnGas, err := interpreter.evm.StaticCall(scope.Contract, toAddr, args, gas) if err == ErrExecutionReverted { diff --git a/core/vm/eof_test.go b/core/vm/eof_test.go index df79430497..07fc448199 100644 --- a/core/vm/eof_test.go +++ b/core/vm/eof_test.go @@ -67,7 +67,7 @@ func TestEOFMarshaling(t *testing.T) { got Container ) t.Logf("b: %#x", b) - if err := got.UnmarshalBinary(b); err != nil && err != test.err { + if err := got.UnmarshalBinary(b, true); err != nil && err != test.err { t.Fatalf("test %d: got error \"%v\", want \"%v\"", i, err, test.err) } if !reflect.DeepEqual(got, test.want) { @@ -78,7 +78,7 @@ func TestEOFMarshaling(t *testing.T) { func TestEOFSubcontainer(t *testing.T) { var subcontainer = new(Container) - if err := subcontainer.UnmarshalBinary(common.Hex2Bytes("ef000101000402000100010400000000800000fe")); err != nil { + if err := subcontainer.UnmarshalBinary(common.Hex2Bytes("ef000101000402000100010400000000800000fe"), true); err != nil { t.Fatal(err) } container := Container{ @@ -92,7 +92,7 @@ func TestEOFSubcontainer(t *testing.T) { b = container.MarshalBinary() got Container ) - if err := got.UnmarshalBinary(b); err != nil { + if err := got.UnmarshalBinary(b, true); err != nil { t.Fatal(err) } fmt.Print(got) @@ -112,7 +112,7 @@ func TestMarshaling(t *testing.T) { t.Fatalf("test %d: error decoding: %v", i, err) } var got Container - if err := got.UnmarshalBinary(s); err != nil { + if err := got.UnmarshalBinary(s, true); err != nil { t.Fatalf("test %d: got error %v", i, err) } } diff --git a/core/vm/evm.go b/core/vm/evm.go index dbd3e103b4..6fec499265 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -485,7 +485,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, if evm.chainRules.IsPrague { if isInitcodeEOF { if !fromEOF { - return nil, common.Address{}, gas, ErrLegacyCode + return nil, common.Address{}, gas, fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, ErrLegacyCode) } // If the initcode is EOF, verify it is well-formed. var c Container @@ -564,7 +564,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // Reject legacy contract deployment from EOF. if err == nil && isInitcodeEOF && !hasEOFMagic(ret) { - err = ErrLegacyCode + err = fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, ErrLegacyCode) } // Reject EOF deployment from legacy. if err == nil && !isInitcodeEOF && hasEOFMagic(ret) {