Merge pull request #128 from ethereum/message-refactor

Reorder evmc_message fields
This commit is contained in:
Paweł Bylica 2018-09-03 22:44:00 +02:00 committed by GitHub
commit d617e193ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 48 deletions

View File

@ -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 = {
*destination,
*sender,
*value,
input_data,
input_size,
*code_hash,
create2_salt,
gas,
depth,
kind,
flags,
depth,
gas,
*destination,
*sender,
input_data,
input_size,
*value,
create2_salt,
};
struct extended_context ctx = {{&evmc_go_host}, context_index};
@ -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 {
@ -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))

View File

@ -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}};
@ -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);

View File

@ -70,58 +70,52 @@ enum evmc_flags
*/
struct evmc_message
{
/** 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;
/** 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;
};

View File

@ -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