-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor EIP-7702: delegation resolution in EVM instead of host function
- Loading branch information
Showing
8 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
Submodule evmc
updated
5 files
+0 −2 | examples/example_host.cpp | |
+0 −20 | include/evmc/evmc.h | |
+0 −14 | include/evmc/evmc.hpp | |
+0 −7 | include/evmc/mocked_host.hpp | |
+0 −5 | test/unittests/cpp_test.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2025 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#pragma once | ||
|
||
#include <evmc/bytes.hpp> | ||
#include <evmc/evmc.hpp> | ||
#include <cassert> | ||
|
||
namespace evmone | ||
{ | ||
using evmc::bytes_view; | ||
|
||
/// Prefix of code for delegated accounts | ||
/// defined by [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) | ||
constexpr uint8_t DELEGATION_MAGIC_BYTES[] = {0xef, 0x01, 0x00}; | ||
constexpr bytes_view DELEGATION_MAGIC{DELEGATION_MAGIC_BYTES, std::size(DELEGATION_MAGIC_BYTES)}; | ||
|
||
/// Check if code contains EIP-7702 delegation designator | ||
inline constexpr bool is_code_delegated(bytes_view code) noexcept | ||
{ | ||
return code.starts_with(DELEGATION_MAGIC); | ||
} | ||
|
||
/// Get EIP-7702 delegate address from the code of addr, if it is delegated. | ||
inline std::optional<evmc::address> get_delegate_address( | ||
const evmc::address& addr, const evmc::HostInterface& host) noexcept | ||
{ | ||
uint8_t prefix[std::size(DELEGATION_MAGIC)] = {}; | ||
host.copy_code(addr, 0, prefix, std::size(prefix)); | ||
|
||
if (!is_code_delegated(bytes_view{prefix, std::size(prefix)})) | ||
return {}; | ||
|
||
evmc::address delegate_address; | ||
assert(host.get_code_size(addr) == | ||
std::size(DELEGATION_MAGIC) + std::size(delegate_address.bytes)); | ||
host.copy_code( | ||
addr, std::size(prefix), delegate_address.bytes, std::size(delegate_address.bytes)); | ||
return delegate_address; | ||
} | ||
} // namespace evmone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters