Skip to content

Commit

Permalink
WIP rename destination
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 7, 2021
1 parent f3b9d78 commit 203b639
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions bindings/go/evmc/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern const struct evmc_host_interface evmc_go_host;
static struct evmc_result execute_wrapper(struct evmc_vm* vm,
uintptr_t context_index, enum evmc_revision rev,
enum evmc_call_kind kind, uint32_t flags, int32_t depth, int64_t gas,
const evmc_address* destination, const evmc_address* sender,
const evmc_address* recipient, const evmc_address* sender,
const uint8_t* input_data, size_t input_size, const evmc_uint256be* value,
const uint8_t* code, size_t code_size)
{
Expand All @@ -37,7 +37,7 @@ static struct evmc_result execute_wrapper(struct evmc_vm* vm,
flags,
depth,
gas,
*destination,
*recipient,
*sender,
input_data,
input_size,
Expand Down Expand Up @@ -194,7 +194,7 @@ func (vm *VM) SetOption(name string, value string) (err error) {

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

flags := C.uint32_t(0)
Expand All @@ -204,12 +204,12 @@ func (vm *VM) Execute(ctx HostContext, rev Revision,

ctxId := addHostContext(ctx)
// FIXME: Clarify passing by pointer vs passing by value.
evmcDestination := evmcAddress(destination)
evmcRecipient := evmcAddress(recipient)
evmcSender := evmcAddress(sender)
evmcValue := evmcBytes32(value)
result := C.execute_wrapper(vm.handle, C.uintptr_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,
&evmcRecipient, &evmcSender, bytesPtr(input), C.size_t(len(input)), &evmcValue,
bytesPtr(code), C.size_t(len(code)))
removeHostContext(ctxId)

Expand Down
4 changes: 2 additions & 2 deletions bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type HostContext interface {
GetBlockHash(number int64) Hash
EmitLog(addr Address, topics []Hash, data []byte)
Call(kind CallKind,
destination Address, sender Address, value Hash, input []byte, gas int64, depth int,
recipient Address, sender Address, value Hash, input []byte, gas int64, depth int,
static bool, salt Hash, codeAddress Address) (output []byte, gasLeft int64, createAddr Address, err error)
AccessAccount(addr Address) AccessStatus
AccessStorage(addr Address, key Hash) AccessStatus
Expand Down Expand Up @@ -207,7 +207,7 @@ func call(pCtx unsafe.Pointer, msg *C.struct_evmc_message) C.struct_evmc_result
ctx := getHostContext(uintptr(pCtx))

kind := CallKind(msg.kind)
output, gasLeft, createAddr, err := ctx.Call(kind, goAddress(msg.destination), goAddress(msg.sender), goHash(msg.value),
output, gasLeft, createAddr, err := ctx.Call(kind, goAddress(msg.recipient), goAddress(msg.sender), goHash(msg.value),
goByteSlice(msg.input_data, msg.input_size), int64(msg.gas), int(msg.depth), msg.flags != 0, goHash(msg.create2_salt),
goAddress(msg.code_address))

Expand Down
2 changes: 1 addition & 1 deletion bindings/go/evmc/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (host *testHostContext) EmitLog(addr Address, topics []Hash, data []byte) {
}

func (host *testHostContext) Call(kind CallKind,
destination Address, sender Address, value Hash, input []byte, gas int64, depth int,
recipient Address, sender Address, value Hash, input []byte, gas int64, depth int,
static bool, salt Hash, codeAddress Address) (output []byte, gasLeft int64, createAddr Address, err error) {
output = []byte("output from testHostContext.Call()")
return output, gas, Address{}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public interface HostContext {
* <p>This function is used by a VM to update the given account storage entry. The VM MUST make
* sure that the account exists. This requirement is only a formality because VM implementations
* only modify storage of the account of the current execution context (i.e. referenced by
* evmc_message::destination).
* evmc_message::recipient).
*
* @param address The address of the account.
* @param key The index of the storage entry.
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/evmc-vm/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod tests {
flags: 0,
depth: 0,
gas: 0,
destination: ::evmc_sys::evmc_address::default(),
recipient: ::evmc_sys::evmc_address::default(),
sender: ::evmc_sys::evmc_address::default(),
input_data: std::ptr::null(),
input_size: 0,
Expand Down
34 changes: 17 additions & 17 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct ExecutionMessage {
flags: u32,
depth: i32,
gas: i64,
destination: Address,
recipient: Address,
sender: Address,
input: Option<Vec<u8>>,
value: Uint256,
Expand Down Expand Up @@ -122,7 +122,7 @@ impl ExecutionMessage {
flags: u32,
depth: i32,
gas: i64,
destination: Address,
recipient: Address,
sender: Address,
input: Option<&[u8]>,
value: Uint256,
Expand All @@ -134,7 +134,7 @@ impl ExecutionMessage {
flags,
depth,
gas,
destination,
recipient,
sender,
input: if let Some(input) = input {
Some(input.to_vec())
Expand Down Expand Up @@ -167,9 +167,9 @@ impl ExecutionMessage {
self.gas
}

/// Read the destination address of the message.
pub fn destination(&self) -> &Address {
&self.destination
/// Read the recipient address of the message.
pub fn recipient(&self) -> &Address {
&self.recipient
}

/// Read the sender address of the message.
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<'a> ExecutionContext<'a> {
flags: message.flags(),
depth: message.depth(),
gas: message.gas(),
destination: *message.destination(),
recipient: *message.recipient(),
sender: *message.sender(),
input_data: input_data,
input_size: input_size,
Expand Down Expand Up @@ -492,7 +492,7 @@ impl From<&ffi::evmc_message> for ExecutionMessage {
flags: message.flags,
depth: message.depth,
gas: message.gas,
destination: message.destination,
recipient: message.recipient,
sender: message.sender,
input: if message.input_data.is_null() {
assert_eq!(message.input_size, 0);
Expand Down Expand Up @@ -659,7 +659,7 @@ mod tests {
#[test]
fn message_new_with_input() {
let input = vec![0xc0, 0xff, 0xee];
let destination = Address { bytes: [32u8; 20] };
let recipient = Address { bytes: [32u8; 20] };
let sender = Address { bytes: [128u8; 20] };
let value = Uint256 { bytes: [0u8; 32] };
let create2_salt = Bytes32 { bytes: [255u8; 32] };
Expand All @@ -670,7 +670,7 @@ mod tests {
44,
66,
4466,
destination,
recipient,
sender,
Some(&input),
value,
Expand All @@ -682,7 +682,7 @@ mod tests {
assert_eq!(ret.flags(), 44);
assert_eq!(ret.depth(), 66);
assert_eq!(ret.gas(), 4466);
assert_eq!(*ret.destination(), destination);
assert_eq!(*ret.recipient(), recipient);
assert_eq!(*ret.sender(), sender);
assert!(ret.input().is_some());
assert_eq!(*ret.input().unwrap(), input);
Expand All @@ -693,7 +693,7 @@ mod tests {

#[test]
fn message_from_ffi() {
let destination = Address { bytes: [32u8; 20] };
let recipient = Address { bytes: [32u8; 20] };
let sender = Address { bytes: [128u8; 20] };
let value = Uint256 { bytes: [0u8; 32] };
let create2_salt = Bytes32 { bytes: [255u8; 32] };
Expand All @@ -704,7 +704,7 @@ mod tests {
flags: 44,
depth: 66,
gas: 4466,
destination: destination,
recipient: recipient,
sender: sender,
input_data: std::ptr::null(),
input_size: 0,
Expand All @@ -719,7 +719,7 @@ mod tests {
assert_eq!(ret.flags(), msg.flags);
assert_eq!(ret.depth(), msg.depth);
assert_eq!(ret.gas(), msg.gas);
assert_eq!(*ret.destination(), msg.destination);
assert_eq!(*ret.recipient(), msg.recipient);
assert_eq!(*ret.sender(), msg.sender);
assert!(ret.input().is_none());
assert_eq!(*ret.value(), msg.value);
Expand All @@ -730,7 +730,7 @@ mod tests {
#[test]
fn message_from_ffi_with_input() {
let input = vec![0xc0, 0xff, 0xee];
let destination = Address { bytes: [32u8; 20] };
let recipient = Address { bytes: [32u8; 20] };
let sender = Address { bytes: [128u8; 20] };
let value = Uint256 { bytes: [0u8; 32] };
let create2_salt = Bytes32 { bytes: [255u8; 32] };
Expand All @@ -741,7 +741,7 @@ mod tests {
flags: 44,
depth: 66,
gas: 4466,
destination: destination,
recipient: recipient,
sender: sender,
input_data: input.as_ptr(),
input_size: input.len(),
Expand All @@ -756,7 +756,7 @@ mod tests {
assert_eq!(ret.flags(), msg.flags);
assert_eq!(ret.depth(), msg.depth);
assert_eq!(ret.gas(), msg.gas);
assert_eq!(*ret.destination(), msg.destination);
assert_eq!(*ret.recipient(), msg.recipient);
assert_eq!(*ret.sender(), msg.sender);
assert!(ret.input().is_some());
assert_eq!(*ret.input().unwrap(), input);
Expand Down
4 changes: 2 additions & 2 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char* argv[])
struct evmc_message msg;
msg.kind = EVMC_CALL;
msg.sender = addr;
msg.destination = addr;
msg.recipient = addr;
msg.value = value;
msg.input_data = input;
msg.input_size = sizeof(input);
Expand All @@ -78,7 +78,7 @@ int main(int argc, char* argv[])
printf("%02x", result.output_data[i]);
printf("\n");
const evmc_bytes32 storage_key = {{0}};
evmc_bytes32 storage_value = host->get_storage(ctx, &msg.destination, &storage_key);
evmc_bytes32 storage_value = host->get_storage(ctx, &msg.recipient, &storage_key);
printf(" Storage at 0x00..00: ");
for (i = 0; i < sizeof(storage_value.bytes) / sizeof(storage_value.bytes[0]); i++)
printf("%02x", storage_value.bytes[i]);
Expand Down
8 changes: 4 additions & 4 deletions examples/example_vm/example_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ evmc_result execute(evmc_vm* instance,

case OP_ADDRESS:
{
evmc_uint256be value = to_uint256(msg->destination);
evmc_uint256be value = to_uint256(msg->recipient);
stack.push(value);
break;
}
Expand Down Expand Up @@ -242,7 +242,7 @@ evmc_result execute(evmc_vm* instance,
case OP_SLOAD:
{
evmc_uint256be index = stack.pop();
evmc_uint256be value = host->get_storage(context, &msg->destination, &index);
evmc_uint256be value = host->get_storage(context, &msg->recipient, &index);
stack.push(value);
break;
}
Expand All @@ -251,7 +251,7 @@ evmc_result execute(evmc_vm* instance,
{
evmc_uint256be index = stack.pop();
evmc_uint256be value = stack.pop();
host->set_storage(context, &msg->destination, &index, &value);
host->set_storage(context, &msg->recipient, &index, &value);
break;
}

Expand Down Expand Up @@ -316,7 +316,7 @@ evmc_result execute(evmc_vm* instance,
{
evmc_message call_msg = {};
call_msg.gas = to_uint32(stack.pop());
call_msg.destination = to_address(stack.pop());
call_msg.recipient = to_address(stack.pop());
call_msg.value = stack.pop();

uint32_t call_input_offset = to_uint32(stack.pop());
Expand Down
6 changes: 3 additions & 3 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ struct evmc_message
*
* Defined as `r` in the Yellow Paper.
*/
evmc_address destination;
evmc_address recipient;

/**
* The sender of the message.
Expand Down Expand Up @@ -177,7 +177,7 @@ struct evmc_message
* The address of the code to be executed.
*
* For ::EVMC_CALLCODE or ::EVMC_DELEGATECALL this may be different from
* the evmc_message::destination (recipient).
* the evmc_message::recipient.
* Not required when invoking evmc_execute_fn(), only when invoking evmc_call_fn().
* Ignored if kind is ::EVMC_CREATE or ::EVMC_CREATE2.
*
Expand Down Expand Up @@ -542,7 +542,7 @@ enum evmc_storage_status
* This callback function is used by a VM to update the given account storage entry.
* The VM MUST make sure that the account exists. This requirement is only a formality because
* VM implementations only modify storage of the account of the current execution context
* (i.e. referenced by evmc_message::destination).
* (i.e. referenced by evmc_message::recipient).
*
* @param context The pointer to the Host execution context.
* @param address The address of the account.
Expand Down
4 changes: 2 additions & 2 deletions include/evmc/mocked_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class MockedHost : public Host
/// Call/create other contract (EVMC host method).
result call(const evmc_message& msg) noexcept override
{
record_account_access(msg.destination);
record_account_access(msg.recipient);

if (recorded_calls.empty())
{
Expand Down Expand Up @@ -327,7 +327,7 @@ class MockedHost : public Host
/// This method is required by EIP-2929 introduced in ::EVMC_BERLIN. It will record the account
/// access in MockedHost::recorded_account_accesses and return previous access status.
/// This methods returns ::EVMC_ACCESS_WARM for known addresses of precompiles.
/// The EIP-2929 specifies that evmc_message::sender and evmc_message::destination are always
/// The EIP-2929 specifies that evmc_message::sender and evmc_message::recipient are always
/// ::EVMC_ACCESS_WARM. Therefore, you should init the MockedHost with:
///
/// mocked_host.access_account(msg.sender);
Expand Down
4 changes: 2 additions & 2 deletions lib/tooling/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int run(evmc::VM& vm,
{
evmc_message create_msg{};
create_msg.kind = EVMC_CREATE;
create_msg.destination = create_address;
create_msg.recipient = create_address;
create_msg.gas = create_gas;

const auto create_result = vm.execute(host, rev, create_msg, code.data(), code.size());
Expand All @@ -99,7 +99,7 @@ int run(evmc::VM& vm,
auto& created_account = host.accounts[create_address];
created_account.code = bytes(create_result.output_data, create_result.output_size);

msg.destination = create_address;
msg.recipient = create_address;
exec_code = created_account.code;
}
out << "\n";
Expand Down
6 changes: 3 additions & 3 deletions test/unittests/example_vm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class example_vm : public testing::Test
example_vm() noexcept
{
msg.sender = 0x5000000000000000000000000000000000000005_address;
msg.destination = 0xd00000000000000000000000000000000000000d_address;
msg.recipient = 0xd00000000000000000000000000000000000000d_address;
}

evmc::result execute_in_example_vm(int64_t gas,
Expand Down Expand Up @@ -90,7 +90,7 @@ TEST_F(example_vm, return_address)
TEST_F(example_vm, counter_in_storage)
{
// Yul: sstore(0, add(sload(0), 1)) stop()
auto& storage_value = host.accounts[msg.destination].storage[{}].value;
auto& storage_value = host.accounts[msg.recipient].storage[{}].value;
storage_value = 0x00000000000000000000000000000000000000000000000000000000000000bb_bytes32;
const auto r = execute_in_example_vm(10, "60016000540160005500");
EXPECT_EQ(r.status_code, EVMC_SUCCESS);
Expand Down Expand Up @@ -162,7 +162,7 @@ TEST_F(example_vm, call)
EXPECT_EQ(host.recorded_calls[0].gas, 3);
EXPECT_EQ(host.recorded_calls[0].value,
0x0000000000000000000000000000000000000000000000000000000000000003_bytes32);
EXPECT_EQ(host.recorded_calls[0].destination,
EXPECT_EQ(host.recorded_calls[0].recipient,
0x0000000000000000000000000000000000000003_address);
EXPECT_EQ(host.recorded_calls[0].input_size, size_t{3});
}
Expand Down

0 comments on commit 203b639

Please sign in to comment.