mirror of
https://github.com/status-im/evmc.git
synced 2025-02-21 15:38:18 +00:00
Rename uint256be to bytes32
This commit is contained in:
parent
1322d7559c
commit
e772fbf28b
@ -35,8 +35,8 @@ 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, const struct evmc_uint256be* create2_salt)
|
||||
const uint8_t* input_data, size_t input_size, const evmc_uint256be* value,
|
||||
const uint8_t* code, size_t code_size, const struct evmc_bytes32* create2_salt)
|
||||
{
|
||||
struct evmc_message msg = {
|
||||
kind,
|
||||
@ -68,8 +68,8 @@ import (
|
||||
|
||||
// Static asserts.
|
||||
const (
|
||||
_ = uint(common.HashLength - C.sizeof_struct_evmc_uint256be) // The size of evmc_uint256be equals the size of Hash.
|
||||
_ = uint(C.sizeof_struct_evmc_uint256be - common.HashLength)
|
||||
_ = uint(common.HashLength - C.sizeof_struct_evmc_bytes32) // The size of evmc_bytes32 equals the size of Hash.
|
||||
_ = uint(C.sizeof_struct_evmc_bytes32 - common.HashLength)
|
||||
_ = uint(common.AddressLength - C.sizeof_struct_evmc_address) // The size of evmc_address equals the size of Address.
|
||||
_ = uint(C.sizeof_struct_evmc_address - common.AddressLength)
|
||||
)
|
||||
@ -212,8 +212,8 @@ func (instance *Instance) Execute(ctx HostContext, rev Revision,
|
||||
// FIXME: Clarify passing by pointer vs passing by value.
|
||||
evmcDestination := evmcAddress(destination)
|
||||
evmcSender := evmcAddress(sender)
|
||||
evmcValue := evmcUint256be(value)
|
||||
evmcCreate2Salt := evmcUint256be(create2Salt)
|
||||
evmcValue := evmcBytes32(value)
|
||||
evmcCreate2Salt := evmcBytes32(create2Salt)
|
||||
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,
|
||||
@ -261,8 +261,8 @@ func getHostContext(idx int) HostContext {
|
||||
return ctx
|
||||
}
|
||||
|
||||
func evmcUint256be(in common.Hash) C.struct_evmc_uint256be {
|
||||
out := C.struct_evmc_uint256be{}
|
||||
func evmcBytes32(in common.Hash) C.struct_evmc_bytes32 {
|
||||
out := C.struct_evmc_bytes32{}
|
||||
for i := 0; i < len(in); i++ {
|
||||
out.bytes[i] = C.uint8_t(in[i])
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ static inline void go_exported_functions_type_checks()
|
||||
{
|
||||
struct evmc_context* context = NULL;
|
||||
struct evmc_address* address = NULL;
|
||||
struct evmc_uint256be* uint256be = NULL;
|
||||
struct evmc_bytes32* bytes32 = NULL;
|
||||
evmc_uint256be* uint256be = NULL;
|
||||
uint8_t* data = NULL;
|
||||
size_t size = 0;
|
||||
int64_t number = 0;
|
||||
@ -61,12 +62,12 @@ static inline void go_exported_functions_type_checks()
|
||||
bool_flag = accountExists(context, address);
|
||||
|
||||
evmc_get_storage_fn get_storage_fn = NULL;
|
||||
get_storage_fn(uint256be, context, address, uint256be);
|
||||
getStorage(uint256be, context, address, uint256be);
|
||||
get_storage_fn(bytes32, context, address, bytes32);
|
||||
getStorage(bytes32, context, address, bytes32);
|
||||
|
||||
evmc_set_storage_fn set_storage_fn = NULL;
|
||||
storage_status = set_storage_fn(context, address, uint256be, uint256be);
|
||||
storage_status = setStorage(context, address, uint256be, uint256be);
|
||||
storage_status = set_storage_fn(context, address, bytes32, bytes32);
|
||||
storage_status = setStorage(context, address, bytes32, bytes32);
|
||||
|
||||
evmc_get_balance_fn get_balance_fn = NULL;
|
||||
bool_flag = get_balance_fn(uint256be, context, address);
|
||||
@ -77,8 +78,8 @@ static inline void go_exported_functions_type_checks()
|
||||
bool_flag = getCodeSize(&size, context, address);
|
||||
|
||||
evmc_get_code_hash_fn get_code_hash_fn = NULL;
|
||||
bool_flag = get_code_hash_fn(uint256be, context, address);
|
||||
bool_flag = getCodeHash(uint256be, context, address);
|
||||
bool_flag = get_code_hash_fn(bytes32, context, address);
|
||||
bool_flag = getCodeHash(bytes32, context, address);
|
||||
|
||||
evmc_copy_code_fn copy_code_fn = NULL;
|
||||
size = copy_code_fn(context, address, size, data, size);
|
||||
@ -97,10 +98,10 @@ static inline void go_exported_functions_type_checks()
|
||||
tx_context = getTxContext(context);
|
||||
|
||||
evmc_get_block_hash_fn get_block_hash_fn = NULL;
|
||||
bool_flag = get_block_hash_fn(uint256be, context, number);
|
||||
bool_flag = getBlockHash(uint256be, context, number);
|
||||
bool_flag = get_block_hash_fn(bytes32, context, number);
|
||||
bool_flag = getBlockHash(bytes32, context, number);
|
||||
|
||||
evmc_emit_log_fn emit_log_fn = NULL;
|
||||
emit_log_fn(context, address, data, size, uint256be, size);
|
||||
emitLog(context, address, data, size, uint256be, size);
|
||||
emit_log_fn(context, address, data, size, bytes32, size);
|
||||
emitLog(context, address, data, size, bytes32, size);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func goAddress(in C.struct_evmc_address) common.Address {
|
||||
return out
|
||||
}
|
||||
|
||||
func goHash(in C.struct_evmc_uint256be) common.Hash {
|
||||
func goHash(in C.struct_evmc_bytes32) common.Hash {
|
||||
out := common.Hash{}
|
||||
for i := 0; i < len(out); i++ {
|
||||
out[i] = byte(in.bytes[i])
|
||||
@ -95,19 +95,19 @@ func accountExists(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
|
||||
}
|
||||
|
||||
//export getStorage
|
||||
func getStorage(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struct_evmc_uint256be) C.bool {
|
||||
func getStorage(pResult *C.struct_evmc_bytes32, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struct_evmc_bytes32) C.bool {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
value, err := ctx.GetStorage(goAddress(*pAddr), goHash(*pKey))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
*pResult = evmcUint256be(value)
|
||||
*pResult = evmcBytes32(value)
|
||||
return true
|
||||
}
|
||||
|
||||
//export setStorage
|
||||
func setStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struct_evmc_uint256be, pVal *C.struct_evmc_uint256be) C.enum_evmc_storage_status {
|
||||
func setStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struct_evmc_bytes32, pVal *C.struct_evmc_bytes32) C.enum_evmc_storage_status {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
status, err := ctx.SetStorage(goAddress(*pAddr), goHash(*pKey), goHash(*pVal))
|
||||
@ -118,14 +118,14 @@ func setStorage(pCtx unsafe.Pointer, pAddr *C.struct_evmc_address, pKey *C.struc
|
||||
}
|
||||
|
||||
//export getBalance
|
||||
func getBalance(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
|
||||
func getBalance(pResult *C.evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
balance, err := ctx.GetBalance(goAddress(*pAddr))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
*pResult = evmcUint256be(balance)
|
||||
*pResult = evmcBytes32(balance)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -142,14 +142,14 @@ func getCodeSize(pResult *C.size_t, pCtx unsafe.Pointer, pAddr *C.struct_evmc_ad
|
||||
}
|
||||
|
||||
//export getCodeHash
|
||||
func getCodeHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
|
||||
func getCodeHash(pResult *C.struct_evmc_bytes32, pCtx unsafe.Pointer, pAddr *C.struct_evmc_address) C.bool {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
codeHash, err := ctx.GetCodeHash(goAddress(*pAddr))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
*pResult = evmcUint256be(codeHash)
|
||||
*pResult = evmcBytes32(codeHash)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -189,18 +189,18 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context {
|
||||
gasPrice, origin, coinbase, number, timestamp, gasLimit, difficulty := ctx.GetTxContext()
|
||||
|
||||
return C.struct_evmc_tx_context{
|
||||
evmcUint256be(gasPrice),
|
||||
evmcBytes32(gasPrice),
|
||||
evmcAddress(origin),
|
||||
evmcAddress(coinbase),
|
||||
C.int64_t(number),
|
||||
C.int64_t(timestamp),
|
||||
C.int64_t(gasLimit),
|
||||
evmcUint256be(difficulty),
|
||||
evmcBytes32(difficulty),
|
||||
}
|
||||
}
|
||||
|
||||
//export getBlockHash
|
||||
func getBlockHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, number int64) C.bool {
|
||||
func getBlockHash(pResult *C.struct_evmc_bytes32, pCtx unsafe.Pointer, number int64) C.bool {
|
||||
idx := int((*C.struct_extended_context)(pCtx).index)
|
||||
ctx := getHostContext(idx)
|
||||
|
||||
@ -209,7 +209,7 @@ func getBlockHash(pResult *C.struct_evmc_uint256be, pCtx unsafe.Pointer, number
|
||||
return false
|
||||
}
|
||||
|
||||
*pResult = evmcUint256be(blockhash)
|
||||
*pResult = evmcBytes32(blockhash)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ int main()
|
||||
const uint8_t code[] = "\x30\x60\x00\x52\x59\x60\x00\xf3";
|
||||
const size_t code_size = sizeof(code);
|
||||
const uint8_t input[] = "Hello World!";
|
||||
const struct evmc_uint256be value = {{1, 0}};
|
||||
const evmc_uint256be value = {{1, 0}};
|
||||
const struct evmc_address addr = {{0, 1, 2}};
|
||||
const int64_t gas = 200000;
|
||||
struct evmc_context* ctx = example_host_create_context();
|
||||
|
@ -114,11 +114,11 @@ static struct evmc_result execute(struct evmc_instance* instance,
|
||||
}
|
||||
else if (code_size == strlen(counter) && strncmp((const char*)code, counter, code_size) == 0)
|
||||
{
|
||||
struct evmc_uint256be value;
|
||||
const struct evmc_uint256be index = {{0}};
|
||||
context->host->get_storage(&value, context, &msg->destination, &index);
|
||||
struct evmc_bytes32 value;
|
||||
const struct evmc_bytes32 key = {{0}};
|
||||
context->host->get_storage(&value, context, &msg->destination, &key);
|
||||
value.bytes[31]++;
|
||||
context->host->set_storage(context, &msg->destination, &index, &value);
|
||||
context->host->set_storage(context, &msg->destination, &key, &value);
|
||||
ret.status_code = EVMC_SUCCESS;
|
||||
return ret;
|
||||
}
|
||||
|
@ -34,20 +34,23 @@ enum
|
||||
EVMC_ABI_VERSION = 6
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Big-endian 256-bit integer.
|
||||
* The fixed size array of 32 bytes.
|
||||
*
|
||||
* 32 bytes of data representing big-endian 256-bit integer. I.e. bytes[0] is
|
||||
* the most significant byte, bytes[31] is the least significant byte.
|
||||
* This type is used to transfer to/from the VM values interpreted by the user
|
||||
* as both 256-bit integers and 256-bit hashes.
|
||||
* 32 bytes of data capable of storing e.g. 256-bit hashes.
|
||||
*/
|
||||
struct evmc_uint256be
|
||||
struct evmc_bytes32
|
||||
{
|
||||
/** The 32 bytes of the big-endian integer or hash. */
|
||||
/** The 32 bytes. */
|
||||
uint8_t bytes[32];
|
||||
};
|
||||
|
||||
/**
|
||||
* The alias for evmc_bytes32 to represent a big-endian 256-bit integer.
|
||||
*/
|
||||
typedef struct evmc_bytes32 evmc_uint256be;
|
||||
|
||||
/** Big-endian 160-bit hash suitable for keeping an Ethereum address. */
|
||||
struct evmc_address
|
||||
{
|
||||
@ -116,27 +119,27 @@ struct evmc_message
|
||||
/**
|
||||
* The amount of Ether transferred with the message.
|
||||
*/
|
||||
struct evmc_uint256be value;
|
||||
evmc_uint256be value;
|
||||
|
||||
/**
|
||||
* The optional value used in new contract address construction.
|
||||
*
|
||||
* Ignored unless kind is EVMC_CREATE2.
|
||||
*/
|
||||
struct evmc_uint256be create2_salt;
|
||||
struct evmc_bytes32 create2_salt;
|
||||
};
|
||||
|
||||
|
||||
/** The transaction and block data for execution. */
|
||||
struct evmc_tx_context
|
||||
{
|
||||
struct evmc_uint256be tx_gas_price; /**< The transaction gas price. */
|
||||
struct evmc_address tx_origin; /**< The transaction origin account. */
|
||||
struct evmc_address block_coinbase; /**< The miner of the block. */
|
||||
int64_t block_number; /**< The block number. */
|
||||
int64_t block_timestamp; /**< The block timestamp. */
|
||||
int64_t block_gas_limit; /**< The block gas limit. */
|
||||
struct evmc_uint256be block_difficulty; /**< The block difficulty. */
|
||||
evmc_uint256be tx_gas_price; /**< The transaction gas price. */
|
||||
struct evmc_address tx_origin; /**< The transaction origin account. */
|
||||
struct evmc_address block_coinbase; /**< The miner of the block. */
|
||||
int64_t block_number; /**< The block number. */
|
||||
int64_t block_timestamp; /**< The block timestamp. */
|
||||
int64_t block_gas_limit; /**< The block gas limit. */
|
||||
evmc_uint256be block_difficulty; /**< The block difficulty. */
|
||||
};
|
||||
|
||||
struct evmc_context;
|
||||
@ -165,7 +168,7 @@ typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_context* co
|
||||
* @param number The block number.
|
||||
* @return true if the information is available, false otherwise.
|
||||
*/
|
||||
typedef bool (*evmc_get_block_hash_fn)(struct evmc_uint256be* result,
|
||||
typedef bool (*evmc_get_block_hash_fn)(struct evmc_bytes32* result,
|
||||
struct evmc_context* context,
|
||||
int64_t number);
|
||||
|
||||
@ -420,10 +423,10 @@ typedef bool (*evmc_account_exists_fn)(struct evmc_context* context,
|
||||
* If the account does not exist false is returned without
|
||||
* modifying the memory pointed by @p result.
|
||||
*/
|
||||
typedef bool (*evmc_get_storage_fn)(struct evmc_uint256be* result,
|
||||
typedef bool (*evmc_get_storage_fn)(struct evmc_bytes32* result,
|
||||
struct evmc_context* context,
|
||||
const struct evmc_address* address,
|
||||
const struct evmc_uint256be* key);
|
||||
const struct evmc_bytes32* key);
|
||||
|
||||
|
||||
/**
|
||||
@ -484,8 +487,8 @@ enum evmc_storage_status
|
||||
*/
|
||||
typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* context,
|
||||
const struct evmc_address* address,
|
||||
const struct evmc_uint256be* key,
|
||||
const struct evmc_uint256be* value);
|
||||
const struct evmc_bytes32* key,
|
||||
const struct evmc_bytes32* value);
|
||||
|
||||
/**
|
||||
* Get balance callback function.
|
||||
@ -502,7 +505,7 @@ typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* con
|
||||
* If the account does not exist false is returned without
|
||||
* modifying the memory pointed by @p result.
|
||||
*/
|
||||
typedef bool (*evmc_get_balance_fn)(struct evmc_uint256be* result,
|
||||
typedef bool (*evmc_get_balance_fn)(evmc_uint256be* result,
|
||||
struct evmc_context* context,
|
||||
const struct evmc_address* address);
|
||||
|
||||
@ -543,7 +546,7 @@ typedef bool (*evmc_get_code_size_fn)(size_t* result,
|
||||
* If the account does not exist false is returned without
|
||||
* modifying the memory pointed by @p result.
|
||||
*/
|
||||
typedef bool (*evmc_get_code_hash_fn)(struct evmc_uint256be* result,
|
||||
typedef bool (*evmc_get_code_hash_fn)(struct evmc_bytes32* result,
|
||||
struct evmc_context* context,
|
||||
const struct evmc_address* address);
|
||||
|
||||
@ -605,7 +608,7 @@ typedef void (*evmc_emit_log_fn)(struct evmc_context* context,
|
||||
const struct evmc_address* address,
|
||||
const uint8_t* data,
|
||||
size_t data_size,
|
||||
const struct evmc_uint256be topics[],
|
||||
const struct evmc_bytes32 topics[],
|
||||
size_t topics_count);
|
||||
|
||||
/**
|
||||
@ -806,7 +809,7 @@ typedef void (*evmc_trace_callback)(struct evmc_tracer_context* context,
|
||||
enum evmc_status_code status_code,
|
||||
int64_t gas_left,
|
||||
size_t stack_num_items,
|
||||
const struct evmc_uint256be* pushed_stack_item,
|
||||
const evmc_uint256be* pushed_stack_item,
|
||||
size_t memory_size,
|
||||
size_t changed_memory_offset,
|
||||
size_t changed_memory_size,
|
||||
|
Loading…
x
Reference in New Issue
Block a user