@@ -283,7 +283,7 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
283
283
stack : & Stack ,
284
284
is_static : bool ,
285
285
config : & Config ,
286
- handler : & H ,
286
+ handler : & mut H ,
287
287
) -> Result < ( GasCost , Option < MemoryCost > ) , ExitError > {
288
288
let gas_cost = match opcode {
289
289
Opcode :: RETURN => GasCost :: Zero ,
@@ -307,40 +307,59 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
307
307
308
308
Opcode :: EXTCODESIZE => {
309
309
let target = stack. peek ( 0 ) ?. into ( ) ;
310
- GasCost :: ExtCodeSize {
311
- target_is_cold : handler. is_cold ( target, None ) ,
312
- }
310
+
311
+ // https://eips.ethereum.org/EIPS/eip-2929
312
+ let target_is_cold = handler. is_cold ( target, None ) ;
313
+ handler. mark_hot ( target, None ) ;
314
+
315
+ GasCost :: ExtCodeSize { target_is_cold }
313
316
}
314
317
Opcode :: BALANCE => {
315
318
let target = stack. peek ( 0 ) ?. into ( ) ;
316
- GasCost :: Balance {
317
- target_is_cold : handler. is_cold ( target, None ) ,
318
- }
319
+
320
+ // https://eips.ethereum.org/EIPS/eip-2929
321
+ let target_is_cold = handler. is_cold ( target, None ) ;
322
+ handler. mark_hot ( target, None ) ;
323
+
324
+ GasCost :: Balance { target_is_cold }
319
325
}
320
326
Opcode :: BLOCKHASH => GasCost :: BlockHash ,
321
327
322
328
Opcode :: EXTCODEHASH if config. has_ext_code_hash => {
323
329
let target = stack. peek ( 0 ) ?. into ( ) ;
324
- GasCost :: ExtCodeHash {
325
- target_is_cold : handler. is_cold ( target, None ) ,
326
- }
330
+
331
+ // https://eips.ethereum.org/EIPS/eip-2929
332
+ let target_is_cold = handler. is_cold ( target, None ) ;
333
+ handler. mark_hot ( target, None ) ;
334
+
335
+ GasCost :: ExtCodeHash { target_is_cold }
327
336
}
328
337
Opcode :: EXTCODEHASH => GasCost :: Invalid ( opcode) ,
329
338
330
339
Opcode :: CALLCODE => {
331
340
let target = stack. peek ( 1 ) ?. into ( ) ;
341
+
342
+ // https://eips.ethereum.org/EIPS/eip-2929
343
+ let target_is_cold = handler. is_cold ( target, None ) ;
344
+ handler. mark_hot ( target, None ) ;
345
+
332
346
GasCost :: CallCode {
333
347
value : U256 :: from_big_endian ( & stack. peek ( 2 ) ?[ ..] ) ,
334
348
gas : U256 :: from_big_endian ( & stack. peek ( 0 ) ?[ ..] ) ,
335
- target_is_cold : handler . is_cold ( target , None ) ,
349
+ target_is_cold,
336
350
target_exists : { handler. exists ( target) } ,
337
351
}
338
352
}
339
353
Opcode :: STATICCALL => {
340
354
let target = stack. peek ( 1 ) ?. into ( ) ;
355
+
356
+ // https://eips.ethereum.org/EIPS/eip-2929
357
+ let target_is_cold = handler. is_cold ( target, None ) ;
358
+ handler. mark_hot ( target, None ) ;
359
+
341
360
GasCost :: StaticCall {
342
361
gas : U256 :: from_big_endian ( & stack. peek ( 0 ) ?[ ..] ) ,
343
- target_is_cold : handler . is_cold ( target , None ) ,
362
+ target_is_cold,
344
363
target_exists : { handler. exists ( target) } ,
345
364
}
346
365
}
@@ -349,8 +368,13 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
349
368
} ,
350
369
Opcode :: EXTCODECOPY => {
351
370
let target = stack. peek ( 0 ) ?. into ( ) ;
371
+
372
+ // https://eips.ethereum.org/EIPS/eip-2929
373
+ let target_is_cold = handler. is_cold ( target, None ) ;
374
+ handler. mark_hot ( target, None ) ;
375
+
352
376
GasCost :: ExtCodeCopy {
353
- target_is_cold : handler . is_cold ( target , None ) ,
377
+ target_is_cold,
354
378
len : U256 :: from_big_endian ( & stack. peek ( 3 ) ?[ ..] ) ,
355
379
}
356
380
}
@@ -365,17 +389,25 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
365
389
} ,
366
390
Opcode :: SLOAD => {
367
391
let index = stack. peek ( 0 ) ?;
368
- GasCost :: SLoad {
369
- target_is_cold : handler. is_cold ( address, Some ( index) ) ,
370
- }
392
+
393
+ // https://eips.ethereum.org/EIPS/eip-2929
394
+ let target_is_cold = handler. is_cold ( address, Some ( index) ) ;
395
+ handler. mark_hot ( address, Some ( index) ) ;
396
+
397
+ GasCost :: SLoad { target_is_cold }
371
398
}
372
399
Opcode :: TLOAD if config. eip_1153_enabled => GasCost :: TLoad ,
373
400
374
401
Opcode :: DELEGATECALL if config. has_delegate_call => {
375
402
let target = stack. peek ( 1 ) ?. into ( ) ;
403
+
404
+ // https://eips.ethereum.org/EIPS/eip-2929
405
+ let target_is_cold = handler. is_cold ( target, None ) ;
406
+ handler. mark_hot ( target, None ) ;
407
+
376
408
GasCost :: DelegateCall {
377
409
gas : U256 :: from_big_endian ( & stack. peek ( 0 ) ?[ ..] ) ,
378
- target_is_cold : handler . is_cold ( target , None ) ,
410
+ target_is_cold,
379
411
target_exists : { handler. exists ( target) } ,
380
412
}
381
413
}
@@ -390,11 +422,16 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
390
422
Opcode :: SSTORE if !is_static => {
391
423
let index = stack. peek ( 0 ) ?;
392
424
let value = stack. peek ( 1 ) ?;
425
+
426
+ // https://eips.ethereum.org/EIPS/eip-2929
427
+ let target_is_cold = handler. is_cold ( address, Some ( index) ) ;
428
+ handler. mark_hot ( address, Some ( index) ) ;
429
+
393
430
GasCost :: SStore {
394
431
original : handler. original_storage ( address, index) ,
395
432
current : handler. storage ( address, index) ,
396
433
new : value,
397
- target_is_cold : handler . is_cold ( address , Some ( index ) ) ,
434
+ target_is_cold,
398
435
}
399
436
}
400
437
Opcode :: TSTORE if !is_static && config. eip_1153_enabled => GasCost :: TStore ,
@@ -424,9 +461,14 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
424
461
} ,
425
462
Opcode :: SUICIDE if !is_static => {
426
463
let target = stack. peek ( 0 ) ?. into ( ) ;
464
+
465
+ // https://eips.ethereum.org/EIPS/eip-2929
466
+ let target_is_cold = handler. is_cold ( target, None ) ;
467
+ handler. mark_hot ( target, None ) ;
468
+
427
469
GasCost :: Suicide {
428
470
value : handler. balance ( address) ,
429
- target_is_cold : handler . is_cold ( target , None ) ,
471
+ target_is_cold,
430
472
target_exists : { handler. exists ( target) } ,
431
473
already_removed : handler. deleted ( address) ,
432
474
}
@@ -436,10 +478,15 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
436
478
|| ( is_static && U256 :: from_big_endian ( & stack. peek ( 2 ) ?[ ..] ) == U256 :: zero ( ) ) =>
437
479
{
438
480
let target = stack. peek ( 1 ) ?. into ( ) ;
481
+
482
+ // https://eips.ethereum.org/EIPS/eip-2929
483
+ let target_is_cold = handler. is_cold ( target, None ) ;
484
+ handler. mark_hot ( target, None ) ;
485
+
439
486
GasCost :: Call {
440
487
value : U256 :: from_big_endian ( & stack. peek ( 2 ) ?[ ..] ) ,
441
488
gas : U256 :: from_big_endian ( & stack. peek ( 0 ) ?[ ..] ) ,
442
- target_is_cold : handler . is_cold ( target , None ) ,
489
+ target_is_cold,
443
490
target_exists : { handler. exists ( target) } ,
444
491
}
445
492
}
0 commit comments