Skip to content

Commit

Permalink
rust: Add support for EIP-2929
Browse files Browse the repository at this point in the history
Implement Rust bindings for access_account() and access_storage()
Host methods.
  • Loading branch information
yperbasis authored and chfast committed Apr 12, 2021
1 parent aaa5065 commit 4f57405
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bindings/rust/evmc-vm/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ mod tests {
get_tx_context: Some(get_dummy_tx_context),
get_block_hash: None,
emit_log: None,
access_account: None,
access_storage: None,
};
let host_context = std::ptr::null_mut();

Expand Down
22 changes: 22 additions & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,26 @@ impl<'a> ExecutionContext<'a> {
)
}
}

/// Access an account.
pub fn access_account(&mut self, address: &Address) -> AccessStatus {
unsafe {
assert!((*self.host).access_account.is_some());
(*self.host).access_account.unwrap()(self.context, address as *const Address)
}
}

/// Access a storage key.
pub fn access_storage(&mut self, address: &Address, key: &Bytes32) -> AccessStatus {
unsafe {
assert!((*self.host).access_storage.is_some());
(*self.host).access_storage.unwrap()(
self.context,
address as *const Address,
key as *const Bytes32,
)
}
}
}

impl From<ffi::evmc_result> for ExecutionResult {
Expand Down Expand Up @@ -793,6 +813,8 @@ mod tests {
get_tx_context: Some(get_dummy_tx_context),
get_block_hash: None,
emit_log: None,
access_account: None,
access_storage: None,
}
}

Expand Down
15 changes: 15 additions & 0 deletions bindings/rust/evmc-vm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub type MessageFlags = ffi::evmc_flags;
/// EVMC status code.
pub type StatusCode = ffi::evmc_status_code;

/// EVMC access status.
pub type AccessStatus = ffi::evmc_access_status;

/// EVMC storage status.
pub type StorageStatus = ffi::evmc_storage_status;

Expand Down Expand Up @@ -81,6 +84,18 @@ mod tests {
);
}

#[test]
fn access_status() {
assert_eq!(
AccessStatus::EVMC_ACCESS_COLD,
ffi::evmc_access_status::EVMC_ACCESS_COLD
);
assert_eq!(
AccessStatus::EVMC_ACCESS_WARM,
ffi::evmc_access_status::EVMC_ACCESS_WARM
);
}

#[test]
fn storage_status() {
assert_eq!(
Expand Down

0 comments on commit 4f57405

Please sign in to comment.