Skip to content

Commit

Permalink
Revert "core, tests: EIP-4844 transaction processing logic (ethereum#…
Browse files Browse the repository at this point in the history
…27721)"

This reverts commit 1481df6.
  • Loading branch information
devopsbo3 committed Nov 10, 2023
1 parent 47377e7 commit f324430
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 268 deletions.
1 change: 0 additions & 1 deletion cmd/evm/staterunner.go
Expand Up @@ -117,7 +117,6 @@ func runStateTest(fname string, cfg vm.Config, jsonOut, dump bool) error {
// Test failed, mark as so and dump any state to aid debugging
result.Pass, result.Error = false, err.Error()
if dump && s != nil {
s, _ = state.New(*result.Root, s.Database(), nil)
dump := s.RawDump(nil)
result.State = &dump
}
Expand Down
14 changes: 12 additions & 2 deletions core/block_validator.go
Expand Up @@ -86,8 +86,18 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
for _, tx := range block.Transactions() {
// Count the number of blobs to validate against the header's dataGasUsed
blobs += len(tx.BlobHashes())
// The individual checks for blob validity (version-check + not empty)
// happens in the state_transition check.

// Validate the data blobs individually too
if tx.Type() == types.BlobTxType {
if len(tx.BlobHashes()) == 0 {
return errors.New("no-blob blob transaction present in block body")
}
for _, hash := range tx.BlobHashes() {
if hash[0] != params.BlobTxHashVersion {
return fmt.Errorf("blob hash version mismatch (have %d, supported %d)", hash[0], params.BlobTxHashVersion)
}
}
}
}
if header.DataGasUsed != nil {
if want := *header.DataGasUsed / params.BlobTxDataGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated
Expand Down
4 changes: 0 additions & 4 deletions core/error.go
Expand Up @@ -100,8 +100,4 @@ var (

// ErrSenderNoEOA is returned if the sender of a transaction is a contract.
ErrSenderNoEOA = errors.New("sender not an eoa")

// ErrBlobFeeCapTooLow is returned if the transaction fee cap is less than the
// data gas fee of the block.
ErrBlobFeeCapTooLow = errors.New("max fee per data gas less than block data gas fee")
)
21 changes: 10 additions & 11 deletions core/evm.go
Expand Up @@ -56,17 +56,16 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
random = &header.MixDigest
}
return vm.BlockContext{
CanTransfer: CanTransfer,
Transfer: Transfer,
GetHash: GetHashFn(header, chain),
Coinbase: beneficiary,
BlockNumber: new(big.Int).Set(header.Number),
Time: header.Time,
Difficulty: new(big.Int).Set(header.Difficulty),
BaseFee: baseFee,
GasLimit: header.GasLimit,
Random: random,
ExcessDataGas: header.ExcessDataGas,
CanTransfer: CanTransfer,
Transfer: Transfer,
GetHash: GetHashFn(header, chain),
Coinbase: beneficiary,
BlockNumber: new(big.Int).Set(header.Number),
Time: header.Time,
Difficulty: new(big.Int).Set(header.Difficulty),
BaseFee: baseFee,
GasLimit: header.GasLimit,
Random: random,
}
}

Expand Down
64 changes: 26 additions & 38 deletions core/gen_genesis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 16 additions & 36 deletions core/genesis.go
Expand Up @@ -59,12 +59,10 @@ type Genesis struct {

// These fields are used for consensus tests. Please don't use them
// in actual genesis blocks.
Number uint64 `json:"number"`
GasUsed uint64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *big.Int `json:"baseFeePerGas"` // EIP-1559
ExcessDataGas *uint64 `json:"excessDataGas"` // EIP-4844
DataGasUsed *uint64 `json:"dataGasUsed"` // EIP-4844
Number uint64 `json:"number"`
GasUsed uint64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *big.Int `json:"baseFeePerGas"`
}

func ReadGenesis(db ethdb.Database) (*Genesis, error) {
Expand Down Expand Up @@ -98,9 +96,6 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) {
genesis.Difficulty = genesisHeader.Difficulty
genesis.Mixhash = genesisHeader.MixDigest
genesis.Coinbase = genesisHeader.Coinbase
genesis.BaseFee = genesisHeader.BaseFee
genesis.ExcessDataGas = genesisHeader.ExcessDataGas
genesis.DataGasUsed = genesisHeader.DataGasUsed

return &genesis, nil
}
Expand Down Expand Up @@ -219,17 +214,15 @@ type GenesisAccount struct {

// field type overrides for gencodec
type genesisSpecMarshaling struct {
Nonce math.HexOrDecimal64
Timestamp math.HexOrDecimal64
ExtraData hexutil.Bytes
GasLimit math.HexOrDecimal64
GasUsed math.HexOrDecimal64
Number math.HexOrDecimal64
Difficulty *math.HexOrDecimal256
Alloc map[common.UnprefixedAddress]GenesisAccount
BaseFee *math.HexOrDecimal256
ExcessDataGas *math.HexOrDecimal64
DataGasUsed *math.HexOrDecimal64
Nonce math.HexOrDecimal64
Timestamp math.HexOrDecimal64
ExtraData hexutil.Bytes
GasLimit math.HexOrDecimal64
GasUsed math.HexOrDecimal64
Number math.HexOrDecimal64
Difficulty *math.HexOrDecimal256
BaseFee *math.HexOrDecimal256
Alloc map[common.UnprefixedAddress]GenesisAccount
}

type genesisAccountMarshaling struct {
Expand Down Expand Up @@ -470,22 +463,9 @@ func (g *Genesis) ToBlock() *types.Block {
}
}
var withdrawals []*types.Withdrawal
if conf := g.Config; conf != nil {
num := big.NewInt(int64(g.Number))
if conf.IsShanghai(num, g.Timestamp) {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = make([]*types.Withdrawal, 0)
}
if conf.IsCancun(num, g.Timestamp) {
head.ExcessDataGas = g.ExcessDataGas
head.DataGasUsed = g.DataGasUsed
if head.ExcessDataGas == nil {
head.ExcessDataGas = new(uint64)
}
if head.DataGasUsed == nil {
head.DataGasUsed = new(uint64)
}
}
if g.Config != nil && g.Config.IsShanghai(big.NewInt(int64(g.Number)), g.Timestamp) {
head.WithdrawalsHash = &types.EmptyWithdrawalsHash
withdrawals = make([]*types.Withdrawal, 0)
}
return types.NewBlock(head, nil, nil, nil, trie.NewStackTrie(nil)).WithWithdrawals(withdrawals)
}
Expand Down
2 changes: 1 addition & 1 deletion core/state_processor.go
Expand Up @@ -157,6 +157,6 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)
vmenv := vm.NewEVM(blockContext, vm.TxContext{BlobHashes: tx.BlobHashes()}, statedb, config, cfg)
vmenv := vm.NewEVM(blockContext, vm.TxContext{}, statedb, config, cfg)
return applyTransaction(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
}

0 comments on commit f324430

Please sign in to comment.