Background

September 1, 2020 · View on GitHub

To check the effects of Gas cost increases for state access opcodes, a modified geth-version with support for the to-be-eip was used.

Setup

The experiment was run on Goerli blocks from number=3321372 to number=3321425, using a fast-synced geth with gcmode=archive, thus not pruning state.

A modified version of standardTraceBlockToFile was added to the geth instance, making it possible to trace blocks using alternate rules, like so:

    debug.standardTraceBlockToFile(blockhash,{"overrides":{
        "yoloV2Block": 0
        }})

The analysis.js was loaded, and the traces were generated (those are 500+Mb, I decided not to include them in this repo), containing the trace for 53 blocks, totalling 106 transactions.

The experiment

When running with new rules, two things can typically happen:

  1. The execution flow is broken. The easiest way to detect this is to compare the number of operations executed. If the exact same operations were executed in both traces, the flow was not broken.
  2. The execution flow was not broken.

For 1), it is interesting to analyse:

A. Would this particular execution have been 'salvaged' if more gas had been provided by the external caller? B. If not, would the POKE precompile have 'salvaged' it? C. If not, would the tx-access list have 'salvaged' it?

For 2), it is interesting to analyse:

A) What was the difference in gas used by the transaction? Did the alternative transaction consume more or less?

Goerli results.

There were 100 transactions that were OK, as in, the execution finished the same way in both the 'canon' version and the 'alt' (gas-cost-increase version):

txhashsteps(canon)steps(alt)OK?gas(canon)gas(alt)diff
0x268883561557015570ok46922651862610.00 %
0x9f79579811ok000.00 %
0xf89eb38e340340ok31967343677.00 %
0xa00845291563015630ok4129824251822.00 %
0xcf9553b21563015630ok4129824251822.00 %
0x5768df5e11ok000.00 %
0xb33b6d6d11ok000.00 %
0xb6dce7791563015630ok4129824251822.00 %
0x20313f8f14111411ok761448994418.00 %
0xbf98737d11ok000.00 %
0x04b95f1b258258ok29362298621.00 %
0x5867d8111563015630ok4129824251822.00 %
0x6e4496c71563015630ok4129824251822.00 %
0x7e005bb011ok000.00 %
0x84a35acb1563015630ok4129824251822.00 %
0xe10171a611ok000.00 %
0x3fd24de9377377ok1548815188-2.00 %
0x3cca6923377377ok1548815188-2.00 %
0xd787848a377377ok1548815188-2.00 %
0xb70224df1563015630ok4129824251822.00 %
0x8f60fe0d377377ok1548815188-2.00 %
0xcd7e7ce61563015630ok4129824251822.00 %
0x5891f56863256325ok2989603121604.00 %
0x578a51ef2399023990ok9061849538845.00 %
0x848ebe81258258ok29362298621.00 %
0x9fdf8667377377ok1548815188-2.00 %
0xef2b2bf2258258ok29362298621.00 %
0x6770fd0411ok000.00 %
0xf276ac6463256325ok2989603121604.00 %
0x94826b3d11ok000.00 %
0xf7c56b8f1563015630ok4321824450822.00 %
0x8973962a63326332ok2989803076802.00 %
0x171ab5c762576257ok169712155612-9.00 %
0x9577d126258258ok29362298621.00 %
0x9301dd6d63256325ok2989603121604.00 %
0x2c10f55a258258ok29362298621.00 %
0x4439231611ok000.00 %
0x75daeceb258258ok2936227862-6.00 %
0x0222d6cf1563015630ok4321824450822.00 %
0x44df7cfa377377ok154889188-41.00 %
0xbdc1c6cf63256325ok2989603121604.00 %
0x23029eec63256325ok298960268160-11.00 %
0x2c2075311563015630ok4129824251822.00 %
0x1a8d48e563256325ok2989603121604.00 %
0x37f83d52258258ok2936227862-6.00 %
0x5395285e11ok000.00 %
0xadfacf22502502ok198542475424.00 %
0x9331a03011ok000.00 %
0x5b7ea6ac377377ok1548815188-2.00 %
0xce51e39e1563015630ok4129824251822.00 %
0x27147082377377ok1548815188-2.00 %
0x9e4b02ee258258ok29362298621.00 %
0x561ca5d863326332ok2989803121804.00 %
0x9ea5e14063326332ok298980268180-11.00 %
0xdbead36b377377ok1548815188-2.00 %
0x8c33128d258258ok29362298621.00 %
0x0150ed20340340ok1276712467-3.00 %
0x0f9a5a0f377377ok1548815188-2.00 %
0x26eecdb0258258ok29362298621.00 %
0x6862245663256325ok298960268160-11.00 %
0x7a18066011ok000.00 %
0xd356e16c1563015630ok4321824450822.00 %
0xda048c47377377ok1548815188-2.00 %
0xdf322b2a11ok000.00 %
0xa66cdfe811ok000.00 %
0x550770b31573115731ok114908712091875.00 %
0xcf57527b62576257ok169712155612-9.00 %
0x113897c1377377ok1548815188-2.00 %
0xb07f73f6258258ok2936227862-6.00 %
0xe1883f4311ok000.00 %
0xf07e2c52210210ok151808715180870.00 %
0x55c2d6df377377ok1548815188-2.00 %
0x7499547c1557015570ok46922651862610.00 %
0xb917dc6711ok000.00 %
0x420cd0e263326332ok2989803076802.00 %
0x90b1ec09377377ok1548815188-2.00 %
0xd5d7cf5c62576257ok169712150612-12.00 %
0xfadc30ea1563015630ok4129824251822.00 %
0x0dffecb463256325ok2989603121604.00 %
0xf7151f6f258258ok29362298621.00 %
0x5c72a21a1563015630ok4129824251822.00 %
0x1d29f0b2377377ok1548815188-2.00 %
0xcdd7a3d5377377ok1548815188-2.00 %
0x672f102711ok000.00 %
0x2f4c2c25258258ok2936227862-6.00 %
0x60f5268a11ok000.00 %
0xac1c6cfe377377ok1548815188-2.00 %
0xd41659a711ok000.00 %
0x7143595911ok000.00 %
0x10e72aa762576257ok169712150612-12.00 %
0xfd89999c62436243ok169658155558-9.00 %
0xd690c1771563015630ok4129824251822.00 %
0xadef95d211ok000.00 %
0x9e1662e4377377ok1548815188-2.00 %
0xa97ab7a711ok000.00 %
0x643d441f11ok000.00 %
0x50f7d37263326332ok2989803121804.00 %
0xff5bbcff1573115731ok114908712091875.00 %
OK: 98, broken: 8
Canon gas used: 17862517, alt gas used: 18284517

And 8 transactions were 'broken':

txhashsteps(canon)steps(alt)OK?gas(canon)gas(alt)diff
0xd67b5067557547BROKEN46354463540.00 %
0x8574e95d32973187BROKEN5195305195300.00 %
0xfc2b04ed47752638BROKEN199854194824-3.00 %
0xd96c736a6044274BROKEN12467315895427.00 %
0xcbd02f656044274BROKEN12467315895427.00 %
0xe85c0e23369362BROKEN61215612150.00 %
0xaeb938091511912190BROKEN400331384420-4.00 %
0xef39d3b16411761159BROKEN439888344014150.00 %

Broken flows

This section was written with traces generated by an earlier implementation of the spec, which undercharged some calls by 700, and where only 6 txs failed. It has not been updated with the data from the regenerated table above

Let's look deeper into the broken ones:

0xd67b5067

block_0x19ef4a84-2-0xd67b5067-742912372:


─────────────────────────Operations─────────────────────────┐┌─────────────────────────Operations──────────────────────────┐
│STEP      PC       OPNAME  OPCODE GAS  GASCOST DEPTH REFUND ││STEP      PC      OPNAME OPCODE GAS  GASCOST DEPTH REFUND    │
│538  2724 (0xaa4) POP      0x50   8187 2       1     0      ││528  2714 (0xa9a) ADD    0x1    5714 3       1     0         │
│539  2725 (0xaa5) POP      0x50   8185 2       1     0      ││529  2715 (0xa9b) DUP3   0x82   5711 3       1     0         │
│540  2726 (0xaa6) POP      0x50   8183 2       1     0      ││530  2716 (0xa9c) SWAP1  0x90   5708 3       1     0         │
│541  2727 (0xaa7) POP      0x50   8181 2       1     0      ││531  2717 (0xa9d) SUB    0x3    5705 3       1     0         │
│542  2728 (0xaa8) POP      0x50   8179 2       1     0      ││532  2718 (0xa9e) SWAP11 0x9a   5702 3       1     0         │
│543  2729 (0xaa9) POP      0x50   8177 2       1     0      ││533  2719 (0xa9f) POP    0x50   5699 2       1     0         │
│544  2730 (0xaaa) POP      0x50   8175 2       1     0      ││534  2720 (0xaa0) SWAP1  0x90   5697 3       1     0         │
│545  2731 (0xaab) LOG1     0xa1   8173 8150    1     0      ││535  2721 (0xaa1) SWAP9  0x98   5694 3       1     0         │
│546  2732 (0xaac) POP      0x50   23   2       1     0      ││536  2722 (0xaa2) POP    0x50   5691 2       1     0         │
│547  2733 (0xaad) POP      0x50   21   2       1     0      ││537  2723 (0xaa3) POP    0x50   5689 2       1     0         │
│548  2734 (0xaae) POP      0x50   19   2       1     0      ││538  2724 (0xaa4) POP    0x50   5687 2       1     0         │
│549  2735 (0xaaf) POP      0x50   17   2       1     0      ││539  2725 (0xaa5) POP    0x50   5685 2       1     0         │
│550  2736 (0xab0) POP      0x50   15   2       1     0      ││540  2726 (0xaa6) POP    0x50   5683 2       1     0         │
│551  2737 (0xab1) POP      0x50   13   2       1     0      ││541  2727 (0xaa7) POP    0x50   5681 2       1     0         │
│552  2738 (0xab2) POP      0x50   11   2       1     0      ││542  2728 (0xaa8) POP    0x50   5679 2       1     0         │
│553  2739 (0xab3) JUMP     0x56   9    8       1     0      ││543  2729 (0xaa9) POP    0x50   5677 2       1     0         │
│554  426 (0x1aa)  JUMPDEST 0x5b   1    1       1     0      ││544  2730 (0xaaa) POP    0x50   5675 2       1     0         │
│555  427 (0x1ab)  STOP     0x0    0    0       1     0      ││545  2731 (0xaab) LOG1   0xa1   5673 8150    1     0         │
└────────────────────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────┘

This tx breaks on a LOG1 instruction on the outermost depth. Therefore, it would have succeeded with some more gas from the EOA. It can also be noted that the canon tx also went OOG, so technically there was no change.

0x8574e95d

This tx also goes OOG in the uppermost depth, at step 3185, where it hits an SSTORE. The canon tx has 63K gas left at this point, but the alt has only 11K. This is also a situation where more gas from outside would have salvaged the call.

It can also be noted that for this transaction too, the canon tx also went OOG, so technically there was no change.

0xfc2b04ed

This tx is actually different - the canon tx does not go OOG. The canon transaction does a series of deep calls, and goes through 4773 steps of execution. The 'alt' transaction fails at step 2638. However, the execution differs even earlier :

┌─────────────────────────Operations─────────────────────────┐┌─────────────────────────Operations──────────────────────────┐
│STEP       PC        OPNAME  OPCODE  GAS  GASCOST DEPTH EFU…││STEP       PC           OPNAME     OPCODE GAS  GASCOST DEPTH │
│2591 18041 (0x4679) SWAP2    0x91   43718 3       4     0   ││2591 18041 (0x4679) SWAP2          0x91   4571 3       4     │
│2592 18042 (0x467a) SSTORE   0x55   43715 800     4     0   ││2592 18042 (0x467a) SSTORE         0x55   4568 2100    4     │
│2593 18043 (0x467b) PUSH1    0x60   42915 3       4     0   ││2593 18043 (0x467b) PUSH1          0x60   2468 3       4     │
│2594 18045 (0x467d) SSTORE   0x55   42912 5000    4     0   ││2594 18045 (0x467d) SSTORE         0x55   2465 3000    4     │
│2595 18046 (0x467e) JUMP     0x56   37912 8       4     0   ││2595 607 (0x25f)    RETURNDATASIZE 0x3d   8097 2       3     │
│2596 4899 (0x1323)  JUMPDEST 0x5b   37904 1       4     0   ││2596 608 (0x260)    PUSH1          0x60   8095 3       3     │
│2597 4900 (0x1324)  PUSH2    0x61   37903 3       4     0   ││2597 610 (0x262)    MLOAD          0x51   8092 3       3     │
│2598 4903 (0x1327)  DUP2     0x81   37900 3       4     0   ││2598 611 (0x263)    DUP2           0x81   8089 3       3     │

At step 2594, a call at depth 4 exits with OOG. The call was initiated at step 1229, and is a DELEGATECALL with gas not being hardcoded, but GAS.

Call ladder:

  1. delegatecall(GAS)
  2. call(GAS)
  3. delegatecall(GAS)

Since the gas is never restricted, it appears that this tx would have been salvageable with more outer gas.

0x8574e95d

The 0x8574e95d transaction has 3295 canon steps, but exits early after 3185 steps on 'alt', where an SSTORE occurs, causing OOG. The event happens on depth=1, meaning that more outer gas would have salvaged the flow.

0xfc2b04ed

The 0xfc2b04ed tx has 4773 steps, but the 'alt' is aborted after '2638' steps. However, the execution flow is disrupted at step 2594, where an SSTORE at depth=4 causes a subcall to go OOG:

─────────────────────────Operations─────────────────────────┐┌─────────────────────────Operations──────────────────────────┐
│STEP       PC        OPNAME  OPCODE  GAS  GASCOST DEPTH EFU…││STEP       PC           OPNAME     OPCODE GAS  GASCOST DEPTH │
│2591 18041 (0x4679) SWAP2    0x91   43718 3       4     0   ││2591 18041 (0x4679) SWAP2          0x91   4571 3       4     │
│2592 18042 (0x467a) SSTORE   0x55   43715 800     4     0   ││2592 18042 (0x467a) SSTORE         0x55   4568 2100    4     │
│2593 18043 (0x467b) PUSH1    0x60   42915 3       4     0   ││2593 18043 (0x467b) PUSH1          0x60   2468 3       4     │
│2594 18045 (0x467d) SSTORE   0x55   42912 5000    4     0   ││2594 18045 (0x467d) SSTORE         0x55   2465 3000    4     │
│2595 18046 (0x467e) JUMP     0x56   37912 8       4     0   ││2595 607 (0x25f)    RETURNDATASIZE 0x3d   8097 2       3     │
│2596 4899 (0x1323)  JUMPDEST 0x5b   37904 1       4     0   ││2596 608 (0x260)    PUSH1          0x60   8095 3       3     │
│2597 4900 (0x1324)  PUSH2    0x61   37903 3       4     0   ││2597 610 (0x262)    MLOAD          0x51   8092 3       3     │
│2598 4903 (0x1327)  DUP2     0x81   37900 3       4     0   ││2598 611 (0x263)    DUP2           0x81   8089 3       3     │
│2599 4904 (0x1328)  DUP6     0x85   37897 3       4     0   ││2599 612 (0x264)    PUSH1          0x60   8086 3       3     │
│2600 4905 (0x1329)  DUP12    0x8b   37894 3       4     0   ││2600 614 (0x266)    DUP3           0x82   8083 3       3     │
│2601 4906 (0x132a)  DUP10    0x89   37891 3       4     0   ││2601 615 (0x267)    RETURNDATACOPY 0x3e   8080 3       3     │
└────────────────────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────┘

Call ladder:

  1. DCALL(GAS-10000) to 0x6b8a780124a2259b... (ctx: NA)
  2. CALL(GAS) to 0x5b67626cbf5d1677...
  3. DCALL(GAS) to 0xfe488f251a7c6e63... (ctx: 0x5b67626cbf5d1677...)

It seems that this one would have been salvaged by more external gas.

0xe85c0e23

The 0xe85c0e23 goes OOG at step 360, where it does a LOG2 operation, where the 'canon' trace continues another 7 steps. This happens at depth=1, meaning that more external gas would have solved it.

0xaeb93809

This is a very long trace, reaching depths of 6. The execution flow is diverted at depth 6, on step 12405, where an SSTORE causes OOG:

┌─────────────────────────Operations─────────────────────────┐┌─────────────────────────Operations──────────────────────────┐
│STEP        PC        OPNAME  OPCODE  GAS  GASCOST DEPTH EF…││STEP        PC           OPNAME     OPCODE GAS  GASCOST DEPTH│
│12398 9075 (0x2373)  POP      0x50   50012 2       6     0  ││12398 9075 (0x2373)  POP            0x50   1275 2       6    │
│12399 9076 (0x2374)  POP      0x50   50010 2       6     0  ││12399 9076 (0x2374)  POP            0x50   1273 2       6    │
│12400 9077 (0x2375)  JUMP     0x56   50008 8       6     0  ││12400 9077 (0x2375)  JUMP           0x56   1271 8       6    │
│12401 10784 (0x2a20) JUMPDEST 0x5b   50000 1       6     0  ││12401 10784 (0x2a20) JUMPDEST       0x5b   1263 1       6    │
│12402 10785 (0x2a21) PUSH1    0x60   49999 3       6     0  ││12402 10785 (0x2a21) PUSH1          0x60   1262 3       6    │
│12403 10787 (0x2a23) DUP2     0x81   49996 3       6     0  ││12403 10787 (0x2a23) DUP2           0x81   1259 3       6    │
│12404 10788 (0x2a24) SWAP1    0x90   49993 3       6     0  ││12404 10788 (0x2a24) SWAP1          0x90   1256 3       6    │
│12405 10789 (0x2a25) SSTORE   0x55   49990 5000    6     0  ││12405 10789 (0x2a25) SSTORE         0x55   1253 0       6    │
│12406 10790 (0x2a26) POP      0x50   44990 2       6     0  ││12406 684 (0x2ac)    RETURNDATASIZE 0x3d   9897 2       5    │
│12407 10791 (0x2a27) PUSH1    0x60   44988 3       6     0  ││12407 685 (0x2ad)    PUSH1          0x60   9895 3       5    │
│12408 10793 (0x2a29) PUSH2    0x61   44985 3       6     0  ││12408 687 (0x2af)    MLOAD          0x51   9892 3       5    │
│12409 10796 (0x2a2c) DUP3     0x82   44982 3       6     0  ││12409 688 (0x2b0)    DUP2           0x81   9889 3       5    │
│12410 10797 (0x2a2d) DUP7     0x86   44979 3       6     0  ││12410 689 (0x2b1)    PUSH1          0x60   9886 3       5    │
│12411 10798 (0x2a2e) PUSH2    0x61   44976 3       6     0  ││12411 691 (0x2b3)    DUP3           0x82   9883 3       5    │
│12412 10801 (0x2a31) SWAP1    0x90   44973 3       6     0  ││12412 692 (0x2b4)    RETURNDATACOPY 0x3e   9880 3       5    │
│12413 10802 (0x2a32) SWAP2    0x91   44970 3       6     0  ││12413 693 (0x2b5)    DUP3           0x82   9877 3       5    │
└────────────────────────────────────────────────────────────┘└─────────────────────────────────────────────────────────────┘

Call ladder:

call 4  DCALL to 0xfd259808f4c08b12... 
	- gas = `GAS-10K`
call 3  CALL to 0xf5e574045298ee3a... 
	- gas = `GAS`
call 2  DCALL to 0x25723f81ebf997f3... 
	- gas = `GAS-10K`
call 1  CALL to 0x00200ea4ee292e25... 
	- gas = `GAS`
call 0  DCALL to 0xce29aedcdbeef0b0... 
	- gas = `GAS-10K`

Since this uses GAS (minus some constant), it seems likely that this could also be salvaged by using more external gas.

0xef39d3b1

This is another extremely long trace, with 60K+ steps. At step 61764, at depth 2, an SLOAD causes the 'alt'-trace to go OOG. The depth 2 was reached via a DELEGATECALL(GAS...), so it appears that this would also have been salvageable via more external gas.

Summary

The test on Goerli, covering 106 transactions, showed

  • Out of 106 transactions, 98 were not meaningfully affected by the change,
  • For those 98 transactions,
    • The 'canon' gas used was 17862517,
    • and the 'alt' gas used was 18284517, which is +2.36%.
  • Out of the 8 failing transactions,
    • 2 went OOG in the 'canon' version aswell as in the alt version
    • All 6 seems to have been salvageable by using more external gas by the caller. (OBS The manual analysis is not updated after rerun with new constants)

Note: the gas here refers to the gas used by the evm execution, and does not take into concern the intrinsic gas used by the envelope transaction. Thus, a non-executing raw ether-send is listed as 0 gas.