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

Reorder evmc_message fields #128

Merged
merged 2 commits into from
Sep 3, 2018
Merged
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
34 changes: 18 additions & 16 deletions bindings/go/evmc/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@ struct extended_context

extern const struct evmc_host_interface evmc_go_host;

static struct evmc_result execute_wrapper(struct evmc_instance* instance, int64_t context_index, enum evmc_revision rev,
const struct evmc_address* destination, const struct evmc_address* sender, const struct evmc_uint256be* value,
const uint8_t* input_data, size_t input_size, const struct evmc_uint256be* code_hash, int64_t gas,
int32_t depth, enum evmc_call_kind kind, uint32_t flags, const uint8_t* code, size_t code_size)
static struct evmc_result execute_wrapper(struct evmc_instance* instance,
int64_t context_index, enum evmc_revision rev,
enum evmc_call_kind kind, uint32_t flags, int32_t depth, int64_t gas,
const struct evmc_address* destination, const struct evmc_address* sender,
const uint8_t* input_data, size_t input_size, const struct evmc_uint256be* value,
const uint8_t* code, size_t code_size)
{
struct evmc_uint256be create2_salt = {};
struct evmc_message msg = {
kind,
flags,
depth,
gas,
*destination,
*sender,
*value,
input_data,
input_size,
*code_hash,
*value,
create2_salt,
gas,
depth,
kind,
flags,
};

struct extended_context ctx = {{&evmc_go_host}, context_index};
Expand Down Expand Up @@ -195,8 +196,9 @@ func (instance *Instance) SetOption(name string, value string) (err error) {
}

func (instance *Instance) Execute(ctx HostContext, rev Revision,
destination common.Address, sender common.Address, value common.Hash, input []byte, codeHash common.Hash, gas int64,
depth int, kind CallKind, static bool, code []byte) (output []byte, gasLeft int64, err error) {
kind CallKind, static bool, depth int, gas int64,
destination common.Address, sender common.Address, input []byte, value common.Hash,
code []byte) (output []byte, gasLeft int64, err error) {

flags := C.uint32_t(0)
if static {
Expand All @@ -208,10 +210,10 @@ func (instance *Instance) Execute(ctx HostContext, rev Revision,
evmcDestination := evmcAddress(destination)
evmcSender := evmcAddress(sender)
evmcValue := evmcUint256be(value)
evmcCodeHash := evmcUint256be(codeHash)
result := C.execute_wrapper(instance.handle, C.int64_t(ctxId), uint32(rev), &evmcDestination, &evmcSender, &evmcValue,
bytesPtr(input), C.size_t(len(input)), &evmcCodeHash, C.int64_t(gas), C.int32_t(depth), C.enum_evmc_call_kind(kind),
flags, bytesPtr(code), C.size_t(len(code)))
result := C.execute_wrapper(instance.handle, C.int64_t(ctxId), uint32(rev),
C.enum_evmc_call_kind(kind), flags, C.int32_t(depth), C.int64_t(gas),
&evmcDestination, &evmcSender, bytesPtr(input), C.size_t(len(input)), &evmcValue,
bytesPtr(code), C.size_t(len(code)))
removeHostContext(ctxId)

output = C.GoBytes(unsafe.Pointer(result.output_data), C.int(result.output_size))
Expand Down
2 changes: 0 additions & 2 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ int main()
// EVM bytecode goes here. This is one of the examples.
const uint8_t code[] = "\x30\x60\x00\x52\x59\x60\x00\xf3";
const size_t code_size = sizeof(code);
const struct evmc_uint256be code_hash = {.bytes = {1, 2, 3}};
const uint8_t input[] = "Hello World!";
const struct evmc_uint256be value = {{1, 0}};
const struct evmc_address addr = {{0, 1, 2}};
Expand All @@ -31,7 +30,6 @@ int main()
msg.value = value;
msg.input_data = input;
msg.input_size = sizeof(input);
msg.code_hash = code_hash;
msg.gas = gas;
msg.depth = 0;
struct evmc_result result = evmc_execute(vm, ctx, EVMC_HOMESTEAD, &msg, code, code_size);
Expand Down
46 changes: 20 additions & 26 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,58 +70,52 @@ enum evmc_flags
*/
struct evmc_message
{
/** The kind of the call. For zero-depth calls ::EVMC_CALL SHOULD be used. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this isn't changed in this PR, but I think this comment is invalid, it can be create even for depth 0.

enum evmc_call_kind kind;

/**
* Additional flags modifying the call execution behavior.
* In the current version the only valid values are ::EVMC_STATIC or 0.
*/
uint32_t flags;

/** The call depth. */
int32_t depth;

/** The amount of gas for message execution. */
int64_t gas;

/** The destination of the message. */
struct evmc_address destination;

/** The sender of the message. */
struct evmc_address sender;

/**
* The amount of Ether transferred with the message.
*/
struct evmc_uint256be value;

/**
* The message input data.
*
* This MAY be NULL.
* This MAY be NULL.
*/
const uint8_t* input_data;

/**
* The size of the message input data.
*
* If input_data is NULL this MUST be 0.
* If input_data is NULL this MUST be 0.
*/
size_t input_size;

/**
* The optional hash of the code of the destination account.
* The null hash MUST be used when not specified.
* The amount of Ether transferred with the message.
*/
struct evmc_uint256be code_hash;
struct evmc_uint256be value;

/**
* The optional value used in new contract address construction.
*
* Ignored unless kind is EVMC_CREATE2.
* Ignored unless kind is EVMC_CREATE2.
*/
struct evmc_uint256be create2_salt;

/** The amount of gas for message execution. */
int64_t gas;

/** The call depth. */
int32_t depth;

/** The kind of the call. For zero-depth calls ::EVMC_CALL SHOULD be used. */
enum evmc_call_kind kind;

/**
* Additional flags modifying the call execution behavior.
* In the current version the only valid values are ::EVMC_STATIC or 0.
*/
uint32_t flags;
};


Expand Down
2 changes: 1 addition & 1 deletion test/vmtester/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static_assert(sizeof(evmc_uint256be) == 32, "evmc_uint256be is too big");
static_assert(sizeof(evmc_address) == 20, "evmc_address is too big");
static_assert(sizeof(evmc_result) <= 64, "evmc_result does not fit cache line");
static_assert(sizeof(evmc_instance) <= 64, "evmc_instance does not fit cache line");
static_assert(offsetof(evmc_message, code_hash) % 8 == 0, "evmc_message.code_hash not aligned");
static_assert(offsetof(evmc_message, value) % 8 == 0, "evmc_message.value not aligned");

// Check enums match int size.
// On GCC/clang the underlying type should be unsigned int, on MSVC int
Expand Down