Skip to content

Commit c53afae

Browse files
committed
Bump evmc to v11.0.0
1 parent 92f383d commit c53afae

File tree

4 files changed

+139
-12
lines changed

4 files changed

+139
-12
lines changed

test/evmc/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# EVMC
22

3-
This is an import of [EVMC](https://github.com/ethereum/evmc) version [10.1.0](https://github.com/ethereum/evmc/releases/tag/v10.1.0).
3+
This is an import of [EVMC](https://github.com/ethereum/evmc) version [11.0.0](https://github.com/ethereum/evmc/releases/tag/v11.0.0).
44

5-
Important: The `MockedAccount.storage` is changed to a `map` from `unordered_map` as ordering is important for fuzzing.
5+
Steps when upgrading:
6+
* Copy all from [include/evmc](https://github.com/ethereum/evmc/tree/master/include/evmc) to [test/evmc](https://github.com/ethereum/solidity/tree/develop/test/evmc)
7+
* Note that you should delete (or not copy in the first place) `tooling.hpp` and `instructions.h`.
8+
* Copy [`loader.c`](https://github.com/ethereum/evmc/blob/master/lib/loader/loader.c) to [test/evmc](https://github.com/ethereum/solidity/tree/develop/test/evmc)
9+
* `MockedAccount.storage` in `mocked_host.hpp` should be changed to a `map` from `unordered_map` as ordering is important for fuzzing. You'll also need to include `<map>`. See [commit] for more details (https://github.com/ethereum/solidity/commit/788eb028255dc31aa108ac300dca52ad064fabf0).

test/evmc/evmc.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum
4444
*
4545
* @see @ref versioning
4646
*/
47-
EVMC_ABI_VERSION = 10
47+
EVMC_ABI_VERSION = 11
4848
};
4949

5050

@@ -202,6 +202,9 @@ struct evmc_tx_context
202202
evmc_uint256be block_prev_randao; /**< The block previous RANDAO (EIP-4399). */
203203
evmc_uint256be chain_id; /**< The blockchain's ChainID. */
204204
evmc_uint256be block_base_fee; /**< The block base fee per gas (EIP-1559, EIP-3198). */
205+
evmc_uint256be blob_base_fee; /**< The blob base fee (EIP-7516). */
206+
const evmc_bytes32* blob_hashes; /**< The array of blob hashes (EIP-4844). */
207+
size_t blob_hashes_count; /**< The number of blob hashes (EIP-4844). */
205208
};
206209

207210
/**
@@ -503,6 +506,22 @@ typedef evmc_bytes32 (*evmc_get_storage_fn)(struct evmc_host_context* context,
503506
const evmc_address* address,
504507
const evmc_bytes32* key);
505508

509+
/**
510+
* Get transient storage callback function.
511+
*
512+
* This callback function is used by a VM to query
513+
* the given account transient storage (EIP-1153) entry.
514+
*
515+
* @param context The Host execution context.
516+
* @param address The address of the account.
517+
* @param key The index of the account's transient storage entry.
518+
* @return The transient storage value at the given storage key or null bytes
519+
* if the account does not exist.
520+
*/
521+
typedef evmc_bytes32 (*evmc_get_transient_storage_fn)(struct evmc_host_context* context,
522+
const evmc_address* address,
523+
const evmc_bytes32* key);
524+
506525

507526
/**
508527
* The effect of an attempt to modify a contract storage item.
@@ -620,6 +639,25 @@ typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_host_context
620639
const evmc_bytes32* key,
621640
const evmc_bytes32* value);
622641

642+
/**
643+
* Set transient storage callback function.
644+
*
645+
* This callback function is used by a VM to update
646+
* the given account's transient storage (EIP-1153) entry.
647+
* The VM MUST make sure that the account exists. This requirement is only a formality because
648+
* VM implementations only modify storage of the account of the current execution context
649+
* (i.e. referenced by evmc_message::recipient).
650+
*
651+
* @param context The pointer to the Host execution context.
652+
* @param address The address of the account.
653+
* @param key The index of the transient storage entry.
654+
* @param value The value to be stored.
655+
*/
656+
typedef void (*evmc_set_transient_storage_fn)(struct evmc_host_context* context,
657+
const evmc_address* address,
658+
const evmc_bytes32* key,
659+
const evmc_bytes32* value);
660+
623661
/**
624662
* Get balance callback function.
625663
*
@@ -825,6 +863,12 @@ struct evmc_host_interface
825863

826864
/** Access storage callback function. */
827865
evmc_access_storage_fn access_storage;
866+
867+
/** Get transient storage callback function. */
868+
evmc_get_transient_storage_fn get_transient_storage;
869+
870+
/** Set transient storage callback function. */
871+
evmc_set_transient_storage_fn set_transient_storage;
828872
};
829873

830874

test/evmc/evmc.hpp

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,15 @@ class HostInterface
493493

494494
/// @copydoc evmc_host_interface::access_storage
495495
virtual evmc_access_status access_storage(const address& addr, const bytes32& key) noexcept = 0;
496+
497+
/// @copydoc evmc_host_interface::get_transient_storage
498+
virtual bytes32 get_transient_storage(const address& addr,
499+
const bytes32& key) const noexcept = 0;
500+
501+
/// @copydoc evmc_host_interface::set_transient_storage
502+
virtual void set_transient_storage(const address& addr,
503+
const bytes32& key,
504+
const bytes32& value) noexcept = 0;
496505
};
497506

498507

@@ -591,6 +600,18 @@ class HostContext : public HostInterface
591600
{
592601
return host->access_storage(context, &address, &key);
593602
}
603+
604+
bytes32 get_transient_storage(const address& address, const bytes32& key) const noexcept final
605+
{
606+
return host->get_transient_storage(context, &address, &key);
607+
}
608+
609+
void set_transient_storage(const address& address,
610+
const bytes32& key,
611+
const bytes32& value) noexcept final
612+
{
613+
host->set_transient_storage(context, &address, &key, &value);
614+
}
594615
};
595616

596617

@@ -844,18 +865,42 @@ inline evmc_access_status access_storage(evmc_host_context* h,
844865
{
845866
return Host::from_context(h)->access_storage(*addr, *key);
846867
}
868+
869+
inline evmc_bytes32 get_transient_storage(evmc_host_context* h,
870+
const evmc_address* addr,
871+
const evmc_bytes32* key) noexcept
872+
{
873+
return Host::from_context(h)->get_transient_storage(*addr, *key);
874+
}
875+
876+
inline void set_transient_storage(evmc_host_context* h,
877+
const evmc_address* addr,
878+
const evmc_bytes32* key,
879+
const evmc_bytes32* value) noexcept
880+
{
881+
Host::from_context(h)->set_transient_storage(*addr, *key, *value);
882+
}
847883
} // namespace internal
848884

849885
inline const evmc_host_interface& Host::get_interface() noexcept
850886
{
851887
static constexpr evmc_host_interface interface = {
852-
::evmc::internal::account_exists, ::evmc::internal::get_storage,
853-
::evmc::internal::set_storage, ::evmc::internal::get_balance,
854-
::evmc::internal::get_code_size, ::evmc::internal::get_code_hash,
855-
::evmc::internal::copy_code, ::evmc::internal::selfdestruct,
856-
::evmc::internal::call, ::evmc::internal::get_tx_context,
857-
::evmc::internal::get_block_hash, ::evmc::internal::emit_log,
858-
::evmc::internal::access_account, ::evmc::internal::access_storage,
888+
::evmc::internal::account_exists,
889+
::evmc::internal::get_storage,
890+
::evmc::internal::set_storage,
891+
::evmc::internal::get_balance,
892+
::evmc::internal::get_code_size,
893+
::evmc::internal::get_code_hash,
894+
::evmc::internal::copy_code,
895+
::evmc::internal::selfdestruct,
896+
::evmc::internal::call,
897+
::evmc::internal::get_tx_context,
898+
::evmc::internal::get_block_hash,
899+
::evmc::internal::emit_log,
900+
::evmc::internal::access_account,
901+
::evmc::internal::access_storage,
902+
::evmc::internal::get_transient_storage,
903+
::evmc::internal::set_transient_storage,
859904
};
860905
return interface;
861906
}

test/evmc/mocked_host.hpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct MockedAccount
6363
/// The account storage map.
6464
std::map<bytes32, StorageValue> storage;
6565

66+
/// The account transient storage.
67+
std::unordered_map<bytes32, bytes32> transient_storage;
68+
6669
/// Helper method for setting balance by numeric type.
6770
void set_balance(uint64_t x) noexcept
6871
{
@@ -467,8 +470,7 @@ class MockedHost : public Host
467470
///
468471
/// @param addr The account address.
469472
/// @param key The account's storage key.
470-
/// @return The ::EVMC_ACCESS_WARM if the storage key has been accessed
471-
/// before,
473+
/// @return The ::EVMC_ACCESS_WARM if the storage key has been accessed before,
472474
/// the ::EVMC_ACCESS_COLD otherwise.
473475
evmc_access_status access_storage(const address& addr, const bytes32& key) noexcept override
474476
{
@@ -477,5 +479,37 @@ class MockedHost : public Host
477479
value.access_status = EVMC_ACCESS_WARM;
478480
return access_status;
479481
}
482+
483+
/// Get account's transient storage.
484+
///
485+
/// @param addr The account address.
486+
/// @param key The account's transient storage key.
487+
/// @return The transient storage value. Null value in case the account does not exist.
488+
bytes32 get_transient_storage(const address& addr, const bytes32& key) const noexcept override
489+
{
490+
record_account_access(addr);
491+
492+
const auto account_iter = accounts.find(addr);
493+
if (account_iter == accounts.end())
494+
return {};
495+
496+
const auto storage_iter = account_iter->second.transient_storage.find(key);
497+
if (storage_iter != account_iter->second.transient_storage.end())
498+
return storage_iter->second;
499+
return {};
500+
}
501+
502+
/// Set account's transient storage.
503+
///
504+
/// @param addr The account address.
505+
/// @param key The account's transient storage key.
506+
/// @param value The value to be stored.
507+
void set_transient_storage(const address& addr,
508+
const bytes32& key,
509+
const bytes32& value) noexcept override
510+
{
511+
record_account_access(addr);
512+
accounts[addr].transient_storage[key] = value;
513+
}
480514
};
481515
} // namespace evmc

0 commit comments

Comments
 (0)