Skip to content

Commit 44863a1

Browse files
committed
Duct-tape get_tx_initcode_by_hash() with get_initcode_validity()
1 parent 5543aae commit 44863a1

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

lib/evmone/execution_state.hpp

+3-16
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class ExecutionState
236236
/// Get initcode by its hash from transaction initcodes.
237237
///
238238
/// Returns empty bytes_view if no such initcode was found.
239-
[[nodiscard]] bytes_view get_tx_initcode_by_hash(const evmc_bytes32& hash) noexcept
239+
[[nodiscard]] TransactionInitcode get_tx_initcode_by_hash(const evmc_bytes32& hash) noexcept
240240
{
241241
if (!m_initcodes.has_value())
242242
{
@@ -251,26 +251,13 @@ class ExecutionState
251251
}
252252

253253
const auto it = m_initcodes->find(hash);
254-
return it != m_initcodes->end() ? it->second.code : bytes_view{};
255-
}
256-
257-
/// Get validity of initcode from transaction initcodes by its hash.
258-
///
259-
/// Returns std::nullopt if no such initcode was validated yet.
260-
[[nodiscard]] std::optional<bool> get_initcode_validity(const evmc_bytes32& hash) noexcept
261-
{
262-
if (!m_initcodes.has_value())
263-
return std::nullopt;
264-
265-
const auto it = m_initcodes->find(hash);
266-
return (it != m_initcodes->end() ? it->second.is_valid : std::nullopt);
254+
return it != m_initcodes->end() ? it->second : TransactionInitcode{};
267255
}
268256

269257
/// Set validity of initcode from transaction initcodes.
270258
void set_initcode_validity(const evmc_bytes32& hash, bool is_valid)
271259
{
272-
if (!m_initcodes.has_value())
273-
return;
260+
assert(m_initcodes.has_value());
274261

275262
(*m_initcodes)[hash].is_valid = is_valid;
276263
}

lib/evmone/instructions_calls.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,16 @@ Result create_eof_impl(
424424
}
425425
else
426426
{
427-
initcontainer = state.get_tx_initcode_by_hash(initcode_hash);
428-
// In case initcode was not found, empty bytes_view was returned.
427+
const auto tx_initcode = state.get_tx_initcode_by_hash(initcode_hash);
428+
// In case initcode was not found, empty tx_initcode.data was returned.
429429
// Transaction initcodes are not allowed to be empty.
430-
if (initcontainer.empty())
430+
if (tx_initcode.code.empty())
431431
return {EVMC_SUCCESS, gas_left}; // "Light" failure
432+
initcontainer = tx_initcode.code;
432433

433-
const auto validity = state.get_initcode_validity(initcode_hash);
434434
bool is_valid = false;
435-
if (validity.has_value())
436-
is_valid = *validity;
435+
if (tx_initcode.is_valid.has_value())
436+
is_valid = *tx_initcode.is_valid;
437437
else
438438
{
439439
const auto error_subcont =

0 commit comments

Comments
 (0)