1919#include < category/core/config.hpp>
2020#include < category/execution/ethereum/chain/chain.hpp>
2121#include < category/execution/ethereum/core/address.hpp>
22+ #include < category/execution/ethereum/core/contract/abi_encode.hpp>
23+ #include < category/execution/ethereum/core/contract/abi_signatures.hpp>
24+ #include < category/execution/ethereum/core/contract/events.hpp>
2225#include < category/execution/ethereum/evm.hpp>
2326#include < category/execution/ethereum/precompiles.hpp>
2427#include < category/execution/ethereum/state3/state.hpp>
@@ -53,13 +56,14 @@ class EvmcHostBase : public vm::Host
5356 State &state_;
5457 CallTracerBase &call_tracer_;
5558 std::function<bool ()> revert_transaction_;
59+ bool simulate_v1_enabled_;
5660
5761public:
5862 EvmcHostBase (
5963 CallTracerBase &, evmc_tx_context const &, BlockHashBuffer const &,
60- State &, std::function< bool ()> const &revert_transaction = [] {
61- return false ;
62- } ) noexcept ;
64+ State &,
65+ std::function< bool ()> const &revert_transaction = [] { return false ; },
66+ bool simulate_v1_enabled = false ) noexcept ;
6367
6468 virtual ~EvmcHostBase () noexcept = default ;
6569
@@ -100,7 +104,7 @@ class EvmcHostBase : public vm::Host
100104 bytes32_t const &value) noexcept override ;
101105};
102106
103- static_assert (sizeof (EvmcHostBase) == 88 );
107+ static_assert (sizeof (EvmcHostBase) == 96 );
104108static_assert (alignof (EvmcHostBase) == 8 );
105109
106110template <Traits traits>
@@ -126,6 +130,12 @@ struct EvmcHost final : public EvmcHostBase
126130 Address const &address, Address const &beneficiary) noexcept override
127131 {
128132 try {
133+ emit_native_transfer_event (
134+ address,
135+ beneficiary,
136+ intx::be::load<uint256_t >(
137+ state_.get_current_balance_pessimistic (address)));
138+
129139 call_tracer_.on_self_destruct (address, beneficiary);
130140 return state_.selfdestruct <traits>(address, beneficiary);
131141 }
@@ -176,13 +186,45 @@ struct EvmcHost final : public EvmcHostBase
176186 stack_unwind ();
177187 }
178188
189+ void transfer_balances (evmc_message const &msg, Address const &to)
190+ {
191+ uint256_t const value = intx::be::load<uint256_t >(msg.value );
192+ state_.subtract_from_balance (msg.sender , value);
193+ state_.add_to_balance (to, value);
194+ emit_native_transfer_event (msg.sender , to, value);
195+ }
196+
179197 CallTracerBase &get_call_tracer () noexcept
180198 {
181199 return call_tracer_;
182200 }
201+
202+ private:
203+ void emit_native_transfer_event (
204+ Address const &from, Address const &to, uint256_t const &value)
205+ {
206+ if (simulate_v1_enabled_) {
207+ constexpr auto sender =
208+ 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_address;
209+ constexpr auto signature =
210+ abi_encode_event_signature (" Transfer(address,address,uint256)" );
211+ static_assert (
212+ signature ==
213+ 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef_bytes32);
214+
215+ auto const event = EventBuilder (sender, signature)
216+ .add_topic (abi_encode_address (from))
217+ .add_topic (abi_encode_address (to))
218+ .add_data (abi_encode_uint (u256_be{value}))
219+ .build ();
220+
221+ state_.store_log (event);
222+ call_tracer_.on_log (event);
223+ }
224+ }
183225};
184226
185- static_assert (sizeof (EvmcHost<EvmTraits<EVMC_LATEST_STABLE_REVISION>>) == 88 );
227+ static_assert (sizeof (EvmcHost<EvmTraits<EVMC_LATEST_STABLE_REVISION>>) == 96 );
186228static_assert (alignof (EvmcHost<EvmTraits<EVMC_LATEST_STABLE_REVISION>>) == 8 );
187229
188230MONAD_NAMESPACE_END
0 commit comments