Skip to content

Commit 9577023

Browse files
committed
Update MONAD_NEXT pricing
1 parent 90f8b79 commit 9577023

File tree

15 files changed

+123
-145
lines changed

15 files changed

+123
-145
lines changed

category/execution/ethereum/evm_test.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,4 +966,95 @@ TYPED_TEST(TraitsTest, nested_call_to_delegated_precompile)
966966
}
967967
}
968968

969+
TYPED_TEST(TraitsTest, cold_account_access)
970+
{
971+
InMemoryMachine machine;
972+
mpt::Db db{machine};
973+
db_t tdb{db};
974+
vm::VM vm;
975+
BlockState bs{tdb, vm};
976+
State s{bs, Incarnation{0, 0}};
977+
978+
static constexpr auto from{
979+
0x00000000000000000000000000000000bbbbbbbb_address};
980+
981+
static constexpr auto contract{
982+
0x00000000000000000000000000000000cccccccc_address};
983+
984+
// push cold address; BALANCE
985+
auto const code =
986+
evmc::from_hex("0x7300000000000000000000000000000000aaaaaaaa31")
987+
.value();
988+
auto const icode = vm::make_shared_intercode(code);
989+
auto const code_hash = to_bytes(keccak256(code));
990+
991+
commit_sequential(
992+
tdb,
993+
StateDeltas{
994+
{from,
995+
StateDelta{
996+
.account =
997+
{std::nullopt,
998+
Account{
999+
.balance = 10'000'000'000,
1000+
}}}},
1001+
{contract,
1002+
StateDelta{
1003+
.account =
1004+
{std::nullopt,
1005+
Account{
1006+
.code_hash = code_hash,
1007+
}}}}},
1008+
Code{
1009+
{code_hash, icode},
1010+
},
1011+
BlockHeader{});
1012+
1013+
constexpr auto gas_limit = 1'000'000;
1014+
1015+
evmc_message const m{
1016+
.kind = EVMC_CALL,
1017+
.gas = gas_limit,
1018+
.recipient = contract,
1019+
.sender = from,
1020+
.code_address = contract,
1021+
};
1022+
1023+
BlockHashBufferFinalized const block_hash_buffer;
1024+
NoopCallTracer call_tracer;
1025+
EvmcHost<typename TestFixture::Trait> h{
1026+
call_tracer, EMPTY_TX_CONTEXT, block_hash_buffer, s};
1027+
auto const result = h.call(m);
1028+
auto const gas_used = gas_limit - result.gas_left;
1029+
1030+
constexpr auto balance_gas = [] {
1031+
if constexpr (TestFixture::is_monad_trait()) {
1032+
if constexpr (TestFixture::Trait::monad_rev() >= MONAD_NEXT) {
1033+
return 10100;
1034+
}
1035+
else {
1036+
return 2600;
1037+
}
1038+
}
1039+
else {
1040+
if constexpr (TestFixture::Trait::evm_rev() >= EVMC_BERLIN) {
1041+
return 2600;
1042+
}
1043+
else if constexpr (TestFixture::Trait::evm_rev() >= EVMC_ISTANBUL) {
1044+
return 700;
1045+
}
1046+
else if constexpr (
1047+
TestFixture::Trait::evm_rev() >= EVMC_TANGERINE_WHISTLE) {
1048+
return 400;
1049+
}
1050+
else {
1051+
return 20;
1052+
}
1053+
}
1054+
}();
1055+
1056+
EXPECT_EQ(result.status_code, EVMC_SUCCESS);
1057+
EXPECT_EQ(gas_used, balance_gas + 3); // +3 for PUSH20
1058+
}
1059+
9691060
#undef PUSH3

category/execution/ethereum/execute_transaction.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ evmc::Result ExecuteTransactionNoValidation<traits>::operator()(
240240
auth_refund = process_authorizations(state, host);
241241
}
242242

243-
if constexpr (!traits::eip_7702_refund_active()) {
244-
// monad doesn't give authorization refunds
245-
auth_refund = 0;
246-
}
247-
248243
// EIP-3651
249244
if constexpr (traits::evm_rev() >= EVMC_SHANGHAI) {
250245
host.access_account(header_.beneficiary);
@@ -357,26 +352,17 @@ Receipt ExecuteTransaction<traits>::execute_final(
357352
tx_,
358353
static_cast<uint64_t>(result.gas_left),
359354
static_cast<uint64_t>(result.gas_refund));
360-
auto const refund_gas_cost =
361-
refund_gas_price<traits>(tx_, header_.base_fee_per_gas.value_or(0));
362-
state.add_to_balance(sender_, refund_gas_cost * gas_refund);
355+
auto const gas_cost =
356+
gas_price<traits>(tx_, header_.base_fee_per_gas.value_or(0));
357+
state.add_to_balance(sender_, gas_cost * gas_refund);
363358

364-
auto gas_used = tx_.gas_limit;
365-
366-
// Monad specification §2.3: Payment Rule for User:
367-
// The storage refund does not reduce the gas consumption of the
368-
// transaction.
369-
if constexpr (traits::should_refund_reduce_gas_used()) {
370-
gas_used -= gas_refund;
371-
}
359+
auto gas_used = tx_.gas_limit - gas_refund;
372360

373361
// EIP-7623
374362
if constexpr (traits::evm_rev() >= EVMC_PRAGUE) {
375363
auto const floor_gas = floor_data_gas(tx_);
376364
if (gas_used < floor_gas) {
377365
auto const delta = floor_gas - gas_used;
378-
auto const gas_cost =
379-
gas_price<traits>(tx_, header_.base_fee_per_gas.value_or(0));
380366
state.subtract_from_balance(sender_, gas_cost * delta);
381367

382368
gas_used = floor_gas;

category/execution/ethereum/execute_transaction_test.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,7 @@ TYPED_TEST(TraitsTest, refunds_delete)
301301
}();
302302
static constexpr auto storage_refund_tx2 = [=] {
303303
if constexpr (TestFixture::is_monad_trait()) {
304-
if constexpr (TestFixture::Trait::monad_rev() >= MONAD_NEXT) {
305-
return 120'000;
306-
}
307-
else if constexpr (TestFixture::Trait::monad_rev() > MONAD_ZERO) {
304+
if constexpr (TestFixture::Trait::monad_rev() > MONAD_ZERO) {
308305
return 0;
309306
}
310307
}
@@ -593,10 +590,6 @@ TYPED_TEST(TraitsTest, refunds_delete_then_set)
593590
static constexpr auto storage_refund = [=] {
594591
if constexpr (TestFixture::is_monad_trait()) {
595592
if constexpr (
596-
TestFixture::Trait::monad_rev() >= MONAD_NEXT) {
597-
return 2800;
598-
}
599-
else if constexpr (
600593
TestFixture::Trait::monad_rev() > MONAD_ZERO) {
601594
return 0;
602595
}

category/execution/ethereum/test/test_monad_chain.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ TYPED_TEST(MonadTraitsTest, compute_gas_refund)
4949
{
5050
uint64_t const refund = compute_gas_refund<typename TestFixture::Trait>(
5151
Transaction{.gas_limit = 21'000}, 20'000, 1'000);
52-
if constexpr (TestFixture::REV >= MONAD_NEXT) {
53-
EXPECT_EQ(refund, 1'000);
54-
}
55-
else if constexpr (TestFixture::REV >= MONAD_ONE) {
52+
if constexpr (TestFixture::REV >= MONAD_ONE) {
5653
EXPECT_EQ(refund, 0);
5754
}
5855
else {

category/execution/ethereum/transaction_gas.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,6 @@ uint64_t compute_gas_refund(
206206

207207
EXPLICIT_EVM_TRAITS(compute_gas_refund);
208208

209-
template <Traits traits>
210-
uint256_t
211-
refund_gas_price(Transaction const &tx, uint256_t const &base_fee_per_gas)
212-
{
213-
return gas_price<traits>(tx, base_fee_per_gas);
214-
}
215-
216-
EXPLICIT_EVM_TRAITS(refund_gas_price);
217-
218209
template <Traits traits>
219210
uint256_t calculate_txn_award(
220211
Transaction const &tx, uint256_t const &base_fee_per_gas,

category/execution/ethereum/transaction_gas.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ template <Traits traits>
5151
uint64_t compute_gas_refund(
5252
Transaction const &, uint64_t gas_remaining, uint64_t refund);
5353

54-
template <Traits traits>
55-
uint256_t
56-
refund_gas_price(Transaction const &, uint256_t const &base_fee_per_gas);
57-
5854
template <Traits traits>
5955
uint256_t calculate_txn_award(
6056
Transaction const &, uint256_t const &base_fee_per_gas,

category/execution/monad/monad_transaction_gas.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ template <Traits traits>
2323
uint64_t compute_gas_refund(
2424
Transaction const &tx, uint64_t const gas_remaining, uint64_t const refund)
2525
{
26-
if constexpr (traits::monad_rev() >= MONAD_NEXT) {
27-
// Monad specification §4.2: Storage Gas Cost and Refunds
28-
return refund;
29-
}
30-
else if constexpr (traits::monad_rev() >= MONAD_ONE) {
26+
if constexpr (traits::monad_rev() >= MONAD_ONE) {
3127
return 0;
3228
}
3329

@@ -36,18 +32,4 @@ uint64_t compute_gas_refund(
3632

3733
EXPLICIT_MONAD_TRAITS(compute_gas_refund);
3834

39-
template <Traits traits>
40-
uint256_t
41-
refund_gas_price(Transaction const &tx, uint256_t const &base_fee_per_gas)
42-
{
43-
if constexpr (traits::monad_rev() >= MONAD_NEXT) {
44-
// Monad specification §4.2: Storage Gas Cost and Refunds
45-
return monad_min_base_fee_wei(traits::monad_rev());
46-
}
47-
48-
return gas_price<traits>(tx, base_fee_per_gas);
49-
}
50-
51-
EXPLICIT_MONAD_TRAITS(refund_gas_price);
52-
5335
MONAD_NAMESPACE_END

category/execution/monad/monad_transaction_gas.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,4 @@ template <Traits traits>
2525
uint64_t compute_gas_refund(
2626
Transaction const &, uint64_t gas_remaining, uint64_t refund);
2727

28-
template <Traits traits>
29-
uint256_t refund_gas_price(Transaction const &, uint256_t const &);
30-
3128
MONAD_NAMESPACE_END

category/rpc/eth_call_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ TEST_F(EthCallFixture, contract_deployment_success)
526526
EXPECT_EQ(returned_code_vec, deployed_code_vec);
527527
EXPECT_EQ(ctx.result->encoded_trace_len, 0);
528528
EXPECT_EQ(ctx.result->gas_refund, 0);
529-
EXPECT_EQ(ctx.result->gas_used, 137'137);
529+
EXPECT_EQ(ctx.result->gas_used, 68'137);
530530

531531
monad_state_override_destroy(state_override);
532532
monad_eth_call_executor_destroy(executor);

category/vm/evm/explicit_traits.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
f<::monad::MonadTraits<MONAD_FOUR>>; \
7070
template decltype(f<::monad::MonadTraits<MONAD_FIVE>>) \
7171
f<::monad::MonadTraits<MONAD_FIVE>>; \
72+
template decltype(f<::monad::MonadTraits<MONAD_SIX>>) \
73+
f<::monad::MonadTraits<MONAD_SIX>>; \
7274
template decltype(f<::monad::MonadTraits<MONAD_NEXT>>) \
7375
f<::monad::MonadTraits<MONAD_NEXT>>;
7476

@@ -102,6 +104,7 @@
102104
template class c<::monad::MonadTraits<MONAD_THREE>>; \
103105
template class c<::monad::MonadTraits<MONAD_FOUR>>; \
104106
template class c<::monad::MonadTraits<MONAD_FIVE>>; \
107+
template class c<::monad::MonadTraits<MONAD_SIX>>; \
105108
template class c<::monad::MonadTraits<MONAD_NEXT>>;
106109

107110
#define EXPLICIT_TRAITS_CLASS(c) \
@@ -167,6 +170,8 @@
167170
id<::monad::MonadTraits<MONAD_FOUR>>; \
168171
template decltype(id<::monad::MonadTraits<MONAD_FIVE>>) \
169172
id<::monad::MonadTraits<MONAD_FIVE>>; \
173+
template decltype(id<::monad::MonadTraits<MONAD_SIX>>) \
174+
id<::monad::MonadTraits<MONAD_SIX>>; \
170175
template decltype(id<::monad::MonadTraits<MONAD_NEXT>>) \
171176
id<::monad::MonadTraits<MONAD_NEXT>>;
172177

0 commit comments

Comments
 (0)