Skip to content

Commit

Permalink
Recent EVMC changes
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 21, 2022
1 parent df4a074 commit 908c356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 8 additions & 5 deletions bindings/rust/evmc-client/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub trait HostContext {
buffer_size: &usize,
) -> usize;
fn selfdestruct(&mut self, addr: &Address, beneficiary: &Address);
fn get_tx_context(&mut self) -> (Bytes32, Address, Address, i64, i64, i64, Bytes32, Bytes32);
fn get_tx_context(&mut self) -> (Bytes32, Address, Address, i64, i64, i64, Bytes32, Bytes32, Bytes32);
fn get_block_hash(&mut self, number: i64) -> Bytes32;
fn emit_log(&mut self, addr: &Address, topics: &Vec<Bytes32>, data: &Bytes);
fn call(
&mut self,
kind: MessageKind,
destination: &Address,
recipient: &Address,
sender: &Address,
value: &Bytes32,
input: &Bytes,
Expand All @@ -58,6 +58,8 @@ pub(crate) fn get_evmc_host_interface() -> ffi::evmc_host_interface {
get_tx_context: Some(get_tx_context),
get_block_hash: Some(get_block_hash),
emit_log: Some(emit_log),
access_account: None, // TODO
access_storage: None, // TODO
}
}

Expand Down Expand Up @@ -152,7 +154,7 @@ unsafe extern "C" fn selfdestruct(
}

unsafe extern "C" fn get_tx_context(context: *mut ffi::evmc_host_context) -> ffi::evmc_tx_context {
let (gas_price, origin, coinbase, number, timestamp, gas_limit, difficulty, chain_id) =
let (gas_price, origin, coinbase, number, timestamp, gas_limit, prev_randao, chain_id, base_fee) =
(*(context as *mut ExtendedContext)).hctx.get_tx_context();
return ffi::evmc_tx_context {
tx_gas_price: evmc_sys::evmc_bytes32 { bytes: gas_price },
Expand All @@ -161,8 +163,9 @@ unsafe extern "C" fn get_tx_context(context: *mut ffi::evmc_host_context) -> ffi
block_number: number,
block_timestamp: timestamp,
block_gas_limit: gas_limit,
block_difficulty: evmc_sys::evmc_bytes32 { bytes: difficulty },
block_prev_randao: evmc_sys::evmc_bytes32 { bytes: prev_randao },
chain_id: evmc_sys::evmc_bytes32 { bytes: chain_id },
block_base_fee: evmc_sys::evmc_bytes32 { bytes: base_fee },
};
}

Expand Down Expand Up @@ -211,7 +214,7 @@ pub unsafe extern "C" fn call(
let (output, gas_left, create_address, status_code) =
(*(context as *mut ExtendedContext)).hctx.call(
msg.kind,
&msg.destination.bytes,
&msg.recipient.bytes,
&msg.sender.bytes,
&msg.value.bytes,
&std::slice::from_raw_parts(msg.input_data, msg.input_size),
Expand Down
8 changes: 5 additions & 3 deletions bindings/rust/evmc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ impl EvmcVm {
is_static: bool,
depth: i32,
gas: i64,
destination: &Address,
recipient: &Address,
sender: &Address,
input: &Bytes,
value: &Bytes32,
code: &Bytes,
create2_salt: &Bytes32,
code_address: &Address,
) -> (&Bytes, i64, StatusCode) {
let ext_ctx = host::ExtendedContext { hctx: ctx };
let mut evmc_flags: u32 = 0;
Expand All @@ -77,8 +78,8 @@ impl EvmcVm {
flags: evmc_flags,
depth: depth,
gas: gas,
destination: ffi::evmc_address {
bytes: *destination,
recipient: ffi::evmc_address {
bytes: *recipient,
},
sender: ffi::evmc_address { bytes: *sender },
input_data: input.as_ptr(),
Expand All @@ -87,6 +88,7 @@ impl EvmcVm {
create2_salt: ffi::evmc_bytes32 {
bytes: *create2_salt,
},
code_address: ffi::evmc_address { bytes: *code_address },
}
}));
unsafe {
Expand Down

0 comments on commit 908c356

Please sign in to comment.