@@ -1715,22 +1715,43 @@ def test_worst_calldataload(
1715
1715
pytest .param (Op .LOG4 , id = "log4" ),
1716
1716
],
1717
1717
)
1718
- def test_worst_log_opcodes (state_test : StateTestFiller , pre : Alloc , fork : Fork , opcode : Opcode ):
1718
+ @pytest .mark .parametrize ("empty_value" , [True , False ])
1719
+ @pytest .mark .parametrize ("offset" , [0 , 1 , 2 , 3 , 4 ])
1720
+ def test_worst_log_opcodes (
1721
+ state_test : StateTestFiller ,
1722
+ pre : Alloc ,
1723
+ fork : Fork ,
1724
+ opcode : Opcode ,
1725
+ empty_value : bool ,
1726
+ offset : int ,
1727
+ ):
1719
1728
"""Test running a block with as many LOG opcodes as possible."""
1720
1729
env = Environment ()
1721
- max_code_size = 20
1730
+ max_code_size = fork . max_code_size ()
1722
1731
1723
- iter_code = Op .PUSH0 * len (opcode .kwargs ) + opcode
1724
- code_prefix = Op .JUMPDEST
1725
- code_suffix = Op .PUSH0 + Op .JUMP
1732
+ push_value = Op .PUSH0 if empty_value else Op .PUSH32 (0xFF )
1726
1733
1727
- iter_count = ( max_code_size - len (code_prefix ) - len ( code_suffix )) // len ( iter_code )
1734
+ topic_count = len (opcode . kwargs ) - 2
1728
1735
1729
- code = code_prefix + iter_code * iter_count + code_suffix
1730
- assert len (code ) <= max_code_size
1736
+ code_sequence = (
1737
+ push_value * topic_count # Push topics
1738
+ + Op .PUSH32 (2 ** offset ) # Push memory size
1739
+ + Op .PUSH32 (10 ** offset ) # Push memory offset
1740
+ + opcode # Add the LOG opcode
1741
+ )
1731
1742
1743
+ # Calculate how many times we can repeat the sequence within code size limits
1744
+ code_prefix = Op .MSTORE (10 ** offset , push_value ) + Op .JUMPDEST
1745
+ code_suffix = Op .PUSH1 (len (code_prefix )) + Op .JUMP
1746
+ max_iterations = (max_code_size - len (code_prefix ) - len (code_suffix )) // len (code_sequence )
1747
+
1748
+ # Build the final code
1749
+ deployed_code = code_prefix + (code_sequence * max_iterations ) + code_suffix
1750
+ assert len (deployed_code ) <= max_code_size
1751
+
1752
+ # Create and execute the transaction
1732
1753
tx = Transaction (
1733
- to = pre .deploy_contract (code = code ),
1754
+ to = pre .deploy_contract (code = deployed_code ),
1734
1755
gas_limit = env .gas_limit ,
1735
1756
sender = pre .fund_eoa (),
1736
1757
)
0 commit comments