From 6022126a4b23f31ac607add71604301a8fe1656b Mon Sep 17 00:00:00 2001 From: Theodoros Kasampalis Date: Tue, 4 Jun 2024 16:23:52 -0500 Subject: [PATCH 1/2] first draft of the USL API --- usl/Makefile | 9 ++ usl/usl_kevm.cpp | 23 +++++ usl/usl_kevm.h | 241 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 273 insertions(+) create mode 100644 usl/Makefile create mode 100644 usl/usl_kevm.cpp create mode 100644 usl/usl_kevm.h diff --git a/usl/Makefile b/usl/Makefile new file mode 100644 index 0000000000..952d9170ff --- /dev/null +++ b/usl/Makefile @@ -0,0 +1,9 @@ +DEF_KOMPILED=$(shell poetry -C ../kevm-pyk run kdist which evm-semantics.llvm) +LLVM_KOMPILE=llvm-kompile + +USL_LIB_NAME=libuslkevm.so +$(USL_LIB_NAME): usl_kevm.cpp usl_kevm.h + $(LLVM_KOMPILE) $(DEF_KOMPILED)/definition.kore $(DEF_KOMPILED)/dt c -- -o $@ $< + +clean: + rm -rf $(USL_LIB_NAME) diff --git a/usl/usl_kevm.cpp b/usl/usl_kevm.cpp new file mode 100644 index 0000000000..6a65270691 --- /dev/null +++ b/usl/usl_kevm.cpp @@ -0,0 +1,23 @@ +#include "usl_kevm.h" + +#include +#include + +#include +#include + +using namespace usl_kevm; + +std::optional network_{std::nullopt}; + +void usl_kevm::init_network(network_t network) { + network_.emplace(std::move(network)); +} + +void usl_kevm::execute_transaction(const kevm_config_t &kevm_config, + const block_t &block, const message_t &tx, + result_t &result, substate_t &substate) { + assert(network_.has_value()); + + kllvm_init(); +} diff --git a/usl/usl_kevm.h b/usl/usl_kevm.h new file mode 100644 index 0000000000..705867eed8 --- /dev/null +++ b/usl/usl_kevm.h @@ -0,0 +1,241 @@ +#ifndef USL_KEVM_H +#define USL_KEVM_H + +#include +#include +#include +#include +#include + +namespace usl_kevm { + +// Common data types +using bytes_t = std::string; +using nonce_t = std::uint64_t; +using ether_t = std::uint64_t; +using gas_t = std::uint64_t; +using hash_t = std::uint64_t; +using account_address_t = std::uint64_t; +using storage_key_t = std::uint64_t; +using storage_value_t = std::uint64_t; +using chain_id_t = std::uint64_t; +using message_id_t = std::uint64_t; +using number_t = std::uint64_t; + +// Ommer List +struct ommer_t { + account_address_t ommer_address; + number_t ommer_number; +}; +using ommer_list_t = std::vector; + +// Block +using difficulty_t = std::uint64_t; +using timestamp_t = std::time_t; +using mix_hash_t = std::uint64_t; +struct block_t { + hash_t previous_hash; + hash_t ommers_hash; + account_address_t coinbase; + hash_t state_root; + hash_t transactions_root; + hash_t receipts_root; + bytes_t logs_bloom; + difficulty_t difficulty; + number_t number; + gas_t gas_limit; + gas_t gas_used; + timestamp_t timestamp; + bytes_t extra_data; + mix_hash_t mix_hash; + nonce_t block_nonce; + ether_t base_fee; + hash_t withdrawals_root; + ommer_list_t ommer_block_headers; +}; + +// Account +struct account_t { + account_address_t account_id; + ether_t balance; + bytes_t code; + nonce_t nonce; +}; + +// Access List +using storage_key_list_t = std::vector; +struct access_pair_t { + account_address_t account_id; + storage_key_list_t storage_keys; +}; +using access_list_t = std::vector; + +// Transaction Type +enum class tx_type_t { LEGACY, ACCESS_LIST, DYNAMIC_FEE }; +using tx_type_option_t = std::optional; + +// Message +using account_address_option_t = std::optional; +using sig_v_t = std::uint64_t; +struct message_t { + message_id_t message_id; + nonce_t tx_nonce; + ether_t tx_gas_price; + gas_t tx_gas_limit; + account_address_option_t to; + ether_t value; + sig_v_t sig_v; + bytes_t sig_r; + bytes_t sig_s; + bytes_t data; + access_list_t tx_access; + chain_id_t tx_chain_id; + ether_t tx_priority_fee; + ether_t tx_max_fee; + tx_type_option_t tx_type; +}; + +// Network Callbacks +using add_account_callback_t = void (*)(account_t); +using remove_account_callback_t = void (*)(account_address_t); + +using get_account_balance_callback_t = + std::optional (*)(account_address_t); +using set_account_balance_callback_t = void (*)(account_address_t, ether_t); + +using get_account_code_callback_t = + std::optional (*)(account_address_t); +using set_account_code_callback_t = void (*)(account_address_t, bytes_t); + +using get_account_nonce_callback_t = + std::optional (*)(account_address_t); +using set_account_nonce_callback_t = void (*)(account_address_t, nonce_t); + +using get_account_storage_callback_t = + std::optional (*)(account_address_t, storage_key_t); +using set_account_storage_callback_t = void (*)(account_address_t, + storage_key_t, storage_value_t); + +using get_account_orig_storage_callback_t = + std::optional (*)(account_address_t, storage_key_t); +using set_account_orig_storage_callback_t = void (*)(account_address_t, + storage_key_t, + storage_value_t); + +using add_message_callback_t = void (*)(message_t); +using get_message_callback_t = std::optional (*)(message_id_t); + +using get_blockhash_callback_t = hash_t (*)(size_t offset); + +// Network +struct network_t { + chain_id_t chain_id; + add_account_callback_t add_account; + remove_account_callback_t remove_account; + get_account_balance_callback_t get_account_balance; + set_account_balance_callback_t set_account_balance; + get_account_code_callback_t get_account_code; + set_account_code_callback_t set_account_code; + get_account_nonce_callback_t get_account_nonce; + set_account_nonce_callback_t set_account_nonce; + get_account_storage_callback_t get_account_storage; + set_account_storage_callback_t set_account_storage; + get_account_orig_storage_callback_t get_account_orig_storage; + set_account_orig_storage_callback_t set_account_orig_storage; + add_message_callback_t add_message; + get_message_callback_t get_message; + get_blockhash_callback_t get_blockhash; +}; + +// Log +using log_topic_t = bytes_t; +using log_topic_list_t = std::vector; +struct log_t { + account_address_t account; + log_topic_list_t topics; + bytes_t data; +}; +using log_list_t = std::vector; + +// Accessed Storage List +struct accessed_storage_t { + account_address_t account_address; + storage_key_t storage_key; +}; +using accessed_storage_list_t = std::vector; + +// Substate +using account_address_list_t = std::vector; +struct substate_t { + account_address_list_t self_destrcut; + log_list_t log; + account_address_list_t touched_accounts; + ether_t refund; + account_address_list_t accessed_accounts; + accessed_storage_list_t accessed_storage; +}; + +// Status Code +enum class status_code_t { + EVMC_REJECTED, + EVMC_INTERNAL_ERROR, + EVMC_SUCCESS, + EVMC_REVERT, + EVMC_FAILURE, + EVMC_INVALID_INSTRUCTION, + EVMC_UNDEFINED_INSTRUCTION, + EVMC_OUT_OF_GAS, + EVMC_BAD_JUMP_DESTINATION, + EVMC_STACK_OVERFLOW, + EVMC_STACK_UNDERFLOW, + EVMC_CALL_DEPTH_EXCEEDED, + EVMC_INVALID_MEMORY_ACCESS, + EVMC_STATIC_MODE_VIOLATION, + EVMC_PRECOMPILE_FAILURE, + EVMC_NONCE_EXCEEDED +}; + +// Result +using status_code_option_t = std::optional; +struct result_t { + bytes_t output; + status_code_option_t status_code; +}; + +// KEVM mode +enum class mode_t { NORMAL, VMTESTS }; + +// Schedule +enum class schedule_t { + DEFAULT, + FRONTIER, + HOMESTEAD, + TANGERINE_WHISTLE, + SPURIOUS_DRAGON, + BYZANTIUM, + CONSTANTINOPLE, + PETERSBURG, + ISTANBUL, + BERLIN, + LONDON, + MERGE, + SHANGHAI +}; + +// KEVM configuartion +struct kevm_config_t { + mode_t mode; + schedule_t schedule; + bool use_gas; +}; + +// APIs +void init_network(network_t network); + +void execute_transaction(const kevm_config_t &kevm_config, const block_t &block, + const message_t &tx, result_t &result, + substate_t &substate); + +} // end namespace usl_kevm + +#endif // USL_KEVM_H From 753ac74b27a3dcff2ffe9cf0855b737f8ae0d916 Mon Sep 17 00:00:00 2001 From: devops Date: Thu, 6 Jun 2024 18:16:32 +0000 Subject: [PATCH 2/2] Set Version: 1.0.592 --- kevm-pyk/pyproject.toml | 2 +- kevm-pyk/src/kevm_pyk/__init__.py | 2 +- package/version | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kevm-pyk/pyproject.toml b/kevm-pyk/pyproject.toml index 00645b8653..de2b1f5ac9 100644 --- a/kevm-pyk/pyproject.toml +++ b/kevm-pyk/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "kevm-pyk" -version = "1.0.587" +version = "1.0.592" description = "" authors = [ "Runtime Verification, Inc. ", diff --git a/kevm-pyk/src/kevm_pyk/__init__.py b/kevm-pyk/src/kevm_pyk/__init__.py index c5031d372a..3fd0e5c549 100644 --- a/kevm-pyk/src/kevm_pyk/__init__.py +++ b/kevm-pyk/src/kevm_pyk/__init__.py @@ -5,4 +5,4 @@ if TYPE_CHECKING: from typing import Final -VERSION: Final = '1.0.587' +VERSION: Final = '1.0.592' diff --git a/package/version b/package/version index f449bb757c..c5ff8f6597 100644 --- a/package/version +++ b/package/version @@ -1 +1 @@ -1.0.587 +1.0.592