@@ -202,20 +202,12 @@ pub struct Cheatcodes {
202
202
pub breakpoints : Breakpoints ,
203
203
204
204
/// Track if cool cheatcode was called on each address
205
- pub addresses : HashMap < Address , CoolState > ,
205
+ /// Mapping tracks if the address itself is cool and if each of it's slots are cool
206
+ pub addresses : HashMap < Address , ( AddressState , HashMap < U256 , StorageSlotState > ) > ,
206
207
/// How much gas to charge in the next step (op code) based on cool cheatcode calculations
207
208
pub additional_gas_next_op : u64 ,
208
209
}
209
210
210
- /// Tracking if an address and it's slots are cool
211
- #[ derive( Debug , Clone ) ]
212
- pub struct CoolState {
213
- /// Track if address is cool
214
- pub address : AddressState ,
215
- /// Track if each storage slot is cool or not
216
- pub slots : HashMap < U256 , StorageSlotState > ,
217
- }
218
-
219
211
/// Whether an Address is accessed or not
220
212
#[ derive( Clone , PartialEq , Debug ) ]
221
213
pub enum AddressState {
@@ -275,10 +267,10 @@ fn add_gas_from_cool_cheatcode<DB: DatabaseExt>(
275
267
// COLD_ACCOUNT_ACCESS_COST is 2600
276
268
// check this is done once per address, unless cheatcode is called again
277
269
// ignore if same as contract address
278
- if let Some ( cool_state ) = state. addresses . get_mut ( & addr) {
279
- if cool_state . address == AddressState :: Cool {
270
+ if let Some ( ( ref mut address , _ ) ) = state. addresses . get_mut ( & addr) {
271
+ if * address == AddressState :: Cool {
280
272
state. additional_gas_next_op = 2500 ;
281
- cool_state . address = AddressState :: Warm ;
273
+ * address = AddressState :: Warm ;
282
274
}
283
275
}
284
276
}
@@ -292,34 +284,34 @@ fn add_gas_from_cool_cheatcode<DB: DatabaseExt>(
292
284
// COLD_ACCOUNT_ACCESS_COST is 2600
293
285
// check this is done once per address, unless cheatcode is called again
294
286
// ignore if same as contract address
295
- if let Some ( cool_state ) = state. addresses . get_mut ( & addr) {
296
- if cool_state . address == AddressState :: Cool {
287
+ if let Some ( ( ref mut address , _ ) ) = state. addresses . get_mut ( & addr) {
288
+ if * address == AddressState :: Cool {
297
289
state. additional_gas_next_op = 2500 ;
298
- cool_state . address = AddressState :: Warm ;
290
+ * address = AddressState :: Warm ;
299
291
}
300
292
}
301
293
}
302
294
}
303
295
_ => { }
304
296
}
305
297
// check target's slots
306
- if let Some ( cool_state ) = state. addresses . get_mut ( & contract_address) {
298
+ if let Some ( ( _ , slots ) ) = state. addresses . get_mut ( & contract_address) {
307
299
match interpreter. current_opcode ( ) {
308
300
opcode:: SLOAD => {
309
301
let key = try_or_continue ! ( interpreter. stack( ) . peek( 0 ) ) ;
310
302
311
303
let account = data. journaled_state . state ( ) . get ( & contract_address) . unwrap ( ) ;
312
304
if account. storage . get ( & key) . is_some ( ) {
313
- match cool_state . slots . get ( & key) {
305
+ match slots. get ( & key) {
314
306
None | Some ( StorageSlotState :: Cool ) => {
315
307
// COLD_SLOAD_COST is 2100
316
308
state. additional_gas_next_op = 2000 ;
317
- cool_state . slots . insert ( key, StorageSlotState :: WarmWithSLOAD ) ;
309
+ slots. insert ( key, StorageSlotState :: WarmWithSLOAD ) ;
318
310
}
319
311
Some ( _) => { }
320
312
}
321
313
} else {
322
- cool_state . slots . insert ( key, StorageSlotState :: WarmWithSLOAD ) ;
314
+ slots. insert ( key, StorageSlotState :: WarmWithSLOAD ) ;
323
315
}
324
316
}
325
317
opcode:: SSTORE => {
@@ -329,7 +321,7 @@ fn add_gas_from_cool_cheatcode<DB: DatabaseExt>(
329
321
let account = data. journaled_state . state ( ) . get ( & contract_address) . unwrap ( ) ;
330
322
if account. storage . get ( & key) . is_some ( ) {
331
323
// only add gas the first time the storage is touched again
332
- match cool_state . slots . get ( & key) {
324
+ match slots. get ( & key) {
333
325
Some ( StorageSlotState :: WarmWithSLOAD ) => {
334
326
// cool keeps the slot value changes
335
327
// as if the previous_or_original_value = present_value`
@@ -348,7 +340,7 @@ fn add_gas_from_cool_cheatcode<DB: DatabaseExt>(
348
340
}
349
341
350
342
// set slot is_warm to true
351
- cool_state . slots . insert ( key, StorageSlotState :: WarmWithSSTORE ) ;
343
+ slots. insert ( key, StorageSlotState :: WarmWithSSTORE ) ;
352
344
}
353
345
None | Some ( StorageSlotState :: Cool ) => {
354
346
// Means SSTORE was called without SLOAD before
@@ -370,12 +362,12 @@ fn add_gas_from_cool_cheatcode<DB: DatabaseExt>(
370
362
state. additional_gas_next_op += 2900 - 100
371
363
}
372
364
}
373
- cool_state . slots . insert ( key, StorageSlotState :: WarmWithSSTORE ) ;
365
+ slots. insert ( key, StorageSlotState :: WarmWithSSTORE ) ;
374
366
}
375
367
Some ( StorageSlotState :: WarmWithSSTORE ) => { }
376
368
}
377
369
} else {
378
- cool_state . slots . insert ( key, StorageSlotState :: WarmWithSSTORE ) ;
370
+ slots. insert ( key, StorageSlotState :: WarmWithSSTORE ) ;
379
371
}
380
372
}
381
373
_ => { }
0 commit comments