diff --git a/simulators/ethereum/pyspec/Dockerfile b/simulators/ethereum/pyspec/Dockerfile index a9befb51d8..529857039d 100644 --- a/simulators/ethereum/pyspec/Dockerfile +++ b/simulators/ethereum/pyspec/Dockerfile @@ -21,8 +21,8 @@ COPY --from=builder /source/pyspec/pyspec . # To run locally generated fixtures, comment the following RUN lines and # uncomment the ADD line. # Download the latest fixture release. -RUN wget https://github.com/ethereum/execution-spec-tests/releases/download/v1.0.3/fixtures.tar.gz -RUN tar -xzvf fixtures.tar.gz +RUN wget https://github.com/ethereum/execution-spec-tests/releases/download/v1.0.4/fixtures_hive.tar.gz +RUN tar -xzvf fixtures_hive.tar.gz RUN mv fixtures /fixtures # ADD ./pyspec/fixtures /fixtures diff --git a/simulators/ethereum/pyspec/gen_bh.go b/simulators/ethereum/pyspec/gen_bh.go deleted file mode 100644 index ea6822e59e..0000000000 --- a/simulators/ethereum/pyspec/gen_bh.go +++ /dev/null @@ -1,190 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -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" -) - -var _ = (*blockHeaderUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (b blockHeader) MarshalJSON() ([]byte, error) { - type blockHeader struct { - ParentHash common.Hash `json:"parentHash"` - UncleHash common.Hash `json:"sha3Uncles"` - UncleHashAlt common.Hash `json:"uncleHash"` - Coinbase common.Address `json:"coinbase"` - CoinbaseAlt common.Address `json:"author"` - CoinbaseAlt2 common.Address `json:"miner"` - StateRoot common.Hash `json:"stateRoot"` - TransactionTrie common.Hash `json:"transactionRoot"` - TransactionTrieAlt common.Hash `json:"transactionTrie"` - ReceiptTrie common.Hash `json:"receiptsRoot"` - ReceiptTrieAlt common.Hash `json:"receiptTrie"` - Bloom types.Bloom `json:"bloom"` - Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Number *math.HexOrDecimal256 `json:"number"` - GasLimit math.HexOrDecimal64 `json:"gasLimit"` - GasUsed math.HexOrDecimal64 `json:"gasUsed"` - Timestamp *math.HexOrDecimal256 `json:"timestamp"` - ExtraData hexutil.Bytes `json:"extraData"` - MixHash common.Hash `json:"mixHash"` - Nonce types.BlockNonce `json:"nonce"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` - Hash common.Hash `json:"hash"` - WithdrawalsRoot common.Hash `json:"withdrawalsRoot"` - BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` - ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"` - } - var enc blockHeader - enc.ParentHash = b.ParentHash - enc.UncleHash = b.UncleHash - enc.UncleHashAlt = b.UncleHashAlt - enc.Coinbase = b.Coinbase - enc.CoinbaseAlt = b.CoinbaseAlt - enc.CoinbaseAlt2 = b.CoinbaseAlt2 - enc.StateRoot = b.StateRoot - enc.TransactionTrie = b.TransactionTrie - enc.TransactionTrieAlt = b.TransactionTrieAlt - enc.ReceiptTrie = b.ReceiptTrie - enc.ReceiptTrieAlt = b.ReceiptTrieAlt - enc.Bloom = b.Bloom - enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty) - enc.Number = (*math.HexOrDecimal256)(b.Number) - enc.GasLimit = math.HexOrDecimal64(b.GasLimit) - enc.GasUsed = math.HexOrDecimal64(b.GasUsed) - enc.Timestamp = (*math.HexOrDecimal256)(b.Timestamp) - enc.ExtraData = b.ExtraData - enc.MixHash = b.MixHash - enc.Nonce = b.Nonce - enc.BaseFee = (*math.HexOrDecimal256)(b.BaseFee) - enc.Hash = b.Hash - enc.WithdrawalsRoot = b.WithdrawalsRoot - enc.BlobGasUsed = (*math.HexOrDecimal64)(b.BlobGasUsed) - enc.ExcessBlobGas = (*math.HexOrDecimal64)(b.ExcessBlobGas) - enc.BeaconRoot = b.BeaconRoot - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (b *blockHeader) UnmarshalJSON(input []byte) error { - type blockHeader struct { - ParentHash *common.Hash `json:"parentHash"` - UncleHash *common.Hash `json:"sha3Uncles"` - UncleHashAlt *common.Hash `json:"uncleHash"` - Coinbase *common.Address `json:"coinbase"` - CoinbaseAlt *common.Address `json:"author"` - CoinbaseAlt2 *common.Address `json:"miner"` - StateRoot *common.Hash `json:"stateRoot"` - TransactionTrie *common.Hash `json:"transactionRoot"` - TransactionTrieAlt *common.Hash `json:"transactionTrie"` - ReceiptTrie *common.Hash `json:"receiptsRoot"` - ReceiptTrieAlt *common.Hash `json:"receiptTrie"` - Bloom *types.Bloom `json:"bloom"` - Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Number *math.HexOrDecimal256 `json:"number"` - GasLimit *math.HexOrDecimal64 `json:"gasLimit"` - GasUsed *math.HexOrDecimal64 `json:"gasUsed"` - Timestamp *math.HexOrDecimal256 `json:"timestamp"` - ExtraData *hexutil.Bytes `json:"extraData"` - MixHash *common.Hash `json:"mixHash"` - Nonce *types.BlockNonce `json:"nonce"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` - Hash *common.Hash `json:"hash"` - WithdrawalsRoot *common.Hash `json:"withdrawalsRoot"` - BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` - ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"` - } - var dec blockHeader - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.ParentHash != nil { - b.ParentHash = *dec.ParentHash - } - if dec.UncleHash != nil { - b.UncleHash = *dec.UncleHash - } - if dec.UncleHashAlt != nil { - b.UncleHashAlt = *dec.UncleHashAlt - } - if dec.Coinbase != nil { - b.Coinbase = *dec.Coinbase - } - if dec.CoinbaseAlt != nil { - b.CoinbaseAlt = *dec.CoinbaseAlt - } - if dec.CoinbaseAlt2 != nil { - b.CoinbaseAlt2 = *dec.CoinbaseAlt2 - } - if dec.StateRoot != nil { - b.StateRoot = *dec.StateRoot - } - if dec.TransactionTrie != nil { - b.TransactionTrie = *dec.TransactionTrie - } - if dec.TransactionTrieAlt != nil { - b.TransactionTrieAlt = *dec.TransactionTrieAlt - } - if dec.ReceiptTrie != nil { - b.ReceiptTrie = *dec.ReceiptTrie - } - if dec.ReceiptTrieAlt != nil { - b.ReceiptTrieAlt = *dec.ReceiptTrieAlt - } - if dec.Bloom != nil { - b.Bloom = *dec.Bloom - } - if dec.Difficulty != nil { - b.Difficulty = (*big.Int)(dec.Difficulty) - } - if dec.Number != nil { - b.Number = (*big.Int)(dec.Number) - } - if dec.GasLimit != nil { - b.GasLimit = uint64(*dec.GasLimit) - } - if dec.GasUsed != nil { - b.GasUsed = uint64(*dec.GasUsed) - } - if dec.Timestamp != nil { - b.Timestamp = (*big.Int)(dec.Timestamp) - } - if dec.ExtraData != nil { - b.ExtraData = *dec.ExtraData - } - if dec.MixHash != nil { - b.MixHash = *dec.MixHash - } - if dec.Nonce != nil { - b.Nonce = *dec.Nonce - } - if dec.BaseFee != nil { - b.BaseFee = (*big.Int)(dec.BaseFee) - } - if dec.Hash != nil { - b.Hash = *dec.Hash - } - if dec.WithdrawalsRoot != nil { - b.WithdrawalsRoot = *dec.WithdrawalsRoot - } - if dec.BlobGasUsed != nil { - b.BlobGasUsed = (*uint64)(dec.BlobGasUsed) - } - if dec.ExcessBlobGas != nil { - b.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) - } - if dec.BeaconRoot != nil { - b.BeaconRoot = dec.BeaconRoot - } - return nil -} diff --git a/simulators/ethereum/pyspec/gen_enp.go b/simulators/ethereum/pyspec/gen_enp.go deleted file mode 100644 index 653b0f48a2..0000000000 --- a/simulators/ethereum/pyspec/gen_enp.go +++ /dev/null @@ -1,62 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -import ( - "encoding/json" - - "github.com/ethereum/go-ethereum/beacon/engine" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/math" -) - -var _ = (*engineNewPayloadUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (e engineNewPayload) MarshalJSON() ([]byte, error) { - type engineNewPayload struct { - Payload *engine.ExecutableData `json:"executionPayload"` - BlobVersionedHashes []common.Hash `json:"expectedBlobVersionedHashes"` - ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` - Version math.HexOrDecimal64 `json:"version"` - ErrorCode int64 `json:"errorCode,string"` - } - var enc engineNewPayload - enc.Payload = e.Payload - enc.BlobVersionedHashes = e.BlobVersionedHashes - enc.ParentBeaconBlockRoot = e.ParentBeaconBlockRoot - enc.Version = math.HexOrDecimal64(e.Version) - enc.ErrorCode = e.ErrorCode - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (e *engineNewPayload) UnmarshalJSON(input []byte) error { - type engineNewPayload struct { - Payload *engine.ExecutableData `json:"executionPayload"` - BlobVersionedHashes []common.Hash `json:"expectedBlobVersionedHashes"` - ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` - Version *math.HexOrDecimal64 `json:"version"` - ErrorCode *int64 `json:"errorCode,string"` - } - var dec engineNewPayload - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Payload != nil { - e.Payload = dec.Payload - } - if dec.BlobVersionedHashes != nil { - e.BlobVersionedHashes = dec.BlobVersionedHashes - } - if dec.ParentBeaconBlockRoot != nil { - e.ParentBeaconBlockRoot = dec.ParentBeaconBlockRoot - } - if dec.Version != nil { - e.Version = uint64(*dec.Version) - } - if dec.ErrorCode != nil { - e.ErrorCode = *dec.ErrorCode - } - return nil -} diff --git a/simulators/ethereum/pyspec/gen_gb.go b/simulators/ethereum/pyspec/gen_gb.go new file mode 100644 index 0000000000..09b9e4bea6 --- /dev/null +++ b/simulators/ethereum/pyspec/gen_gb.go @@ -0,0 +1,100 @@ +// Code generated by github.com/fjl/gencodec. DO NOT EDIT. + +package main + +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" +) + +var _ = (*genesisBlockUnmarshaling)(nil) + +// MarshalJSON marshals as JSON. +func (g genesisBlock) MarshalJSON() ([]byte, error) { + type genesisBlock struct { + Coinbase common.Address `json:"coinbase"` + Difficulty *math.HexOrDecimal256 `json:"difficulty"` + GasLimit math.HexOrDecimal64 `json:"gasLimit"` + Timestamp *math.HexOrDecimal256 `json:"timestamp"` + ExtraData hexutil.Bytes `json:"extraData"` + MixHash common.Hash `json:"mixHash"` + Nonce types.BlockNonce `json:"nonce"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` + BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` + ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` + Hash common.Hash `json:"hash"` + } + var enc genesisBlock + enc.Coinbase = g.Coinbase + enc.Difficulty = (*math.HexOrDecimal256)(g.Difficulty) + enc.GasLimit = math.HexOrDecimal64(g.GasLimit) + enc.Timestamp = (*math.HexOrDecimal256)(g.Timestamp) + enc.ExtraData = g.ExtraData + enc.MixHash = g.MixHash + enc.Nonce = g.Nonce + enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee) + enc.BlobGasUsed = (*math.HexOrDecimal64)(g.BlobGasUsed) + enc.ExcessBlobGas = (*math.HexOrDecimal64)(g.ExcessBlobGas) + enc.Hash = g.Hash + return json.Marshal(&enc) +} + +// UnmarshalJSON unmarshals from JSON. +func (g *genesisBlock) UnmarshalJSON(input []byte) error { + type genesisBlock struct { + Coinbase *common.Address `json:"coinbase"` + Difficulty *math.HexOrDecimal256 `json:"difficulty"` + GasLimit *math.HexOrDecimal64 `json:"gasLimit"` + Timestamp *math.HexOrDecimal256 `json:"timestamp"` + ExtraData *hexutil.Bytes `json:"extraData"` + MixHash *common.Hash `json:"mixHash"` + Nonce *types.BlockNonce `json:"nonce"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` + BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"` + ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"` + Hash *common.Hash `json:"hash"` + } + var dec genesisBlock + if err := json.Unmarshal(input, &dec); err != nil { + return err + } + if dec.Coinbase != nil { + g.Coinbase = *dec.Coinbase + } + if dec.Difficulty != nil { + g.Difficulty = (*big.Int)(dec.Difficulty) + } + if dec.GasLimit != nil { + g.GasLimit = uint64(*dec.GasLimit) + } + if dec.Timestamp != nil { + g.Timestamp = (*big.Int)(dec.Timestamp) + } + if dec.ExtraData != nil { + g.ExtraData = *dec.ExtraData + } + if dec.MixHash != nil { + g.MixHash = *dec.MixHash + } + if dec.Nonce != nil { + g.Nonce = *dec.Nonce + } + if dec.BaseFee != nil { + g.BaseFee = (*big.Int)(dec.BaseFee) + } + if dec.BlobGasUsed != nil { + g.BlobGasUsed = (*uint64)(dec.BlobGasUsed) + } + if dec.ExcessBlobGas != nil { + g.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) + } + if dec.Hash != nil { + g.Hash = *dec.Hash + } + return nil +} diff --git a/simulators/ethereum/pyspec/gen_txs.go b/simulators/ethereum/pyspec/gen_txs.go deleted file mode 100644 index 9dd464ee33..0000000000 --- a/simulators/ethereum/pyspec/gen_txs.go +++ /dev/null @@ -1,142 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -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" -) - -var _ = (*transactionUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (t transaction) MarshalJSON() ([]byte, error) { - type transaction struct { - Type *math.HexOrDecimal64 `json:"type"` - ChainId *math.HexOrDecimal256 `json:"chainId"` - Nonce math.HexOrDecimal64 `json:"nonce"` - GasPrice *math.HexOrDecimal256 `json:"gasPrice"` - MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` - MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` - Gas math.HexOrDecimal64 `json:"gasLimit"` - Value *math.HexOrDecimal256 `json:"value"` - Input hexutil.Bytes `json:"data"` - To string `json:"to"` - Protected bool `json:"protected"` - AccessList *types.AccessList `json:"accessList"` - SecretKey *common.Hash `json:"secretKey"` - V *math.HexOrDecimal256 `json:"v"` - R *math.HexOrDecimal256 `json:"r"` - S *math.HexOrDecimal256 `json:"s"` - MaxFeePerDataGas *math.HexOrDecimal256 `json:"maxFeePerDataGas"` - BlobVersionedHashes []*common.Hash `json:"blobVersionedHashes"` - } - var enc transaction - enc.Type = (*math.HexOrDecimal64)(t.Type) - enc.ChainId = (*math.HexOrDecimal256)(t.ChainId) - enc.Nonce = math.HexOrDecimal64(t.Nonce) - enc.GasPrice = (*math.HexOrDecimal256)(t.GasPrice) - enc.MaxPriorityFeePerGas = (*math.HexOrDecimal256)(t.MaxPriorityFeePerGas) - enc.MaxFeePerGas = (*math.HexOrDecimal256)(t.MaxFeePerGas) - enc.Gas = math.HexOrDecimal64(t.Gas) - enc.Value = (*math.HexOrDecimal256)(t.Value) - enc.Input = t.Input - enc.To = t.To - enc.Protected = t.Protected - enc.AccessList = t.AccessList - enc.SecretKey = t.SecretKey - enc.V = (*math.HexOrDecimal256)(t.V) - enc.R = (*math.HexOrDecimal256)(t.R) - enc.S = (*math.HexOrDecimal256)(t.S) - enc.MaxFeePerDataGas = (*math.HexOrDecimal256)(t.MaxFeePerDataGas) - enc.BlobVersionedHashes = t.BlobVersionedHashes - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (t *transaction) UnmarshalJSON(input []byte) error { - type transaction struct { - Type *math.HexOrDecimal64 `json:"type"` - ChainId *math.HexOrDecimal256 `json:"chainId"` - Nonce *math.HexOrDecimal64 `json:"nonce"` - GasPrice *math.HexOrDecimal256 `json:"gasPrice"` - MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` - MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` - Gas *math.HexOrDecimal64 `json:"gasLimit"` - Value *math.HexOrDecimal256 `json:"value"` - Input *hexutil.Bytes `json:"data"` - To *string `json:"to"` - Protected *bool `json:"protected"` - AccessList *types.AccessList `json:"accessList"` - SecretKey *common.Hash `json:"secretKey"` - V *math.HexOrDecimal256 `json:"v"` - R *math.HexOrDecimal256 `json:"r"` - S *math.HexOrDecimal256 `json:"s"` - MaxFeePerDataGas *math.HexOrDecimal256 `json:"maxFeePerDataGas"` - BlobVersionedHashes []*common.Hash `json:"blobVersionedHashes"` - } - var dec transaction - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Type != nil { - t.Type = (*uint64)(dec.Type) - } - if dec.ChainId != nil { - t.ChainId = (*big.Int)(dec.ChainId) - } - if dec.Nonce != nil { - t.Nonce = uint64(*dec.Nonce) - } - if dec.GasPrice != nil { - t.GasPrice = (*big.Int)(dec.GasPrice) - } - if dec.MaxPriorityFeePerGas != nil { - t.MaxPriorityFeePerGas = (*big.Int)(dec.MaxPriorityFeePerGas) - } - if dec.MaxFeePerGas != nil { - t.MaxFeePerGas = (*big.Int)(dec.MaxFeePerGas) - } - if dec.Gas != nil { - t.Gas = uint64(*dec.Gas) - } - if dec.Value != nil { - t.Value = (*big.Int)(dec.Value) - } - if dec.Input != nil { - t.Input = *dec.Input - } - if dec.To != nil { - t.To = *dec.To - } - if dec.Protected != nil { - t.Protected = *dec.Protected - } - if dec.AccessList != nil { - t.AccessList = dec.AccessList - } - if dec.SecretKey != nil { - t.SecretKey = dec.SecretKey - } - if dec.V != nil { - t.V = (*big.Int)(dec.V) - } - if dec.R != nil { - t.R = (*big.Int)(dec.R) - } - if dec.S != nil { - t.S = (*big.Int)(dec.S) - } - if dec.MaxFeePerDataGas != nil { - t.MaxFeePerDataGas = (*big.Int)(dec.MaxFeePerDataGas) - } - if dec.BlobVersionedHashes != nil { - t.BlobVersionedHashes = dec.BlobVersionedHashes - } - return nil -} diff --git a/simulators/ethereum/pyspec/gen_wds.go b/simulators/ethereum/pyspec/gen_wds.go deleted file mode 100644 index 44bbf8084f..0000000000 --- a/simulators/ethereum/pyspec/gen_wds.go +++ /dev/null @@ -1,55 +0,0 @@ -// Code generated by github.com/fjl/gencodec. DO NOT EDIT. - -package main - -import ( - "encoding/json" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/math" -) - -var _ = (*withdrawalsUnmarshaling)(nil) - -// MarshalJSON marshals as JSON. -func (w withdrawals) MarshalJSON() ([]byte, error) { - type withdrawals struct { - Index math.HexOrDecimal64 `json:"index"` - ValidatorIndex math.HexOrDecimal64 `json:"validatorIndex"` - Address common.Address `json:"address"` - Amount math.HexOrDecimal64 `json:"amount"` - } - var enc withdrawals - enc.Index = math.HexOrDecimal64(w.Index) - enc.ValidatorIndex = math.HexOrDecimal64(w.ValidatorIndex) - enc.Address = w.Address - enc.Amount = math.HexOrDecimal64(w.Amount) - return json.Marshal(&enc) -} - -// UnmarshalJSON unmarshals from JSON. -func (w *withdrawals) UnmarshalJSON(input []byte) error { - type withdrawals struct { - Index *math.HexOrDecimal64 `json:"index"` - ValidatorIndex *math.HexOrDecimal64 `json:"validatorIndex"` - Address *common.Address `json:"address"` - Amount *math.HexOrDecimal64 `json:"amount"` - } - var dec withdrawals - if err := json.Unmarshal(input, &dec); err != nil { - return err - } - if dec.Index != nil { - w.Index = uint64(*dec.Index) - } - if dec.ValidatorIndex != nil { - w.ValidatorIndex = uint64(*dec.ValidatorIndex) - } - if dec.Address != nil { - w.Address = *dec.Address - } - if dec.Amount != nil { - w.Amount = uint64(*dec.Amount) - } - return nil -} diff --git a/simulators/ethereum/pyspec/main.go b/simulators/ethereum/pyspec/main.go index 5a3f14585c..545f2bc210 100644 --- a/simulators/ethereum/pyspec/main.go +++ b/simulators/ethereum/pyspec/main.go @@ -20,12 +20,9 @@ import ( func main() { suite := hivesim.Suite{ Name: "pyspec", - Description: "The 'pyspec' test suite runs every test fixture from " + - "the execution-spec-tests repository (https://github.com/ethereum/execution-spec-tests)" + - "against each client specified in the hive simulation run for forks >= Merge. " + - "The clients are first fed a fixture genesis field, followed by each fixture block. " + - "The last valid block is then queried for its storage, nonce & balance, that are compared" + - "against the expected values from the test fixture file. This is all achieved using the EngineAPI.", + Description: "The pyspec test suite runs every fixture from " + + "the execution-spec-tests repo (https://github.com/ethereum/execution-spec-tests) where the fork >= Merge. " + + "For each test clients are first fed the fixture genesis data followed by engine new payloads specfic to the test.", } suite.Add(hivesim.TestSpec{ Name: "pytest_fixture_runner", @@ -121,14 +118,12 @@ func fixtureRunner(t *hivesim.T) { // repoLink coverts a pyspec test path into a github repository link. func repoLink(testPath string) string { - // Example for withdrawals_zero_amout.json: - // Converts '/fixtures/withdrawals/withdrawals/withdrawals_zero_amount.json' - // into 'fillers/withdrawals/withdrawals.py', - // and appends onto main branch repo link. - filePath := strings.Replace(testPath, "/fixtures", "fillers", -1) - fileDir := strings.TrimSuffix(filePath, "/"+filepath.Base(filePath)) + ".py" - repoLink := fmt.Sprintf( - "https://github.com/ethereum/execution-spec-tests/blob/main/%v", - fileDir) + // Example: Converts '/fixtures/cancun/eip4844_blobs/blob_txs/invalid_normal_gas.json' + // into 'tests/cancun/eip4844_blobs/test_blob_txs.py', and appends onto main branch repo link. + filePath := strings.Replace(testPath, "/fixtures", "tests", -1) + fileDir := filepath.Dir(filePath) + fileBase := filepath.Base(fileDir) + fileName := filepath.Join(filepath.Dir(fileDir), "test_"+fileBase+".py") + repoLink := fmt.Sprintf("https://github.com/ethereum/execution-spec-tests/tree/main/%v", fileName) return repoLink } diff --git a/simulators/ethereum/pyspec/runner.go b/simulators/ethereum/pyspec/runner.go index 02168d5b82..4c6d7a9a19 100644 --- a/simulators/ethereum/pyspec/runner.go +++ b/simulators/ethereum/pyspec/runner.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "context" "errors" "fmt" @@ -20,6 +19,8 @@ import ( "github.com/ethereum/hive/hivesim" "github.com/ethereum/hive/simulators/ethereum/engine/client/hive_rpc" "github.com/ethereum/hive/simulators/ethereum/engine/globals" + + typ "github.com/ethereum/hive/simulators/ethereum/engine/types" ) // loadFixtureTests extracts tests from fixture.json files in a given directory, @@ -49,7 +50,7 @@ func loadFixtureTests(t *hivesim.T, root string, re *regexp.Regexp, fn func(test // create testcase structure from fixtureTests for name, fixture := range fixtureTests { // skip networks post merge or not supported - network := fixture.json.Network + network := fixture.json.Fork if _, exist := envForks[network]; !exist { continue } @@ -123,35 +124,27 @@ func (tc *testcase) run(t *hivesim.T) { // send payloads and check response latestValidHash := common.Hash{} - latestVersion := uint64(1) - for i, engineNewPayload := range tc.payloads { - // execute fixture block payload - ed, err := engineNewPayload.ToExecutableData() - if err != nil { - tc.failedErr = err - t.Fatalf("unable to convert engineNewPayload to executableData: %v", err) - } + for _, engineNewPayload := range tc.engineNewPayloads { plStatus, plErr := engineClient.NewPayload( context.Background(), int(engineNewPayload.Version), - ed, + engineNewPayload.HiveExecutionPayload, ) - latestVersion = engineNewPayload.Version // check for rpc errors and compare error codes - fxErrCode := int(tc.fixture.json.Blocks[i].EngineNewPayload.ErrorCode) - if fxErrCode != 0 { - checkRPCErrors(plErr, fxErrCode, t, tc) + errCode := int(engineNewPayload.ErrorCode) + if errCode != 0 { + checkRPCErrors(plErr, errCode, t, tc) continue } // set expected payload return status expectedStatus := "VALID" - if tc.fixture.json.Blocks[i].Exception != "" { + if !engineNewPayload.Valid { expectedStatus = "INVALID" } // check payload status matches expected if plStatus.Status != expectedStatus { tc.failedErr = fmt.Errorf("payload status mismatch: client returned %v and fixture expected %v", plStatus.Status, expectedStatus) - t.Fatalf("payload status mismatch: client returned %v\n fixture expected %v\n", plStatus.Status, expectedStatus, tc.name) + t.Fatalf("payload status mismatch: client returned %v fixture expected %v", plStatus.Status, expectedStatus) } // update latest valid block hash if payload status is VALID if plStatus.Status == "VALID" { @@ -164,9 +157,7 @@ func (tc *testcase) run(t *hivesim.T) { if latestValidHash != (common.Hash{}) { // update with latest valid response fcState := &api.ForkchoiceStateV1{HeadBlockHash: latestValidHash} - // TODO: This is incorrect, up to this point, the `engine_forkchoiceUpdated` and `engine_newPayload` versions for each - // fork match, but it could change in the future. Ideally we should embed the version in the fixture. - if _, fcErr := engineClient.ForkchoiceUpdated(ctx, int(latestVersion), fcState, nil); fcErr != nil { + if _, fcErr := engineClient.ForkchoiceUpdated(ctx, int(tc.fixture.json.EngineFcuVersion), fcState, nil); fcErr != nil { tc.failedErr = fcErr t.Fatalf("unable to update head of beacon chain in test %s: %v ", tc.name, fcErr) } @@ -215,8 +206,7 @@ func (tc *testcase) run(t *hivesim.T) { for _, key := range keys { if genesisAccount.Storage[key] != *gotStorage[key] { tc.failedErr = errors.New("storage recieved doesn't match expected from fixture") - t.Errorf(`storage recieved from account %v doesn't match expected from fixture in test %s: - from storage address: %v + t.Errorf(`storage recieved from account %v doesn't match expected from fixture in test %s: from storage address: %v recieved from block: %v expected in fixture: %v`, account, tc.name, key, gotStorage[key], genesisAccount.Storage[key]) } @@ -240,7 +230,7 @@ func (tc *testcase) run(t *hivesim.T) { // updateEnv updates the environment variables against the fork rules // defined in envForks, for the network specified in the testcase fixture. func (tc *testcase) updateEnv(env hivesim.Params) { - forkRules := envForks[tc.fixture.json.Network] + forkRules := envForks[tc.fixture.json.Fork] for k, v := range forkRules { env[k] = fmt.Sprintf("%d", v) } @@ -248,35 +238,21 @@ func (tc *testcase) updateEnv(env hivesim.Params) { // extractFixtureFields extracts the genesis, post allocation and payload // fields from the given fixture test and stores them in the testcase struct. -func (tc *testcase) extractFixtureFields(fixture fixtureJSON) error { - var err error - tc.genesis, err = extractGenesis(fixture) - if err != nil { - return err +func (tc *testcase) extractFixtureFields(fixture fixtureJSON) (err error) { + if tc.genesis, err = extractGenesis(fixture); err != nil { + return fmt.Errorf("failed to extract genesis: %w", err) } - tc.postAlloc = &fixture.Post - var engineNewPayloads []*engineNewPayload - for _, bl := range fixture.Blocks { - if bl.EngineNewPayload == nil { - return errors.New("engineNewPayload is nil") - } - engineNewPayloads = append(engineNewPayloads, bl.EngineNewPayload) + if tc.engineNewPayloads, err = extractEngineNewPayloads(fixture); err != nil { + return fmt.Errorf("failed to extract engineNewPayloads: %w", err) } - tc.payloads = engineNewPayloads + tc.postAlloc = &fixture.Post return nil } -// extractGenesis extracts the genesis block information from the given fixture -// and returns a core.Genesis struct containing the extracted information. +// extracts the genesis block information from the given fixture. func extractGenesis(fixture fixtureJSON) (*core.Genesis, error) { - if fixture.Genesis.BeaconRoot != nil { - emptyHash := common.Hash{} - if !bytes.Equal(fixture.Genesis.BeaconRoot[:], emptyHash[:]) { - return nil, errors.New("beacon root in genesis is not empty") - } - } genesis := &core.Genesis{ - Config: tests.Forks[fixture.Network], + Config: tests.Forks[fixture.Fork], Coinbase: fixture.Genesis.Coinbase, Difficulty: fixture.Genesis.Difficulty, GasLimit: fixture.Genesis.GasLimit, @@ -292,7 +268,24 @@ func extractGenesis(fixture fixtureJSON) (*core.Genesis, error) { return genesis, nil } -// checkRPCErrors checks for RPC errors and compares error codes if expected. +// extracts all the engineNewPayload information from the given fixture. +func extractEngineNewPayloads(fixture fixtureJSON) ([]engineNewPayload, error) { + var engineNewPayloads []engineNewPayload + for _, engineNewPayload := range fixture.EngineNewPayloads { + engineNewPayload := engineNewPayload + hiveExecutionPayload, err := typ.FromBeaconExecutableData(engineNewPayload.ExecutionPayload) + if err != nil { + return nil, errors.New("executionPayload param within engineNewPayload is invalid") + } + hiveExecutionPayload.VersionedHashes = &engineNewPayload.BlobVersionedHashes + hiveExecutionPayload.ParentBeaconBlockRoot = engineNewPayload.ParentBeaconBlockRoot + engineNewPayload.HiveExecutionPayload = &hiveExecutionPayload + engineNewPayloads = append(engineNewPayloads, engineNewPayload) + } + return engineNewPayloads, nil +} + +// checks for RPC errors and compares error codes if expected. func checkRPCErrors(plErr error, fxErrCode int, t *hivesim.T, tc *testcase) { rpcErr, isRpcErr := plErr.(rpc.Error) if isRpcErr { diff --git a/simulators/ethereum/pyspec/types.go b/simulators/ethereum/pyspec/types.go index c774c0f584..63486948ea 100644 --- a/simulators/ethereum/pyspec/types.go +++ b/simulators/ethereum/pyspec/types.go @@ -21,10 +21,10 @@ type testcase struct { clientType string failedErr error // test fixture data - fixture fixtureTest - genesis *core.Genesis - postAlloc *core.GenesisAlloc - payloads []*engineNewPayload + fixture fixtureTest + genesis *core.Genesis + postAlloc *core.GenesisAlloc + engineNewPayloads []engineNewPayload } type fixtureTest struct { @@ -39,63 +39,33 @@ func (t *fixtureTest) UnmarshalJSON(in []byte) error { } type fixtureJSON struct { - Blocks []block `json:"blocks"` - Genesis blockHeader `json:"genesisBlockHeader"` - Pre core.GenesisAlloc `json:"pre"` - Post core.GenesisAlloc `json:"postState"` - BestBlock common.UnprefixedHash `json:"lastblockhash"` - Network string `json:"network"` - SealEngine string `json:"sealEngine"` + Fork string `json:"network"` + Genesis genesisBlock `json:"genesisBlockHeader"` + EngineNewPayloads []engineNewPayload `json:"engineNewPayloads"` + EngineFcuVersion math.HexOrDecimal64 `json:"engineFcuVersion"` + Pre core.GenesisAlloc `json:"pre"` + Post core.GenesisAlloc `json:"postState"` } -type block struct { - Rlp string `json:"rlp"` - BlockHeader *blockHeader `json:"blockHeader"` - Transactions []transaction `json:"transactions"` - UncleHeaders []byte `json:"uncleHeaders"` - Withdrawals []withdrawals `json:"withdrawals"` - Exception string `json:"expectException"` - EngineNewPayload *engineNewPayload `json:"engineNewPayload"` +//go:generate go run github.com/fjl/gencodec -type genesisBlock -field-override genesisBlockUnmarshaling -out gen_gb.go +type genesisBlock struct { + Coinbase common.Address `json:"coinbase"` + Difficulty *big.Int `json:"difficulty"` + GasLimit uint64 `json:"gasLimit"` + Timestamp *big.Int `json:"timestamp"` + ExtraData []byte `json:"extraData"` + MixHash common.Hash `json:"mixHash"` + Nonce types.BlockNonce `json:"nonce"` + BaseFee *big.Int `json:"baseFeePerGas"` + BlobGasUsed *uint64 `json:"blobGasUsed"` + ExcessBlobGas *uint64 `json:"excessBlobGas"` + + Hash common.Hash `json:"hash"` } -//go:generate go run github.com/fjl/gencodec -type blockHeader -field-override blockHeaderUnmarshaling -out gen_bh.go -//go:generate go run github.com/fjl/gencodec -type transaction -field-override transactionUnmarshaling -out gen_txs.go -//go:generate go run github.com/fjl/gencodec -type withdrawals -field-override withdrawalsUnmarshaling -out gen_wds.go -//go:generate go run github.com/fjl/gencodec -type engineNewPayload -field-override engineNewPayloadUnmarshaling -out gen_enp.go -type blockHeader struct { - ParentHash common.Hash `json:"parentHash"` - UncleHash common.Hash `json:"sha3Uncles"` - UncleHashAlt common.Hash `json:"uncleHash"` // name in fixtures - Coinbase common.Address `json:"coinbase"` - CoinbaseAlt common.Address `json:"author"` // nethermind name - CoinbaseAlt2 common.Address `json:"miner"` // geth/besu name - StateRoot common.Hash `json:"stateRoot"` - TransactionTrie common.Hash `json:"transactionRoot"` - TransactionTrieAlt common.Hash `json:"transactionTrie"` // name in fixtures - ReceiptTrie common.Hash `json:"receiptsRoot"` - ReceiptTrieAlt common.Hash `json:"receiptTrie"` // name in fixtures - Bloom types.Bloom `json:"bloom"` - Difficulty *big.Int `json:"difficulty"` - Number *big.Int `json:"number"` - GasLimit uint64 `json:"gasLimit"` - GasUsed uint64 `json:"gasUsed"` - Timestamp *big.Int `json:"timestamp"` - ExtraData []byte `json:"extraData"` - MixHash common.Hash `json:"mixHash"` - Nonce types.BlockNonce `json:"nonce"` - BaseFee *big.Int `json:"baseFeePerGas"` - Hash common.Hash `json:"hash"` - WithdrawalsRoot common.Hash `json:"withdrawalsRoot"` - BlobGasUsed *uint64 `json:"blobGasUsed"` - ExcessBlobGas *uint64 `json:"excessBlobGas"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot"` -} - -type blockHeaderUnmarshaling struct { +type genesisBlockUnmarshaling struct { Difficulty *math.HexOrDecimal256 `json:"difficulty"` - Number *math.HexOrDecimal256 `json:"number"` GasLimit math.HexOrDecimal64 `json:"gasLimit"` - GasUsed math.HexOrDecimal64 `json:"gasUsed"` Timestamp *math.HexOrDecimal256 `json:"timestamp"` ExtraData hexutil.Bytes `json:"extraData"` BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` @@ -103,74 +73,13 @@ type blockHeaderUnmarshaling struct { ExcessBlobGas *math.HexOrDecimal64 `json:"excessDataGas"` } -type transaction struct { - Type *uint64 `json:"type"` - ChainId *big.Int `json:"chainId"` - Nonce uint64 `json:"nonce"` - GasPrice *big.Int `json:"gasPrice"` - MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"` - MaxFeePerGas *big.Int `json:"maxFeePerGas"` - Gas uint64 `json:"gasLimit"` - Value *big.Int `json:"value"` - Input []byte `json:"data"` - To string `json:"to"` - Protected bool `json:"protected"` - AccessList *types.AccessList `json:"accessList"` - SecretKey *common.Hash `json:"secretKey"` - V *big.Int `json:"v"` - R *big.Int `json:"r"` - S *big.Int `json:"s"` - MaxFeePerDataGas *big.Int `json:"maxFeePerDataGas"` - BlobVersionedHashes []*common.Hash `json:"blobVersionedHashes"` -} - -type transactionUnmarshaling struct { - Type *math.HexOrDecimal64 `json:"type"` - ChainId *math.HexOrDecimal256 `json:"chainId"` - Nonce math.HexOrDecimal64 `json:"nonce"` - GasPrice *math.HexOrDecimal256 `json:"gasPrice"` - MaxPriorityFeePerGas *math.HexOrDecimal256 `json:"maxPriorityFeePerGas"` - MaxFeePerGas *math.HexOrDecimal256 `json:"maxFeePerGas"` - Gas math.HexOrDecimal64 `json:"gasLimit"` - Value *math.HexOrDecimal256 `json:"value"` - Input hexutil.Bytes `json:"data"` - V *math.HexOrDecimal256 `json:"v"` - R *math.HexOrDecimal256 `json:"r"` - S *math.HexOrDecimal256 `json:"s"` - MaxFeePerDataGas *math.HexOrDecimal256 `json:"maxFeePerDataGas"` -} - -type withdrawals struct { - Index uint64 `json:"index"` - ValidatorIndex uint64 `json:"validatorIndex"` - Address common.Address `json:"address"` - Amount uint64 `json:"amount"` -} - -type withdrawalsUnmarshaling struct { - Index math.HexOrDecimal64 `json:"index"` - ValidatorIndex math.HexOrDecimal64 `json:"validatorIndex"` - Amount math.HexOrDecimal64 `json:"amount"` -} - type engineNewPayload struct { - Payload *api.ExecutableData `json:"executionPayload"` + ExecutionPayload *api.ExecutableData `json:"executionPayload"` BlobVersionedHashes []common.Hash `json:"expectedBlobVersionedHashes"` ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` - Version uint64 `json:"version"` + Version math.HexOrDecimal64 `json:"version"` + Valid bool `json:"valid"` ErrorCode int64 `json:"errorCode,string"` -} -type engineNewPayloadUnmarshaling struct { - Version math.HexOrDecimal64 `json:"version"` -} - -func (p *engineNewPayload) ToExecutableData() (*typ.ExecutableData, error) { - ed, err := typ.FromBeaconExecutableData(p.Payload) - if err != nil { - return nil, err - } - ed.VersionedHashes = &p.BlobVersionedHashes - ed.ParentBeaconBlockRoot = p.ParentBeaconBlockRoot - return &ed, nil + HiveExecutionPayload *typ.ExecutableData }