@@ -21,6 +21,7 @@ import (
2121 "fmt"
2222 "math/big"
2323
24+ "github.com/ethereum/go-ethereum/antimev"
2425 "github.com/ethereum/go-ethereum/common"
2526 "github.com/ethereum/go-ethereum/consensus"
2627 "github.com/ethereum/go-ethereum/consensus/misc"
@@ -60,22 +61,24 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
6061// transactions failed to execute due to insufficient gas it will return an error.
6162func (p * StateProcessor ) Process (block * types.Block , statedb * state.StateDB , cfg vm.Config ) (types.Receipts , []* types.Log , uint64 , error ) {
6263 var (
63- receipts types.Receipts
64- usedGas = new (uint64 )
65- header = block .Header ()
66- blockHash = block .Hash ()
67- blockNumber = block .Number ()
68- allLogs []* types.Log
69- gp = new (GasPool ).AddGas (block .GasLimit ())
64+ receipts types.Receipts
65+ usedGas = new (uint64 )
66+ envelopeCount = uint64 (0 )
67+ header = block .Header ()
68+ blockHash = block .Hash ()
69+ blockNumber = block .Number ()
70+ allLogs []* types.Log
71+ gp = new (GasPool ).AddGas (block .GasLimit ())
7072 )
7173 // Mutate the block and state according to any hard-fork specs
7274 if p .config .DAOForkSupport && p .config .DAOForkBlock != nil && p .config .DAOForkBlock .Cmp (block .Number ()) == 0 {
7375 misc .ApplyDAOHardFork (statedb )
7476 }
7577 var (
76- context = NewEVMBlockContext (header , p .bc , nil )
77- vmenv = vm .NewEVM (context , vm.TxContext {}, statedb , p .config , cfg )
78- signer = types .MakeSigner (p .config , header .Number , header .Time )
78+ context = NewEVMBlockContext (header , p .bc , nil )
79+ vmenv = vm .NewEVM (context , vm.TxContext {}, statedb , p .config , cfg )
80+ signer = types .MakeSigner (p .config , header .Number , header .Time )
81+ envelopeNumberLimit = statedb .GetState (systemcontracts .PolicyProxyHash , systemcontracts .GetMaxEnvelopesPerBlockStateHash ()).Big ().Uint64 ()
7982 )
8083 if beaconRoot := block .BeaconRoot (); beaconRoot != nil {
8184 ProcessBeaconBlockRoot (* beaconRoot , vmenv , statedb )
@@ -88,6 +91,14 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
8891 }
8992 // Iterate over and process the individual transactions
9093 for i , tx := range block .Transactions () {
94+ // Check against envelope number policy
95+ if p .bc .chainConfig .IsNeoXAMEV (blockNumber ) && antimev .IsEnvelope (tx ) {
96+ if envelopeCount >= envelopeNumberLimit {
97+ return nil , nil , 0 , fmt .Errorf ("could not apply tx %d [%v]: %w, envelope limit %v" , i , tx .Hash ().Hex (),
98+ ErrEnvelopeNumberLimitReached , envelopeNumberLimit )
99+ }
100+ envelopeCount ++
101+ }
91102 msg , err := TransactionToMessage (tx , signer , header .BaseFee )
92103 if err != nil {
93104 return nil , nil , 0 , fmt .Errorf ("could not apply tx %d [%v]: %w" , i , tx .Hash ().Hex (), err )
0 commit comments