diff --git a/blockchain/state/statedb.go b/blockchain/state/statedb.go index 5284651c3..584e82741 100644 --- a/blockchain/state/statedb.go +++ b/blockchain/state/statedb.go @@ -775,8 +775,6 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) s.journal.append(resetObjectChange{prev: prev, prevdestruct: prevdestruct}) } - newobj.created = true - s.setStateObject(newobj) if prev != nil && !prev.deleted { return newobj, prev @@ -811,8 +809,6 @@ func (s *StateDB) createObjectWithMap(addr common.Address, accountType account.A s.journal.append(resetObjectChange{prev: prev, prevdestruct: prevdestruct}) } - newobj.created = true - s.setStateObject(newobj) if prev != nil && !prev.deleted { return newobj, prev @@ -856,6 +852,7 @@ func (s *StateDB) CreateSmartContractAccountWithKey(addr common.Address, humanRe account.AccountValueKeyCodeInfo: params.NewCodeInfoWithRules(format, r), } new, prev := s.createObjectWithMap(addr, account.SmartContractAccountType, values) + new.created = true if prev != nil { new.setBalance(prev.account.GetBalance()) } diff --git a/blockchain/state_transition.go b/blockchain/state_transition.go index 4be355208..55b1620cc 100644 --- a/blockchain/state_transition.go +++ b/blockchain/state_transition.go @@ -368,10 +368,13 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { // - reset transient storage(eip 1153) st.state.Prepare(rules, msg.ValidatedSender(), msg.ValidatedFeePayer(), st.evm.Context.Coinbase, msg.To(), vm.ActivePrecompiles(rules), msg.AccessList()) + // SetCode sender nonce increment should be done before set code process. + if msg.Type() == types.TxTypeEthereumSetCode { + st.state.IncNonce(msg.ValidatedSender()) + } + // Check authorization list validity and set code. if msg.AuthorizationList() != nil { - // SetCode sender nonce increment should be done before set code process. - st.state.IncNonce(msg.ValidatedSender()) st.processAuthorizationList(msg.AuthorizationList(), *msg.To(), rules) } diff --git a/node/cn/tracers/tracers_test.go b/node/cn/tracers/tracers_test.go index c442b89b2..a6379e5a3 100644 --- a/node/cn/tracers/tracers_test.go +++ b/node/cn/tracers/tracers_test.go @@ -152,7 +152,7 @@ func runTracer(t *testing.T, tc *tracerTestdata, tracer vm.Tracer) (*types.Trans signer = types.MakeSigner(config, header.Number) blockContext = blockchain.NewEVMBlockContext(header, nil, &common.Address{}) // stub author (COINBASE) to 0x0 txContext = blockchain.NewEVMTxContext(tx, header, config) - statedb = tests.MakePreState(database.NewMemoryDBManager(), alloc, false) + statedb = tests.MakePreState(database.NewMemoryDBManager(), alloc, false, config.Rules(new(big.Int).SetUint64(uint64(tc.Context.Number)))) evm = vm.NewEVM(blockContext, txContext, statedb, config, &vm.Config{Debug: true, Tracer: tracer}) ) diff --git a/tests/state_test.go b/tests/state_test.go index 3bce06d74..ebe1e0ea9 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -87,11 +87,16 @@ func (suite *ExecutionSpecStateTestSuite) TestExecutionSpecState() { } st := new(testMatcher) + // TODO-Kaia: should remove these skip + // json format error + st.skipLoad(`^prague\/eip7702_set_code_tx\/set_code_txs\/invalid_tx_invalid_auth_signature.json`) + st.skipLoad(`^prague\/eip7702_set_code_tx\/set_code_txs\/tx_validity_chain_id.json`) + st.skipLoad(`^prague\/eip7702_set_code_tx\/set_code_txs\/tx_validity_nonce.json`) + // tests to skip // unsupported EIPs st.skipLoad(`^cancun\/eip4788_beacon_root\/`) st.skipLoad(`^cancun\/eip4844_blobs\/`) - st.skipLoad(`^prague\/eip7702_set_code_tx\/`) // calculate the different consumed gas because 0x0a and 0x0b contract is set to access list by ActivePrecompiles in Cancun st.skipLoad(`^prague\/eip2537_bls_12_381_precompiles\/bls12_precompiles_before_fork\/precompile_before_fork.json\/tests\/prague\/eip2537_bls_12_381_precompiles\/test_bls12_precompiles_before_fork.py::test_precompile_before_fork`) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index bcbfab0d1..10fcd5ac6 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -255,10 +255,10 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, isTest blockchain.InitDeriveSha(config) block := t.genesis(config).ToBlock(common.Hash{}, nil) memDBManager := database.NewMemoryDBManager() - st = MakePreState(memDBManager, t.json.Pre, isTestExecutionSpecState) + rules := config.Rules(block.Number()) + st = MakePreState(memDBManager, t.json.Pre, isTestExecutionSpecState, rules) post := t.json.Post[subtest.Fork][subtest.Index] - rules := config.Rules(block.Number()) msg, err := t.json.Tx.toMessage(post, rules, isTestExecutionSpecState) if err != nil { return st, common.Hash{}, err @@ -331,15 +331,19 @@ func (t *StateTest) gasLimit(subtest StateSubtest) uint64 { return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas] } -func MakePreState(db database.DBManager, accounts blockchain.GenesisAlloc, isTestExecutionSpecState bool) *state.StateDB { +func MakePreState(db database.DBManager, accounts blockchain.GenesisAlloc, isTestExecutionSpecState bool, rules params.Rules) *state.StateDB { sdb := state.NewDatabase(db) statedb, _ := state.New(common.Hash{}, sdb, nil, nil) for addr, a := range accounts { if len(a.Code) != 0 { - if isTestExecutionSpecState { - statedb.CreateSmartContractAccount(addr, params.CodeFormatEVM, params.Rules{IsIstanbul: true}) + if _, ok := types.ParseDelegation(a.Code); ok { + statedb.SetCodeToEOA(addr, a.Code, rules) + } else { + if isTestExecutionSpecState { + statedb.CreateSmartContractAccount(addr, params.CodeFormatEVM, rules) + } + statedb.SetCode(addr, a.Code) } - statedb.SetCode(addr, a.Code) } for k, v := range a.Storage { statedb.SetState(addr, k, v) @@ -414,12 +418,6 @@ func (tx *stTransaction) toMessage(ps stPostState, r params.Rules, isTestExecuti accessList = *tx.AccessLists[ps.Indexes.Data] } - var intrinsicGas uint64 - if isTestExecutionSpecState { - intrinsicGas, err = useEthIntrinsicGas(data, accessList, to == nil, r) - } else { - intrinsicGas, err = types.IntrinsicGas(data, nil, nil, to == nil, r) - } var authorizationList types.AuthorizationList if tx.AuthorizationList != nil { authorizationList = make(types.AuthorizationList, 0) @@ -435,6 +433,13 @@ func (tx *stTransaction) toMessage(ps stPostState, r params.Rules, isTestExecuti } } + var intrinsicGas uint64 + if isTestExecutionSpecState { + intrinsicGas, err = useEthIntrinsicGas(data, accessList, authorizationList, to == nil, r) + } else { + intrinsicGas, err = types.IntrinsicGas(data, nil, nil, to == nil, r) + } + if err != nil { return nil, err } @@ -491,11 +496,11 @@ func useEthOpCodeGas(r params.Rules, evm *vm.EVM) { } } -func useEthIntrinsicGas(data []byte, accessList types.AccessList, contractCreation bool, r params.Rules) (uint64, error) { +func useEthIntrinsicGas(data []byte, accessList types.AccessList, authorizationList types.AuthorizationList, contractCreation bool, r params.Rules) (uint64, error) { if r.IsIstanbul { r.IsPrague = true } - return types.IntrinsicGas(data, accessList, nil, contractCreation, r) + return types.IntrinsicGas(data, accessList, authorizationList, contractCreation, r) } func useEthMiningReward(statedb *state.StateDB, evm *vm.EVM, tx *stTransaction, envBaseFee *big.Int, usedGas uint64, gasPrice *big.Int) { diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index 75af32a51..0fb5a333f 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -86,7 +86,8 @@ type vmExecMarshaling struct { func (t *VMTest) Run(vmconfig vm.Config) error { memDBManager := database.NewMemoryDBManager() - statedb := MakePreState(memDBManager, t.json.Pre, false) + rules := params.MainnetChainConfig.Rules(new(big.Int).SetUint64(t.json.Env.Number)) + statedb := MakePreState(memDBManager, t.json.Pre, false, rules) ret, gasRemaining, err := t.exec(statedb, vmconfig) if t.json.GasRemaining == nil {