diff --git a/simulators/ethereum/engine/clmock/clmock.go b/simulators/ethereum/engine/clmock/clmock.go index e4a4e803bf..4da0b0e553 100644 --- a/simulators/ethereum/engine/clmock/clmock.go +++ b/simulators/ethereum/engine/clmock/clmock.go @@ -16,6 +16,7 @@ import ( "github.com/ethereum/go-ethereum/core/forkid" "github.com/ethereum/hive/simulators/ethereum/engine/client" "github.com/ethereum/hive/simulators/ethereum/engine/config" + "github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" "github.com/ethereum/hive/simulators/ethereum/engine/globals" "github.com/ethereum/hive/simulators/ethereum/engine/helper" typ "github.com/ethereum/hive/simulators/ethereum/engine/types" @@ -27,15 +28,14 @@ import ( ) var ( - DefaultSlotsToSafe = big.NewInt(1) - DefaultSlotsToFinalized = big.NewInt(2) + DefaultSafeSlotsToImportOptimistically = big.NewInt(0) + DefaultSlotsToSafe = big.NewInt(1) + DefaultSlotsToFinalized = big.NewInt(2) + DefaultBlockTimestampIncrement = big.NewInt(1) // Time delay between ForkchoiceUpdated and GetPayload to allow the clients // to produce a new Payload DefaultPayloadProductionClientDelay = time.Second - - // Fork specific constants - BLOB_COMMITMENT_VERSION_KZG = byte(0x01) ) type ExecutableDataHistory map[uint64]*typ.ExecutableData @@ -127,36 +127,31 @@ type CLMocker struct { TimeoutContext context.Context } -func NewCLMocker(t *hivesim.T, genesis *core.Genesis, slotsToSafe, slotsToFinalized, safeSlotsToImportOptimistically *big.Int, forkConfig *config.ForkConfig) *CLMocker { +func NewCLMocker(t *hivesim.T, genesis *core.Genesis, forkConfig *config.ForkConfig) *CLMocker { // Init random seed for different purposes seed := time.Now().Unix() t.Logf("Randomness seed: %v\n", seed) rand.Seed(seed) - if slotsToSafe == nil { - // Use default - slotsToSafe = DefaultSlotsToSafe - } - if slotsToFinalized == nil { - // Use default - slotsToFinalized = DefaultSlotsToFinalized - } // Create the new CL mocker newCLMocker := &CLMocker{ - T: t, - EngineClients: make([]client.EngineClient, 0), - PrevRandaoHistory: map[uint64]common.Hash{}, - ExecutedPayloadHistory: ExecutableDataHistory{}, - SlotsToSafe: slotsToSafe, - SlotsToFinalized: slotsToFinalized, - SafeSlotsToImportOptimistically: safeSlotsToImportOptimistically, + T: t, + EngineClients: make([]client.EngineClient, 0), + PrevRandaoHistory: map[uint64]common.Hash{}, + ExecutedPayloadHistory: ExecutableDataHistory{}, + + SlotsToSafe: DefaultSlotsToSafe, + SlotsToFinalized: DefaultSlotsToFinalized, + SafeSlotsToImportOptimistically: DefaultSafeSlotsToImportOptimistically, PayloadProductionClientDelay: DefaultPayloadProductionClientDelay, - PayloadIDHistory: make(map[api.PayloadID]interface{}), - LatestHeader: nil, - FirstPoSBlockNumber: nil, - LatestHeadNumber: nil, - TTDReached: false, - NextFeeRecipient: common.Address{}, + BlockTimestampIncrement: DefaultBlockTimestampIncrement, + + PayloadIDHistory: make(map[api.PayloadID]interface{}), + LatestHeader: nil, + FirstPoSBlockNumber: nil, + LatestHeadNumber: nil, + TTDReached: false, + NextFeeRecipient: common.Address{}, LatestForkchoice: api.ForkchoiceStateV1{ HeadBlockHash: common.Hash{}, SafeBlockHash: common.Hash{}, @@ -327,9 +322,6 @@ func (cl *CLMocker) IsBlockPoS(bn *big.Int) bool { // Return the per-block timestamp value increment func (cl *CLMocker) GetTimestampIncrement() uint64 { - if cl.BlockTimestampIncrement == nil { - return 1 - } return cl.BlockTimestampIncrement.Uint64() } @@ -513,7 +505,7 @@ func (cl *CLMocker) GetNextPayload() { cl.Fatalf("CLMocker: No blob bundle on cancun") } // Broadcast the blob bundle to all clients - cl.LatestPayloadBuilt.VersionedHashes, err = cl.LatestBlobBundle.VersionedHashes(BLOB_COMMITMENT_VERSION_KZG) + cl.LatestPayloadBuilt.VersionedHashes, err = cl.LatestBlobBundle.VersionedHashes(cancun.BLOB_COMMITMENT_VERSION_KZG) if err != nil { cl.Fatalf("CLMocker: Could not get versioned hashes from blob bundle: %v", err) } diff --git a/simulators/ethereum/engine/config/cancun/constants.go b/simulators/ethereum/engine/config/cancun/constants.go new file mode 100644 index 0000000000..e829b1b470 --- /dev/null +++ b/simulators/ethereum/engine/config/cancun/constants.go @@ -0,0 +1,31 @@ +package cancun + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" +) + +var ( + // EIP 4844 + GAS_PER_BLOB = uint64(0x20000) + + MIN_DATA_GASPRICE = uint64(1) + MAX_BLOB_GAS_PER_BLOCK = uint64(786432) + TARGET_BLOB_GAS_PER_BLOCK = uint64(393216) + + TARGET_BLOBS_PER_BLOCK = uint64(TARGET_BLOB_GAS_PER_BLOCK / GAS_PER_BLOB) + MAX_BLOBS_PER_BLOCK = uint64(MAX_BLOB_GAS_PER_BLOCK / GAS_PER_BLOB) + + BLOB_GASPRICE_UPDATE_FRACTION = uint64(3338477) + + BLOB_COMMITMENT_VERSION_KZG = byte(0x01) + + // EIP 4788 + HISTORY_STORAGE_ADDRESS = common.HexToAddress("0x000000000000000000000000000000000000000b") + HISTORICAL_ROOTS_MODULUS = uint64(98304) + + // Test constants + DATAHASH_START_ADDRESS = big.NewInt(0x20000) + DATAHASH_ADDRESS_COUNT = 1000 +) diff --git a/simulators/ethereum/engine/config/cancun/genesis.go b/simulators/ethereum/engine/config/cancun/genesis.go new file mode 100644 index 0000000000..2d32207d6d --- /dev/null +++ b/simulators/ethereum/engine/config/cancun/genesis.go @@ -0,0 +1,77 @@ +package cancun + +import ( + "fmt" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" +) + +// ConfigGenesis configures the genesis block for the Cancun fork. +func ConfigGenesis(genesis *core.Genesis, forkTimestamp uint64) error { + if genesis.Config.ShanghaiTime == nil { + return fmt.Errorf("cancun fork requires shanghai fork") + } + genesis.Config.CancunTime = &forkTimestamp + if *genesis.Config.ShanghaiTime > forkTimestamp { + return fmt.Errorf("cancun fork must be after shanghai fork") + } + if genesis.Timestamp >= forkTimestamp { + if genesis.BlobGasUsed == nil { + genesis.BlobGasUsed = new(uint64) + } + if genesis.ExcessBlobGas == nil { + genesis.ExcessBlobGas = new(uint64) + } + } + + // Add bytecode pre deploy to the EIP-4788 address. + genesis.Alloc[HISTORY_STORAGE_ADDRESS] = core.GenesisAccount{ + Balance: common.Big0, + Nonce: 1, + Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b42620180004206555f3562018000420662018000015500"), + } + + return nil +} + +// Configure specific test genesis accounts related to Cancun funtionality. +func ConfigTestAccounts(genesis *core.Genesis) error { + // Add accounts that use the DATAHASH opcode + datahashCode := []byte{ + 0x5F, // PUSH0 + 0x80, // DUP1 + 0x49, // DATAHASH + 0x55, // SSTORE + 0x60, // PUSH1(0x01) + 0x01, + 0x80, // DUP1 + 0x49, // DATAHASH + 0x55, // SSTORE + 0x60, // PUSH1(0x02) + 0x02, + 0x80, // DUP1 + 0x49, // DATAHASH + 0x55, // SSTORE + 0x60, // PUSH1(0x03) + 0x03, + 0x80, // DUP1 + 0x49, // DATAHASH + 0x55, // SSTORE + } + + for i := 0; i < DATAHASH_ADDRESS_COUNT; i++ { + address := common.BigToAddress(big.NewInt(0).Add(DATAHASH_START_ADDRESS, big.NewInt(int64(i)))) + // check first if the address is already in the genesis + if _, ok := genesis.Alloc[address]; ok { + panic(fmt.Errorf("reused address %s during genesis configuration for cancun", address.Hex())) + } + genesis.Alloc[address] = core.GenesisAccount{ + Code: datahashCode, + Balance: common.Big0, + } + } + + return nil +} diff --git a/simulators/ethereum/engine/config/fork.go b/simulators/ethereum/engine/config/fork.go index 54b66f71ab..75d75b6e9c 100644 --- a/simulators/ethereum/engine/config/fork.go +++ b/simulators/ethereum/engine/config/fork.go @@ -1,11 +1,7 @@ package config import ( - "fmt" "math/big" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" ) type Fork string @@ -21,40 +17,6 @@ type ForkConfig struct { CancunTimestamp *big.Int } -func (f *ForkConfig) ConfigGenesis(genesis *core.Genesis) error { - if f.ShanghaiTimestamp != nil { - shanghaiTime := f.ShanghaiTimestamp.Uint64() - genesis.Config.ShanghaiTime = &shanghaiTime - - if genesis.Timestamp >= shanghaiTime { - // Remove PoW altogether - genesis.Difficulty = common.Big0 - genesis.Config.TerminalTotalDifficulty = common.Big0 - genesis.Config.Clique = nil - genesis.ExtraData = []byte{} - } - } - if f.CancunTimestamp != nil { - if genesis.Config.ShanghaiTime == nil { - return fmt.Errorf("cancun fork requires Shanghai fork") - } - cancunTime := f.CancunTimestamp.Uint64() - genesis.Config.CancunTime = &cancunTime - if *genesis.Config.ShanghaiTime > cancunTime { - return fmt.Errorf("cancun fork must be after Shanghai fork") - } - if genesis.Timestamp >= cancunTime { - if genesis.BlobGasUsed == nil { - genesis.BlobGasUsed = new(uint64) - } - if genesis.ExcessBlobGas == nil { - genesis.ExcessBlobGas = new(uint64) - } - } - } - return nil -} - func (f *ForkConfig) IsShanghai(blockTimestamp uint64) bool { return f.ShanghaiTimestamp != nil && new(big.Int).SetUint64(blockTimestamp).Cmp(f.ShanghaiTimestamp) >= 0 } diff --git a/simulators/ethereum/engine/config/genesis.go b/simulators/ethereum/engine/config/genesis.go new file mode 100644 index 0000000000..7fe0645900 --- /dev/null +++ b/simulators/ethereum/engine/config/genesis.go @@ -0,0 +1,30 @@ +package config + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" +) + +func (f *ForkConfig) ConfigGenesis(genesis *core.Genesis) error { + if f.ShanghaiTimestamp != nil { + shanghaiTime := f.ShanghaiTimestamp.Uint64() + genesis.Config.ShanghaiTime = &shanghaiTime + + if genesis.Timestamp >= shanghaiTime { + // Remove PoW altogether + genesis.Difficulty = common.Big0 + genesis.Config.TerminalTotalDifficulty = common.Big0 + genesis.Config.Clique = nil + genesis.ExtraData = []byte{} + } + } + if f.CancunTimestamp != nil { + if err := cancun.ConfigGenesis(genesis, f.CancunTimestamp.Uint64()); err != nil { + return fmt.Errorf("failed to configure cancun fork: %v", err) + } + } + return nil +} diff --git a/simulators/ethereum/engine/globals/errors.go b/simulators/ethereum/engine/globals/errors.go new file mode 100644 index 0000000000..b13b624bba --- /dev/null +++ b/simulators/ethereum/engine/globals/errors.go @@ -0,0 +1,21 @@ +package globals + +var ( + // Engine API errors + SERVER_ERROR = pInt(-32000) + INVALID_REQUEST = pInt(-32600) + METHOD_NOT_FOUND = pInt(-32601) + INVALID_PARAMS_ERROR = pInt(-32602) + INTERNAL_ERROR = pInt(-32603) + INVALID_JSON = pInt(-32700) + + UNKNOWN_PAYLOAD = pInt(-38001) + INVALID_FORKCHOICE_STATE = pInt(-38002) + INVALID_PAYLOAD_ATTRIBUTES = pInt(-38003) + TOO_LARGE_REQUEST = pInt(-38004) + UNSUPPORTED_FORK_ERROR = pInt(-38005) +) + +func pInt(v int) *int { + return &v +} diff --git a/simulators/ethereum/engine/globals/globals.go b/simulators/ethereum/engine/globals/globals.go index 4998e95410..de0efcf181 100644 --- a/simulators/ethereum/engine/globals/globals.go +++ b/simulators/ethereum/engine/globals/globals.go @@ -44,7 +44,7 @@ var ( GasPrice = big.NewInt(30 * params.GWei) GasTipPrice = big.NewInt(1 * params.GWei) NetworkID = big.NewInt(7) - GenesisTimestamp = int64(0x1234) + GenesisTimestamp = uint64(0x1234) // RPC Timeout for every call RPCTimeout = 10 * time.Second diff --git a/simulators/ethereum/engine/suites/cancun/config.go b/simulators/ethereum/engine/suites/cancun/config.go index c361c14d86..688671e5d9 100644 --- a/simulators/ethereum/engine/suites/cancun/config.go +++ b/simulators/ethereum/engine/suites/cancun/config.go @@ -1,124 +1,19 @@ package suite_cancun import ( - "math/big" "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/hive/simulators/ethereum/engine/clmock" - "github.com/ethereum/hive/simulators/ethereum/engine/config" - "github.com/ethereum/hive/simulators/ethereum/engine/globals" "github.com/ethereum/hive/simulators/ethereum/engine/test" ) // Contains the base spec for all cancun tests. type CancunBaseSpec struct { test.BaseSpec - TimeIncrements uint64 // Timestamp increments per block throughout the test - GetPayloadDelay uint64 // Delay between FcU and GetPayload calls - CancunForkHeight uint64 // Withdrawals activation fork height - GenesisTimestamp *uint64 + GetPayloadDelay uint64 // Delay between FcU and GetPayload calls TestSequence } -// Timestamp delta between genesis and the withdrawals fork -func (cs *CancunBaseSpec) GetCancunGenesisTimeDelta() uint64 { - return cs.CancunForkHeight * cs.GetBlockTimeIncrements() -} - -func (cs *CancunBaseSpec) GetGenesisTimestamp() uint64 { - if cs.GenesisTimestamp != nil { - return *cs.GenesisTimestamp - } - return uint64(globals.GenesisTimestamp) -} - -// Calculates Cancun fork timestamp given the amount of blocks that need to be -// produced beforehand. -func (cs *CancunBaseSpec) GetCancunForkTime() uint64 { - return cs.GetGenesisTimestamp() + cs.GetCancunGenesisTimeDelta() -} - -// Generates the fork config, including cancun fork timestamp. -func (cs *CancunBaseSpec) GetForkConfig() *config.ForkConfig { - return &config.ForkConfig{ - ShanghaiTimestamp: big.NewInt(0), // No test starts before Shanghai - CancunTimestamp: new(big.Int).SetUint64(cs.GetCancunForkTime()), - } -} - -// Get the per-block timestamp increments configured for this test -func (cs *CancunBaseSpec) GetBlockTimeIncrements() uint64 { - if cs.TimeIncrements == 0 { - return 1 - } - return cs.TimeIncrements -} - -// Timestamp delta between genesis and the withdrawals fork -func (cs *CancunBaseSpec) GetBlobsGenesisTimeDelta() uint64 { - return cs.CancunForkHeight * cs.GetBlockTimeIncrements() -} - -// Calculates Cancun fork timestamp given the amount of blocks that need to be -// produced beforehand. -func (cs *CancunBaseSpec) GetBlobsForkTime() uint64 { - return cs.GetGenesisTimestamp() + cs.GetBlobsGenesisTimeDelta() -} - -// Append the accounts we are going to withdraw to, which should also include -// bytecode for testing purposes. -func (cs *CancunBaseSpec) GetGenesis() *core.Genesis { - genesis := cs.BaseSpec.GetGenesis() - - // Add accounts that use the DATAHASH opcode - datahashCode := []byte{ - 0x5F, // PUSH0 - 0x80, // DUP1 - 0x49, // DATAHASH - 0x55, // SSTORE - 0x60, // PUSH1(0x01) - 0x01, - 0x80, // DUP1 - 0x49, // DATAHASH - 0x55, // SSTORE - 0x60, // PUSH1(0x02) - 0x02, - 0x80, // DUP1 - 0x49, // DATAHASH - 0x55, // SSTORE - 0x60, // PUSH1(0x03) - 0x03, - 0x80, // DUP1 - 0x49, // DATAHASH - 0x55, // SSTORE - } - - for i := 0; i < DATAHASH_ADDRESS_COUNT; i++ { - address := big.NewInt(0).Add(DATAHASH_START_ADDRESS, big.NewInt(int64(i))) - genesis.Alloc[common.BigToAddress(address)] = core.GenesisAccount{ - Code: datahashCode, - Balance: common.Big0, - } - } - - // Add bytecode pre deploy to the EIP-4788 address. - genesis.Alloc[HISTORY_STORAGE_ADDRESS] = core.GenesisAccount{ - Balance: common.Big0, - Nonce: 1, - Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b42620180004206555f3562018000420662018000015500"), - } - - return genesis -} - -// Changes the CL Mocker default time increments of 1 to the value specified -// in the test spec. -func (cs *CancunBaseSpec) ConfigureCLMock(cl *clmock.CLMocker) { - cl.BlockTimestampIncrement = big.NewInt(int64(cs.GetBlockTimeIncrements())) -} - // Base test case execution procedure for blobs tests. func (cs *CancunBaseSpec) Execute(t *test.Env) { diff --git a/simulators/ethereum/engine/suites/cancun/helpers.go b/simulators/ethereum/engine/suites/cancun/helpers.go index a19a76487b..2f76ddf195 100644 --- a/simulators/ethereum/engine/suites/cancun/helpers.go +++ b/simulators/ethereum/engine/suites/cancun/helpers.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/hive/simulators/ethereum/engine/client" + "github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" "github.com/ethereum/hive/simulators/ethereum/engine/helper" typ "github.com/ethereum/hive/simulators/ethereum/engine/types" ) @@ -31,7 +32,7 @@ func FakeExponential(factor, numerator, denominator uint64) uint64 { } func GetBlobGasPrice(excessBlobGas uint64) uint64 { - return FakeExponential(MIN_DATA_GASPRICE, excessBlobGas, BLOB_GASPRICE_UPDATE_FRACTION) + return FakeExponential(cancun.MIN_DATA_GASPRICE, excessBlobGas, cancun.BLOB_GASPRICE_UPDATE_FRACTION) } func GetMinExcessBlobGasForBlobGasPrice(data_gas_price uint64) uint64 { @@ -40,7 +41,7 @@ func GetMinExcessBlobGasForBlobGasPrice(data_gas_price uint64) uint64 { current_data_gas_price = uint64(1) ) for current_data_gas_price < data_gas_price { - current_excess_data_gas += GAS_PER_BLOB + current_excess_data_gas += cancun.GAS_PER_BLOB current_data_gas_price = GetBlobGasPrice(current_excess_data_gas) } @@ -48,14 +49,14 @@ func GetMinExcessBlobGasForBlobGasPrice(data_gas_price uint64) uint64 { } func GetMinExcessBlobsForBlobGasPrice(data_gas_price uint64) uint64 { - return GetMinExcessBlobGasForBlobGasPrice(data_gas_price) / GAS_PER_BLOB + return GetMinExcessBlobGasForBlobGasPrice(data_gas_price) / cancun.GAS_PER_BLOB } func CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed uint64) uint64 { - if (parentExcessBlobGas + parentBlobGasUsed) < TARGET_BLOB_GAS_PER_BLOCK { + if (parentExcessBlobGas + parentBlobGasUsed) < cancun.TARGET_BLOB_GAS_PER_BLOCK { return 0 } else { - return (parentExcessBlobGas + parentBlobGasUsed) - TARGET_BLOB_GAS_PER_BLOCK + return (parentExcessBlobGas + parentBlobGasUsed) - cancun.TARGET_BLOB_GAS_PER_BLOCK } } @@ -131,8 +132,8 @@ func VerifyTransactionFromNode(ctx context.Context, eth client.Eth, tx typ.Trans func BeaconRootStorageIndexes(timestamp uint64) (common.Hash, common.Hash) { // Calculate keys - timestampReduced := timestamp % HISTORICAL_ROOTS_MODULUS - timestampExtended := timestampReduced + HISTORICAL_ROOTS_MODULUS + timestampReduced := timestamp % cancun.HISTORICAL_ROOTS_MODULUS + timestampExtended := timestampReduced + cancun.HISTORICAL_ROOTS_MODULUS return common.BigToHash(new(big.Int).SetUint64(timestampReduced)), common.BigToHash(new(big.Int).SetUint64(timestampExtended)) } diff --git a/simulators/ethereum/engine/suites/cancun/steps.go b/simulators/ethereum/engine/suites/cancun/steps.go index 49eb2aeee8..d34149c897 100644 --- a/simulators/ethereum/engine/suites/cancun/steps.go +++ b/simulators/ethereum/engine/suites/cancun/steps.go @@ -14,6 +14,7 @@ import ( "github.com/ethereum/hive/simulators/ethereum/engine/client" "github.com/ethereum/hive/simulators/ethereum/engine/clmock" "github.com/ethereum/hive/simulators/ethereum/engine/config" + "github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" "github.com/ethereum/hive/simulators/ethereum/engine/devp2p" "github.com/ethereum/hive/simulators/ethereum/engine/globals" "github.com/ethereum/hive/simulators/ethereum/engine/helper" @@ -260,7 +261,7 @@ func VerifyBeaconRootStorage(ctx context.Context, testEngine *test.TestEngineCli // Read the storage keys from the stateful precompile that stores the beacon roots and verify // that the beacon root is the same as the one in the payload blockNumber := new(big.Int).SetUint64(payload.Number) - precompileAddress := HISTORY_STORAGE_ADDRESS + precompileAddress := cancun.HISTORY_STORAGE_ADDRESS timestampKey, beaconRootKey := BeaconRootStorageIndexes(payload.Timestamp) @@ -314,7 +315,7 @@ func (step NewPayloads) VerifyPayload(ctx context.Context, forkConfig *config.Fo // Retrieve receipt from client r := testEngine.TestTransactionReceipt(tx.Hash()) - expectedBlobGasUsed := blobCount * GAS_PER_BLOB + expectedBlobGasUsed := blobCount * cancun.GAS_PER_BLOB r.ExpectBlobGasUsed(expectedBlobGasUsed) r.ExpectBlobGasPrice(expectedBlobGasPrice) } @@ -634,7 +635,7 @@ func (step SendBlobTransactions) GetBlobsPerTransaction() uint64 { func (step SendBlobTransactions) Execute(t *CancunTestContext) error { // Send a blob transaction - addr := common.BigToAddress(DATAHASH_START_ADDRESS) + addr := common.BigToAddress(cancun.DATAHASH_START_ADDRESS) blobCountPerTx := step.GetBlobsPerTransaction() var engine client.EngineClient if step.ClientIndex >= uint64(len(t.Engines)) { diff --git a/simulators/ethereum/engine/suites/cancun/tests.go b/simulators/ethereum/engine/suites/cancun/tests.go index 73b022bb19..a8475a0bef 100644 --- a/simulators/ethereum/engine/suites/cancun/tests.go +++ b/simulators/ethereum/engine/suites/cancun/tests.go @@ -8,38 +8,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/hive/simulators/ethereum/engine/client/hive_rpc" "github.com/ethereum/hive/simulators/ethereum/engine/config" + "github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" + "github.com/ethereum/hive/simulators/ethereum/engine/globals" "github.com/ethereum/hive/simulators/ethereum/engine/helper" suite_engine "github.com/ethereum/hive/simulators/ethereum/engine/suites/engine" "github.com/ethereum/hive/simulators/ethereum/engine/test" ) -var ( - DATAHASH_START_ADDRESS = big.NewInt(0x100) - DATAHASH_ADDRESS_COUNT = 1000 - - // EIP 4844 specific constants - GAS_PER_BLOB = uint64(0x20000) - - MIN_DATA_GASPRICE = uint64(1) - MAX_BLOB_GAS_PER_BLOCK = uint64(786432) - TARGET_BLOB_GAS_PER_BLOCK = uint64(393216) - - TARGET_BLOBS_PER_BLOCK = uint64(TARGET_BLOB_GAS_PER_BLOCK / GAS_PER_BLOB) - MAX_BLOBS_PER_BLOCK = uint64(MAX_BLOB_GAS_PER_BLOCK / GAS_PER_BLOB) - - BLOB_GASPRICE_UPDATE_FRACTION = uint64(3338477) - - BLOB_COMMITMENT_VERSION_KZG = byte(0x01) - - // EIP 4788 specific constants - HISTORY_STORAGE_ADDRESS = common.HexToAddress("0x000000000000000000000000000000000000000b") - HISTORICAL_ROOTS_MODULUS = uint64(98304) - - // Engine API errors - INVALID_PARAMS_ERROR = pInt(-32602) - UNSUPPORTED_FORK_ERROR = pInt(-38005) -) - // Precalculate the first data gas cost increase var ( DATA_GAS_COST_INCREMENT_EXCEED_BLOBS = GetMinExcessBlobsForBlobGasPrice(2) @@ -49,10 +24,6 @@ func pUint64(v uint64) *uint64 { return &v } -func pInt(v int) *int { - return &v -} - // Execution specification reference: // https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md @@ -77,11 +48,11 @@ var Tests = []test.Spec{ - Beacon root in eth_getBlockByNumber - Blob fields in transaction receipts from eth_getTransactionReceipt `, + MainFork: config.Cancun, + // We fork after genesis + ForkHeight: 1, }, - // We fork on genesis - CancunForkHeight: 1, - TestSequence: TestSequence{ // We are starting at Shanghai genesis so send a couple payloads to reach the fork NewPayloads{}, @@ -89,7 +60,7 @@ var Tests = []test.Spec{ // First, we send a couple of blob transactions on genesis, // with enough data gas cost to make sure they are included in the first block. SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, @@ -97,22 +68,22 @@ var Tests = []test.Spec{ // are included in the payload. // We also verify that the blob transactions are included in the blobs bundle. NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, // Try to increase the data gas cost of the blob transactions // by maxing out the number of blobs for the next payloads. SendBlobTransactions{ - TransactionCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS/(MAX_BLOBS_PER_BLOCK-TARGET_BLOBS_PER_BLOCK) + 1, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + TransactionCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS/(cancun.MAX_BLOBS_PER_BLOCK-cancun.TARGET_BLOBS_PER_BLOCK) + 1, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, // Next payloads will have max data blobs each NewPayloads{ - PayloadCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS / (MAX_BLOBS_PER_BLOCK - TARGET_BLOBS_PER_BLOCK), - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + PayloadCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS / (cancun.MAX_BLOBS_PER_BLOCK - cancun.TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, // But there will be an empty payload, since the data gas cost increased @@ -123,7 +94,7 @@ var Tests = []test.Spec{ // But it will be included in the next payload NewPayloads{ - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, }, }, @@ -138,17 +109,15 @@ var Tests = []test.Spec{ Verifications performed: * See Blob Transactions On Block 1, Shanghai Genesis `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ NewPayloads{}, // Create a single empty payload to push the client through the fork. // First, we send a couple of blob transactions on genesis, // with enough data gas cost to make sure they are included in the first block. SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, @@ -156,22 +125,22 @@ var Tests = []test.Spec{ // are included in the payload. // We also verify that the blob transactions are included in the blobs bundle. NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, // Try to increase the data gas cost of the blob transactions // by maxing out the number of blobs for the next payloads. SendBlobTransactions{ - TransactionCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS/(MAX_BLOBS_PER_BLOCK-TARGET_BLOBS_PER_BLOCK) + 1, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + TransactionCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS/(cancun.MAX_BLOBS_PER_BLOCK-cancun.TARGET_BLOBS_PER_BLOCK) + 1, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, // Next payloads will have max data blobs each NewPayloads{ - PayloadCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS / (MAX_BLOBS_PER_BLOCK - TARGET_BLOBS_PER_BLOCK), - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + PayloadCount: DATA_GAS_COST_INCREMENT_EXCEED_BLOBS / (cancun.MAX_BLOBS_PER_BLOCK - cancun.TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, // But there will be an empty payload, since the data gas cost increased @@ -182,7 +151,7 @@ var Tests = []test.Spec{ // But it will be included in the next payload NewPayloads{ - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, }, }, @@ -191,7 +160,7 @@ var Tests = []test.Spec{ BaseSpec: test.BaseSpec{ Name: "Blob Transaction Ordering, Single Account", About: ` - Send N blob transactions with MAX_BLOBS_PER_BLOCK-1 blobs each, + Send N blob transactions with cancun.MAX_BLOBS_PER_BLOCK-1 blobs each, using account A. Using same account, and an increased nonce from the previously sent transactions, send N blob transactions with 1 blob each. @@ -201,35 +170,33 @@ var Tests = []test.Spec{ All transactions have sufficient data gas price to be included any of the payloads. `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ - // First send the MAX_BLOBS_PER_BLOCK-1 blob transactions. + // First send the cancun.MAX_BLOBS_PER_BLOCK-1 blob transactions. SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK - 1, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK - 1, BlobTransactionMaxBlobGasCost: big.NewInt(100), }, // Then send the single-blob transactions SendBlobTransactions{ - TransactionCount: MAX_BLOBS_PER_BLOCK + 1, + TransactionCount: cancun.MAX_BLOBS_PER_BLOCK + 1, BlobsPerTransaction: 1, BlobTransactionMaxBlobGasCost: big.NewInt(100), }, - // First four payloads have MAX_BLOBS_PER_BLOCK-1 blobs each + // First four payloads have cancun.MAX_BLOBS_PER_BLOCK-1 blobs each NewPayloads{ PayloadCount: 4, - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK - 1, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK - 1, }, // The rest of the payloads have full blobs NewPayloads{ PayloadCount: 2, - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, }, }, @@ -238,7 +205,7 @@ var Tests = []test.Spec{ BaseSpec: test.BaseSpec{ Name: "Blob Transaction Ordering, Single Account 2", About: ` - Send N blob transactions with MAX_BLOBS_PER_BLOCK-1 blobs each, + Send N blob transactions with cancun.MAX_BLOBS_PER_BLOCK-1 blobs each, using account A. Using same account, and an increased nonce from the previously sent transactions, send a single 2-blob transaction, and send N blob @@ -249,16 +216,14 @@ var Tests = []test.Spec{ All transactions have sufficient data gas price to be included any of the payloads. `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ - // First send the MAX_BLOBS_PER_BLOCK-1 blob transactions. + // First send the cancun.MAX_BLOBS_PER_BLOCK-1 blob transactions. SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK - 1, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK - 1, BlobTransactionMaxBlobGasCost: big.NewInt(100), }, @@ -271,21 +236,21 @@ var Tests = []test.Spec{ // Then send the single-blob transactions SendBlobTransactions{ - TransactionCount: MAX_BLOBS_PER_BLOCK - 2, + TransactionCount: cancun.MAX_BLOBS_PER_BLOCK - 2, BlobsPerTransaction: 1, BlobTransactionMaxBlobGasCost: big.NewInt(100), }, - // First five payloads have MAX_BLOBS_PER_BLOCK-1 blobs each + // First five payloads have cancun.MAX_BLOBS_PER_BLOCK-1 blobs each NewPayloads{ PayloadCount: 5, - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK - 1, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK - 1, }, // The rest of the payloads have full blobs NewPayloads{ PayloadCount: 1, - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, }, }, @@ -295,7 +260,7 @@ var Tests = []test.Spec{ BaseSpec: test.BaseSpec{ Name: "Blob Transaction Ordering, Multiple Accounts", About: ` - Send N blob transactions with MAX_BLOBS_PER_BLOCK-1 blobs each, + Send N blob transactions with cancun.MAX_BLOBS_PER_BLOCK-1 blobs each, using account A. Send N blob transactions with 1 blob each from account B. Verify that the payloads are created with the correct ordering: @@ -303,17 +268,15 @@ var Tests = []test.Spec{ All transactions have sufficient data gas price to be included any of the payloads. `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ - // First send the MAX_BLOBS_PER_BLOCK-1 blob transactions from + // First send the cancun.MAX_BLOBS_PER_BLOCK-1 blob transactions from // account A. SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK - 1, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK - 1, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 0, }, @@ -328,7 +291,7 @@ var Tests = []test.Spec{ // All payloads have full blobs NewPayloads{ PayloadCount: 5, - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, }, }, }, @@ -338,7 +301,7 @@ var Tests = []test.Spec{ BaseSpec: test.BaseSpec{ Name: "Blob Transaction Ordering, Multiple Clients", About: ` - Send N blob transactions with MAX_BLOBS_PER_BLOCK-1 blobs each, + Send N blob transactions with cancun.MAX_BLOBS_PER_BLOCK-1 blobs each, using account A, to client A. Send N blob transactions with 1 blob each from account B, to client B. @@ -347,11 +310,9 @@ var Tests = []test.Spec{ All transactions have sufficient data gas price to be included any of the payloads. `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ // Start a secondary client to also receive blob transactions LaunchClients{ @@ -369,11 +330,11 @@ var Tests = []test.Spec{ ExpectedIncludedBlobCount: 0, }, - // First send the MAX_BLOBS_PER_BLOCK-1 blob transactions from + // First send the cancun.MAX_BLOBS_PER_BLOCK-1 blob transactions from // account A, to client A. SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK - 1, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK - 1, BlobTransactionMaxBlobGasCost: big.NewInt(120), AccountIndex: 0, ClientIndex: 0, @@ -391,7 +352,7 @@ var Tests = []test.Spec{ // All payloads have full blobs NewPayloads{ PayloadCount: 5, - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, // Wait a bit more on before requesting the built payload from the client GetPayloadDelay: 2, }, @@ -406,11 +367,9 @@ var Tests = []test.Spec{ Test sending multiple blob transactions with the same nonce, but higher gas tip so the transaction is replaced. `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ // Send multiple blob transactions with the same nonce. SendBlobTransactions{ // Blob ID 0 @@ -459,82 +418,80 @@ var Tests = []test.Spec{ Verify that a payload is created with the maximum number of blobs. `, + MainFork: config.Cancun, }, - // We fork on genesis - CancunForkHeight: 0, - TestSequence: TestSequence{ // Send multiple blob transactions with the same nonce. ParallelSteps{ Steps: []TestStep{ SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 0, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 1, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 2, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 3, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 4, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 5, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 6, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 7, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 8, }, SendBlobTransactions{ TransactionCount: 5, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), AccountIndex: 9, }, }, }, - // We create the first payload, which is guaranteed to have the first MAX_BLOBS_PER_BLOCK blobs. + // We create the first payload, which is guaranteed to have the first cancun.MAX_BLOBS_PER_BLOCK blobs. NewPayloads{ - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, MAX_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.MAX_BLOBS_PER_BLOCK), }, }, }, @@ -550,10 +507,10 @@ var Tests = []test.Spec{ Verify that client returns no error. `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ FcUOnHeadSet: &helper.UpgradeForkchoiceUpdatedVersion{ @@ -576,20 +533,20 @@ var Tests = []test.Spec{ Verify that client returns INVALID_PARAMS_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ FcUOnPayloadRequest: &helper.UpgradeForkchoiceUpdatedVersion{ ForkchoiceUpdatedCustomizer: &helper.BaseForkchoiceUpdatedCustomizer{ - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` ForkchoiceUpdatedV3 before Cancun with any nil field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -604,10 +561,10 @@ var Tests = []test.Spec{ Verify that client returns UNSUPPORTED_FORK_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ FcUOnPayloadRequest: &helper.UpgradeForkchoiceUpdatedVersion{ @@ -615,12 +572,12 @@ var Tests = []test.Spec{ PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{ BeaconRoot: &(common.Hash{}), }, - ExpectedError: UNSUPPORTED_FORK_ERROR, + ExpectedError: globals.UNSUPPORTED_FORK_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` ForkchoiceUpdatedV3 before Cancun with beacon root must return UNSUPPORTED_FORK_ERROR (code %d) - `, *UNSUPPORTED_FORK_ERROR), + `, *globals.UNSUPPORTED_FORK_ERROR), }, }, }, @@ -636,10 +593,10 @@ var Tests = []test.Spec{ Verify that client returns INVALID_PARAMS_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ FcUOnPayloadRequest: &helper.DowngradeForkchoiceUpdatedVersion{ @@ -647,12 +604,12 @@ var Tests = []test.Spec{ PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{ BeaconRoot: &(common.Hash{}), }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` ForkchoiceUpdatedV2 before Cancun with beacon root field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -668,20 +625,20 @@ var Tests = []test.Spec{ Verify that client returns INVALID_PARAMS_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ FcUOnPayloadRequest: &helper.DowngradeForkchoiceUpdatedVersion{ ForkchoiceUpdatedCustomizer: &helper.BaseForkchoiceUpdatedCustomizer{ - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` ForkchoiceUpdatedV2 after Cancun with beacon root field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -695,10 +652,10 @@ var Tests = []test.Spec{ Verify that client returns UNSUPPORTED_FORK_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ FcUOnPayloadRequest: &helper.DowngradeForkchoiceUpdatedVersion{ @@ -706,12 +663,12 @@ var Tests = []test.Spec{ PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{ RemoveBeaconRoot: true, }, - ExpectedError: UNSUPPORTED_FORK_ERROR, + ExpectedError: globals.UNSUPPORTED_FORK_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` ForkchoiceUpdatedV2 after Cancun must return UNSUPPORTED_FORK_ERROR (code %d) - `, *UNSUPPORTED_FORK_ERROR), + `, *globals.UNSUPPORTED_FORK_ERROR), }, }, }, @@ -725,18 +682,17 @@ var Tests = []test.Spec{ payload attribute as the only change between requests and verify that the payload ID is different. `, + MainFork: config.Cancun, }, - CancunForkHeight: 0, - TestSequence: TestSequence{ SendBlobTransactions{ TransactionCount: 1, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), }, NewPayloads{ - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, FcUOnPayloadRequest: &helper.BaseForkchoiceUpdatedCustomizer{ PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{ BeaconRoot: &(common.Hash{}), @@ -745,11 +701,11 @@ var Tests = []test.Spec{ }, SendBlobTransactions{ TransactionCount: 1, - BlobsPerTransaction: MAX_BLOBS_PER_BLOCK, + BlobsPerTransaction: cancun.MAX_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(100), }, NewPayloads{ - ExpectedIncludedBlobCount: MAX_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.MAX_BLOBS_PER_BLOCK, FcUOnPayloadRequest: &helper.BaseForkchoiceUpdatedCustomizer{ PayloadAttributesCustomizer: &helper.BasePayloadAttributesCustomizer{ BeaconRoot: &(common.Hash{1}), @@ -767,20 +723,20 @@ var Tests = []test.Spec{ Test requesting a Shanghai PayloadID using GetPayloadV3. Verify that client returns UNSUPPORTED_FORK_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ GetPayloadCustomizer: &helper.UpgradeGetPayloadVersion{ GetPayloadCustomizer: &helper.BaseGetPayloadCustomizer{ - ExpectedError: UNSUPPORTED_FORK_ERROR, + ExpectedError: globals.UNSUPPORTED_FORK_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` GetPayloadV3 To Request Shanghai Payload must return UNSUPPORTED_FORK_ERROR (code %d) - `, *UNSUPPORTED_FORK_ERROR), + `, *globals.UNSUPPORTED_FORK_ERROR), }, }, }, @@ -793,20 +749,20 @@ var Tests = []test.Spec{ Test requesting a Cancun PayloadID using GetPayloadV2. Verify that client returns UNSUPPORTED_FORK_ERROR. `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ GetPayloadCustomizer: &helper.DowngradeGetPayloadVersion{ GetPayloadCustomizer: &helper.BaseGetPayloadCustomizer{ - ExpectedError: UNSUPPORTED_FORK_ERROR, + ExpectedError: globals.UNSUPPORTED_FORK_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` GetPayloadV2 To Request Cancun Payload must return UNSUPPORTED_FORK_ERROR (code %d) - `, *UNSUPPORTED_FORK_ERROR), + `, *globals.UNSUPPORTED_FORK_ERROR), }, }, }, @@ -824,10 +780,10 @@ var Tests = []test.Spec{ Verify that client returns INVALID_PARAMS_ERROR `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.UpgradeNewPayloadVersion{ @@ -837,12 +793,12 @@ var Tests = []test.Spec{ Blobs: nil, }, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 before Cancun with any nil field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -856,10 +812,10 @@ var Tests = []test.Spec{ - nil Versioned Hashes Array - nil Beacon Root `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.UpgradeNewPayloadVersion{ @@ -867,12 +823,12 @@ var Tests = []test.Spec{ PayloadCustomizer: &helper.CustomPayloadData{ BlobGasUsed: pUint64(0), }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 before Cancun with any nil field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -886,10 +842,10 @@ var Tests = []test.Spec{ - nil Versioned Hashes Array - nil Beacon Root `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.UpgradeNewPayloadVersion{ @@ -897,12 +853,12 @@ var Tests = []test.Spec{ PayloadCustomizer: &helper.CustomPayloadData{ ExcessBlobGas: pUint64(0), }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 before Cancun with any nil field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -916,10 +872,10 @@ var Tests = []test.Spec{ - Empty Versioned Hashes Array - nil Beacon Root `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.UpgradeNewPayloadVersion{ @@ -929,12 +885,12 @@ var Tests = []test.Spec{ Blobs: []helper.BlobID{}, }, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 before Cancun with any nil field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -948,10 +904,10 @@ var Tests = []test.Spec{ - nil Versioned Hashes Array - Zero Beacon Root `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.UpgradeNewPayloadVersion{ @@ -959,12 +915,12 @@ var Tests = []test.Spec{ PayloadCustomizer: &helper.CustomPayloadData{ ParentBeaconRoot: &(common.Hash{}), }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 before Cancun with any nil field must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -978,10 +934,10 @@ var Tests = []test.Spec{ - Empty Versioned Hashes Array - Zero Beacon Root `, + MainFork: config.Cancun, + ForkHeight: 2, }, - CancunForkHeight: 2, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.UpgradeNewPayloadVersion{ @@ -994,12 +950,12 @@ var Tests = []test.Spec{ Blobs: []helper.BlobID{}, }, }, - ExpectedError: UNSUPPORTED_FORK_ERROR, + ExpectedError: globals.UNSUPPORTED_FORK_ERROR, }, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 before Cancun with no nil fields must return UNSUPPORTED_FORK_ERROR (code %d) - `, *UNSUPPORTED_FORK_ERROR), + `, *globals.UNSUPPORTED_FORK_ERROR), }, }, }, @@ -1015,21 +971,21 @@ var Tests = []test.Spec{ - Empty Versioned Hashes Array - Zero Beacon Root `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ RemoveExcessBlobGas: true, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 after Cancun with nil ExcessBlobGas must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -1042,21 +998,21 @@ var Tests = []test.Spec{ - nil BlobGasUsed - Empty Versioned Hashes Array `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ RemoveBlobGasUsed: true, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 after Cancun with nil BlobGasUsed must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -1069,21 +1025,21 @@ var Tests = []test.Spec{ - nil BlobGasUsed - Empty Versioned Hashes Array `, + MainFork: config.Cancun, + ForkHeight: 1, }, - CancunForkHeight: 1, - TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ RemoveParentBeaconRoot: true, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, ExpectationDescription: fmt.Sprintf(` NewPayloadV3 after Cancun with nil parentBeaconBlockRoot must return INVALID_PARAMS_ERROR (code %d) - `, *INVALID_PARAMS_ERROR), + `, *globals.INVALID_PARAMS_ERROR), }, }, }, @@ -1096,23 +1052,23 @@ var Tests = []test.Spec{ Test requesting a Shanghai ForkchoiceUpdatedV2 payload followed by a Cancun ForkchoiceUpdatedV3 request. Verify that client correctly returns the Cancun payload. `, + MainFork: config.Cancun, + // We request two blocks from the client, first on shanghai and then on cancun, both with + // the same parent. + // Client must respond correctly to later request. + ForkHeight: 1, + BlockTimestampIncrement: 2, }, - // We request two blocks from the client, first on shanghai and then on cancun, both with - // the same parent. - // Client must respond correctly to later request. - CancunForkHeight: 1, - TimeIncrements: 2, - TestSequence: TestSequence{ // First, we send a couple of blob transactions on genesis, // with enough data gas cost to make sure they are included in the first block. SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, // This customizer only simulates requesting a Shanghai payload 1 second before cancun. // CL Mock will still request the Cancun payload afterwards FcUOnPayloadRequest: &helper.BaseForkchoiceUpdatedCustomizer{ @@ -1139,19 +1095,20 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is missing one of the hashes. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK-1), + Blobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK-1), }, }, ExpectInvalidStatus: true, @@ -1170,21 +1127,22 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is has an extra hash for a blob that is not in the payload. `, + MainFork: config.Cancun, }, // TODO: It could be worth it to also test this with a blob that is in the // mempool but was not included in the payload. TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK+1), + Blobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK+1), }, }, ExpectInvalidStatus: true, @@ -1203,19 +1161,20 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is out of order. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobListByIndex(helper.BlobID(TARGET_BLOBS_PER_BLOCK-1), 0), + Blobs: helper.GetBlobListByIndex(helper.BlobID(cancun.TARGET_BLOBS_PER_BLOCK-1), 0), }, }, ExpectInvalidStatus: true, @@ -1234,19 +1193,20 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array has a blob that is repeated in the array. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: append(helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), helper.BlobID(TARGET_BLOBS_PER_BLOCK-1)), + Blobs: append(helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), helper.BlobID(cancun.TARGET_BLOBS_PER_BLOCK-1)), }, }, ExpectInvalidStatus: true, @@ -1265,19 +1225,20 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array has a blob hash that does not belong to any blob contained in the payload. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: append(helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK-1), helper.BlobID(TARGET_BLOBS_PER_BLOCK)), + Blobs: append(helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK-1), helper.BlobID(cancun.TARGET_BLOBS_PER_BLOCK)), }, }, ExpectInvalidStatus: true, @@ -1295,20 +1256,21 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array has a single blob that has an incorrect version. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), - HashVersions: []byte{BLOB_COMMITMENT_VERSION_KZG, BLOB_COMMITMENT_VERSION_KZG + 1}, + Blobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), + HashVersions: []byte{cancun.BLOB_COMMITMENT_VERSION_KZG, cancun.BLOB_COMMITMENT_VERSION_KZG + 1}, }, }, ExpectInvalidStatus: true, @@ -1327,22 +1289,23 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is nil, even though the fork has already happened. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ Blobs: nil, }, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, ExpectationDescription: ` NewPayloadV3 after Cancun with nil VersionedHashes must return INVALID_PARAMS_ERROR (code -32602) @@ -1358,15 +1321,16 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is empty, even though there are blobs in the payload. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ @@ -1389,6 +1353,7 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is contains hashes, even though there are no blobs in the payload. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{ @@ -1417,16 +1382,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is missing one of the hashes. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1439,7 +1405,7 @@ var Tests = []test.Spec{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK-1), + Blobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK-1), }, }, ExpectInvalidStatus: true, @@ -1455,18 +1421,19 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is has an extra hash for a blob that is not in the payload. `, + MainFork: config.Cancun, }, // TODO: It could be worth it to also test this with a blob that is in the // mempool but was not included in the payload. TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1479,7 +1446,7 @@ var Tests = []test.Spec{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK+1), + Blobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK+1), }, }, ExpectInvalidStatus: true, @@ -1495,16 +1462,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is out of order. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ EngineStarter: hive_rpc.HiveRPCEngineStarter{}, @@ -1516,7 +1484,7 @@ var Tests = []test.Spec{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobListByIndex(helper.BlobID(TARGET_BLOBS_PER_BLOCK-1), 0), + Blobs: helper.GetBlobListByIndex(helper.BlobID(cancun.TARGET_BLOBS_PER_BLOCK-1), 0), }, }, ExpectInvalidStatus: true, @@ -1532,16 +1500,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array has a blob that is repeated in the array. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1554,7 +1523,7 @@ var Tests = []test.Spec{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: append(helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), helper.BlobID(TARGET_BLOBS_PER_BLOCK-1)), + Blobs: append(helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), helper.BlobID(cancun.TARGET_BLOBS_PER_BLOCK-1)), }, }, ExpectInvalidStatus: true, @@ -1570,16 +1539,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array has a blob that is repeated in the array. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1592,7 +1562,7 @@ var Tests = []test.Spec{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: append(helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK-1), helper.BlobID(TARGET_BLOBS_PER_BLOCK)), + Blobs: append(helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK-1), helper.BlobID(cancun.TARGET_BLOBS_PER_BLOCK)), }, }, ExpectInvalidStatus: true, @@ -1607,16 +1577,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array has a single blob that has an incorrect version. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1629,8 +1600,8 @@ var Tests = []test.Spec{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ VersionedHashesCustomizer: &VersionedHashes{ - Blobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), - HashVersions: []byte{BLOB_COMMITMENT_VERSION_KZG, BLOB_COMMITMENT_VERSION_KZG + 1}, + Blobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), + HashVersions: []byte{cancun.BLOB_COMMITMENT_VERSION_KZG, cancun.BLOB_COMMITMENT_VERSION_KZG + 1}, }, }, ExpectInvalidStatus: true, @@ -1646,16 +1617,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is nil, even though the fork has already happened. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1671,7 +1643,7 @@ var Tests = []test.Spec{ Blobs: nil, }, }, - ExpectedError: INVALID_PARAMS_ERROR, + ExpectedError: globals.INVALID_PARAMS_ERROR, }, }, }, @@ -1684,16 +1656,17 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is empty, even though there are blobs in the payload. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client SendBlobTransactions{ - TransactionCount: TARGET_BLOBS_PER_BLOCK, + TransactionCount: cancun.TARGET_BLOBS_PER_BLOCK, BlobTransactionMaxBlobGasCost: big.NewInt(1), }, NewPayloads{ - ExpectedIncludedBlobCount: TARGET_BLOBS_PER_BLOCK, - ExpectedBlobs: helper.GetBlobList(0, TARGET_BLOBS_PER_BLOCK), + ExpectedIncludedBlobCount: cancun.TARGET_BLOBS_PER_BLOCK, + ExpectedBlobs: helper.GetBlobList(0, cancun.TARGET_BLOBS_PER_BLOCK), }, LaunchClients{ @@ -1722,6 +1695,7 @@ var Tests = []test.Spec{ Tests VersionedHashes in Engine API NewPayloadV3 where the array is contains hashes, even though there are no blobs in the payload. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{}, // Send new payload so the parent is unknown to the secondary client @@ -1752,12 +1726,12 @@ var Tests = []test.Spec{ // Most cases are contained in https://github.com/ethereum/execution-spec-tests/tree/main/tests/cancun/eip4844_blobs // and can be executed using `pyspec` simulator. &CancunBaseSpec{ - BaseSpec: test.BaseSpec{ Name: "Incorrect BlobGasUsed: Non-Zero on Zero Blobs", About: ` Send a payload with zero blobs, but non-zero BlobGasUsed. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{ @@ -1777,12 +1751,13 @@ var Tests = []test.Spec{ About: ` Send a payload with zero blobs, but non-zero BlobGasUsed. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ NewPayloads{ NewPayloadCustomizer: &helper.BaseNewPayloadVersionCustomizer{ PayloadCustomizer: &helper.CustomPayloadData{ - BlobGasUsed: pUint64(GAS_PER_BLOB), + BlobGasUsed: pUint64(cancun.GAS_PER_BLOB), }, ExpectInvalidStatus: true, }, @@ -1797,6 +1772,7 @@ var Tests = []test.Spec{ About: ` Requests blob pooled transactions and verify correct encoding. `, + MainFork: config.Cancun, }, TestSequence: TestSequence{ // Get past the genesis diff --git a/simulators/ethereum/engine/suites/exchange_capabilities/tests.go b/simulators/ethereum/engine/suites/exchange_capabilities/tests.go index 3f4cfc9d8a..26872516eb 100644 --- a/simulators/ethereum/engine/suites/exchange_capabilities/tests.go +++ b/simulators/ethereum/engine/suites/exchange_capabilities/tests.go @@ -48,7 +48,7 @@ func init() { for _, active := range []bool{true, false} { var ( nameStr string - forkTime int64 + forkTime uint64 ) if active { nameStr = "Active" diff --git a/simulators/ethereum/engine/test/env.go b/simulators/ethereum/engine/test/env.go index cc722b3093..1226e1cc5a 100644 --- a/simulators/ethereum/engine/test/env.go +++ b/simulators/ethereum/engine/test/env.go @@ -52,15 +52,12 @@ type Env struct { func Run(testSpec Spec, ttd *big.Int, timeout time.Duration, t *hivesim.T, c *hivesim.Client, genesis *core.Genesis, cParams hivesim.Params, cFiles hivesim.Params) { // Setup the CL Mocker for this test - consensusConfig := testSpec.GetConsensusConfig() forkConfig := testSpec.GetForkConfig() clMocker := clmock.NewCLMocker( t, genesis, - consensusConfig.SlotsToSafe, - consensusConfig.SlotsToFinalized, - big.NewInt(consensusConfig.SafeSlotsToImportOptimistically), - forkConfig) + forkConfig, + ) // Send the CLMocker for configuration by the spec, if any. testSpec.ConfigureCLMock(clMocker) diff --git a/simulators/ethereum/engine/test/expect.go b/simulators/ethereum/engine/test/expect.go index 76e96e5b6f..c587892de0 100644 --- a/simulators/ethereum/engine/test/expect.go +++ b/simulators/ethereum/engine/test/expect.go @@ -14,6 +14,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/hive/simulators/ethereum/engine/client" + "github.com/ethereum/hive/simulators/ethereum/engine/config/cancun" "github.com/ethereum/hive/simulators/ethereum/engine/globals" typ "github.com/ethereum/hive/simulators/ethereum/engine/types" ) @@ -421,17 +422,13 @@ func (tec *TestEngineClient) TestEngineGetPayloadV3(payloadID *api.PayloadID) *G return ret } -var ( - BLOB_COMMITMENT_VERSION_KZG = byte(0x01) -) - func (tec *TestEngineClient) TestEngineGetPayload(payloadID *api.PayloadID, payloadAttributes *typ.PayloadAttributes) *GetPayloadResponseExpectObject { version := tec.EngineAPIVersionResolver.GetPayloadVersion(payloadAttributes.Timestamp) ctx, cancel := context.WithTimeout(tec.TestContext, globals.RPCTimeout) defer cancel() payload, blockValue, blobBundle, shouldOverride, err := tec.Engine.GetPayload(ctx, version, payloadID) if blobBundle != nil { - payload.VersionedHashes, err = blobBundle.VersionedHashes(BLOB_COMMITMENT_VERSION_KZG) + payload.VersionedHashes, err = blobBundle.VersionedHashes(cancun.BLOB_COMMITMENT_VERSION_KZG) if err != nil { panic(err) } diff --git a/simulators/ethereum/engine/test/spec.go b/simulators/ethereum/engine/test/spec.go index f7688cbc40..a2cf8797b6 100644 --- a/simulators/ethereum/engine/test/spec.go +++ b/simulators/ethereum/engine/test/spec.go @@ -12,12 +12,6 @@ import ( "github.com/ethereum/hive/simulators/ethereum/engine/helper" ) -type ConsensusConfig struct { - SlotsToSafe *big.Int - SlotsToFinalized *big.Int - SafeSlotsToImportOptimistically int64 -} - type Spec interface { // Execute the test Execute(*Env) @@ -27,8 +21,6 @@ type Spec interface { GetName() string // Get a brief description of the test GetAbout() string - // Get the consensus configuration for this test - GetConsensusConfig() ConsensusConfig // Get the chain file to initialize the clients GetChainFile() string // Get the main fork for this test @@ -65,12 +57,15 @@ type BaseSpec struct { // Default: 0 TTD int64 + // CL Mocker configuration for time increments + BlockTimestampIncrement uint64 + // CL Mocker configuration for slots to `safe` and `finalized` respectively SlotsToSafe *big.Int SlotsToFinalized *big.Int // CL Mocker configuration for SafeSlotsToImportOptimistically - SafeSlotsToImportOptimistically int64 + SafeSlotsToImportOptimistically *big.Int // Test maximum execution time until a timeout is raised. // Default: 60 seconds @@ -94,29 +89,32 @@ type BaseSpec struct { // Fork Config MainFork config.Fork - ForkTime int64 - PreviousForkTime int64 + ForkTime uint64 + ForkHeight uint64 + PreviousForkTime uint64 } func (s BaseSpec) Execute(env *Env) { s.Run(env) } -func (s BaseSpec) ConfigureCLMock(*clmock.CLMocker) { - // No-op +func (s BaseSpec) ConfigureCLMock(cl *clmock.CLMocker) { + if s.SlotsToSafe != nil { + cl.SlotsToSafe = s.SlotsToSafe + } + if s.SlotsToFinalized != nil { + cl.SlotsToFinalized = s.SlotsToFinalized + } + if s.SafeSlotsToImportOptimistically != nil { + cl.SafeSlotsToImportOptimistically = s.SafeSlotsToImportOptimistically + } + cl.BlockTimestampIncrement = new(big.Int).SetUint64(s.GetBlockTimeIncrements()) } func (s BaseSpec) GetAbout() string { return s.About } -func (s BaseSpec) GetConsensusConfig() ConsensusConfig { - return ConsensusConfig{ - SlotsToSafe: s.SlotsToSafe, - SlotsToFinalized: s.SlotsToFinalized, - SafeSlotsToImportOptimistically: s.SafeSlotsToImportOptimistically, - } -} func (s BaseSpec) GetChainFile() string { return s.ChainFile } @@ -135,15 +133,39 @@ func (s BaseSpec) WithMainFork(fork config.Fork) Spec { return specCopy } +func (s BaseSpec) GetGenesisTimestamp() uint64 { + genesisTimestamp := globals.GenesisTimestamp + if s.GenesisTimestamp != nil { + genesisTimestamp = *s.GenesisTimestamp + } + return genesisTimestamp +} + +func (s BaseSpec) GetBlockTimeIncrements() uint64 { + if s.BlockTimestampIncrement == 0 { + return 1 + } + return s.BlockTimestampIncrement +} + +func (s BaseSpec) GetBlockTime(blockNumber uint64) uint64 { + return s.GetGenesisTimestamp() + blockNumber*s.GetBlockTimeIncrements() +} + +func (s BaseSpec) GetForkTime() uint64 { + forkTime := s.ForkTime + if s.ForkHeight > 0 { + forkTime = s.GetBlockTime(s.ForkHeight) + } + return forkTime +} + func (s BaseSpec) GetForkConfig() *config.ForkConfig { forkTime := s.ForkTime previousForkTime := s.PreviousForkTime forkConfig := config.ForkConfig{} mainFork := s.GetMainFork() - genesisTimestamp := globals.GenesisTimestamp - if s.GenesisTimestamp != nil { - genesisTimestamp = int64(*s.GenesisTimestamp) - } + genesisTimestamp := s.GetGenesisTimestamp() if previousForkTime > forkTime { panic(errors.New("previous fork time cannot be greater than fork time")) } @@ -155,10 +177,10 @@ func (s BaseSpec) GetForkConfig() *config.ForkConfig { if previousForkTime != 0 { return nil // Cannot configure a fork before Shanghai, skip test } - forkConfig.ShanghaiTimestamp = big.NewInt(forkTime) + forkConfig.ShanghaiTimestamp = new(big.Int).SetUint64(forkTime) } else if mainFork == config.Cancun { - forkConfig.ShanghaiTimestamp = big.NewInt(previousForkTime) - forkConfig.CancunTimestamp = big.NewInt(forkTime) + forkConfig.ShanghaiTimestamp = new(big.Int).SetUint64(previousForkTime) + forkConfig.CancunTimestamp = new(big.Int).SetUint64(forkTime) } else { panic(fmt.Errorf("unknown fork: %s", mainFork)) } @@ -166,16 +188,20 @@ func (s BaseSpec) GetForkConfig() *config.ForkConfig { } func (s BaseSpec) GetGenesis() *core.Genesis { + // Load the default test genesis file genesisPath := "./init/genesis.json" if s.GenesisFile != "" { genesisPath = fmt.Sprintf("./init/%s", s.GenesisFile) } genesis := helper.LoadGenesis(genesisPath) + + // Set the terminal total difficulty genesis.Config.TerminalTotalDifficulty = big.NewInt(genesis.Difficulty.Int64() + s.TTD) if genesis.Difficulty.Cmp(genesis.Config.TerminalTotalDifficulty) <= 0 { genesis.Config.TerminalTotalDifficultyPassed = true } + // Set the genesis timestamp if provided if s.GenesisTimestamp != nil { genesis.Timestamp = *s.GenesisTimestamp }