Skip to content

Commit

Permalink
evmone: upgrade to version 0.13.0
Browse files Browse the repository at this point in the history
Upgrade evmone to version 0.13.0 by rebasing erigontech's fork of it.
Upgrade intx to version 0.12.0.

The new version of evmone manages `ExecutionState` internally and
removes it from public API. This makes object pools for
`ExecutionState`s in Silkworm unnecessary.
  • Loading branch information
chfast committed Sep 23, 2024
1 parent 7d8050e commit 226b3e8
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 61 deletions.
2 changes: 0 additions & 2 deletions cmd/dev/check_changes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ int main(int argc, char* argv[]) {
db::DataModel access_layer{txn};

AnalysisCache analysis_cache{/*max_size=*/5'000};
ObjectPool<evmone::ExecutionState> state_pool;
std::vector<Receipt> receipts;
auto rule_set{protocol::rule_set_factory(*chain_config)};
Block block;
Expand All @@ -133,7 +132,6 @@ int main(int argc, char* argv[]) {

ExecutionProcessor processor{block, *rule_set, buffer, *chain_config};
processor.evm().analysis_cache = &analysis_cache;
processor.evm().state_pool = &state_pool;

if (const ValidationResult res = processor.execute_block(receipts); res != ValidationResult::kOk) {
log::Error() << "Failed execution for block " << block_num << " result " << magic_enum::enum_name<>(res);
Expand Down
2 changes: 0 additions & 2 deletions cmd/dev/scan_txs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ int main(int argc, char* argv[]) {
// std::unique_ptr<lmdb::Transaction> txn{env->begin_ro_transaction()};

AnalysisCache analysis_cache{/*max_size=*/5'000};
ObjectPool<evmone::ExecutionState> state_pool;
std::vector<Receipt> receipts;

try {
Expand Down Expand Up @@ -94,7 +93,6 @@ int main(int argc, char* argv[]) {

ExecutionProcessor processor{block, *rule_set, buffer, *chain_config};
processor.evm().analysis_cache = &analysis_cache;
processor.evm().state_pool = &state_pool;

// Execute the block and retrieve the receipts
if (const ValidationResult res = processor.execute_block(receipts); res != ValidationResult::kOk) {
Expand Down
5 changes: 3 additions & 2 deletions cmd/test/ethereum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ static const std::vector<fs::path> kFailingTests{};

static constexpr size_t kColumnWidth{80};

ObjectPool<evmone::ExecutionState> execution_state_pool{/*thread_safe=*/true};
/// External EVMC VM.
/// It is used in potential multiple test execution threads
/// so usage may be broken if the VM is not thread-safe.
evmc_vm* exo_evm{nullptr};

enum class Status {
Expand Down Expand Up @@ -223,7 +225,6 @@ RunResults blockchain_test(const nlohmann::json& json_test) {

InMemoryState state{read_genesis_allocation(json_test["pre"])};
Blockchain blockchain{state, config_it->second, genesis_block};
blockchain.state_pool = &execution_state_pool;
blockchain.exo_evm = exo_evm;

for (const auto& json_block : json_test["blocks"]) {
Expand Down
6 changes: 2 additions & 4 deletions silkworm/capi/silkworm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ int silkworm_execute_blocks_ephemeral(SilkwormHandle handle, MDBX_txn* mdbx_txn,
db::DataModel da_layer{txn};

AnalysisCache analysis_cache{execution::block::BlockExecutor::kDefaultAnalysisCacheSize};
ObjectPool<evmone::ExecutionState> state_pool;
execution::block::BlockExecutor block_executor{*chain_info, write_receipts, write_call_traces, write_change_sets};
const auto now = std::chrono::steady_clock::now();
ExecutionProgress execution_progress{.start_time = now, .next_log_time = now + 20s};
Expand All @@ -519,7 +518,7 @@ int silkworm_execute_blocks_ephemeral(SilkwormHandle handle, MDBX_txn* mdbx_txn,
const Block& block{prefetched_blocks.front()};

try {
last_exec_result = block_executor.execute_single(block, state_buffer, analysis_cache, state_pool);
last_exec_result = block_executor.execute_single(block, state_buffer, analysis_cache);
update_execution_progress(execution_progress, block, state_buffer, max_batch_size);
} catch (const db::Buffer::MemoryLimitError&) {
// batch done
Expand Down Expand Up @@ -611,7 +610,6 @@ int silkworm_execute_blocks_perpetual(SilkwormHandle handle, MDBX_env* mdbx_env,
BlockNum block_number{start_block};
BlockNum last_block_number = 0;
AnalysisCache analysis_cache{execution::block::BlockExecutor::kDefaultAnalysisCacheSize};
ObjectPool<evmone::ExecutionState> state_pool;
execution::block::BlockExecutor block_executor{*chain_info, write_receipts, write_call_traces, write_change_sets};
const auto now = std::chrono::steady_clock::now();
ExecutionProgress execution_progress{.start_time = now, .next_log_time = now + 20s};
Expand All @@ -626,7 +624,7 @@ int silkworm_execute_blocks_perpetual(SilkwormHandle handle, MDBX_env* mdbx_env,
SILKWORM_ASSERT(block->header.number == block_number);

try {
last_exec_result = block_executor.execute_single(*block, state_buffer, analysis_cache, state_pool);
last_exec_result = block_executor.execute_single(*block, state_buffer, analysis_cache);
update_execution_progress(execution_progress, *block, state_buffer, max_batch_size);
} catch (const db::Buffer::MemoryLimitError&) {
// batch done
Expand Down
2 changes: 1 addition & 1 deletion silkworm/core/execution/call_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ inline bool check_memory_gas(int64_t& gas_left, Memory& memory, const uint256& o
template <Opcode Op>
inline evmc_status_code check_preconditions(const intx::uint256* stack_top, int stack_height, int64_t gas,
const evmone::ExecutionState& state) noexcept {
const auto& cost_table{get_baseline_cost_table(state.rev, state.analysis.baseline->eof_header.version)};
const auto& cost_table{get_baseline_cost_table(state.rev, state.analysis.baseline->eof_header().version)};
return check_requirements<Op>(cost_table, gas, stack_top, stack_top - stack_height);
}

Expand Down
29 changes: 3 additions & 26 deletions silkworm/core/execution/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,25 +319,6 @@ evmc_result EVM::execute(const evmc_message& message, ByteView code, const evmc:
return execute_with_baseline_interpreter(rev, message, code, code_hash);
}

gsl::owner<evmone::ExecutionState*> EVM::acquire_state() const noexcept {
gsl::owner<evmone::ExecutionState*> state{nullptr};
if (state_pool) {
state = state_pool->acquire();
}
if (!state) {
state = new evmone::ExecutionState;
}
return state;
}

void EVM::release_state(gsl::owner<evmone::ExecutionState*> state) const noexcept {
if (state_pool) {
state_pool->add(state);
} else {
delete state;
}
}

evmc_result EVM::execute_with_baseline_interpreter(evmc_revision rev, const evmc_message& message, ByteView code,
const evmc::bytes32* code_hash) noexcept {
std::shared_ptr<evmone::baseline::CodeAnalysis> analysis;
Expand All @@ -349,19 +330,15 @@ evmc_result EVM::execute_with_baseline_interpreter(evmc_revision rev, const evmc
}
}
if (!analysis) {
analysis = std::make_shared<evmone::baseline::CodeAnalysis>(evmone::baseline::analyze(rev, code));
// EOF is disabled although evmone supports it. This will be needed as early as Prague, maybe later.
analysis = std::make_shared<evmone::baseline::CodeAnalysis>(evmone::baseline::analyze(code, /*eof_enabled=*/false));
if (use_cache) {
analysis_cache->put(*code_hash, analysis);
}
}

EvmHost host{*this};
gsl::owner<evmone::ExecutionState*> state{acquire_state()};
state->reset(message, rev, EvmHost::get_interface(), host.to_context(), code, {});

evmc_result res{evmone::baseline::execute(*evm1_, message.gas, *state, *analysis)};

release_state(state);
evmc_result res{evmone::baseline::execute(*evm1_, EvmHost::get_interface(), host.to_context(), rev, message, *analysis)};
return res;
}

Expand Down
6 changes: 1 addition & 5 deletions silkworm/core/execution/evm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class EVM {
void add_tracer(EvmTracer& tracer) noexcept;
[[nodiscard]] const EvmTracers& tracers() const noexcept { return tracers_; };

AnalysisCache* analysis_cache{nullptr}; // provide one for better performance
ObjectPool<evmone::ExecutionState>* state_pool{nullptr}; // ditto
AnalysisCache* analysis_cache{nullptr}; // provide one for better performance

evmc_vm* exo_evm{nullptr}; // it's possible to use an exogenous EVMC VM

Expand All @@ -137,9 +136,6 @@ class EVM {
evmc_result execute_with_baseline_interpreter(evmc_revision rev, const evmc_message& message, ByteView code,
const evmc::bytes32* code_hash) noexcept;

gsl::owner<evmone::ExecutionState*> acquire_state() const noexcept;
void release_state(gsl::owner<evmone::ExecutionState*> state) const noexcept;

const Block& block_;
IntraBlockState& state_;
const ChainConfig& config_;
Expand Down
1 change: 0 additions & 1 deletion silkworm/core/protocol/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ ValidationResult Blockchain::insert_block(Block& block, bool check_state_root) {

ValidationResult Blockchain::execute_block(const Block& block, bool check_state_root) {
ExecutionProcessor processor{block, *rule_set_, state_, config_};
processor.evm().state_pool = state_pool;
processor.evm().exo_evm = exo_evm;

if (const ValidationResult res = processor.execute_block(receipts_); res != ValidationResult::kOk) {
Expand Down
2 changes: 0 additions & 2 deletions silkworm/core/protocol/blockchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class Blockchain {

ValidationResult insert_block(Block& block, bool check_state_root);

ObjectPool<evmone::ExecutionState>* state_pool{nullptr};

evmc_vm* exo_evm{nullptr};

private:
Expand Down
3 changes: 1 addition & 2 deletions silkworm/node/execution/block/block_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ BlockExecutor::BlockExecutor(const ChainConfig* chain_config, bool write_receipt
write_call_traces_{write_call_traces},
write_change_sets_{write_change_sets} {}

ValidationResult BlockExecutor::execute_single(const Block& block, db::Buffer& state_buffer, AnalysisCache& analysis_cache, ObjectPool<evmone::ExecutionState>& state_pool) {
ValidationResult BlockExecutor::execute_single(const Block& block, db::Buffer& state_buffer, AnalysisCache& analysis_cache) {
ExecutionProcessor processor{block, *protocol_rule_set_, state_buffer, *chain_config_};
processor.evm().analysis_cache = &analysis_cache;
processor.evm().state_pool = &state_pool;

CallTraces traces;
CallTracer tracer{traces};
Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/execution/block/block_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BlockExecutor {

BlockExecutor(const ChainConfig* chain_config, bool write_receipts, bool write_call_traces, bool write_change_sets);

ValidationResult execute_single(const Block& block, db::Buffer& state_buffer, AnalysisCache& analysis_cache, ObjectPool<evmone::ExecutionState>& state_pool);
ValidationResult execute_single(const Block& block, db::Buffer& state_buffer, AnalysisCache& analysis_cache);

private:
const ChainConfig* chain_config_;
Expand All @@ -38,4 +38,4 @@ class BlockExecutor {
bool write_change_sets_;
};

} // namespace silkworm::execution::block
} // namespace silkworm::execution::block
9 changes: 4 additions & 5 deletions silkworm/node/stagedsync/stages/stage_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ Stage::Result Execution::forward(db::RWTxn& txn) {

static constexpr size_t kCacheSize{5'000};
AnalysisCache analysis_cache{kCacheSize};
ObjectPool<evmone::ExecutionState> state_pool;

prefetched_blocks_.clear();

while (block_num_ <= max_block_num) {
throw_if_stopping();
const auto execution_result{execute_batch(txn, max_block_num, analysis_cache, state_pool,
const auto execution_result{execute_batch(txn, max_block_num, analysis_cache,
prune_history, prune_receipts, prune_call_traces)};

// If we return with success we must persist data. Though counterintuitive, we must also persist on
Expand Down Expand Up @@ -201,8 +200,8 @@ void Execution::prefetch_blocks(db::RWTxn& txn, const BlockNum from, const Block
}

Stage::Result Execution::execute_batch(db::RWTxn& txn, BlockNum max_block_num, AnalysisCache& analysis_cache,
ObjectPool<evmone::ExecutionState>& state_pool, BlockNum prune_history_threshold,
BlockNum prune_receipts_threshold, BlockNum prune_call_traces_threshold) {
BlockNum prune_history_threshold, BlockNum prune_receipts_threshold,
BlockNum prune_call_traces_threshold) {
Result ret{Result::kSuccess};
using namespace std::chrono_literals;
auto log_time{std::chrono::steady_clock::now()};
Expand Down Expand Up @@ -240,7 +239,7 @@ Stage::Result Execution::execute_batch(db::RWTxn& txn, BlockNum max_block_num, A

execution::block::BlockExecutor block_executor{&chain_config_, write_receipts, write_traces, kWriteChangeSets};
try {
if (const ValidationResult res = block_executor.execute_single(block, buffer, analysis_cache, state_pool); res != ValidationResult::kOk) {
if (const ValidationResult res = block_executor.execute_single(block, buffer, analysis_cache); res != ValidationResult::kOk) {
// Flush work done so far not to lose progress up to the previous valid block and to correctly trigger unwind
// This requires to commit in Execution::forward also for kInvalidBlock: unwind will remove last invalid block updates
if (write_receipts) {
Expand Down
4 changes: 2 additions & 2 deletions silkworm/node/stagedsync/stages/stage_execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Execution final : public Stage {
//! \brief Executes a batch of blocks
//! \remarks A batch completes when either max block is reached or buffer dimensions overflow
Stage::Result execute_batch(db::RWTxn& txn, BlockNum max_block_num, AnalysisCache& analysis_cache,
ObjectPool<evmone::ExecutionState>& state_pool, BlockNum prune_history_threshold,
BlockNum prune_receipts_threshold, BlockNum prune_call_traces_threshold);
BlockNum prune_history_threshold, BlockNum prune_receipts_threshold,
BlockNum prune_call_traces_threshold);

//! \brief For given changeset cursor/bucket it reverts the changes on states buckets
static void unwind_state_from_changeset(db::ROCursor& source_changeset, db::RWCursorDupSort& plain_state_table,
Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/core/evm_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ ExecutionResult EVMExecutor::call(
auto& svc = use_service<AnalysisCacheService>(workers_);
EVM evm{block, ibs_state_, config_, gas_bailout};
evm.analysis_cache = svc.get_analysis_cache();
evm.state_pool = svc.get_object_pool();
evm.beneficiary = rule_set_->get_beneficiary(block.header);
evm.transfer = rule_set_->transfer_func();

Expand Down
2 changes: 0 additions & 2 deletions silkworm/rpc/core/evm_executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ class AnalysisCacheService : public ServiceBase<AnalysisCacheService> {
: ServiceBase<AnalysisCacheService>(owner) {}

void shutdown() override {}
ObjectPool<evmone::ExecutionState>* get_object_pool() { return &state_pool_; }
AnalysisCache* get_analysis_cache() { return &analysis_cache_; }

private:
ObjectPool<evmone::ExecutionState> state_pool_{true};
AnalysisCache analysis_cache_{kCacheSize, true};
};

Expand Down
2 changes: 1 addition & 1 deletion third_party/evmone/evmone
Submodule evmone updated 75 files
+1 −1 .bumpversion.cfg
+79 −2 CHANGELOG.md
+1 −1 CMakeLists.txt
+21 −55 circle.yml
+3 −3 cmake/Hunter/config.cmake
+50 −0 cmake/blst.cmake
+6 −7 lib/evmone/advanced_analysis.hpp
+1 −2 lib/evmone/advanced_execution.cpp
+0 −1 lib/evmone/advanced_instructions.cpp
+43 −13 lib/evmone/baseline.hpp
+5 −5 lib/evmone/baseline_analysis.cpp
+14 −11 lib/evmone/baseline_execution.cpp
+10 −89 lib/evmone/baseline_instruction_table.cpp
+6 −5 lib/evmone/eof.cpp
+1 −1 lib/evmone/eof.hpp
+20 −48 lib/evmone/execution_state.hpp
+23 −28 lib/evmone/instructions.hpp
+7 −45 lib/evmone/instructions_calls.cpp
+0 −1 lib/evmone/instructions_opcodes.hpp
+169 −164 lib/evmone/instructions_traits.hpp
+1 −1 lib/evmone/instructions_xmacro.hpp
+15 −2 lib/evmone/vm.cpp
+6 −1 lib/evmone/vm.hpp
+7 −1 lib/evmone_precompiles/CMakeLists.txt
+418 −0 lib/evmone_precompiles/bls.cpp
+79 −0 lib/evmone_precompiles/bls.hpp
+1 −5 lib/evmone_precompiles/ecc.hpp
+168 −0 lib/evmone_precompiles/kzg.cpp
+32 −0 lib/evmone_precompiles/kzg.hpp
+8 −8 test/bench/helpers.hpp
+1 −0 test/blockchaintest/blockchaintest_runner.cpp
+24 −0 test/precompiles_bench/precompiles_bench.cpp
+2 −0 test/state/CMakeLists.txt
+0 −9 test/state/errors.hpp
+33 −23 test/state/host.cpp
+1 −11 test/state/host.hpp
+253 −1 test/state/precompiles.cpp
+11 −1 test/state/precompiles.hpp
+29 −0 test/state/precompiles_internal.hpp
+0 −54 test/state/precompiles_stubs.cpp
+0 −2 test/state/precompiles_stubs.hpp
+4 −67 test/state/state.cpp
+0 −10 test/state/state.hpp
+78 −0 test/state/system_contracts.cpp
+29 −0 test/state/system_contracts.hpp
+1 −1 test/statetest/statetest_export.cpp
+6 −8 test/statetest/statetest_loader.cpp
+6 −0 test/t8n/t8n.cpp
+3 −0 test/unittests/CMakeLists.txt
+34 −0 test/unittests/baseline_analysis_test.cpp
+6 −1 test/unittests/eof_validation_test.cpp
+1 −1 test/unittests/evm_eip7516_blobbasefee_test.cpp
+14 −4 test/unittests/evm_eof_rjump_test.cpp
+0 −5 test/unittests/evmmax_bn254_add_test.cpp
+0 −5 test/unittests/evmmax_bn254_mul_test.cpp
+0 −4 test/unittests/evmmax_secp256k1_test.cpp
+0 −6 test/unittests/evmmax_test.cpp
+6 −6 test/unittests/execution_state_test.cpp
+5 −2 test/unittests/instructions_test.cpp
+310 −0 test/unittests/precompiles_bls_test.cpp
+69 −0 test/unittests/precompiles_kzg_test.cpp
+1 −1 test/unittests/state_block_test.cpp
+1 −1 test/unittests/state_mpt_hash_test.cpp
+1 −1 test/unittests/state_mpt_test.cpp
+15 −5 test/unittests/state_precompiles_test.cpp
+41 −16 test/unittests/state_system_call_test.cpp
+5 −7 test/unittests/state_transition.cpp
+0 −1,160 test/unittests/state_transition_eof_create_test.cpp
+37 −0 test/unittests/state_transition_selfdestruct_test.cpp
+0 −3 test/unittests/state_tx_test.cpp
+1 −1 test/unittests/statetest_loader_test.cpp
+2 −2 test/unittests/statetest_loader_tx_test.cpp
+4 −5 test/unittests/tracing_test.cpp
+2 −18 test/utils/bytecode.hpp
+2 −0 test/utils/utils.cpp
2 changes: 1 addition & 1 deletion third_party/intx/intx

0 comments on commit 226b3e8

Please sign in to comment.