Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Shanghai consensus tests #709

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions include/evm_runtime/test/block_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ struct block_info {
uint64_t gasLimit;
uint64_t number;
uint64_t timestamp;
//std::optional<bytes> base_fee_per_gas;
std::optional<bytes> base_fee_per_gas;
bytes mixhash;

BlockHeader get_block_header()const {
address beneficiary;
Expand All @@ -30,13 +31,15 @@ struct block_info {
res.number = number;
res.timestamp = timestamp;

//if(base_fee_per_gas.has_value()) res.base_fee_per_gas = to_uint256(*base_fee_per_gas);
check(mixhash.size() == 32, "invalid mixhash");
memcpy(res.prev_randao.bytes, mixhash.data(), mixhash.size());

if(base_fee_per_gas.has_value()) res.base_fee_per_gas = to_uint256(*base_fee_per_gas);

return res;
}

//EOSLIB_SERIALIZE(block_info,(coinbase)(difficulty)(gasLimit)(number)(timestamp)(base_fee_per_gas))
EOSLIB_SERIALIZE(block_info,(coinbase)(difficulty)(gasLimit)(number)(timestamp))
EOSLIB_SERIALIZE(block_info,(coinbase)(difficulty)(gasLimit)(number)(timestamp)(base_fee_per_gas)(mixhash))
};

} //namespace test
Expand Down
7 changes: 7 additions & 0 deletions include/evm_runtime/test/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ inline constexpr ChainConfig kTestNetwork{
._constantinople_block = 0,
._petersburg_block = 0,
._istanbul_block = 0,
._muir_glacier_block = 0,
._berlin_block = 0,
._london_block = 0,
._arrow_glacier_block = 0,
._gray_glacier_block = 0,
._terminal_total_difficulty = 0,
._shanghai_time = 0
};

} //namespace test
Expand Down
6 changes: 4 additions & 2 deletions include/evm_runtime/test/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class engine : public silkworm::protocol::IRuleSet {
miner_reward += block_reward / 32;

}
eosio::print("add balance to beneficiary\n");
state.add_to_balance(block.header.beneficiary, miner_reward);
if(revision < EVMC_PARIS) {
eosio::print("add balance to beneficiary\n");
state.add_to_balance(block.header.beneficiary, miner_reward);
}
}

//! \brief Performs validation of block body that can be done prior to sender recovery and execution.
Expand Down
63 changes: 51 additions & 12 deletions tests/evm_runtime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <silkworm/core/types/block.hpp>
#include <silkworm/core/types/transaction.hpp>
#include <silkworm/core/rlp/encode.hpp>
#include <silkworm/core/rlp/decode_vector.hpp>

#include <silkworm/core/state/state.hpp>
#include <silkworm/core/protocol/blockchain.hpp>
Expand All @@ -35,6 +36,8 @@
#include <ethash/keccak.hpp>
#include <magic_enum.hpp>

#include <functional>

using namespace eosio_system;
using namespace eosio;
using namespace std;
Expand Down Expand Up @@ -231,7 +234,8 @@ struct block_info {
uint64_t gasLimit;
uint64_t number;
uint64_t timestamp;
//fc::optional<bytes> base_fee_per_gas;
std::optional<bytes> base_fee_per_gas;
bytes mixhash;

static block_info create(const Block& block) {
block_info bi;
Expand All @@ -240,15 +244,15 @@ struct block_info {
bi.gasLimit = block.header.gas_limit;
bi.number = block.header.number;
bi.timestamp = block.header.timestamp;
bi.mixhash = to_bytes(block.header.prev_randao);

// if(block.header.base_fee_per_gas.has_value())
// bi.base_fee_per_gas = to_bytes(*block.header.base_fee_per_gas);
if(block.header.base_fee_per_gas.has_value())
bi.base_fee_per_gas = to_bytes(*block.header.base_fee_per_gas);

return bi;
}
};
//FC_REFLECT(block_info, (coinbase)(difficulty)(gasLimit)(number)(timestamp)(base_fee_per_gas));
FC_REFLECT(block_info, (coinbase)(difficulty)(gasLimit)(number)(timestamp));
FC_REFLECT(block_info, (coinbase)(difficulty)(gasLimit)(number)(timestamp)(base_fee_per_gas)(mixhash));

struct account {
uint64_t id;
Expand Down Expand Up @@ -398,8 +402,42 @@ struct assert_message_check {
}
};

namespace silkworm { namespace rlp {
DecodingResult decode_legacy(ByteView& from, Block& to, Leftover mode=silkworm::rlp::Leftover::kProhibit) noexcept {
const auto rlp_head{decode_header(from)};
if (!rlp_head) {
return tl::unexpected{rlp_head.error()};
}
if (!rlp_head->list) {
return tl::unexpected{DecodingError::kUnexpectedString};
}
const uint64_t leftover{from.length() - rlp_head->payload_length};
if (mode != Leftover::kAllow && leftover) {
return tl::unexpected{DecodingError::kInputTooLong};
}

if (DecodingResult res{silkworm::rlp::decode_items(from, to.header, to.transactions, to.ommers)}; !res) {
return res;
}

to.withdrawals = std::nullopt;
if (from.length() > leftover) {
std::vector<Withdrawal> withdrawals;
if (DecodingResult res{silkworm::rlp::decode(from, withdrawals, Leftover::kAllow)}; !res) {
return res;
}
to.withdrawals = withdrawals;
}

if (from.length() != leftover) {
return tl::unexpected{DecodingError::kUnexpectedListElements};
}
return {};
}
}}

struct evm_runtime_tester : eosio_system_tester, silkworm::State {

abi_serializer evm_runtime_abi;
std::map< name, private_key> key_map;
bool is_verbose = false;
Expand Down Expand Up @@ -884,7 +922,7 @@ struct evm_runtime_tester : eosio_system_tester, silkworm::State {

Block block;
ByteView view{*rlp};
if (!rlp::decode(view, block) || !view.empty()) {
if (!rlp::decode_legacy(view, block) || !view.empty()) {
if (invalid) {
dlog("invalid=kPassed 2");
return Status::kPassed;
Expand Down Expand Up @@ -946,6 +984,7 @@ struct evm_runtime_tester : eosio_system_tester, silkworm::State {
}

bool post_check(const nlohmann::json& expected) {

if (number_of_accounts() != expected.size()) {
std::cout << "Account number mismatch: " << number_of_accounts() << " != " << expected.size()
<< std::endl;
Expand Down Expand Up @@ -1019,10 +1058,10 @@ struct evm_runtime_tester : eosio_system_tester, silkworm::State {
RunResults blockchain_test(const std::string& test_name, const nlohmann::json& json_test) {

//mod_exp restriction: exponent bit size cannot exceed bit size of either base or modulus
if( test_name == "modexp_d27g0v0_Istanbul" ||
test_name == "modexp_d27g1v0_Istanbul" ||
test_name == "modexp_d27g2v0_Istanbul" ||
test_name == "modexp_d27g3v0_Istanbul" ) {
if( test_name == "modexp_d27g0v0_Shanghai" ||
test_name == "modexp_d27g1v0_Shanghai" ||
test_name == "modexp_d27g2v0_Shanghai" ||
test_name == "modexp_d27g3v0_Shanghai" ) {
return Status::kSkipped;
}

Expand Down Expand Up @@ -1069,7 +1108,7 @@ struct evm_runtime_tester : eosio_system_tester, silkworm::State {
std::string network{json_test["network"].get<std::string>()};

//Only Istanbul
if(network != "Istanbul") continue;
if(network != "Shanghai") continue;

const RunResults r{(*this.*runner)(test.key(), json_test)};
total += r;
Expand Down
6 changes: 5 additions & 1 deletion tests/skip_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@
#BlockchainTests/GeneralStateTests/stZeroKnowledge
#BlockchainTests/GeneralStateTests/stAttackTest
#BlockchainTests/GeneralStateTests/stEIP1559
#BlockchainTests/GeneralStateTests/stMemoryStressTest
#BlockchainTests/GeneralStateTests/stMemoryStressTest
#BlockchainTests/GeneralStateTests/Shanghai
#BlockchainTests/GeneralStateTests/Shanghai/stEIP3651-warmcoinbase
#BlockchainTests/GeneralStateTests/Shanghai/stEIP3860-limitmeterinitcode
#BlockchainTests/GeneralStateTests/Shanghai/stEIP3855-push0
Loading