diff --git a/eosevm/consensus_parameters.hpp b/eosevm/consensus_parameters.hpp index 1bb4e6ea..7abb068d 100644 --- a/eosevm/consensus_parameters.hpp +++ b/eosevm/consensus_parameters.hpp @@ -66,7 +66,7 @@ struct GasFeeParameters { }; struct ConsensusParameters { - std::optional min_gas_price; + std::optional min_gas_price; std::optional gas_fee_parameters; //! \brief Return the JSON representation of this object @@ -75,7 +75,7 @@ struct ConsensusParameters { nlohmann::json ret; if (min_gas_price) { - ret["minGasPrice"] = intx::to_string(min_gas_price.value()); + ret["minGasPrice"] = min_gas_price.value(); } if (gas_fee_parameters) { ret["gasFeeParameters"] = gas_fee_parameters.value().to_json(); @@ -91,7 +91,7 @@ struct ConsensusParameters { static std::optional from_json(const nlohmann::json& json) noexcept { ConsensusParameters config{}; if (json.contains("minGasPrice")) { - config.min_gas_price = intx::from_string(json["minGasPrice"].get()); + config.min_gas_price = json["minGasPrice"].get(); } if (json.contains("gasFeeParameters")) { diff --git a/silkworm/core/types/block.cpp b/silkworm/core/types/block.cpp index ad48ab96..08b6139f 100644 --- a/silkworm/core/types/block.cpp +++ b/silkworm/core/types/block.cpp @@ -29,11 +29,11 @@ bool operator==(const BlockHeader& a, const BlockHeader& b) { a.receipts_root == b.receipts_root && a.logs_bloom == b.logs_bloom && a.difficulty == b.difficulty && a.number == b.number && a.gas_limit == b.gas_limit && a.gas_used == b.gas_used && a.timestamp == b.timestamp && a.extra_data == b.extra_data && a.prev_randao == b.prev_randao && - a.nonce == b.nonce && a.base_fee_per_gas == b.base_fee_per_gas && a.consensus_parameter_index == b.consensus_parameter_index; + a.nonce == b.nonce && a.base_fee_per_gas == b.base_fee_per_gas; } bool operator==(const BlockBody& a, const BlockBody& b) { - return a.transactions == b.transactions && a.ommers == b.ommers; + return a.transactions == b.transactions && a.ommers == b.ommers && a.consensus_parameter_index == b.consensus_parameter_index; } BlockNum height(const BlockId& b) { return b.number; } @@ -110,9 +110,6 @@ namespace rlp { rlp_head.payload_length += kHashLength + 1; // prev_randao rlp_head.payload_length += 8 + 1; // nonce } - if (header.consensus_parameter_index) { - rlp_head.payload_length += length(*header.consensus_parameter_index); - } if (header.base_fee_per_gas) { rlp_head.payload_length += length(*header.base_fee_per_gas); } @@ -158,9 +155,6 @@ namespace rlp { encode(to, header.prev_randao); encode(to, header.nonce); } - if (header.consensus_parameter_index) { - encode(to, *header.consensus_parameter_index); - } if (header.base_fee_per_gas) { encode(to, *header.base_fee_per_gas); } @@ -208,15 +202,6 @@ namespace rlp { return res; } - if (from.length() > leftover) { - to.consensus_parameter_index = 0; - if (DecodingResult res{decode(from, *to.consensus_parameter_index, Leftover::kAllow)}; !res) { - return res; - } - } else { - to.consensus_parameter_index = std::nullopt; - } - if (from.length() > leftover) { to.base_fee_per_gas = 0; if (DecodingResult res{decode(from, *to.base_fee_per_gas, Leftover::kAllow)}; !res) { @@ -271,6 +256,9 @@ namespace rlp { encode_header(to, rlp_header_body(block_body)); encode(to, block_body.transactions); encode(to, block_body.ommers); + if (block_body.consensus_parameter_index) { + encode(to, *block_body.consensus_parameter_index); + } if (block_body.withdrawals) { encode(to, *block_body.withdrawals); } @@ -293,6 +281,15 @@ namespace rlp { return res; } + to.consensus_parameter_index = std::nullopt; + if (from.length() > leftover) { + uint64_t consensus_parameter_index; + if (DecodingResult res{decode(from, consensus_parameter_index, Leftover::kAllow)}; !res) { + return res; + } + to.consensus_parameter_index = consensus_parameter_index; + } + to.withdrawals = std::nullopt; if (from.length() > leftover) { std::vector withdrawals; @@ -325,6 +322,15 @@ namespace rlp { return res; } + to.consensus_parameter_index = std::nullopt; + if (from.length() > leftover) { + uint64_t consensus_parameter_index; + if (DecodingResult res{decode(from, consensus_parameter_index, Leftover::kAllow)}; !res) { + return res; + } + to.consensus_parameter_index = consensus_parameter_index; + } + to.withdrawals = std::nullopt; if (from.length() > leftover) { std::vector withdrawals; @@ -356,6 +362,9 @@ namespace rlp { encode(to, block.header); encode(to, block.transactions); encode(to, block.ommers); + if (block.consensus_parameter_index) { + encode(to, *block.consensus_parameter_index); + } if (block.withdrawals) { encode(to, *block.withdrawals); } diff --git a/silkworm/core/types/block.hpp b/silkworm/core/types/block.hpp index 67757f9c..3472d66a 100644 --- a/silkworm/core/types/block.hpp +++ b/silkworm/core/types/block.hpp @@ -32,6 +32,8 @@ #include #include +#include + namespace silkworm { using TotalDifficulty = intx::uint256; @@ -70,9 +72,6 @@ struct BlockHeader { evmc::bytes32 prev_randao{}; // mix hash prior to EIP-4399 NonceType nonce{}; - // EOS-EVM - std::optional consensus_parameter_index{std::nullopt}; - std::optional base_fee_per_gas{std::nullopt}; // EIP-1559 std::optional withdrawals_root{std::nullopt}; // EIP-4895 @@ -97,6 +96,9 @@ struct BlockBody { std::vector ommers; std::optional> withdrawals{std::nullopt}; + // EOS-EVM + std::optional consensus_parameter_index{std::nullopt}; + friend bool operator==(const BlockBody&, const BlockBody&); }; @@ -104,6 +106,7 @@ struct Block : public BlockBody { BlockHeader header; bool irreversible{false}; + std::optional consensus_parameters_cache; void recover_senders(); }; diff --git a/silkworm/core/types/block_test.cpp b/silkworm/core/types/block_test.cpp index 7b4c9843..674ed942 100644 --- a/silkworm/core/types/block_test.cpp +++ b/silkworm/core/types/block_test.cpp @@ -172,27 +172,9 @@ TEST_CASE("EIP-2718 Block RLP") { CHECK(block.transactions[1].access_list.size() == 1); } -TEST_CASE("Consensus Parameters Header RLP") { - BlockHeader h{ - .number = 13'500'000, - .consensus_parameter_index= 1234, - }; - - Bytes rlp; - rlp::encode(rlp, h); - - ByteView view{rlp}; - BlockHeader decoded; - REQUIRE(rlp::decode(view, decoded)); - - CHECK(view.empty()); - CHECK(decoded == h); -} - TEST_CASE("EIP-1559 Header RLP") { BlockHeader h{ .number = 13'500'000, - .consensus_parameter_index= 0, .base_fee_per_gas = 2'700'000'000, }; @@ -212,7 +194,6 @@ TEST_CASE("EIP-4844 Header RLP") { .ommers_hash = kEmptyListHash, .number = 17'000'000, .prev_randao = 0xd01681d2b3acdebff0288a02a1648b3910500961982d5ecdbef064af7c34090b_bytes32, - .consensus_parameter_index= 0, .base_fee_per_gas = 2'700'000'000, .withdrawals_root = 0xbac9348581b0ee244d6eb61076b63c4e4afa70430c804ab0e6a0ab69d9a9d323_bytes32, .data_gas_used = 456, diff --git a/silkworm/node/db/util_test.cpp b/silkworm/node/db/util_test.cpp index 38a4c24c..0d28ec8f 100644 --- a/silkworm/node/db/util_test.cpp +++ b/silkworm/node/db/util_test.cpp @@ -36,7 +36,6 @@ TEST_CASE("BlockBodyForStorage encoding") { .extra_data = *from_hex("0001FF0100"), .prev_randao = 0x0000000000000000000000000000000000000000000000000000000000000001_bytes32, .nonce = {0, 0, 0, 0, 0, 0, 0, 255}, - .consensus_parameter_index = 0x1234, .base_fee_per_gas = 0x244428, }; diff --git a/silkworm/silkrpc/json/types.cpp b/silkworm/silkrpc/json/types.cpp index 2359b6f1..34c7776c 100644 --- a/silkworm/silkrpc/json/types.cpp +++ b/silkworm/silkrpc/json/types.cpp @@ -211,11 +211,6 @@ void to_json(nlohmann::json& json, const BlockHeader& header) { json["gasLimit"] = rpc::to_quantity(header.gas_limit); json["gasUsed"] = rpc::to_quantity(header.gas_used); json["timestamp"] = rpc::to_quantity(header.timestamp); - if (header.consensus_parameter_index.has_value()) { - json["consensusParameterIndex"] = rpc::to_quantity(header.consensus_parameter_index.value_or(0)); - } else { - json["consensusParameterIndex"] = nullptr; - } if (header.base_fee_per_gas.has_value()) { json["baseFeePerGas"] = rpc::to_quantity(header.base_fee_per_gas.value_or(0)); } else { diff --git a/silkworm/silkrpc/json/types_test.cpp b/silkworm/silkrpc/json/types_test.cpp index 749f9d6d..593f75d0 100644 --- a/silkworm/silkrpc/json/types_test.cpp +++ b/silkworm/silkrpc/json/types_test.cpp @@ -164,7 +164,6 @@ TEST_CASE("serialize empty block header", "[silkrpc][to_json]") { nlohmann::json j = header; CHECK(j == R"({ "baseFeePerGas":null, - "consensusParameterIndex":null, "hash": "0xc3bd2d00745c03048a5616146a96f5ff78e54efb9e5b04af208cdaff6f3830ee", "parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000", "sha3Uncles":"0x0000000000000000000000000000000000000000000000000000000000000000", @@ -211,7 +210,6 @@ TEST_CASE("serialize block header", "[silkrpc][to_json]") { nlohmann::json j = header; CHECK(j == R"({ "baseFeePerGas":null, - "consensusParameterIndex":null, "hash": "0x5e053b099d472a3fc02394243961937ffa008bad0daa81a984a0830ba0beee01", "parentHash":"0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c", "sha3Uncles":"0x474f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126d", @@ -238,55 +236,6 @@ TEST_CASE("serialize block header", "[silkrpc][to_json]") { })"_json); } -TEST_CASE("serialize block header with consensus parameter index", "[silkrpc][to_json]") { - silkworm::BlockHeader header{ - 0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c_bytes32, - 0x474f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126d_bytes32, - 0x0715a7794a1dc8e42615f059dd6e406a6594651a_address, - 0xb02a3b0ee16c858afaa34bcd6770b3c20ee56aa2f75858733eb0e927b5b7126d_bytes32, - 0xb02a3b0ee16c858afaa34bcd6770b3c20ee56aa2f75858733eb0e927b5b7126e_bytes32, - 0xb02a3b0ee16c858afaa34bcd6770b3c20ee56aa2f75858733eb0e927b5b7126f_bytes32, - silkworm::Bloom{}, - intx::uint256{0}, - uint64_t(5), - uint64_t(1000000), - uint64_t(1000000), - uint64_t(5405021), - *silkworm::from_hex("0001FF0100"), // extradata - 0x0000000000000000000000000000000000000000000000000000000000000001_bytes32, // mixhash - {1, 2, 3, 4, 5, 6, 7, 8}, // nonce - std::optional(1001), // consensus_parameter_index // base_fee_per_gas - }; - nlohmann::json j = header; - CHECK(j == R"({ - "baseFeePerGas":null, - "hash": "0x74b164b2a76408c5c0a69c99325438a90ece1353817ef6e239fc0dcb7ac76d09", - "parentHash":"0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c", - "sha3Uncles":"0x474f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126d", - "miner":"0x0715a7794a1dc8e42615f059dd6e406a6594651a", - "stateRoot":"0xb02a3b0ee16c858afaa34bcd6770b3c20ee56aa2f75858733eb0e927b5b7126d", - "transactionsRoot":"0xb02a3b0ee16c858afaa34bcd6770b3c20ee56aa2f75858733eb0e927b5b7126e", - "receiptsRoot":"0xb02a3b0ee16c858afaa34bcd6770b3c20ee56aa2f75858733eb0e927b5b7126f", - "logsBloom":"0x000000000000000000000000000000000000000000000000000000000000000000000000)" - R"(000000000000000000000000000000000000000000000000000000000000000000000000)" - R"(000000000000000000000000000000000000000000000000000000000000000000000000)" - R"(000000000000000000000000000000000000000000000000000000000000000000000000)" - R"(000000000000000000000000000000000000000000000000000000000000000000000000)" - R"(000000000000000000000000000000000000000000000000000000000000000000000000)" - R"(00000000000000000000000000000000000000000000000000000000000000000000000000000000", - "difficulty":"0x0", - "number":"0x5", - "gasLimit":"0xf4240", - "gasUsed":"0xf4240", - "timestamp":"0x52795d", - "extraData":"0x0001ff0100", - "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000001", - "nonce":"0x0102030405060708", - "consensusParameterIndex":"0x3e9", - "withdrawalsRoot":null - })"_json); -} - TEST_CASE("serialize block header with baseFeePerGas", "[silkrpc][to_json]") { silkworm::BlockHeader header{ 0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c_bytes32, @@ -304,13 +253,12 @@ TEST_CASE("serialize block header with baseFeePerGas", "[silkrpc][to_json]") { *silkworm::from_hex("0001FF0100"), // extradata 0x0000000000000000000000000000000000000000000000000000000000000001_bytes32, // mixhash {1, 2, 3, 4, 5, 6, 7, 8}, // nonce - std::optional(1001), // consensus_parameter_index std::optional(1000), // base_fee_per_gas }; nlohmann::json j = header; CHECK(j == R"({ "baseFeePerGas":"0x3e8", - "hash": "0xa88494b78d8cb3ad596637990fa04fd4e9068a9271f044e4d3cdb313a24973b9", + "hash": "0x5e3a9484b3ee70cc9ae7673051efd0369cfa4126430075921c70255cbdefbe6", "parentHash":"0x374f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126c", "sha3Uncles":"0x474f3a049e006f36f6cf91b02a3b0ee16c858af2f75858733eb0e927b5b7126d", "miner":"0x0715a7794a1dc8e42615f059dd6e406a6594651a", @@ -332,7 +280,6 @@ TEST_CASE("serialize block header with baseFeePerGas", "[silkrpc][to_json]") { "extraData":"0x0001ff0100", "mixHash":"0x0000000000000000000000000000000000000000000000000000000000000001", "nonce":"0x0102030405060708", - "consensusParameterIndex":"0x3e9", "baseFeePerGas":"0x3e8", "withdrawalsRoot":null })"_json);