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

Add necessary defines for AVAX support #698

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions bindings/java/c/evmc-vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ JNIEXPORT jobject JNICALL Java_org_ethereum_evmc_EvmcVm_execute(JNIEnv* jenv,
struct evmc_result* result =
(struct evmc_result*)(*jenv)->GetDirectBufferAddress(jenv, jresult);
assert(result != NULL);
*result = evmc_execute(evm, host, (struct evmc_host_context*)jcontext, (enum evmc_revision)jrev,
msg, code, code_size);
*result = evmc_execute(evm, host, (struct evmc_host_context*)jcontext, (size_t)jrev, msg, code,
code_size);
return jresult;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/example_precompiles_vm/example_precompiles_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ evmc_result not_implemented()
evmc_result execute(evmc_vm* /*vm*/,
const evmc_host_interface* /*host*/,
evmc_host_context* /*context*/,
enum evmc_revision rev,
size_t rev,
const evmc_message* msg,
const uint8_t* /*code*/,
size_t /*code_size*/)
Expand Down
2 changes: 1 addition & 1 deletion examples/example_vm/example_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ inline evmc_address to_address(evmc_uint256be value)
evmc_result execute(evmc_vm* instance,
const evmc_host_interface* host,
evmc_host_context* context,
enum evmc_revision rev,
size_t rev,
const evmc_message* msg,
const uint8_t* code,
size_t code_size)
Expand Down
30 changes: 29 additions & 1 deletion include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,17 @@ typedef enum evmc_set_option_result (*evmc_set_option_fn)(struct evmc_vm* vm,
char const* name,
char const* value);

/**
* EVM execution ID
*
* Allow to specialize parts of the execution to adapt for different chains types
*/
enum evmc_execution_id
{
EVMC_ETHEREUM = 0,
EVMC_AVAX
};


/**
* EVM revision.
Expand Down Expand Up @@ -1030,6 +1041,23 @@ enum evmc_revision
EVMC_LATEST_STABLE_REVISION = EVMC_SHANGHAI
};

enum evmc_avax_revision
{
EVMC_AVAX_ISTANBUL = 0,
EVMC_AVAX_APRICOT_1,
EVMC_AVAX_APRICOT_2,
EVMC_AVAX_APRICOT_3,
EVMC_AVAX_APRICOT_4,
EVMC_AVAX_APRICOT_5,
EVMC_AVAX_APRICOT_6_PRE,
EVMC_AVAX_APRICOT_6,
EVMC_AVAX_APRICOT_6_POST,
EVMC_AVAX_BANFF,

EVMC_AVAX_MAX_REVISION = EVMC_AVAX_BANFF,
EVMC_AVAX_LATEST_STABLE_REVISION = EVMC_AVAX_BANFF,
};


/**
* Executes the given code using the input from the message.
Expand All @@ -1052,7 +1080,7 @@ enum evmc_revision
typedef struct evmc_result (*evmc_execute_fn)(struct evmc_vm* vm,
const struct evmc_host_interface* host,
struct evmc_host_context* context,
enum evmc_revision rev,
size_t rev,
const struct evmc_message* msg,
uint8_t const* code,
size_t code_size);
Expand Down
43 changes: 42 additions & 1 deletion include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <initializer_list>
#include <ostream>
#include <string_view>
#include <type_traits>
#include <utility>
#include <variant>

static_assert(EVMC_LATEST_STABLE_REVISION <= EVMC_MAX_REVISION,
"latest stable revision ill-defined");
Expand All @@ -22,6 +24,45 @@ namespace evmc
{
/// String view of uint8_t chars.
using bytes_view = std::basic_string_view<uint8_t>;
using Revision = std::variant<evmc_revision, evmc_avax_revision>;

template <evmc_execution_id Id>
struct RevisionTypeImpl;

template <>
struct RevisionTypeImpl<EVMC_ETHEREUM>
{
using type = evmc_revision;
};

template <>
struct RevisionTypeImpl<EVMC_AVAX>
{
using type = evmc_avax_revision;
};

template <evmc_execution_id Id>
using RevisionType = typename RevisionTypeImpl<Id>::type;

template <typename EthereumFunction, typename AvaxFunction>
auto visit(const Revision revision,
EthereumFunction ethereum,
AvaxFunction avax) noexcept(noexcept(ethereum) && noexcept(avax))
{
return std::visit(
[&](const auto rev) {
if constexpr (std::is_same_v<decltype(rev), evmc_revision>)
{
return ethereum(rev);
}
else
{
return avax(rev);
}
},
revision);
}


/// The big-endian 160-bit hash suitable for keeping an Ethereum address.
///
Expand Down Expand Up @@ -745,7 +786,7 @@ class VM
/// but without providing the Host context and interface.
/// This method is for experimental precompiles support where execution is
/// guaranteed not to require any Host access.
Result execute(evmc_revision rev,
Result execute(size_t rev,
const evmc_message& msg,
const uint8_t* code,
size_t code_size) noexcept
Expand Down
7 changes: 7 additions & 0 deletions include/evmc/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ enum evmc_opcode
OP_LOG3 = 0xa3,
OP_LOG4 = 0xa4,

// AVAX SPECIAL OPCODES (begin)
OP_BALANCEMC = 0xcd,
OP_CALLEX = 0xcf,
// AVAX SPECIAL OPCODES (end)

OP_CREATE = 0xf0,
OP_CALL = 0xf1,
OP_CALLCODE = 0xf2,
Expand Down Expand Up @@ -219,6 +224,8 @@ EVMC_EXPORT const struct evmc_instruction_metrics* evmc_get_instruction_metrics_
* an invalid EVM revision provided.
*/
EVMC_EXPORT const char* const* evmc_get_instruction_names_table(enum evmc_revision revision);
EVMC_EXPORT const char* const* evmc_get_instruction_names_table_avax(
enum evmc_avax_revision revision);

#ifdef __cplusplus
}
Expand Down
Loading