From 9badaa3bc06bf59953e6c11f17e1cd0d3d74b208 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Thu, 21 Nov 2024 17:31:53 +0100 Subject: [PATCH] Add get_delegate_address() host function --- include/evmc/evmc.h | 20 ++++++++++++++++++++ include/evmc/evmc.hpp | 14 ++++++++++++++ include/evmc/mocked_host.hpp | 7 +++++++ 3 files changed, 41 insertions(+) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 4fc513f7a..5849a5b28 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -834,6 +834,23 @@ typedef enum evmc_access_status (*evmc_access_storage_fn)(struct evmc_host_conte typedef struct evmc_result (*evmc_call_fn)(struct evmc_host_context* context, const struct evmc_message* msg); +/** + * Get delegate address function. + * + * This callback function is used by a VM to get target address of EIP-7702 delegation designation, + * in case it is set for given account. + * If account's code does not contain delegation designation, this function returns address + * 0x0000000000000000000000000000000000000000. + * + * @param context The pointer to the Host execution context. + * @param address The address of the account. + * @return The address of delegation designation target account + * or 0 if delegation is not set. + */ +typedef evmc_address (*evmc_get_delegate_address_fn)(struct evmc_host_context* context, + const evmc_address* address); + + /** * The Host interface. * @@ -891,6 +908,9 @@ struct evmc_host_interface /** Set transient storage callback function. */ evmc_set_transient_storage_fn set_transient_storage; + + /** Get delegate address function. */ + evmc_get_delegate_address_fn get_delegate_address; }; diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index 2dfabf826..2104d80ad 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -499,6 +499,9 @@ class HostInterface virtual void set_transient_storage(const address& addr, const bytes32& key, const bytes32& value) noexcept = 0; + + /// @copydoc evmc_host_interface::get_delegate_address + virtual address get_delegate_address(const address& addr) const noexcept = 0; }; @@ -609,6 +612,11 @@ class HostContext : public HostInterface { host->set_transient_storage(context, &address, &key, &value); } + + address get_delegate_address(const address& address) const noexcept final + { + return host->get_delegate_address(context, &address); + } }; @@ -877,6 +885,11 @@ inline void set_transient_storage(evmc_host_context* h, { Host::from_context(h)->set_transient_storage(*addr, *key, *value); } + +inline evmc_address get_delegate_address(evmc_host_context* h, const evmc_address* addr) noexcept +{ + return Host::from_context(h)->get_delegate_address(*addr); +} } // namespace internal inline const evmc_host_interface& Host::get_interface() noexcept @@ -898,6 +911,7 @@ inline const evmc_host_interface& Host::get_interface() noexcept ::evmc::internal::access_storage, ::evmc::internal::get_transient_storage, ::evmc::internal::set_transient_storage, + ::evmc::internal::get_delegate_address, }; return interface; } diff --git a/include/evmc/mocked_host.hpp b/include/evmc/mocked_host.hpp index 8aad17c46..7147b2377 100644 --- a/include/evmc/mocked_host.hpp +++ b/include/evmc/mocked_host.hpp @@ -507,5 +507,12 @@ class MockedHost : public Host record_account_access(addr); accounts[addr].transient_storage[key] = value; } + + /// Get account's delegate address. + address get_delegate_address(const address& addr) const noexcept override + { + record_account_access(addr); + return {}; + } }; } // namespace evmc