|
23 | 23 | # SLOAD, SSTORE, TLOAD, TSTORE |
24 | 24 |
|
25 | 25 |
|
26 | | -# `key_mut` indicates the key isn't fixed. |
27 | | -@pytest.mark.parametrize("key_mut", [True, False]) |
28 | | -# `val_mut` indicates that at the end of each big-loop, the value of the target |
29 | | -# key changes. |
30 | | -@pytest.mark.parametrize("val_mut", [True, False]) |
| 26 | +@pytest.mark.parametrize("fixed_key", [True, False]) |
| 27 | +@pytest.mark.parametrize("fixed_value", [True, False]) |
31 | 28 | def test_tload( |
32 | 29 | benchmark_test: BenchmarkTestFiller, |
33 | | - key_mut: bool, |
34 | | - val_mut: bool, |
| 30 | + fixed_key: bool, |
| 31 | + fixed_value: bool, |
35 | 32 | ) -> None: |
36 | 33 | """Benchmark TLOAD instruction.""" |
37 | 34 | setup = Bytecode() |
38 | | - if key_mut and val_mut: |
| 35 | + if not fixed_key and not fixed_value: |
39 | 36 | setup = Op.GAS + Op.TSTORE(Op.DUP2, Op.GAS) |
40 | 37 | attack_block = Op.TLOAD(Op.DUP1) |
41 | | - if key_mut and not val_mut: |
| 38 | + if not fixed_key and fixed_value: |
42 | 39 | attack_block = Op.TLOAD(Op.GAS) |
43 | | - if not key_mut and val_mut: |
44 | | - setup = Op.TSTORE(Op.CALLVALUE, Op.GAS) |
45 | | - attack_block = Op.TLOAD(Op.CALLVALUE) |
46 | | - if not key_mut and not val_mut: |
47 | | - attack_block = Op.TLOAD(Op.CALLVALUE) |
| 40 | + if fixed_key and not fixed_value: |
| 41 | + setup = Op.TSTORE(Op.CALLDATASIZE, Op.GAS) |
| 42 | + attack_block = Op.TLOAD(Op.CALLDATASIZE) |
| 43 | + if fixed_key and fixed_value: |
| 44 | + attack_block = Op.TLOAD(Op.CALLDATASIZE) |
48 | 45 |
|
49 | | - tx_value = 42 if not key_mut and val_mut else 0 |
| 46 | + tx_data = b"42" if fixed_key and not fixed_value else 0 |
50 | 47 |
|
51 | 48 | benchmark_test( |
52 | 49 | code_generator=ExtCallGenerator( |
53 | 50 | setup=setup, |
54 | 51 | attack_block=attack_block, |
55 | | - contract_balance=tx_value, |
| 52 | + tx_kwargs={"data": tx_data}, |
56 | 53 | ), |
57 | 54 | ) |
58 | 55 |
|
59 | 56 |
|
60 | | -@pytest.mark.parametrize("key_mut", [True, False]) |
61 | | -@pytest.mark.parametrize("dense_val_mut", [True, False]) |
| 57 | +@pytest.mark.parametrize("fixed_key", [True, False]) |
| 58 | +@pytest.mark.parametrize("fixed_value", [True, False]) |
62 | 59 | def test_tstore( |
63 | 60 | benchmark_test: BenchmarkTestFiller, |
64 | | - key_mut: bool, |
65 | | - dense_val_mut: bool, |
| 61 | + fixed_key: bool, |
| 62 | + fixed_value: bool, |
66 | 63 | ) -> None: |
67 | 64 | """Benchmark TSTORE instruction.""" |
68 | 65 | init_key = 42 |
69 | 66 | setup = Op.PUSH1(init_key) |
70 | 67 |
|
71 | | - # If `dense_val_mut` is set, we use GAS as a cheap way of always |
72 | | - # storing a different value than |
73 | | - # the previous one. |
74 | | - attack_block = Op.TSTORE(Op.DUP2, Op.GAS if dense_val_mut else Op.DUP1) |
| 68 | + # If fixed_value is False, we use GAS as a cheap way of always |
| 69 | + # storing a different value than the previous one. |
| 70 | + attack_block = Op.TSTORE(Op.DUP2, Op.GAS if not fixed_value else Op.DUP1) |
75 | 71 |
|
76 | | - # If `key_mut` is True, we mutate the key on every iteration of the |
| 72 | + # If fixed_key is False, we mutate the key on every iteration of the |
77 | 73 | # big loop. |
78 | | - cleanup = Op.POP + Op.GAS if key_mut else Bytecode() |
| 74 | + cleanup = Op.POP + Op.GAS if not fixed_key else Bytecode() |
79 | 75 |
|
80 | 76 | benchmark_test( |
81 | 77 | code_generator=JumpLoopGenerator( |
|
0 commit comments