Skip to content

Commit

Permalink
Rename evmc_message::{destination -> recipient}
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Sep 8, 2021
1 parent ef00d72 commit 5766c9f
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 64 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
24 changes: 12 additions & 12 deletions bindings/java/java/src/test/java/org/ethereum/evmc/EvmcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ void testExecute_returnAddress() throws Exception {
int EVMC_CALL = 0;
int kind = EVMC_CALL;
char[] sender = "39bf71de1b7d7be3b51\0".toCharArray();
char[] destination = "53cf77204eEef952e25\0".toCharArray();
char[] recipient = "53cf77204eEef952e25\0".toCharArray();
char[] value = "1\0".toCharArray();
char[] inputData = "hello w\0".toCharArray();
long gas = 200000;
int depth = 0;
ByteBuffer msg =
new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer();
new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer();

byte[] code = {0x30, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3}; // return_address
ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code);
Expand All @@ -98,13 +98,13 @@ void testExecute_counter() throws Exception {
int EVMC_CALL = 0;
int kind = EVMC_CALL;
char[] sender = "39bf71de1b7d7be3b51\0".toCharArray();
char[] destination = "53cf77204eEef952e25\0".toCharArray();
char[] recipient = "53cf77204eEef952e25\0".toCharArray();
char[] value = "1\0".toCharArray();
char[] inputData = "hello w\0".toCharArray();
long gas = 200000;
int depth = 0;
ByteBuffer msg =
new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer();
new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer();

byte[] code = {0x60, 0x01, 0x60, 0x00, 0x54, 0x01, 0x60, 0x00, 0x55}; // counter
ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code);
Expand All @@ -128,13 +128,13 @@ void testExecute_returnBlockNumber() throws Exception {
int EVMC_CALL = 0;
int kind = EVMC_CALL;
char[] sender = "39bf71de1b7d7be3b51\0".toCharArray();
char[] destination = "53cf77204eEef952e25\0".toCharArray();
char[] recipient = "53cf77204eEef952e25\0".toCharArray();
char[] value = "1\0".toCharArray();
char[] inputData = "hello w\0".toCharArray();
long gas = 200000;
int depth = 0;
ByteBuffer msg =
new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer();
new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer();

byte[] code = {0x43, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3}; // return_block_number(
ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code);
Expand All @@ -158,13 +158,13 @@ void testExecute_saveReturnBlockNumber() throws Exception {
int EVMC_CALL = 0;
int kind = EVMC_CALL;
char[] sender = "39bf71de1b7d7be3b51\0".toCharArray();
char[] destination = "53cf77204eEef952e25\0".toCharArray();
char[] recipient = "53cf77204eEef952e25\0".toCharArray();
char[] value = "1\0".toCharArray();
char[] inputData = "hello w\0".toCharArray();
long gas = 200000;
int depth = 0;
ByteBuffer msg =
new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer();
new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer();

byte[] code = {
0x43, 0x60, 0x00, 0x55, 0x43, 0x60, 0x00, 0x52, 0x59, 0x60, 0x00, (byte) 0xf3
Expand All @@ -190,13 +190,13 @@ void testExecute_makeCall() throws Exception {
int EVMC_CALL = 0;
int kind = EVMC_CALL;
char[] sender = "39bf71de1b7d7be3b51\0".toCharArray();
char[] destination = "53cf77204eEef952e25\0".toCharArray();
char[] recipient = "53cf77204eEef952e25\0".toCharArray();
char[] value = "1\0".toCharArray();
char[] inputData = "hello w\0".toCharArray();
long gas = 200000;
int depth = 0;
ByteBuffer msg =
new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer();
new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer();
byte[] code = {
0x60,
0x00,
Expand Down Expand Up @@ -228,13 +228,13 @@ void testExecute_EVMC_CREATE() throws Exception {
int EVMC_CREATE = 3;
int kind = EVMC_CREATE;
char[] sender = "39bf71de1b7d7be3b51\\0".toCharArray();
char[] destination = "53cf77204eEef952e25\0".toCharArray();
char[] recipient = "53cf77204eEef952e25\0".toCharArray();
char[] value = "1\0".toCharArray();
char[] inputData = "hello w\0".toCharArray();
long gas = 200000;
int depth = 0;
ByteBuffer msg =
new TestMessage(kind, sender, destination, value, inputData, gas, depth).toByteBuffer();
new TestMessage(kind, sender, recipient, value, inputData, gas, depth).toByteBuffer();
byte[] code = {0x00};
ByteBuffer bbcode = ByteBuffer.allocateDirect(code.length).put(code);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TestMessage {
int flags;
int depth;
long gas;
char[] destination;
char[] recipient;
char[] sender;
char[] inputData;
long inputSize;
Expand All @@ -24,7 +24,7 @@ public class TestMessage {
public TestMessage(
int kind,
char[] sender,
char[] destination,
char[] recipient,
char[] value,
char[] inputData,
long gas,
Expand All @@ -33,7 +33,7 @@ public TestMessage(
this.flags = 0;
this.depth = depth;
this.gas = gas;
this.destination = destination;
this.recipient = recipient;
this.sender = sender;
this.inputData = inputData;
this.inputSize = (long) inputData.length;
Expand All @@ -49,7 +49,7 @@ public TestMessage(ByteBuffer msg) {
msg.getInt(); // padding
this.gas = msg.getLong();
ByteBuffer tmpbuf = msg.get(new byte[20]);
this.destination = StandardCharsets.ISO_8859_1.decode(tmpbuf).array();
this.recipient = StandardCharsets.ISO_8859_1.decode(tmpbuf).array();
tmpbuf = msg.get(new byte[20]);
this.sender = StandardCharsets.ISO_8859_1.decode(tmpbuf).array();
tmpbuf = msg.get(new byte[8]);
Expand All @@ -70,7 +70,7 @@ public ByteBuffer toByteBuffer() {
.putInt(depth) // 4
.put(new byte[4]) // 4 (padding)
.putLong(gas) // 8
.put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(destination))) // 20
.put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(recipient))) // 20
.put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(sender))) // 20
.put(StandardCharsets.ISO_8859_1.encode(CharBuffer.wrap(inputData))) // 8
.putLong(inputSize) // 8
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
2 changes: 1 addition & 1 deletion examples/example-rust-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl EvmcVm for ExampleRustVM {
let storage_key = Bytes32::default();
let mut storage_value = Bytes32::default();
storage_value.bytes[31] = block_number;
_context.set_storage(&message.destination(), &storage_key, &storage_value);
_context.set_storage(&message.recipient(), &storage_key, &storage_value);

let ret = format!("{}", block_number).into_bytes();
ExecutionResult::success(message.gas() / 2, Some(&ret))
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
Loading

0 comments on commit 5766c9f

Please sign in to comment.