core, tests: EIP-4844 transaction processing logic (#27721)

This updates the reference tests to the latest version and also adds logic
to process EIP-4844 blob transactions into the state transition. We are now
passing most Cancun fork tests.

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Martin Holst Swende
2023-07-15 23:27:36 +02:00
committed by GitHub
co-authored by Marius van der Wijden Felix Lange
parent 99e000cb13
commit b058cf454b
14 changed files with 268 additions and 185 deletions
+13
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/types"
@@ -26,6 +27,8 @@ func (s stTransaction) MarshalJSON() ([]byte, error) {
GasLimit []math.HexOrDecimal64 `json:"gasLimit"`
Value []string `json:"value"`
PrivateKey hexutil.Bytes `json:"secretKey"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
BlobGasFeeCap *math.HexOrDecimal256 `json:"maxFeePerDataGas,omitempty"`
}
var enc stTransaction
enc.GasPrice = (*math.HexOrDecimal256)(s.GasPrice)
@@ -43,6 +46,8 @@ func (s stTransaction) MarshalJSON() ([]byte, error) {
}
enc.Value = s.Value
enc.PrivateKey = s.PrivateKey
enc.BlobVersionedHashes = s.BlobVersionedHashes
enc.BlobGasFeeCap = (*math.HexOrDecimal256)(s.BlobGasFeeCap)
return json.Marshal(&enc)
}
@@ -59,6 +64,8 @@ func (s *stTransaction) UnmarshalJSON(input []byte) error {
GasLimit []math.HexOrDecimal64 `json:"gasLimit"`
Value []string `json:"value"`
PrivateKey *hexutil.Bytes `json:"secretKey"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
BlobGasFeeCap *math.HexOrDecimal256 `json:"maxFeePerDataGas,omitempty"`
}
var dec stTransaction
if err := json.Unmarshal(input, &dec); err != nil {
@@ -97,5 +104,11 @@ func (s *stTransaction) UnmarshalJSON(input []byte) error {
if dec.PrivateKey != nil {
s.PrivateKey = *dec.PrivateKey
}
if dec.BlobVersionedHashes != nil {
s.BlobVersionedHashes = dec.BlobVersionedHashes
}
if dec.BlobGasFeeCap != nil {
s.BlobGasFeeCap = (*big.Int)(dec.BlobGasFeeCap)
}
return nil
}
+7 -6
View File
@@ -48,23 +48,24 @@ func TestState(t *testing.T) {
st.slow(`^stStaticCall/static_Return50000`)
st.slow(`^stSystemOperationsTest/CallRecursiveBomb`)
st.slow(`^stTransactionTest/Opcodes_TransactionInit`)
// Very time consuming
st.skipLoad(`^stTimeConsuming/`)
st.skipLoad(`.*vmPerformance/loop.*`)
// Uses 1GB RAM per tested fork
st.skipLoad(`^stStaticCall/static_Call1MB`)
// Broken tests:
//
// The stEOF tests are generated with EOF as part of Shanghai, which
// is erroneous. Therefore, these tests are skipped.
st.skipLoad(`^EIPTests/stEOF/`)
// EOF is not part of cancun
st.skipLoad(`^stEOF/`)
// Expected failures:
// These EIP-4844 tests need to be regenerated.
st.fails(`stEIP4844-blobtransactions/opcodeBlobhashOutOfRange.json`, "test has incorrect state root")
st.fails(`stEIP4844-blobtransactions/opcodeBlobhBounds.json`, "test has incorrect state root")
// For Istanbul, older tests were moved into LegacyTests
for _, dir := range []string{
filepath.Join(baseDir, "EIPTests", "StateTests"),
stateTestDir,
legacyStateTestDir,
benchmarksDir,
+15 -10
View File
@@ -113,6 +113,8 @@ type stTransaction struct {
GasLimit []uint64 `json:"gasLimit"`
Value []string `json:"value"`
PrivateKey []byte `json:"secretKey"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
BlobGasFeeCap *big.Int `json:"maxFeePerDataGas,omitempty"`
}
type stTransactionMarshaling struct {
@@ -122,6 +124,7 @@ type stTransactionMarshaling struct {
Nonce math.HexOrDecimal64
GasLimit []math.HexOrDecimal64
PrivateKey hexutil.Bytes
BlobGasFeeCap *math.HexOrDecimal256
}
// GetChainConfig takes a fork definition and returns a chain config.
@@ -403,16 +406,18 @@ func (tx *stTransaction) toMessage(ps stPostState, baseFee *big.Int) (*core.Mess
}
msg := &core.Message{
From: from,
To: to,
Nonce: tx.Nonce,
Value: value,
GasLimit: gasLimit,
GasPrice: gasPrice,
GasFeeCap: tx.MaxFeePerGas,
GasTipCap: tx.MaxPriorityFeePerGas,
Data: data,
AccessList: accessList,
From: from,
To: to,
Nonce: tx.Nonce,
Value: value,
GasLimit: gasLimit,
GasPrice: gasPrice,
GasFeeCap: tx.MaxFeePerGas,
GasTipCap: tx.MaxPriorityFeePerGas,
Data: data,
AccessList: accessList,
BlobHashes: tx.BlobVersionedHashes,
BlobGasFeeCap: tx.BlobGasFeeCap,
}
return msg, nil
}