-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update-tests-to-use-leap-dev-install
- Loading branch information
Showing
18 changed files
with
440 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace evm_common { | ||
|
||
struct block_mapping { | ||
|
||
/** | ||
* @brief Construct object that maps from Antelope timestamp to EVM block number and timestamp | ||
* | ||
* @param genesis_timestamp_sec - the EVM genesis timestamp in seconds | ||
* @param block_interval_sec - time interval between consecutive EVM blocks in seconds (must be positive) | ||
* | ||
* @note The timestamp of the Antelope block containing the init action rounded down to the nearest second must equal genesis_timestamp_sec. | ||
*/ | ||
block_mapping(uint64_t genesis_timestamp_sec, uint32_t block_interval_sec = 1) | ||
: block_interval(block_interval_sec == 0 ? 1 : block_interval_sec), | ||
genesis_timestamp(genesis_timestamp_sec) | ||
{} | ||
|
||
const uint64_t block_interval; // seconds | ||
const uint64_t genesis_timestamp; // seconds | ||
|
||
/** | ||
* @brief Map Antelope timestamp to EVM block num | ||
* | ||
* @param timestamp - Antelope timestamp in microseconds | ||
* @return mapped EVM block number (returns 0 for all timestamps prior to the genesis timestamp) | ||
*/ | ||
inline uint32_t timestamp_to_evm_block_num(uint64_t timestamp_us) const { | ||
uint64_t timestamp = timestamp_us / 1e6; // map Antelope block timestamp to EVM block timestamp | ||
if( timestamp < genesis_timestamp ) { | ||
// There should not be any transactions prior to the init action. | ||
// But any entity with an associated timestamp prior to the genesis timestamp can be considered as part of the genesis block. | ||
return 0; | ||
} | ||
return 1 + (timestamp - genesis_timestamp) / block_interval; | ||
} | ||
|
||
/** | ||
* @brief Map EVM block num to EVM block timestamp | ||
* | ||
* @param block_num - EVM block number | ||
* @return EVM block timestamp associated with the given EVM block number | ||
*/ | ||
inline uint64_t evm_block_num_to_evm_timestamp(uint32_t block_num) const { | ||
return genesis_timestamp + block_num * block_interval; | ||
} | ||
}; | ||
|
||
} // namespace evm_common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
#pragma once | ||
|
||
#include <evmc/instructions.h> | ||
namespace evm_runtime { | ||
|
||
struct print_tracer : EvmTracer { | ||
|
||
void on_execution_start(evmc_revision rev, const evmc_message& msg, evmone::bytes_view code) override { | ||
const char* const* opcode_names_ = nullptr; | ||
|
||
void on_execution_start(evmc_revision rev, const evmc_message& msg, evmone::bytes_view code) noexcept override { | ||
eosio::print("TRACE: start\n"); | ||
}; | ||
if (opcode_names_ == nullptr) { | ||
opcode_names_ = evmc_get_instruction_names_table(rev); | ||
} | ||
} | ||
|
||
void on_instruction_start(uint32_t pc, const evmone::ExecutionState& state, | ||
const IntraBlockState& intra_block_state) override { | ||
eosio::print("TRACE[inst] ", uint64_t(pc), ": ", uint64_t(state.gas_left), "\n"); | ||
std::string get_opcode_name(const char* const* names, std::uint8_t opcode) { | ||
const auto name = names[opcode]; | ||
return (name != nullptr) ?name : "opcode 0x" + evmc::hex(opcode) + " not defined"; | ||
} | ||
|
||
}; | ||
void on_instruction_start(uint32_t pc, const intx::uint256* stack_top, int stack_height, | ||
const evmone::ExecutionState& state, | ||
const IntraBlockState& intra_block_state) noexcept override { | ||
const auto opcode = state.code[pc]; | ||
auto opcode_name = get_opcode_name(opcode_names_, opcode); | ||
eosio::print(opcode_name.c_str(), "\n"); | ||
} | ||
|
||
void on_execution_end(const evmc_result& result, const IntraBlockState& intra_block_state) override { | ||
void on_execution_end(const evmc_result& result, const IntraBlockState& intra_block_state) noexcept override { | ||
eosio::print("TRACE: end\n"); | ||
} | ||
|
||
}; | ||
void on_creation_completed(const evmc_result& result, const IntraBlockState& intra_block_state) noexcept override { | ||
|
||
} | ||
|
||
void on_precompiled_run(const evmc_result& result, int64_t gas, | ||
const IntraBlockState& intra_block_state) noexcept override { | ||
|
||
} | ||
|
||
void on_reward_granted(const CallResult& result, const IntraBlockState& intra_block_state) noexcept override { | ||
|
||
} | ||
|
||
}; | ||
} //namespace evm_runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.