From aab9ac205eeae73abef6236a9839b50f31c7cdcd Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 7 Sep 2023 18:09:53 +0200 Subject: [PATCH 1/8] Upgrade blst to v0.3.11 --- third_party/blst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/blst b/third_party/blst index a7fd1f584d..3dd0f804b1 160000 --- a/third_party/blst +++ b/third_party/blst @@ -1 +1 @@ -Subproject commit a7fd1f584d26b0ae6cdc427976ea1d8980f7e15d +Subproject commit 3dd0f804b1819e5d03fb22ca2e6fac105932043a From ebbdf0f8de81e6c31bc427e3c8d28a355c03e166 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 7 Sep 2023 18:33:09 +0200 Subject: [PATCH 2/8] Update params to 3/6 blobs in block --- silkworm/core/protocol/param.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/silkworm/core/protocol/param.hpp b/silkworm/core/protocol/param.hpp index 9064c51842..8a53dc58dc 100644 --- a/silkworm/core/protocol/param.hpp +++ b/silkworm/core/protocol/param.hpp @@ -61,11 +61,11 @@ inline constexpr uint64_t kElasticityMultiplier{2}; // EIP-4844: Shard Blob Transactions inline constexpr uint8_t kBlobCommitmentVersionKzg{1}; -inline constexpr uint64_t kMaxDataGasPerBlock{1u << 19}; -inline constexpr uint64_t kTargetDataGasPerBlock{1u << 18}; inline constexpr uint64_t kDataGasPerBlob{1u << 17}; +inline constexpr uint64_t kTargetDataGasPerBlock{3 * kDataGasPerBlob}; +inline constexpr uint64_t kMaxDataGasPerBlock{6 * kDataGasPerBlob}; inline constexpr uint64_t kMinDataGasPrice{1}; -inline constexpr uint64_t kDataGasPriceUpdateFraction{2225652}; +inline constexpr uint64_t kDataGasPriceUpdateFraction{3338477}; // EIP-4788: Beacon block root in the EVM inline constexpr uint64_t kSystemCallGasLimit{30'000'000}; From c345b44a7cecac9546409d78a96abae4e6340dca Mon Sep 17 00:00:00 2001 From: yperbasis Date: Thu, 7 Sep 2023 18:37:34 +0200 Subject: [PATCH 3/8] Update precompile address --- silkworm/core/execution/precompile.hpp | 12 +----------- silkworm/core/execution/precompile_test.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/silkworm/core/execution/precompile.hpp b/silkworm/core/execution/precompile.hpp index 3b06243c1c..37aef4b764 100644 --- a/silkworm/core/execution/precompile.hpp +++ b/silkworm/core/execution/precompile.hpp @@ -86,17 +86,7 @@ inline constexpr std::optional kContracts[]{ SupportedContract{{bn_mul_gas, bn_mul_run}, EVMC_BYZANTIUM}, // 0x07 SupportedContract{{snarkv_gas, snarkv_run}, EVMC_BYZANTIUM}, // 0x08 SupportedContract{{blake2_f_gas, blake2_f_run}, EVMC_ISTANBUL}, // 0x09 - std::nullopt, // 0x0a - std::nullopt, // 0x0b - std::nullopt, // 0x0c - std::nullopt, // 0x0d - std::nullopt, // 0x0e - std::nullopt, // 0x0f - std::nullopt, // 0x10 - std::nullopt, // 0x11 - std::nullopt, // 0x12 - std::nullopt, // 0x13 - SupportedContract{{point_evaluation_gas, point_evaluation_run}, EVMC_CANCUN}, // 0x14 + SupportedContract{{point_evaluation_gas, point_evaluation_run}, EVMC_CANCUN}, // 0x0a }; [[nodiscard]] bool is_precompile(const evmc::address&, evmc_revision) noexcept; diff --git a/silkworm/core/execution/precompile_test.cpp b/silkworm/core/execution/precompile_test.cpp index 152f8c035e..fc662f14ab 100644 --- a/silkworm/core/execution/precompile_test.cpp +++ b/silkworm/core/execution/precompile_test.cpp @@ -581,7 +581,7 @@ TEST_CASE("is_precompile") { CHECK(is_precompile(0x0000000000000000000000000000000000000007_address, EVMC_CANCUN) == true); CHECK(is_precompile(0x0000000000000000000000000000000000000008_address, EVMC_CANCUN) == true); CHECK(is_precompile(0x0000000000000000000000000000000000000009_address, EVMC_CANCUN) == true); - CHECK(is_precompile(0x000000000000000000000000000000000000000a_address, EVMC_CANCUN) == false); + CHECK(is_precompile(0x000000000000000000000000000000000000000a_address, EVMC_CANCUN) == true); CHECK(is_precompile(0x000000000000000000000000000000000000000b_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x000000000000000000000000000000000000000c_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x000000000000000000000000000000000000000d_address, EVMC_CANCUN) == false); @@ -591,7 +591,7 @@ TEST_CASE("is_precompile") { CHECK(is_precompile(0x0000000000000000000000000000000000000011_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000012_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000013_address, EVMC_CANCUN) == false); - CHECK(is_precompile(0x0000000000000000000000000000000000000014_address, EVMC_CANCUN) == true); + CHECK(is_precompile(0x0000000000000000000000000000000000000014_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000015_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000016_address, EVMC_CANCUN) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000017_address, EVMC_CANCUN) == false); @@ -611,7 +611,7 @@ TEST_CASE("is_precompile") { CHECK(is_precompile(0x0000000000000000000000000000000000000007_address, EVMC_PRAGUE) == true); CHECK(is_precompile(0x0000000000000000000000000000000000000008_address, EVMC_PRAGUE) == true); CHECK(is_precompile(0x0000000000000000000000000000000000000009_address, EVMC_PRAGUE) == true); - CHECK(is_precompile(0x000000000000000000000000000000000000000a_address, EVMC_PRAGUE) == false); + CHECK(is_precompile(0x000000000000000000000000000000000000000a_address, EVMC_PRAGUE) == true); CHECK(is_precompile(0x000000000000000000000000000000000000000b_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x000000000000000000000000000000000000000c_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x000000000000000000000000000000000000000d_address, EVMC_PRAGUE) == false); @@ -621,7 +621,7 @@ TEST_CASE("is_precompile") { CHECK(is_precompile(0x0000000000000000000000000000000000000011_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000012_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000013_address, EVMC_PRAGUE) == false); - CHECK(is_precompile(0x0000000000000000000000000000000000000014_address, EVMC_PRAGUE) == true); + CHECK(is_precompile(0x0000000000000000000000000000000000000014_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000015_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000016_address, EVMC_PRAGUE) == false); CHECK(is_precompile(0x0000000000000000000000000000000000000017_address, EVMC_PRAGUE) == false); From 714b6366ddf13fd8a5447bb59eb4427fbe5e7de4 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 12 Sep 2023 16:21:58 +0200 Subject: [PATCH 4/8] data gas -> blob gas --- cmd/dev/snapshots.cpp | 6 ++-- cmd/dev/toolbox.cpp | 4 +-- cmd/state-transition/state_transition.cpp | 2 +- cmd/test/ethereum.cpp | 2 +- silkworm/core/execution/processor.cpp | 6 ++-- silkworm/core/protocol/base_rule_set.cpp | 20 ++++++------ silkworm/core/protocol/param.hpp | 10 +++--- silkworm/core/protocol/validation.cpp | 22 ++++++------- silkworm/core/protocol/validation.hpp | 10 +++--- silkworm/core/protocol/validation_test.cpp | 36 +++++++++++----------- silkworm/core/types/block.cpp | 36 +++++++++++----------- silkworm/core/types/block.hpp | 6 ++-- silkworm/core/types/block_test.cpp | 4 +-- silkworm/core/types/transaction.cpp | 16 +++++----- silkworm/core/types/transaction.hpp | 4 +-- silkworm/core/types/transaction_test.cpp | 10 +++--- silkworm/node/snapshot/snapshot_test.cpp | 2 +- silkworm/node/stagedsync/remote_client.cpp | 12 ++++---- 18 files changed, 104 insertions(+), 104 deletions(-) diff --git a/cmd/dev/snapshots.cpp b/cmd/dev/snapshots.cpp index 4d01f68b6f..0fe5070251 100644 --- a/cmd/dev/snapshots.cpp +++ b/cmd/dev/snapshots.cpp @@ -349,8 +349,8 @@ static void print_header(const BlockHeader& header, const std::string& snapshot_ << "difficulty=" << intx::to_string(header.difficulty) << "\n" << "gas_limit=" << header.gas_limit << "\n" << "gas_used=" << header.gas_used << "\n" - << "data_gas_used=" << (header.data_gas_used ? *header.data_gas_used : 0) << "\n" - << "excess_data_gas=" << (header.excess_data_gas ? *header.excess_data_gas : 0) << "\n" + << "blob_gas_used=" << header.blob_gas_used.value_or(0) << "\n" + << "excess_blob_gas=" << header.excess_blob_gas.value_or(0) << "\n" << "logs_bloom=" << to_hex(header.logs_bloom) << "\n" << "extra_data=" << to_hex(header.extra_data) << "\n" << "rlp=" << to_hex([&]() { Bytes b; rlp::encode(b, header); return b; }()) << "\n"; @@ -494,7 +494,7 @@ static void print_txn(const Transaction& txn, const std::string& snapshot_filena << "value=" << intx::to_string(txn.value) << "\n" << "gas_limit=" << txn.gas_limit << "\n" << "max_fee_per_gas=" << intx::to_string(txn.max_fee_per_gas) << "\n" - << "max_fee_per_data_gas=" << intx::to_string(txn.max_fee_per_data_gas) << "\n" + << "max_fee_per_blob_gas=" << intx::to_string(txn.max_fee_per_blob_gas) << "\n" << "max_priority_fee_per_gas=" << intx::to_string(txn.max_priority_fee_per_gas) << "\n" << "odd_y_parity=" << txn.odd_y_parity << "\n" << "v=" << intx::to_string(txn.v()) << "\n" diff --git a/cmd/dev/toolbox.cpp b/cmd/dev/toolbox.cpp index be6be95fd0..47eb74a20d 100644 --- a/cmd/dev/toolbox.cpp +++ b/cmd/dev/toolbox.cpp @@ -171,8 +171,8 @@ static void print_header(const BlockHeader& header) { << "difficulty=" << intx::to_string(header.difficulty) << "\n" << "gas_limit=" << header.gas_limit << "\n" << "gas_used=" << header.gas_used << "\n" - << "data_gas_used=" << (header.data_gas_used ? *header.data_gas_used : 0) << "\n" - << "excess_data_gas=" << (header.excess_data_gas ? *header.excess_data_gas : 0) << "\n" + << "blob_gas_used=" << header.blob_gas_used.value_or(0) << "\n" + << "excess_blob_gas=" << header.excess_blob_gas.value_or(0) << "\n" << "logs_bloom=" << to_hex(header.logs_bloom) << "\n" << "extra_data=" << to_hex(header.extra_data) << "\n" << "rlp=" << to_hex([&]() { Bytes b; rlp::encode(b, header); return b; }()) << "\n"; diff --git a/cmd/state-transition/state_transition.cpp b/cmd/state-transition/state_transition.cpp index 7595db6e8e..bb9a7e6280 100644 --- a/cmd/state-transition/state_transition.cpp +++ b/cmd/state-transition/state_transition.cpp @@ -336,7 +336,7 @@ void StateTransition::run() { auto pre_block_validation = ruleSet->pre_validate_block_body(block, *state); auto block_validation = ruleSet->validate_block_header(block.header, *state, true); - auto pre_txn_validation = protocol::pre_validate_transaction(txn, rev, config.chain_id, block.header.base_fee_per_gas, block.header.data_gas_price()); + auto pre_txn_validation = protocol::pre_validate_transaction(txn, rev, config.chain_id, block.header.base_fee_per_gas, block.header.blob_gas_price()); auto txn_validation = protocol::validate_transaction(txn, processor.evm().state(), processor.available_gas()); // std::cout << "pre: " << std::endl; diff --git a/cmd/test/ethereum.cpp b/cmd/test/ethereum.cpp index 02218e5051..2c65b1f8e3 100644 --- a/cmd/test/ethereum.cpp +++ b/cmd/test/ethereum.cpp @@ -387,7 +387,7 @@ RunResults transaction_test(const nlohmann::json& j, bool) { if (ValidationResult err{ pre_validate_transaction(txn, rev, config.chain_id, /*base_fee_per_gas=*/std::nullopt, - /*data_gas_price=*/std::nullopt)}; + /*blob_gas_price=*/std::nullopt)}; err != ValidationResult::kOk) { if (should_be_valid) { std::cout << "Validation error " << magic_enum::enum_name(err) << std::endl; diff --git a/silkworm/core/execution/processor.cpp b/silkworm/core/execution/processor.cpp index 703b8c701b..dae8675857 100644 --- a/silkworm/core/execution/processor.cpp +++ b/silkworm/core/execution/processor.cpp @@ -65,9 +65,9 @@ void ExecutionProcessor::execute_transaction(const Transaction& txn, Receipt& re const intx::uint256 effective_gas_price{txn.effective_gas_price(base_fee_per_gas)}; state_.subtract_from_balance(*txn.from, txn.gas_limit * effective_gas_price); - // EIP-4844 data gas cost (calc_data_fee) - const intx::uint256 data_gas_price{evm_.block().header.data_gas_price().value_or(0)}; - state_.subtract_from_balance(*txn.from, txn.total_data_gas() * data_gas_price); + // EIP-4844 blob gas cost (calc_data_fee) + const intx::uint256 blob_gas_price{evm_.block().header.blob_gas_price().value_or(0)}; + state_.subtract_from_balance(*txn.from, txn.total_blob_gas() * blob_gas_price); const intx::uint128 g0{protocol::intrinsic_gas(txn, rev)}; assert(g0 <= UINT64_MAX); // true due to the precondition (transaction must be valid) diff --git a/silkworm/core/protocol/base_rule_set.cpp b/silkworm/core/protocol/base_rule_set.cpp index 834d1d97fc..02ffafc4a9 100644 --- a/silkworm/core/protocol/base_rule_set.cpp +++ b/silkworm/core/protocol/base_rule_set.cpp @@ -48,18 +48,18 @@ ValidationResult BaseRuleSet::pre_validate_block_body(const Block& block, const return ValidationResult::kWrongWithdrawalsRoot; } - std::optional data_gas_used{std::nullopt}; + std::optional blob_gas_used{std::nullopt}; if (rev >= EVMC_CANCUN) { - data_gas_used = 0; + blob_gas_used = 0; for (const Transaction& tx : block.transactions) { - *data_gas_used += tx.total_data_gas(); + *blob_gas_used += tx.total_blob_gas(); } - if (data_gas_used > kMaxDataGasPerBlock) { + if (blob_gas_used > kMaxBlobGasPerBlock) { return ValidationResult::kTooManyBlobs; } } - if (header.data_gas_used != data_gas_used) { - return ValidationResult::kWrongDataGasUsed; + if (header.blob_gas_used != blob_gas_used) { + return ValidationResult::kWrongBlobGasUsed; } if (block.ommers.empty()) { @@ -201,15 +201,15 @@ ValidationResult BaseRuleSet::validate_block_header(const BlockHeader& header, c } if (rev < EVMC_CANCUN) { - if (header.data_gas_used || header.excess_data_gas || header.parent_beacon_block_root) { + if (header.blob_gas_used || header.excess_blob_gas || header.parent_beacon_block_root) { return ValidationResult::kFieldBeforeFork; } } else { - if (!header.data_gas_used || !header.excess_data_gas || !header.parent_beacon_block_root) { + if (!header.blob_gas_used || !header.excess_blob_gas || !header.parent_beacon_block_root) { return ValidationResult::kMissingField; } - if (header.excess_data_gas != calc_excess_data_gas(*parent)) { - return ValidationResult::kWrongExcessDataGas; + if (header.excess_blob_gas != calc_excess_blob_gas(*parent)) { + return ValidationResult::kWrongExcessBlobGas; } } diff --git a/silkworm/core/protocol/param.hpp b/silkworm/core/protocol/param.hpp index 8a53dc58dc..5bb7745e00 100644 --- a/silkworm/core/protocol/param.hpp +++ b/silkworm/core/protocol/param.hpp @@ -61,11 +61,11 @@ inline constexpr uint64_t kElasticityMultiplier{2}; // EIP-4844: Shard Blob Transactions inline constexpr uint8_t kBlobCommitmentVersionKzg{1}; -inline constexpr uint64_t kDataGasPerBlob{1u << 17}; -inline constexpr uint64_t kTargetDataGasPerBlock{3 * kDataGasPerBlob}; -inline constexpr uint64_t kMaxDataGasPerBlock{6 * kDataGasPerBlob}; -inline constexpr uint64_t kMinDataGasPrice{1}; -inline constexpr uint64_t kDataGasPriceUpdateFraction{3338477}; +inline constexpr uint64_t kBlobGasPerBlob{1u << 17}; +inline constexpr uint64_t kTargetBlobGasPerBlock{3 * kBlobGasPerBlob}; +inline constexpr uint64_t kMaxBlobGasPerBlock{6 * kBlobGasPerBlob}; +inline constexpr uint64_t kMinBlobGasPrice{1}; +inline constexpr uint64_t kBlobGasPriceUpdateFraction{3338477}; // EIP-4788: Beacon block root in the EVM inline constexpr uint64_t kSystemCallGasLimit{30'000'000}; diff --git a/silkworm/core/protocol/validation.cpp b/silkworm/core/protocol/validation.cpp index 0f99a449f0..882fefa9c9 100644 --- a/silkworm/core/protocol/validation.cpp +++ b/silkworm/core/protocol/validation.cpp @@ -40,7 +40,7 @@ bool transaction_type_is_supported(TransactionType type, evmc_revision rev) { ValidationResult pre_validate_transaction(const Transaction& txn, const evmc_revision rev, const uint64_t chain_id, const std::optional& base_fee_per_gas, - const std::optional& data_gas_price) { + const std::optional& blob_gas_price) { if (txn.chain_id.has_value()) { if (rev < EVMC_SPURIOUS_DRAGON) { // EIP-155 transaction before EIP-155 was activated @@ -101,9 +101,9 @@ ValidationResult pre_validate_transaction(const Transaction& txn, const evmc_rev return ValidationResult::kWrongBlobCommitmentVersion; } } - SILKWORM_ASSERT(data_gas_price); - if (txn.max_fee_per_data_gas < data_gas_price) { - return ValidationResult::kMaxFeePerDataGasTooLow; + SILKWORM_ASSERT(blob_gas_price); + if (txn.max_fee_per_blob_gas < blob_gas_price) { + return ValidationResult::kMaxFeePerBlobGasTooLow; } // TODO(yperbasis): There is an equal amount of versioned hashes, kzg commitments and blobs. // The KZG commitments hash to the versioned hashes, i.e. kzg_to_versioned_hash(kzg[i]) == versioned_hash[i] @@ -147,11 +147,11 @@ ValidationResult validate_transaction(const Transaction& txn, const IntraBlockSt ValidationResult pre_validate_transactions(const Block& block, const ChainConfig& config) { const BlockHeader& header{block.header}; const evmc_revision rev{config.revision(header.number, header.timestamp)}; - const std::optional data_gas_price{header.data_gas_price()}; + const std::optional blob_gas_price{header.blob_gas_price()}; for (const Transaction& txn : block.transactions) { ValidationResult err{pre_validate_transaction(txn, rev, config.chain_id, - header.base_fee_per_gas, data_gas_price)}; + header.base_fee_per_gas, blob_gas_price)}; if (err != ValidationResult::kOk) { return err; } @@ -192,14 +192,14 @@ intx::uint256 expected_base_fee_per_gas(const BlockHeader& parent) { } } -uint64_t calc_excess_data_gas(const BlockHeader& parent) { - const uint64_t parent_excess_data_gas{parent.excess_data_gas.value_or(0)}; - const uint64_t consumed_data_gas{parent.data_gas_used.value_or(0)}; +uint64_t calc_excess_blob_gas(const BlockHeader& parent) { + const uint64_t parent_excess_blob_gas{parent.excess_blob_gas.value_or(0)}; + const uint64_t consumed_blob_gas{parent.blob_gas_used.value_or(0)}; - if (parent_excess_data_gas + consumed_data_gas < kTargetDataGasPerBlock) { + if (parent_excess_blob_gas + consumed_blob_gas < kTargetBlobGasPerBlock) { return 0; } else { - return parent_excess_data_gas + consumed_data_gas - kTargetDataGasPerBlock; + return parent_excess_blob_gas + consumed_blob_gas - kTargetBlobGasPerBlock; } } diff --git a/silkworm/core/protocol/validation.hpp b/silkworm/core/protocol/validation.hpp index 0123340660..fd3dec875e 100644 --- a/silkworm/core/protocol/validation.hpp +++ b/silkworm/core/protocol/validation.hpp @@ -94,12 +94,12 @@ enum class [[nodiscard]] ValidationResult{ kWrongWithdrawalsRoot, // EIP-4844: Shard Blob Transactions - kWrongDataGasUsed, - kWrongExcessDataGas, + kWrongBlobGasUsed, + kWrongExcessBlobGas, kNoBlobs, kTooManyBlobs, kWrongBlobCommitmentVersion, - kMaxFeePerDataGasTooLow, // max_fee_per_data_gas < data_gas_price + kMaxFeePerBlobGasTooLow, // max_fee_per_blob_gas < blob_gas_price }; namespace protocol { @@ -112,7 +112,7 @@ namespace protocol { //! \remarks These function is agnostic to whole block validity ValidationResult pre_validate_transaction(const Transaction& txn, evmc_revision revision, uint64_t chain_id, const std::optional& base_fee_per_gas, - const std::optional& data_gas_price); + const std::optional& blob_gas_price); ValidationResult pre_validate_transactions(const Block& block, const ChainConfig& config); @@ -128,7 +128,7 @@ namespace protocol { intx::uint256 expected_base_fee_per_gas(const BlockHeader& parent); //! \see EIP-4844: Shard Blob Transactions - uint64_t calc_excess_data_gas(const BlockHeader& parent); + uint64_t calc_excess_blob_gas(const BlockHeader& parent); //! \brief Calculate the transaction root of a block body evmc::bytes32 compute_transaction_root(const BlockBody& body); diff --git a/silkworm/core/protocol/validation_test.cpp b/silkworm/core/protocol/validation_test.cpp index e95bf1b2ae..727495de80 100644 --- a/silkworm/core/protocol/validation_test.cpp +++ b/silkworm/core/protocol/validation_test.cpp @@ -25,67 +25,67 @@ namespace silkworm::protocol { TEST_CASE("Validate transaction types") { const std::optional base_fee_per_gas{std::nullopt}; - const std::optional data_gas_price{std::nullopt}; + const std::optional blob_gas_price{std::nullopt}; Transaction txn; txn.type = TransactionType::kLegacy; - CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kUnsupportedTransactionType); txn.type = static_cast(0x03); // unsupported transaction type - CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kUnsupportedTransactionType); txn.type = TransactionType::kAccessList; - CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kUnsupportedTransactionType); txn.type = TransactionType::kDynamicFee; - CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_ISTANBUL, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_BERLIN, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kUnsupportedTransactionType); - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kUnsupportedTransactionType); } TEST_CASE("Validate max_fee_per_gas") { const std::optional base_fee_per_gas{1'000'000'000}; - const std::optional data_gas_price{std::nullopt}; + const std::optional blob_gas_price{std::nullopt}; Transaction txn; txn.type = TransactionType::kDynamicFee; txn.max_priority_fee_per_gas = 500'000'000; txn.max_fee_per_gas = 700'000'000; - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kMaxFeeLessThanBase); txn.max_priority_fee_per_gas = 3'000'000'000; txn.max_fee_per_gas = 2'000'000'000; - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) == + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) == ValidationResult::kMaxPriorityFeeGreaterThanMax); txn.max_priority_fee_per_gas = 2'000'000'000; txn.max_fee_per_gas = 2'000'000'000; - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kMaxPriorityFeeGreaterThanMax); txn.max_priority_fee_per_gas = 1'000'000'000; txn.max_fee_per_gas = 2'000'000'000; - CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, data_gas_price) != + CHECK(pre_validate_transaction(txn, EVMC_LONDON, 1, base_fee_per_gas, blob_gas_price) != ValidationResult::kMaxPriorityFeeGreaterThanMax); } diff --git a/silkworm/core/types/block.cpp b/silkworm/core/types/block.cpp index cffac08b75..23f2288c3d 100644 --- a/silkworm/core/types/block.cpp +++ b/silkworm/core/types/block.cpp @@ -54,15 +54,15 @@ static intx::uint256 fake_exponential(const intx::uint256& factor, return output / denominator; } -std::optional BlockHeader::data_gas_price() const { - if (!excess_data_gas) { +std::optional BlockHeader::blob_gas_price() const { + if (!excess_blob_gas) { return std::nullopt; } return fake_exponential( - protocol::kMinDataGasPrice, - *excess_data_gas, - protocol::kDataGasPriceUpdateFraction); + protocol::kMinBlobGasPrice, + *excess_blob_gas, + protocol::kBlobGasPriceUpdateFraction); } //! \brief Recover transaction senders for each block. @@ -104,11 +104,11 @@ namespace rlp { if (header.withdrawals_root) { rlp_head.payload_length += kHashLength + 1; } - if (header.data_gas_used) { - rlp_head.payload_length += length(*header.data_gas_used); + if (header.blob_gas_used) { + rlp_head.payload_length += length(*header.blob_gas_used); } - if (header.excess_data_gas) { - rlp_head.payload_length += length(*header.excess_data_gas); + if (header.excess_blob_gas) { + rlp_head.payload_length += length(*header.excess_blob_gas); } if (header.parent_beacon_block_root) { rlp_head.payload_length += kHashLength + 1; @@ -152,11 +152,11 @@ namespace rlp { if (header.withdrawals_root) { encode(to, *header.withdrawals_root); } - if (header.data_gas_used) { - encode(to, *header.data_gas_used); + if (header.blob_gas_used) { + encode(to, *header.blob_gas_used); } - if (header.excess_data_gas) { - encode(to, *header.excess_data_gas); + if (header.excess_blob_gas) { + encode(to, *header.excess_blob_gas); } if (header.parent_beacon_block_root) { encode(to, *header.parent_beacon_block_root); @@ -215,17 +215,17 @@ namespace rlp { } if (from.length() > leftover) { - to.data_gas_used = 0; - to.excess_data_gas = 0; + to.blob_gas_used = 0; + to.excess_blob_gas = 0; to.parent_beacon_block_root = evmc::bytes32{}; - if (DecodingResult res{decode_items(from, *to.data_gas_used, *to.excess_data_gas, + if (DecodingResult res{decode_items(from, *to.blob_gas_used, *to.excess_blob_gas, *to.parent_beacon_block_root)}; !res) { return res; } } else { - to.data_gas_used = std::nullopt; - to.excess_data_gas = std::nullopt; + to.blob_gas_used = std::nullopt; + to.excess_blob_gas = std::nullopt; to.parent_beacon_block_root = std::nullopt; } diff --git a/silkworm/core/types/block.hpp b/silkworm/core/types/block.hpp index f22945e7be..c44b006889 100644 --- a/silkworm/core/types/block.hpp +++ b/silkworm/core/types/block.hpp @@ -77,8 +77,8 @@ struct BlockHeader { std::optional withdrawals_root{std::nullopt}; // EIP-4895 // Added in Cancun - std::optional data_gas_used{std::nullopt}; // EIP-4844 - std::optional excess_data_gas{std::nullopt}; // EIP-4844 + std::optional blob_gas_used{std::nullopt}; // EIP-4844 + std::optional excess_blob_gas{std::nullopt}; // EIP-4844 std::optional parent_beacon_block_root{std::nullopt}; // EIP-4788 [[nodiscard]] evmc::bytes32 hash(bool for_sealing = false, bool exclude_extra_data_sig = false) const; @@ -88,7 +88,7 @@ struct BlockHeader { [[nodiscard]] ethash::hash256 boundary() const; //! \see https://eips.ethereum.org/EIPS/eip-4844#gas-accounting - [[nodiscard]] std::optional data_gas_price() const; + [[nodiscard]] std::optional blob_gas_price() const; friend bool operator==(const BlockHeader&, const BlockHeader&) = default; }; diff --git a/silkworm/core/types/block_test.cpp b/silkworm/core/types/block_test.cpp index c218300b57..b09c52e014 100644 --- a/silkworm/core/types/block_test.cpp +++ b/silkworm/core/types/block_test.cpp @@ -197,8 +197,8 @@ TEST_CASE("Cancun Header RLP") { .prev_randao = 0xd01681d2b3acdebff0288a02a1648b3910500961982d5ecdbef064af7c34090b_bytes32, .base_fee_per_gas = 2'700'000'000, .withdrawals_root = 0xbac9348581b0ee244d6eb61076b63c4e4afa70430c804ab0e6a0ab69d9a9d323_bytes32, - .data_gas_used = 456, - .excess_data_gas = 789633, + .blob_gas_used = 456, + .excess_blob_gas = 789633, .parent_beacon_block_root = 0x22_bytes32, }; diff --git a/silkworm/core/types/transaction.cpp b/silkworm/core/types/transaction.cpp index 8bc42670ce..4891eea5e0 100644 --- a/silkworm/core/types/transaction.cpp +++ b/silkworm/core/types/transaction.cpp @@ -91,7 +91,7 @@ namespace rlp { if (txn.type != TransactionType::kLegacy) { h.payload_length += length(txn.access_list); if (txn.type == TransactionType::kBlob) { - h.payload_length += length(txn.max_fee_per_data_gas); + h.payload_length += length(txn.max_fee_per_blob_gas); h.payload_length += length(txn.blob_versioned_hashes); } } @@ -172,7 +172,7 @@ namespace rlp { encode(to, txn.access_list); if (txn.type == TransactionType::kBlob) { - encode(to, txn.max_fee_per_data_gas); + encode(to, txn.max_fee_per_blob_gas); encode(to, txn.blob_versioned_hashes); } } @@ -273,9 +273,9 @@ namespace rlp { } if (to.type != TransactionType::kBlob) { - to.max_fee_per_data_gas = 0; + to.max_fee_per_blob_gas = 0; to.blob_versioned_hashes.clear(); - } else if (DecodingResult res{decode_items(from, to.max_fee_per_data_gas, to.blob_versioned_hashes)}; !res) { + } else if (DecodingResult res{decode_items(from, to.max_fee_per_blob_gas, to.blob_versioned_hashes)}; !res) { return res; } @@ -309,7 +309,7 @@ namespace rlp { if (h->list) { // Legacy transaction to.type = TransactionType::kLegacy; to.access_list.clear(); - to.max_fee_per_data_gas = 0; + to.max_fee_per_blob_gas = 0; to.blob_versioned_hashes.clear(); const uint64_t leftover{from.length() - h->payload_length}; @@ -420,7 +420,7 @@ intx::uint512 UnsignedTransaction::maximum_gas_cost() const { // See https://github.com/ethereum/EIPs/pull/3594 intx::uint512 max_gas_cost{intx::umul(intx::uint256{gas_limit}, max_fee_per_gas)}; // and https://eips.ethereum.org/EIPS/eip-4844#gas-accounting - max_gas_cost += intx::umul(intx::uint256{total_data_gas()}, max_fee_per_data_gas); + max_gas_cost += intx::umul(intx::uint256{total_blob_gas()}, max_fee_per_blob_gas); return max_gas_cost; } @@ -436,8 +436,8 @@ intx::uint256 UnsignedTransaction::effective_gas_price(const intx::uint256& base return priority_fee_per_gas(base_fee_per_gas) + base_fee_per_gas; } -uint64_t UnsignedTransaction::total_data_gas() const { - return protocol::kDataGasPerBlob * blob_versioned_hashes.size(); +uint64_t UnsignedTransaction::total_blob_gas() const { + return protocol::kBlobGasPerBlob * blob_versioned_hashes.size(); } } // namespace silkworm diff --git a/silkworm/core/types/transaction.hpp b/silkworm/core/types/transaction.hpp index b13b91b567..3aa3a3ca7c 100644 --- a/silkworm/core/types/transaction.hpp +++ b/silkworm/core/types/transaction.hpp @@ -64,7 +64,7 @@ struct UnsignedTransaction { std::vector access_list{}; // EIP-2930 // EIP-4844: Shard Blob Transactions - intx::uint256 max_fee_per_data_gas{0}; + intx::uint256 max_fee_per_blob_gas{0}; std::vector blob_versioned_hashes{}; //! \brief Maximum possible cost of normal and data (EIP-4844) gas @@ -73,7 +73,7 @@ struct UnsignedTransaction { [[nodiscard]] intx::uint256 priority_fee_per_gas(const intx::uint256& base_fee_per_gas) const; // EIP-1559 [[nodiscard]] intx::uint256 effective_gas_price(const intx::uint256& base_fee_per_gas) const; // EIP-1559 - [[nodiscard]] uint64_t total_data_gas() const; // EIP-4844 + [[nodiscard]] uint64_t total_blob_gas() const; // EIP-4844 void encode_for_signing(Bytes& into) const; diff --git a/silkworm/core/types/transaction_test.cpp b/silkworm/core/types/transaction_test.cpp index dab9583449..20d8fd4c97 100644 --- a/silkworm/core/types/transaction_test.cpp +++ b/silkworm/core/types/transaction_test.cpp @@ -57,11 +57,11 @@ TEST_CASE("Legacy Transaction RLP") { CHECK(view.empty()); CHECK(decoded == txn); - // Check that non-legacy fields (access_list, max_fee_per_data_gas, blob_versioned_hashes) and from are cleared + // Check that non-legacy fields (access_list, max_fee_per_blob_gas, blob_versioned_hashes) and from are cleared decoded.max_priority_fee_per_gas = 17; decoded.max_fee_per_gas = 31; decoded.access_list = access_list; - decoded.max_fee_per_data_gas = 123; + decoded.max_fee_per_blob_gas = 123; decoded.blob_versioned_hashes.push_back(0xefc552d1df2a6a8e2643912171d040e4de0db43cd53b728c3e4d26952f710be8_bytes32); decoded.from = 0x811a752c8cd697e3cb27279c330ed1ada745a8d7_address; view = encoded; @@ -125,10 +125,10 @@ TEST_CASE("EIP-2930 Transaction RLP") { CHECK(view.empty()); CHECK(decoded == txn); - // Check that post-EIP-2930 fields (max_fee_per_data_gas, blob_versioned_hashes) and from are cleared + // Check that post-EIP-2930 fields (max_fee_per_blob_gas, blob_versioned_hashes) and from are cleared decoded.max_priority_fee_per_gas = 17; decoded.max_fee_per_gas = 31; - decoded.max_fee_per_data_gas = 123; + decoded.max_fee_per_blob_gas = 123; decoded.blob_versioned_hashes.push_back(0xefc552d1df2a6a8e2643912171d040e4de0db43cd53b728c3e4d26952f710be8_bytes32); decoded.from = 0x811a752c8cd697e3cb27279c330ed1ada745a8d7_address; view = encoded_wrapped; @@ -175,7 +175,7 @@ TEST_CASE("EIP-4844 Transaction RLP") { .to = 0x811a752c8cd697e3cb27279c330ed1ada745a8d7_address, .data = *from_hex("04f7"), .access_list = access_list, - .max_fee_per_data_gas = 123, + .max_fee_per_blob_gas = 123, .blob_versioned_hashes = { 0xc6bdd1de713471bd6cfa62dd8b5a5b42969ed09e26212d3377f3f8426d8ec210_bytes32, 0x8aaeccaf3873d07cef005aca28c39f8a9f8bdb1ec8d79ffc25afc0a4fa2ab736_bytes32, diff --git a/silkworm/node/snapshot/snapshot_test.cpp b/silkworm/node/snapshot/snapshot_test.cpp index 6d2aa4b21a..943b172287 100644 --- a/silkworm/node/snapshot/snapshot_test.cpp +++ b/silkworm/node/snapshot/snapshot_test.cpp @@ -393,7 +393,7 @@ TEST_CASE("TransactionSnapshot::slice_tx_payload", "[silkworm][node][snapshot]") .to = 0x811a752c8cd697e3cb27279c330ed1ada745a8d7_address, .data = *from_hex("04f7"), .access_list = access_list, - .max_fee_per_data_gas = 123, + .max_fee_per_blob_gas = 123, .blob_versioned_hashes = { 0xc6bdd1de713471bd6cfa62dd8b5a5b42969ed09e26212d3377f3f8426d8ec210_bytes32, 0x8aaeccaf3873d07cef005aca28c39f8a9f8bdb1ec8d79ffc25afc0a4fa2ab736_bytes32, diff --git a/silkworm/node/stagedsync/remote_client.cpp b/silkworm/node/stagedsync/remote_client.cpp index 4f4af8ddb7..b6a45a87bf 100644 --- a/silkworm/node/stagedsync/remote_client.cpp +++ b/silkworm/node/stagedsync/remote_client.cpp @@ -51,11 +51,11 @@ static void serialize_header(const BlockHeader& bh, ::execution::Header* header) if (bh.withdrawals_root) { header->set_allocated_withdrawal_hash(rpc::H256_from_bytes32(*bh.withdrawals_root).release()); } - if (bh.data_gas_used) { - header->set_data_gas_used(*bh.data_gas_used); + if (bh.blob_gas_used) { + header->set_data_gas_used(*bh.blob_gas_used); } - if (bh.excess_data_gas) { - header->set_excess_data_gas(*bh.excess_data_gas); + if (bh.excess_blob_gas) { + header->set_excess_data_gas(*bh.excess_blob_gas); } } @@ -83,10 +83,10 @@ static void deserialize_header(const ::execution::Header& received_header, Block header.withdrawals_root = rpc::bytes32_from_H256(received_header.withdrawal_hash()); } if (received_header.has_data_gas_used()) { - header.data_gas_used = received_header.data_gas_used(); + header.blob_gas_used = received_header.data_gas_used(); } if (received_header.has_excess_data_gas()) { - header.excess_data_gas = received_header.excess_data_gas(); + header.excess_blob_gas = received_header.excess_data_gas(); } } From c94e217bfec70e96cc79816029f9dbc676d08ac4 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Sun, 17 Sep 2023 18:25:58 +0200 Subject: [PATCH 5/8] Blob transactions cannot have the form of a create transaction --- silkworm/core/protocol/validation.cpp | 6 +++--- silkworm/core/protocol/validation.hpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/silkworm/core/protocol/validation.cpp b/silkworm/core/protocol/validation.cpp index 882fefa9c9..bf3bc27c4a 100644 --- a/silkworm/core/protocol/validation.cpp +++ b/silkworm/core/protocol/validation.cpp @@ -105,9 +105,9 @@ ValidationResult pre_validate_transaction(const Transaction& txn, const evmc_rev if (txn.max_fee_per_blob_gas < blob_gas_price) { return ValidationResult::kMaxFeePerBlobGasTooLow; } - // TODO(yperbasis): There is an equal amount of versioned hashes, kzg commitments and blobs. - // The KZG commitments hash to the versioned hashes, i.e. kzg_to_versioned_hash(kzg[i]) == versioned_hash[i] - // The KZG commitments match the blob contents. + if (!txn.to) { + return ValidationResult::kBlobCreateTransaction; + } } return ValidationResult::kOk; diff --git a/silkworm/core/protocol/validation.hpp b/silkworm/core/protocol/validation.hpp index fd3dec875e..9832ad2656 100644 --- a/silkworm/core/protocol/validation.hpp +++ b/silkworm/core/protocol/validation.hpp @@ -100,6 +100,7 @@ enum class [[nodiscard]] ValidationResult{ kTooManyBlobs, kWrongBlobCommitmentVersion, kMaxFeePerBlobGasTooLow, // max_fee_per_blob_gas < blob_gas_price + kBlobCreateTransaction, // Blob transactions cannot have the form of a create transaction }; namespace protocol { From 3c8828e53abb9c4d7b3e56597e1def06ae90df75 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Sun, 17 Sep 2023 18:39:53 +0200 Subject: [PATCH 6/8] Update evmone --- third_party/evmone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/evmone b/third_party/evmone index 778dfcb724..5304e07692 160000 --- a/third_party/evmone +++ b/third_party/evmone @@ -1 +1 @@ -Subproject commit 778dfcb7248d0cd7080f23b0cb9fe62a39f51eae +Subproject commit 5304e07692a1a283d8a5cfd3f1ec5f7ee749afe6 From 8dcd4a2a786434f4915907b888b14a89ca237c26 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 19 Sep 2023 15:53:40 +0200 Subject: [PATCH 7/8] refresh evmone --- third_party/evmone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/evmone b/third_party/evmone index 5304e07692..33c66e70f5 160000 --- a/third_party/evmone +++ b/third_party/evmone @@ -1 +1 @@ -Subproject commit 5304e07692a1a283d8a5cfd3f1ec5f7ee749afe6 +Subproject commit 33c66e70f5ac1bc575f71cde1ebb9c2e5b1c4d22 From 60b1117825bdf4342f7370f84b442947b7a38d34 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Wed, 20 Sep 2023 10:39:11 +0200 Subject: [PATCH 8/8] kBlobGasPerBlob -> kGasPerBlob --- silkworm/core/protocol/param.hpp | 6 +++--- silkworm/core/types/transaction.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/silkworm/core/protocol/param.hpp b/silkworm/core/protocol/param.hpp index e53f590ff2..7f9162963f 100644 --- a/silkworm/core/protocol/param.hpp +++ b/silkworm/core/protocol/param.hpp @@ -62,9 +62,9 @@ inline constexpr uint64_t kElasticityMultiplier{2}; // EIP-4844: Shard Blob Transactions inline constexpr uint8_t kBlobCommitmentVersionKzg{1}; -inline constexpr uint64_t kBlobGasPerBlob{1u << 17}; -inline constexpr uint64_t kTargetBlobGasPerBlock{3 * kBlobGasPerBlob}; -inline constexpr uint64_t kMaxBlobGasPerBlock{6 * kBlobGasPerBlob}; +inline constexpr uint64_t kGasPerBlob{1u << 17}; +inline constexpr uint64_t kTargetBlobGasPerBlock{3 * kGasPerBlob}; +inline constexpr uint64_t kMaxBlobGasPerBlock{6 * kGasPerBlob}; inline constexpr uint64_t kMinBlobGasPrice{1}; inline constexpr uint64_t kBlobGasPriceUpdateFraction{3338477}; diff --git a/silkworm/core/types/transaction.cpp b/silkworm/core/types/transaction.cpp index 1b803a1930..3fe59a5f16 100644 --- a/silkworm/core/types/transaction.cpp +++ b/silkworm/core/types/transaction.cpp @@ -439,7 +439,7 @@ intx::uint256 UnsignedTransaction::effective_gas_price(const intx::uint256& base } uint64_t UnsignedTransaction::total_blob_gas() const { - return protocol::kBlobGasPerBlob * blob_versioned_hashes.size(); + return protocol::kGasPerBlob * blob_versioned_hashes.size(); } } // namespace silkworm