@@ -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
0 commit comments