Skip to content

test_max_code_size_high_jumpdest()

Documentation for tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py::test_max_code_size_high_jumpdest@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py::test_max_code_size_high_jumpdest --fork Amsterdam

Ensure jump destination validity is enforced past the old size limits.

Deploy a MAX_CODE_SIZE contract that stores a sentinel and then jumps near the new limit, far beyond the old 24 KiB code and 48 KiB initcode limits, then call it through a caller that records the call's success:

  • valid_high_jumpdest: the target byte is a real JUMPDEST, so the jump succeeds, the frame returns, and the sentinel store is kept.
  • invalid_high_dest: the target byte is a STOP (not a JUMPDEST), so the jump is rejected, the frame reverts, and the sentinel store is discarded.

A client whose jumpdest analysis or code execution does not cover the full new code range fails one of the two cases. No existing test executes a contract at a program counter beyond the old limit.

Source code in tests/amsterdam/eip7954_increase_max_contract_size/test_max_code_size.py
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
@pytest.mark.parametrize(
    "valid_jumpdest",
    [
        pytest.param(True, id="valid_high_jumpdest"),
        pytest.param(False, id="invalid_high_dest"),
    ],
)
def test_max_code_size_high_jumpdest(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    valid_jumpdest: bool,
) -> None:
    """
    Ensure jump destination validity is enforced past the old size limits.

    Deploy a `MAX_CODE_SIZE` contract that stores a sentinel and then jumps
    near the new limit, far beyond the old 24 KiB code and 48 KiB initcode
    limits, then call it through a caller that records the call's success:

    - ``valid_high_jumpdest``: the target byte is a real ``JUMPDEST``, so the
      jump succeeds, the frame returns, and the sentinel store is kept.
    - ``invalid_high_dest``: the target byte is a ``STOP`` (not a
      ``JUMPDEST``), so the jump is rejected, the frame reverts, and the
      sentinel store is discarded.

    A client whose jumpdest analysis or code execution does not cover the
    full new code range fails one of the two cases. No existing test
    executes a contract at a program counter beyond the old limit.
    """
    if valid_jumpdest:
        tail = Op.JUMPDEST
    else:
        # A bare STOP, not a JUMPDEST: jumping here is invalid. A client that
        # wrongly accepts it halts normally and keeps the prefix store (1).
        tail = Op.STOP

    dest = fork.max_code_size() - len(tail)
    push_size = (dest.bit_length() + 7) // 8
    push_op = getattr(Op, f"PUSH{push_size}")
    prefix = Op.SSTORE(0, 1) + push_op(dest) + Op.JUMP
    target_code = prefix + Op.INVALID * (dest - len(prefix)) + tail
    assert len(target_code) == fork.max_code_size()

    target = pre.deploy_contract(target_code)
    caller = pre.deploy_contract(
        Op.SSTORE(0, Op.CALL(gas=Op.GAS, address=target)) + Op.STOP
    )

    tx = Transaction(sender=pre.fund_eoa(), to=caller)

    # Valid: jump completes, call succeeds (1), and the store is kept.
    # Invalid: jump reverts, call fails (0), and nothing is stored.
    stored = 1 if valid_jumpdest else 0
    post = {
        caller: Account(storage={0: stored}),
        target: Account(storage={0: stored}),
    }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.