105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 | @EIPChecklist.BlockLevelConstraint.Test.Content.TransactionTypes()
@pytest.mark.inclusion_test
@pytest.mark.parametrize(
"typed_tx_position",
[
pytest.param(TypedTxPosition.HEAD, id="typed_head_tx"),
pytest.param(TypedTxPosition.TRAILING, id="typed_trailing_tx"),
],
)
@pytest.mark.with_all_tx_types()
@pytest.mark.with_all_refund_types()
@pytest.mark.filter_combinations(
lambda tx_type, typed_tx_position, **_: not (
tx_type == 0 and typed_tx_position is TypedTxPosition.TRAILING
),
reason=(
"a type-0 envelope on either side of the gate builds the same "
"block, already covered by the head parametrization"
),
)
@pytest.mark.parametrize(
"trailing_tx_block_gas_limit_delta",
[
pytest.param(
1,
id="extra_block_gas_limit",
),
pytest.param(
0,
id="exact_block_gas_limit",
),
pytest.param(
-1,
marks=[pytest.mark.exception_test],
id="exceeds_block_gas_limit",
),
],
)
def test_trailing_tx_admission_all_transaction_types(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
fork: Fork,
tx_type: int,
refund_type: RefundTypes,
typed_tx_position: TypedTxPosition,
authorization_list: list[AuthorizationTuple] | None,
trailing_tx_block_gas_limit_delta: int,
) -> None:
"""
Pin the admission gate with each tx type on either side of the gate.
The block gas limit leaves room for the trailing transaction only
under post-refund accounting, so it must be rejected whichever
envelope carries the refund and whichever one is turned away.
"""
typed_head = typed_tx_position is TypedTxPosition.HEAD
trailing_tx_succeeds = trailing_tx_block_gas_limit_delta >= 0
refund_tx = RefundTransaction.build(
fork=fork,
sender=pre.fund_eoa(INITIAL_FUND),
refund_types={refund_type},
refunds_count=REFUNDS_COUNT,
ty=tx_type if typed_head else 0,
authorization_list=authorization_list if typed_head else None,
)
refund_tx.set_pre(pre)
receipt_gas_used = refund_tx.expected_receipt.gas_used
assert receipt_gas_used is not None
assert refund_tx.block_execution() > receipt_gas_used, (
"Parametrization must produce a refund; without one pre- and "
"post-refund accounting agree"
)
stop_address = pre.deterministic_deploy_contract(deploy_code=Op.STOP)
trailing_auth = None if typed_head else authorization_list
trailing_ty = 0 if typed_head else tx_type
intrinsic_cost_calc = fork.transaction_intrinsic_cost_calculator()
# Slack so a post-refund gate admits the trailing tx and still keeps
# the block within its gas limit. The grant must also outgrow the
# refund tx's state gas: the admission gate weighs a full gas limit
# against the execution budget, so a block sized off the execution
# dimension alone would turn the refund tx itself away.
trailing_tx_gas_limit = (
2
* intrinsic_cost_calc(
calldata=b"",
authorization_list_or_count=trailing_auth,
)
+ refund_tx.state_gas
)
trailing_tx = Transaction(
ty=trailing_ty,
to=stop_address,
gas_limit=trailing_tx_gas_limit,
sender=pre.fund_eoa(),
authorization_list=trailing_auth,
blob_versioned_hashes=(
add_kzg_version([0x01], 0x01) if trailing_ty == 3 else None
),
error=None
if trailing_tx_succeeds
else TransactionException.GAS_ALLOWANCE_EXCEEDED,
)
block_gas_limit = (
refund_tx.block_execution()
+ trailing_tx_gas_limit
+ trailing_tx_block_gas_limit_delta
)
assert block_gas_limit >= refund_tx.gas_limit, (
"block must admit the refund transaction itself"
)
blockchain_test(
pre=pre,
blocks=[
Block(
txs=[refund_tx, trailing_tx],
gas_limit=block_gas_limit,
exception=None
if trailing_tx_succeeds
else [
BlockException.GAS_USED_OVERFLOW,
TransactionException.GAS_ALLOWANCE_EXCEEDED,
],
)
],
post=refund_tx.post(pre, block_is_invalid=not trailing_tx_succeeds),
genesis_environment=Environment(gas_limit=block_gas_limit),
)
|