Skip to content

Commit a7fcd0e

Browse files
committed
new(tests): Add tests for OOGing in LOGx variable gas
1 parent 1e90f5e commit a7fcd0e

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

tests/frontier/opcodes/test_log.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
Test LOGx opcodes.
3+
"""
4+
5+
import pytest
6+
7+
from ethereum_test_base_types.base_types import ZeroPaddedHexNumber
8+
from ethereum_test_forks import Fork
9+
from ethereum_test_tools import (
10+
Alloc,
11+
Environment,
12+
StateTestFiller,
13+
)
14+
from ethereum_test_vm import Opcodes as Op
15+
from tests.unscheduled.eip7692_eof_v1.gas_test import gas_test
16+
17+
REFERENCE_SPEC_GIT_PATH = "N/A"
18+
REFERENCE_SPEC_VERSION = "N/A"
19+
20+
21+
def log_gas(fork: Fork, topics: int, data_size: int) -> int:
22+
"""
23+
Calculate gas cost for LOGx opcodes given the number of topics and data
24+
size.
25+
"""
26+
return (
27+
fork.gas_costs().G_LOG
28+
+ fork.gas_costs().G_LOG_TOPIC * topics
29+
+ fork.gas_costs().G_LOG_DATA * data_size
30+
)
31+
32+
33+
@pytest.mark.valid_from("Berlin")
34+
@pytest.mark.parametrize(
35+
"opcode,topics", [(Op.LOG0, 0), (Op.LOG1, 1), (Op.LOG2, 2), (Op.LOG3, 3), (Op.LOG4, 4)]
36+
)
37+
@pytest.mark.parametrize(
38+
"data_size",
39+
[
40+
0,
41+
1,
42+
2,
43+
1023,
44+
1024,
45+
],
46+
)
47+
def test_gas(
48+
state_test: StateTestFiller,
49+
pre: Alloc,
50+
opcode: Op,
51+
topics: int,
52+
data_size: int,
53+
fork: Fork,
54+
env: Environment,
55+
) -> None:
56+
"""Test that LOGx gas works as expected."""
57+
warm_gas = log_gas(fork, topics, data_size)
58+
59+
if cap := fork.transaction_gas_limit_cap():
60+
env.gas_limit = ZeroPaddedHexNumber(cap)
61+
print(hex(data_size))
62+
63+
gas_test(
64+
fork,
65+
state_test,
66+
env,
67+
pre,
68+
setup_code=Op.MSTORE8(data_size, 0)
69+
+ Op.PUSH1(0) * topics
70+
+ Op.PUSH32(data_size)
71+
+ Op.PUSH1(0),
72+
subject_code=opcode,
73+
tear_down_code=Op.STOP,
74+
cold_gas=warm_gas,
75+
warm_gas=warm_gas,
76+
eof=False,
77+
)

0 commit comments

Comments
 (0)