Skip to content

Commit 5c139b6

Browse files
authored
Merge pull request #13694 from ethereum/evmhost_set_storage
test: Improve precision of SSTORE cost in EVMHost
2 parents bbb9eb3 + 4830194 commit 5c139b6

9 files changed

+41
-50
lines changed

test/EVMHost.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void EVMHost::newTransactionFrame()
179179
for (auto& [slot, value]: account.storage)
180180
{
181181
value.access_status = EVMC_ACCESS_COLD; // Clear EIP-2929 storage access indicator
182-
value.dirty = false; // Clear EIP-2200 dirty slot flag
182+
value.original = value.current; // Clear EIP-2200 dirty slot
183183
}
184184
// Process selfdestruct list
185185
for (auto& [address, _]: recorded_selfdestructs)
@@ -1195,7 +1195,7 @@ void EVMHostPrinter::storage()
11951195
m_stateStream << " "
11961196
<< m_host.convertFromEVMC(slot)
11971197
<< ": "
1198-
<< m_host.convertFromEVMC(value.value)
1198+
<< m_host.convertFromEVMC(value.current)
11991199
<< endl;
12001200
}
12011201

test/ExecutionFramework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ bool ExecutionFramework::storageEmpty(h160 const& _addr) const
282282
if (it != m_evmcHost->accounts.end())
283283
{
284284
for (auto const& entry: it->second.storage)
285-
if (!(entry.second.value == evmc::bytes32{}))
285+
if (entry.second.current != evmc::bytes32{})
286286
return false;
287287
}
288288
return true;

test/evmc/mocked_host.hpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,20 @@ namespace evmc
1515
/// The string of bytes.
1616
using bytes = std::basic_string<uint8_t>;
1717

18-
/// Extended value (by dirty flag) for account storage.
18+
/// Extended value (with original value and access flag) for account storage.
1919
struct storage_value
2020
{
21-
/// The storage value.
22-
bytes32 value;
21+
/// The current storage value.
22+
bytes32 current;
2323

24-
/// True means this value has been modified already by the current transaction.
25-
bool dirty{false};
24+
/// The original storage value.
25+
bytes32 original;
2626

2727
/// Is the storage key cold or warm.
28-
evmc_access_status access_status{EVMC_ACCESS_COLD};
28+
evmc_access_status access_status = EVMC_ACCESS_COLD;
2929

3030
/// Default constructor.
3131
storage_value() noexcept = default;
32-
33-
/// Constructor.
34-
storage_value(const bytes32& _value, bool _dirty = false) noexcept // NOLINT
35-
: value{_value}, dirty{_dirty}
36-
{}
37-
38-
/// Constructor with initial access status.
39-
storage_value(const bytes32& _value, evmc_access_status _access_status) noexcept
40-
: value{_value}, access_status{_access_status}
41-
{}
4232
};
4333

4434
/// Mocked account.
@@ -176,7 +166,7 @@ class MockedHost : public Host
176166

177167
const auto storage_iter = account_iter->second.storage.find(key);
178168
if (storage_iter != account_iter->second.storage.end())
179-
return storage_iter->second.value;
169+
return storage_iter->second.current;
180170
return {};
181171
}
182172

@@ -195,14 +185,13 @@ class MockedHost : public Host
195185
// Follow https://eips.ethereum.org/EIPS/eip-1283 specification.
196186
// WARNING! This is not complete implementation as refund is not handled here.
197187

198-
if (old.value == value)
188+
if (old.current == value)
199189
return EVMC_STORAGE_UNCHANGED;
200190

201191
evmc_storage_status status{};
202-
if (!old.dirty)
192+
if (old.original == old.current) // Storage slot not dirty
203193
{
204-
old.dirty = true;
205-
if (!old.value)
194+
if (!old.current)
206195
status = EVMC_STORAGE_ADDED;
207196
else if (value)
208197
status = EVMC_STORAGE_MODIFIED;
@@ -212,7 +201,7 @@ class MockedHost : public Host
212201
else
213202
status = EVMC_STORAGE_MODIFIED_AGAIN;
214203

215-
old.value = value;
204+
old.current = value;
216205
return status;
217206
}
218207

test/libsolidity/semanticTests/array/byte_array_storage_layout.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ contract c {
4646
// storageEmpty -> 0
4747
// test_long() -> 67
4848
// gas irOptimized: 89148
49-
// gas legacy: 105839
50-
// gas legacyOptimized: 103293
49+
// gas legacy: 108639
50+
// gas legacyOptimized: 106093
5151
// storageEmpty -> 0
5252
// test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020
5353
// gas legacy: 61930

test/libsolidity/semanticTests/array/copying/array_copy_storage_storage_different_base_nested.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ contract c {
2424
// ----
2525
// test() -> 3, 4
2626
// gas irOptimized: 189690
27-
// gas legacy: 195353
28-
// gas legacyOptimized: 192441
27+
// gas legacy: 215253
28+
// gas legacyOptimized: 212341

test/libsolidity/semanticTests/array/copying/copy_byte_array_to_storage.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ contract C {
4646
}
4747
// ----
4848
// f() -> 0xff
49-
// gas irOptimized: 119584
50-
// gas legacy: 132274
51-
// gas legacyOptimized: 123756
49+
// gas irOptimized: 179284
50+
// gas legacy: 191974
51+
// gas legacyOptimized: 183456

test/libsolidity/semanticTests/array/delete/delete_storage_array_packed.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ contract C {
1515
// ----
1616
// f() -> 0, 0, 0
1717
// gas irOptimized: 90992
18+
// gas legacy: 111037
19+
// gas legacyOptimized: 109633

test/libsolidity/semanticTests/structs/struct_delete_storage_with_array.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ contract C {
4242
}
4343
// ----
4444
// f() ->
45-
// gas irOptimized: 121657
46-
// gas legacy: 122132
47-
// gas legacyOptimized: 121500
45+
// gas irOptimized: 141557
46+
// gas legacy: 142032
47+
// gas legacyOptimized: 141400
4848
// g() ->
49-
// gas irOptimized: 145472
50-
// gas legacy: 145707
51-
// gas legacyOptimized: 144940
49+
// gas irOptimized: 148272
50+
// gas legacy: 148507
51+
// gas legacyOptimized: 147740

test/libsolidity/semanticTests/viaYul/array_storage_index_zeroed_test.sol

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ contract C {
5252
// ----
5353
// test_zeroed_indicies(uint256): 1 ->
5454
// test_zeroed_indicies(uint256): 5 ->
55-
// gas irOptimized: 153874
56-
// gas legacy: 155001
57-
// gas legacyOptimized: 152239
55+
// gas irOptimized: 165074
56+
// gas legacy: 166201
57+
// gas legacyOptimized: 163439
5858
// test_zeroed_indicies(uint256): 10 ->
59-
// gas irOptimized: 277077
60-
// gas legacy: 279488
61-
// gas legacyOptimized: 274412
59+
// gas irOptimized: 282677
60+
// gas legacy: 285088
61+
// gas legacyOptimized: 280012
6262
// test_zeroed_indicies(uint256): 15 ->
63-
// gas irOptimized: 399822
64-
// gas legacy: 403538
65-
// gas legacyOptimized: 396227
63+
// gas irOptimized: 405422
64+
// gas legacy: 409138
65+
// gas legacyOptimized: 401827
6666
// test_zeroed_indicies(uint256): 0xFF ->
67-
// gas irOptimized: 6399212
68-
// gas legacy: 6460633
69-
// gas legacyOptimized: 6327477
67+
// gas irOptimized: 6404812
68+
// gas legacy: 6466233
69+
// gas legacyOptimized: 6333077

0 commit comments

Comments
 (0)