@@ -1003,6 +1003,49 @@ def test_worst_mod(
1003
1003
)
1004
1004
1005
1005
1006
+ @pytest .mark .valid_from ("Cancun" )
1007
+ @pytest .mark .parametrize ("opcode" , [Op .MLOAD , Op .MSTORE , Op .MSTORE8 ])
1008
+ @pytest .mark .parametrize ("offset" , [0 , 1 , 31 ])
1009
+ @pytest .mark .parametrize ("offset_initialized" , [True , False ])
1010
+ @pytest .mark .parametrize ("big_memory_expansion" , [True , False ])
1011
+ def test_worst_memory_access (
1012
+ state_test : StateTestFiller ,
1013
+ pre : Alloc ,
1014
+ opcode : Op ,
1015
+ offset : int ,
1016
+ offset_initialized : bool ,
1017
+ big_memory_expansion : bool ,
1018
+ ):
1019
+ """Test running a block with as many memory access instructions as possible."""
1020
+ env = Environment ()
1021
+
1022
+ mem_exp_code = Op .MSTORE8 (10 * 1024 , 1 ) if big_memory_expansion else Bytecode ()
1023
+ offset_set_code = Op .MSTORE (offset , 43 ) if offset_initialized else Bytecode ()
1024
+ code_prefix = mem_exp_code + offset_set_code + Op .PUSH1 (42 ) + Op .PUSH1 (offset ) + Op .JUMPDEST
1025
+
1026
+ code_suffix = Op .JUMP (len (code_prefix ) - 1 )
1027
+
1028
+ loop_iter = Op .POP (Op .MLOAD (Op .DUP1 )) if opcode == Op .MLOAD else opcode (Op .DUP2 , Op .DUP2 )
1029
+
1030
+ code_body_len = (MAX_CODE_SIZE - len (code_prefix ) - len (code_suffix )) // len (loop_iter )
1031
+ code_body = loop_iter * code_body_len
1032
+ code = code_prefix + code_body + code_suffix
1033
+ assert len (code ) <= MAX_CODE_SIZE
1034
+
1035
+ tx = Transaction (
1036
+ to = pre .deploy_contract (code = code ),
1037
+ gas_limit = env .gas_limit ,
1038
+ sender = pre .fund_eoa (),
1039
+ )
1040
+
1041
+ state_test (
1042
+ env = env ,
1043
+ pre = pre ,
1044
+ post = {},
1045
+ tx = tx ,
1046
+ )
1047
+
1048
+
1006
1049
@pytest .mark .valid_from ("Cancun" )
1007
1050
def test_empty_block (
1008
1051
blockchain_test : BlockchainTestFiller ,
0 commit comments