You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 6, 2020. It is now read-only.
EIP 1283: Net gas metering for SSTORE without dirty maps (#9319)
* Implement last_checkpoint_storage_at
* Add reverted_storage_at for externalities
* sstore_clears_count -> sstore_clears_refund
* Implement eip1283 for evm
* Add eip1283Transition params
* evm: fix tests
* jsontests: fix test
* Return checkpoint index when creating
* Comply with spec Version II
* Fix docs
* Fix jsontests feature compile
* Address grumbles
* Fix no-checkpoint-entry case
* Remove unnecessary expect
* Add test for State::checkpoint_storage_at
* Add executive level test for eip1283
* Hard-code transaction_checkpoint_index to 0
* Fix jsontests
* Add tests for checkpoint discard/revert
* Require checkpoint to be empty for kill_account and commit
* Get code coverage
* Use saturating_add/saturating_sub
* Fix issues in insert_cache
* Clear the state again
* Fix original_storage_at
* Early return for empty RLP trie storage
* Update comments
* Fix borrow_mut issue
* Simplify checkpoint_storage_at if branches
* Better commenting for gas handling code
* Address naming grumbles
* More tests
* Fix an issue in overwrite_with
* Add another test
* Fix comment
* Remove unnecessary bracket
* Move orig to inner if
* Remove test coverage for this PR
* Add tests for executive original value
* Add warn! for an unreachable cause
// 1. If current value equals new value (this is a no-op), 200 gas is deducted.
355
+
schedule.sload_gas
356
+
}else{
357
+
// 2. If current value does not equal new value
358
+
if original == current {
359
+
// 2.1. If original value equals current value (this storage slot has not been changed by the current execution context)
360
+
if original.is_zero(){
361
+
// 2.1.1. If original value is 0, 20000 gas is deducted.
362
+
schedule.sstore_set_gas
363
+
}else{
364
+
// 2.1.2. Otherwise, 5000 gas is deducted.
365
+
schedule.sstore_reset_gas
366
+
367
+
// 2.1.2.1. If new value is 0, add 15000 gas to refund counter.
368
+
}
369
+
}else{
370
+
// 2.2. If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
371
+
schedule.sload_gas
372
+
373
+
// 2.2.1. If original value is not 0
374
+
// 2.2.1.1. If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
375
+
// 2.2.1.2. If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
376
+
377
+
// 2.2.2. If original value equals new value (this storage slot is reset)
378
+
// 2.2.2.1. If original value is 0, add 19800 gas to refund counter.
379
+
// 2.2.2.2. Otherwise, add 4800 gas to refund counter.
let sstore_clears_schedule = U256::from(ext.schedule().sstore_refund_gas);
387
+
388
+
if current == new {
389
+
// 1. If current value equals new value (this is a no-op), 200 gas is deducted.
390
+
}else{
391
+
// 2. If current value does not equal new value
392
+
if original == current {
393
+
// 2.1. If original value equals current value (this storage slot has not been changed by the current execution context)
394
+
if original.is_zero(){
395
+
// 2.1.1. If original value is 0, 20000 gas is deducted.
396
+
}else{
397
+
// 2.1.2. Otherwise, 5000 gas is deducted.
398
+
if new.is_zero(){
399
+
// 2.1.2.1. If new value is 0, add 15000 gas to refund counter.
400
+
ext.add_sstore_refund(sstore_clears_schedule);
401
+
}
402
+
}
403
+
}else{
404
+
// 2.2. If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
405
+
406
+
if !original.is_zero(){
407
+
// 2.2.1. If original value is not 0
408
+
if current.is_zero(){
409
+
// 2.2.1.1. If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
410
+
ext.sub_sstore_refund(sstore_clears_schedule);
411
+
}elseif new.is_zero(){
412
+
// 2.2.1.2. If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
413
+
ext.add_sstore_refund(sstore_clears_schedule);
414
+
}
415
+
}
416
+
417
+
if original == new {
418
+
// 2.2.2. If original value equals new value (this storage slot is reset)
419
+
if original.is_zero(){
420
+
// 2.2.2.1. If original value is 0, add 19800 gas to refund counter.
421
+
let refund = U256::from(ext.schedule().sstore_set_gas - ext.schedule().sload_gas);
422
+
ext.add_sstore_refund(refund);
423
+
}else{
424
+
// 2.2.2.2. Otherwise, add 4800 gas to refund counter.
425
+
let refund = U256::from(ext.schedule().sstore_reset_gas - ext.schedule().sload_gas);
0 commit comments