From fe7dc37be1a7f560e91cc069d79242e65bcd017a Mon Sep 17 00:00:00 2001 From: Shogo Hyodo Date: Fri, 6 Dec 2024 18:01:14 +0900 Subject: [PATCH] Enable 7702 tests --- blockchain/state/statedb.go | 2 +- blockchain/state_transition.go | 7 +++++-- tests/state_test.go | 7 ++++++- tests/state_test_util.go | 27 ++++++++++++++++----------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/blockchain/state/statedb.go b/blockchain/state/statedb.go index 5284651c3..a62af9972 100644 --- a/blockchain/state/statedb.go +++ b/blockchain/state/statedb.go @@ -1111,7 +1111,7 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (root common.Hash, err error) for addr, stateObject := range s.stateObjects { _, isDirty := s.stateObjectsDirty[addr] switch { - case stateObject.selfDestructed || (isDirty && deleteEmptyObjects && stateObject.empty()): + case (stateObject.selfDestructed && stateObject.account.Type() == account.SmartContractAccountType) || (isDirty && deleteEmptyObjects && stateObject.empty()): // If the object has been removed, don't bother syncing it // and just mark it for deletion in the trie. s.deleteStateObject(stateObject) 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/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..834f26ca1 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -336,10 +336,14 @@ func MakePreState(db database.DBManager, accounts blockchain.GenesisAlloc, isTes 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, params.Rules{IsIstanbul: true}) + } else { + if isTestExecutionSpecState { + statedb.CreateSmartContractAccount(addr, params.CodeFormatEVM, params.Rules{IsIstanbul: true}) + } + 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) {