14 #include "example_vm.h" 51 if (strcmp(name,
"verbose") == 0)
54 return EVMC_SET_OPTION_INVALID_VALUE;
57 long int v = strtol(value, &end, 0);
59 return EVMC_SET_OPTION_INVALID_VALUE;
61 return EVMC_SET_OPTION_INVALID_VALUE;
63 return EVMC_SET_OPTION_SUCCESS;
66 return EVMC_SET_OPTION_INVALID_NAME;
89 const char* error = rev ==
EVMC_BYZANTIUM ?
"Welcome to Byzantium!" :
"Hello Ethereum!";
104 const char return_address[] =
"\x30\x60\x00\x52\x59\x60\x00\xf3";
107 const char counter[] =
"\x60\x01\x60\x00\x54\x01\x60\x00\x55";
110 const char return_block_number[] =
"\x43\x60\x00\x52\x59\x60\x00\xf3";
113 const char save_return_block_number[] =
"\x43\x60\x00\x55\x43\x60\x00\x52\x59\x60\x00\xf3";
116 const char make_a_call[] =
"\x60\x00\x80\x80\x80\x80\x80\x80\xf1";
124 else if (code_size == (
sizeof(return_address) - 1) &&
125 strncmp((
const char*)code, return_address, code_size) == 0)
127 static const size_t address_size =
sizeof(msg->
destination);
128 uint8_t* output_data = (uint8_t*)malloc(address_size);
135 memcpy(output_data, &msg->
destination, address_size);
142 else if (code_size == (
sizeof(counter) - 1) &&
143 strncmp((
const char*)code, counter, code_size) == 0)
152 else if (code_size == (
sizeof(return_block_number) - 1) &&
153 strncmp((
const char*)code, return_block_number, code_size) == 0)
156 const size_t output_size = 20;
158 uint8_t* output_data = (uint8_t*)calloc(1, output_size);
159 snprintf((
char*)output_data, output_size,
"%u", (
unsigned)tx_context.
block_number);
167 else if (code_size == (
sizeof(save_return_block_number) - 1) &&
168 strncmp((
const char*)code, save_return_block_number, code_size) == 0)
171 const size_t output_size = 20;
181 uint8_t* output_data = (uint8_t*)calloc(1, output_size);
182 snprintf((
char*)output_data, output_size,
"%u", (
unsigned)tx_context.
block_number);
190 else if (code_size == (
sizeof(make_a_call) - 1) &&
191 strncmp((
const char*)code, make_a_call, code_size) == 0)
194 memset(&call_msg, 0,
sizeof(call_msg));
197 call_msg.
gas = msg->
gas - (msg->
gas / 64);
199 return host->
call(context, &call_msg);
206 printf(
"Execution done.\n");
213 #if !defined(PROJECT_VERSION) 214 #define PROJECT_VERSION "0.0.0" 223 .name =
"example_vm",
224 .version = PROJECT_VERSION,
232 memcpy(interface, &init,
sizeof(init));
static enum evmc_set_option_result set_option(struct evmc_vm *instance, const char *name, const char *value)
Example VM options.
evmc_set_storage_fn set_storage
Set storage callback function.
struct evmc_vm * evmc_create_example_vm()
Example of a function creating an instance of an example EVM implementation.
static evmc_capabilities_flagset get_capabilities(struct evmc_vm *vm)
The example implementation of the evmc_vm::get_capabilities() method.
evmc_address destination
The destination of the message.
const char * name
The name of the EVMC VM implementation.
static void destroy(struct evmc_vm *vm)
The implementation of the evmc_vm::destroy() method.
struct evmc_vm instance
The base struct.
enum evmc_status_code status_code
The execution status code.
The VM is capable of executing ewasm bytecode.
const int abi_version
EVMC ABI version implemented by the VM instance.
The example VM instance struct extending the evmc_vm.
evmc_release_result_fn release
The method releasing all resources associated with the result object.
The VM is capable of executing EVM1 bytecode.
uint8_t bytes[32]
The 32 bytes.
size_t output_size
The size of the output data.
int64_t gas_left
The amount of gas left after the execution.
The EVMC ABI version number of the interface declared in this file.
EVM implementation generic internal error.
int verbose
The verbosity level.
evmc_get_storage_fn get_storage
Get storage callback function.
uint32_t evmc_capabilities_flagset
Alias for unsigned integer representing a set of bit flags of EVMC capabilities.
The opaque data type representing the Host execution context.
int32_t depth
The call depth.
static struct evmc_result execute(struct evmc_vm *instance, const struct evmc_host_interface *host, struct evmc_host_context *context, enum evmc_revision rev, const struct evmc_message *msg, const uint8_t *code, size_t code_size)
The example implementation of the evmc_vm::execute() method.
evmc_get_tx_context_fn get_tx_context
Get transaction context callback function.
enum evmc_call_kind kind
The kind of the call.
The message describing an EVM call, including a zero-depth calls from a transaction origin...
evmc_set_option_result
Possible outcomes of evmc_set_option.
static void free_result_output_data(const struct evmc_result *result)
The implementation of the evmc_result::release() method that frees the output buffer attached to the ...
int64_t block_number
The block number.
evmc_call_fn call
Call callback function.
int64_t gas
The amount of gas for message execution.
The EVM code execution result.
The fixed size array of 32 bytes.
evmc_address sender
The sender of the message.
const uint8_t * output_data
The reference to output data.
evmc_revision
EVM revision.
Generic execution failure.
The transaction and block data for execution.
Execution finished with success.