File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1159,3 +1159,43 @@ def _generate_bn128_pairs(n: int, seed: int = 0):
1159
1159
calldata = Bytes (calldata + pair_calldata )
1160
1160
1161
1161
return calldata
1162
+
1163
+
1164
+ @pytest .mark .parametrize (
1165
+ "calldata" ,
1166
+ [
1167
+ pytest .param (b"" , id = "empty" ),
1168
+ pytest .param (b"\x00 " , id = "zero-loop" ),
1169
+ pytest .param (b"\x00 " * 31 + b"\x20 " , id = "one-loop" ),
1170
+ ],
1171
+ )
1172
+ def test_worst_calldataload (
1173
+ state_test : StateTestFiller ,
1174
+ pre : Alloc ,
1175
+ fork : Fork ,
1176
+ calldata : bytes ,
1177
+ ):
1178
+ """Test running a block with as many CALLDATALOAD as possible."""
1179
+ env = Environment ()
1180
+
1181
+ code_prefix = Op .PUSH0 + Op .JUMPDEST
1182
+ code_suffix = Op .PUSH1 (1 ) + Op .JUMP
1183
+ code_body_len = MAX_CODE_SIZE - len (code_prefix ) - len (code_suffix )
1184
+ code_loop_iter = Op .CALLDATALOAD
1185
+ code_body = code_loop_iter * (code_body_len // len (code_loop_iter ))
1186
+ code = code_prefix + code_body + code_suffix
1187
+ assert len (code ) <= MAX_CODE_SIZE
1188
+
1189
+ tx = Transaction (
1190
+ to = pre .deploy_contract (code = code ),
1191
+ data = calldata ,
1192
+ gas_limit = env .gas_limit ,
1193
+ sender = pre .fund_eoa (),
1194
+ )
1195
+
1196
+ state_test (
1197
+ env = env ,
1198
+ pre = pre ,
1199
+ post = {},
1200
+ tx = tx ,
1201
+ )
You can’t perform that action at this time.
0 commit comments