@@ -90,6 +90,69 @@ TYPED_TEST(TraitsTest, create_with_insufficient)
9090 EXPECT_EQ (result.status_code , EVMC_INSUFFICIENT_BALANCE);
9191}
9292
93+ // Test that CREATE transactions that fail due to insufficient balance
94+ // do not bump nonce prior to MONAD_FIVE but do bump it after
95+ TYPED_TEST (TraitsTest, create_insufficient_balance_nonce_bump)
96+ {
97+ InMemoryMachine machine;
98+ mpt::Db db{machine};
99+ db_t tdb{db};
100+ vm::VM vm;
101+ BlockState bs{tdb, vm};
102+ State s{bs, Incarnation{0 , 0 }};
103+
104+ static constexpr auto from{
105+ 0xf8636377b7a998b51a3cf2bd711b870b3ab0ad56_address};
106+ static constexpr uint64_t initial_nonce = 5 ;
107+
108+ commit_sequential (
109+ tdb,
110+ StateDeltas{
111+ {from,
112+ StateDelta{
113+ .account =
114+ {std::nullopt ,
115+ Account{
116+ .balance = 10'000'000'000 ,
117+ .nonce = initial_nonce}}}}},
118+ Code{},
119+ BlockHeader{});
120+
121+ evmc_message m{
122+ .kind = EVMC_CREATE,
123+ .depth = 0 , // top-level transaction
124+ .gas = 20'000 ,
125+ .sender = from,
126+ };
127+ uint256_t const v{70'000'000'000'000'000 }; // too much balance required
128+ intx::be::store (m.value .bytes , v);
129+
130+ BlockHashBufferFinalized const block_hash_buffer;
131+ NoopCallTracer call_tracer;
132+ EvmcHost<typename TestFixture::Trait> h{
133+ call_tracer, EMPTY_TX_CONTEXT, block_hash_buffer, s};
134+
135+ auto const result = create<typename TestFixture::Trait>(&h, s, m);
136+
137+ EXPECT_EQ (result.status_code , EVMC_INSUFFICIENT_BALANCE);
138+
139+ auto const final_nonce = s.get_nonce (from);
140+ if constexpr (is_monad_trait_v<typename TestFixture::Trait>) {
141+ if constexpr (TestFixture::Trait::monad_rev () >= MONAD_FIVE) {
142+ EXPECT_EQ (final_nonce, initial_nonce + 1 );
143+ }
144+ else {
145+ EXPECT_EQ (final_nonce, initial_nonce);
146+ }
147+ }
148+ else {
149+ // Asserting expected behavior here but noting that this test is
150+ // unrealistic for ethereum since the sender balance is always
151+ // sufficient to pay for the gas + value
152+ EXPECT_EQ (final_nonce, initial_nonce);
153+ }
154+ }
155+
93156TYPED_TEST (TraitsTest, eip684_existing_code)
94157{
95158 InMemoryMachine machine;
0 commit comments