Skip to content

Commit

Permalink
Add get_delegate_address() host function
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jan 10, 2025
1 parent 37b0084 commit 3845070
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/example_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ class ExampleHost : public evmc::Host
{
accounts[addr].transient_storage[key] = value;
}

evmc::address get_delegate_address(const evmc::address&) const noexcept override { return {}; }
};


Expand Down
20 changes: 20 additions & 0 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
};


Expand Down
14 changes: 14 additions & 0 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down Expand Up @@ -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);
}
};


Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions include/evmc/mocked_host.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions test/unittests/cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class NullHost : public evmc::Host
const evmc::bytes32& /*key*/,
const evmc::bytes32& /*value*/) noexcept override
{}

evmc::address get_delegate_address(const evmc::address& addr) const noexcept override
{
return {};
}
};

TEST(cpp, address)
Expand Down

0 comments on commit 3845070

Please sign in to comment.