EIP-4844: fix wiring of maxFeePerBlobGas (#7981)

Previously maxFeePerBlobGas was lost in the `BlobTx` -> `Message`
conversion.

Also added initial support of [EL
EIPTests](https://github.com/ethereum/tests/tree/develop/EIPTests).
This commit is contained in:
Andrew Ashikhmin 2023-08-08 17:44:02 +02:00 committed by GitHub
parent ae76df1b8a
commit 9b3f3bd118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 10 deletions

View File

@ -51,6 +51,7 @@ func (stx BlobTx) AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Mes
if err != nil { if err != nil {
return Message{}, err return Message{}, err
} }
msg.maxFeePerBlobGas = *stx.MaxFeePerBlobGas
msg.blobHashes = stx.BlobVersionedHashes msg.blobHashes = stx.BlobVersionedHashes
return msg, err return msg, err
} }

2
go.mod
View File

@ -49,7 +49,7 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/hashicorp/golang-lru/arc/v2 v2.0.4 github.com/hashicorp/golang-lru/arc/v2 v2.0.4
github.com/hashicorp/golang-lru/v2 v2.0.4 github.com/hashicorp/golang-lru/v2 v2.0.4
github.com/holiman/uint256 v1.2.2 github.com/holiman/uint256 v1.2.3
github.com/huandu/xstrings v1.4.0 github.com/huandu/xstrings v1.4.0
github.com/huin/goupnp v1.2.0 github.com/huin/goupnp v1.2.0
github.com/jackpal/go-nat-pmp v1.0.2 github.com/jackpal/go-nat-pmp v1.0.2

4
go.sum
View File

@ -429,8 +429,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.4 h1:7GHuZcgid37q8o5i3QI9KMT4nCWQQ3Kx3Ov
github.com/hashicorp/golang-lru/v2 v2.0.4/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/golang-lru/v2 v2.0.4/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw= github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.2.2 h1:TXKcSGc2WaxPD2+bmzAsVthL4+pEN0YwXcL5qED83vk= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
github.com/holiman/uint256 v1.2.2/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo= github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbcucJdbSo=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4= github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=

View File

@ -58,3 +58,26 @@ func TestBlockchain(t *testing.T) {
} }
}) })
} }
func TestBlockchainEIP(t *testing.T) {
defer log.Root().SetHandler(log.Root().GetHandler())
log.Root().SetHandler(log.LvlFilterHandler(log.LvlError, log.StderrHandler))
bt := new(testMatcher)
// EOF is not supported yet
bt.skipLoad(`^StateTests/stEOF/`)
// TODO(yperbasis): fix me
bt.skipLoad(`^StateTests/stEIP4844-blobtransactions/`)
bt.skipLoad(`^StateTests/stExample/`)
// TODO(yperbasis): re-enable checkStateRoot
checkStateRoot := false
bt.walk(t, blockEipTestDir, func(t *testing.T, name string, test *BlockTest) {
if err := bt.checkFailure(t, test.Run(t, checkStateRoot)); err != nil {
t.Error(err)
}
})
}

View File

@ -35,6 +35,7 @@ import (
var ( var (
baseDir = filepath.Join(".", "testdata") baseDir = filepath.Join(".", "testdata")
blockTestDir = filepath.Join(baseDir, "BlockchainTests") blockTestDir = filepath.Join(baseDir, "BlockchainTests")
blockEipTestDir = filepath.Join(baseDir, "EIPTests", "BlockchainTests")
stateTestDir = filepath.Join(baseDir, "GeneralStateTests") stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests") rlpTestDir = filepath.Join(baseDir, "RLPTests")

View File

@ -68,7 +68,7 @@ func (t *StateTest) UnmarshalJSON(in []byte) error {
type stJSON struct { type stJSON struct {
Env stEnv `json:"env"` Env stEnv `json:"env"`
Pre types.GenesisAlloc `json:"pre"` Pre types.GenesisAlloc `json:"pre"`
Tx stTransactionMarshaling `json:"transaction"` Tx stTransaction `json:"transaction"`
Out hexutility.Bytes `json:"out"` Out hexutility.Bytes `json:"out"`
Post map[string][]stPostState `json:"post"` Post map[string][]stPostState `json:"post"`
} }
@ -85,7 +85,7 @@ type stPostState struct {
} }
} }
type stTransactionMarshaling struct { type stTransaction struct {
GasPrice *math.HexOrDecimal256 `json:"gasPrice"` GasPrice *math.HexOrDecimal256 `json:"gasPrice"`
MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"`
MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"`
@ -96,6 +96,7 @@ type stTransactionMarshaling struct {
Data []string `json:"data"` Data []string `json:"data"`
Value []string `json:"value"` Value []string `json:"value"`
AccessLists []*types2.AccessList `json:"accessLists,omitempty"` AccessLists []*types2.AccessList `json:"accessLists,omitempty"`
BlobGasFeeCap *math.HexOrDecimal256 `json:"maxFeePerBlobGas,omitempty"`
} }
//go:generate gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go //go:generate gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
@ -375,7 +376,7 @@ func vmTestBlockHash(n uint64) libcommon.Hash {
return libcommon.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String()))) return libcommon.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
} }
func toMessage(tx stTransactionMarshaling, ps stPostState, baseFee *big.Int) (core.Message, error) { func toMessage(tx stTransaction, ps stPostState, baseFee *big.Int) (core.Message, error) {
// Derive sender from private key if present. // Derive sender from private key if present.
var from libcommon.Address var from libcommon.Address
if len(tx.PrivateKey) > 0 { if len(tx.PrivateKey) > 0 {
@ -458,6 +459,11 @@ func toMessage(tx stTransactionMarshaling, ps stPostState, baseFee *big.Int) (co
gpi := big.Int(*gasPrice) gpi := big.Int(*gasPrice)
gasPriceInt := uint256.NewInt(gpi.Uint64()) gasPriceInt := uint256.NewInt(gpi.Uint64())
var blobFeeCap *big.Int
if tx.BlobGasFeeCap != nil {
blobFeeCap = (*big.Int)(tx.BlobGasFeeCap)
}
// TODO the conversion to int64 then uint64 then new int isn't working! // TODO the conversion to int64 then uint64 then new int isn't working!
msg := types.NewMessage( msg := types.NewMessage(
from, from,
@ -466,13 +472,13 @@ func toMessage(tx stTransactionMarshaling, ps stPostState, baseFee *big.Int) (co
value, value,
uint64(gasLimit), uint64(gasLimit),
gasPriceInt, gasPriceInt,
uint256.NewInt(feeCap.Uint64()), uint256.MustFromBig(&feeCap),
uint256.NewInt(tipCap.Uint64()), uint256.MustFromBig(&tipCap),
data, data,
accessList, accessList,
false, /* checkNonce */ false, /* checkNonce */
false, /* isFree */ false, /* isFree */
uint256.NewInt(tipCap.Uint64()), uint256.MustFromBig(blobFeeCap),
) )
return msg, nil return msg, nil

@ -1 +1 @@
Subproject commit 06e276776bc87817c38f6efb492bf6f4527fa904 Subproject commit 9b6382b122140b5479a4ff6152ccf1459440ddff