|
| 1 | +# 10 |
| 2 | +# Revert undoes transient storage writes from inner calls that successfully returned. |
| 3 | +# TSTORE(x, y), CALL(self, ...), CALL(self, ...), TSTORE(x, y + 1), RETURN, REVERT, TLOAD(x) returns y |
| 4 | +# |
| 5 | +# Expect slot 0 to have 5 from the first tstore & tload. |
| 6 | +# Expect slot 1 to have 0. Call was unsuccessful. |
| 7 | +# Expect slot 2 to have 1. Inner call was successful. |
| 8 | +# Expect slot 3 to have 5. Should load the value stored before the unsuccessful call. |
| 9 | + |
| 10 | +10_revertUndoesStoreAfterReturn: |
| 11 | + _info: |
| 12 | + comment: Revert undoes the transient storage writes after a successful call. |
| 13 | + |
| 14 | + env: |
| 15 | + currentCoinbase: 2adc25665018aa1fe0e6bc666dac8fc2697ff9ba |
| 16 | + currentDifficulty: 0x20000 |
| 17 | + currentNumber: 1 |
| 18 | + currentTimestamp: 1000 |
| 19 | + currentGasLimit: 0x10000000000000 |
| 20 | + currentBaseFee: 10 |
| 21 | + |
| 22 | + pre: |
| 23 | + A00000000000000000000000000000000000000A: |
| 24 | + balance: 1000000000000000000 |
| 25 | + nonce: 0 |
| 26 | + code: | |
| 27 | + :yul { |
| 28 | + switch selector() |
| 29 | +
|
| 30 | + case 0x70ac643e { // doFirstCall() |
| 31 | + doFirstCall() |
| 32 | + } |
| 33 | +
|
| 34 | + case 0x76b85d23 { // doCallThenRevert() |
| 35 | + doCallThenRevert() |
| 36 | + } |
| 37 | +
|
| 38 | + case 0x4ccca553 { // doSuccessfulStore() |
| 39 | + doSuccessfulStore() |
| 40 | + } |
| 41 | +
|
| 42 | + function doFirstCall() { |
| 43 | + verbatim_2i_0o(hex"5D", 0, 5) |
| 44 | +
|
| 45 | + let v := verbatim_1i_1o(hex"5C", 0) |
| 46 | + sstore(0, v) |
| 47 | +
|
| 48 | + mstore(0, hex"76b85d23") // calls doCallThenRevert() |
| 49 | + let fail := call(gas(), address(), 0, 0, 32, 0, 32) |
| 50 | +
|
| 51 | + sstore(1, fail) // should be 0 (revert) |
| 52 | + sstore(2, mload(0)) // load 1 (successful call) |
| 53 | +
|
| 54 | + let val := verbatim_1i_1o(hex"5C", 0) |
| 55 | + sstore(3, val) |
| 56 | + } |
| 57 | +
|
| 58 | + |
| 59 | + function doCallThenRevert() { |
| 60 | + mstore(0, hex"4ccca553") // calls doSuccessfulStore() |
| 61 | + let s := call(gas(), address(), 0, 0, 32, 0, 0) |
| 62 | + mstore(0, s) |
| 63 | + revert(0, 32) |
| 64 | + } |
| 65 | +
|
| 66 | + function doSuccessfulStore() { |
| 67 | + verbatim_2i_0o(hex"5D", 0, 6) |
| 68 | + } |
| 69 | +
|
| 70 | + function doReenter(fs) -> f { |
| 71 | + mstore(0, fs) |
| 72 | + f := call(gas(), address(), 0, 0, 32, 0, 0) |
| 73 | + } |
| 74 | +
|
| 75 | + function selector() -> s { |
| 76 | + let value := calldataload(0) |
| 77 | + s := shr(224, value) |
| 78 | + } |
| 79 | + } |
| 80 | + storage: { 0x01: 0xffff } |
| 81 | + a94f5374fce5edbc8e2a8697c15331677e6ebf0b: |
| 82 | + balance: 1000000000000000000000 |
| 83 | + code: "0x" |
| 84 | + nonce: 0 |
| 85 | + storage: {} |
| 86 | + |
| 87 | + transaction: |
| 88 | + data: |
| 89 | + - data: :abi doFirstCall() |
| 90 | + accessList: [] |
| 91 | + gasLimit: |
| 92 | + - "400000" |
| 93 | + nonce: 0 |
| 94 | + to: A00000000000000000000000000000000000000A |
| 95 | + value: |
| 96 | + - 0 |
| 97 | + secretKey: "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8" |
| 98 | + maxPriorityFeePerGas: 0 |
| 99 | + maxFeePerGas: 2000 |
| 100 | + |
| 101 | + expect: |
| 102 | + - network: |
| 103 | + - ">=Cancun" |
| 104 | + result: |
| 105 | + A00000000000000000000000000000000000000A: |
| 106 | + storage: |
| 107 | + 0x00: 5 |
| 108 | + 0x01: 0 |
| 109 | + 0x02: 1 |
| 110 | + 0x03: 5 |
0 commit comments