From 3a9822a3dd9eb21397867ceb988dfa6c3d824aef Mon Sep 17 00:00:00 2001 From: awskii Date: Wed, 5 Aug 2026 20:14:06 +0700 Subject: [PATCH 1/2] tests(binary_tree): consecutive deploys into a shared code zone Every existing overflow-code case deploys into an empty code zone. Chunks past the header are content-addressed and share one zone chain-wide, so every deploy after the first inserts beside stems already there. --- .../test_multi_block.py | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py b/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py index 7253f26a74..024d70ffd0 100644 --- a/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py +++ b/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py @@ -27,7 +27,7 @@ ) from .helpers import FACTORY_CANARY_SLOT, create_contract_via_factory -from .spec import ref_spec_8297 +from .spec import Spec, ref_spec_8297 REFERENCE_SPEC_GIT_PATH = ref_spec_8297.git_path REFERENCE_SPEC_VERSION = ref_spec_8297.version @@ -314,3 +314,66 @@ def test_wrong_state_root_expectation_is_recorded_for_consumers( ) blockchain_test(pre=pre, post={}, blocks=[block]) + + +def test_consecutive_deploys_share_the_code_zone( + blockchain_test: BlockchainTestFiller, + pre: Alloc, +) -> None: + """ + Deploy three contracts that each overflow the account header, one + per block, then call all three. + + Header code chunks are keyed by address, so they never meet. Chunks + past the header are content-addressed and land in one zone shared by + every contract on the chain, so each deploy after the first inserts + beside stems that are already there. The first deploy is the only + one that reaches an empty zone, and it is the case a single-deploy + test covers; what these blocks add is every deploy after it. + + The three contracts differ only in the byte they store and in their + length, so their stems are distinct and cannot collide by accident. + Each writes its own marker on the final block, which fails if any + deploy disturbed the code of a contract deployed before it. + """ + sender = pre.fund_eoa() + marker_slot = 0 + header_chunks = Spec.STEM_SUBTREE_WIDTH - Spec.CODE_OFFSET + sizes = tuple( + Spec.CODE_CHUNK_SIZE * (header_chunks + extra) + for extra in (1, 9, header_chunks) + ) + + runtimes: list[Bytecode] = [] + deploys: list[Transaction] = [] + for index, size in enumerate(sizes): + marker = index + 1 + runtime = Op.SSTORE(marker_slot, marker) + Op.STOP + runtime += Op.INVALID * (size - len(runtime)) + assert len(runtime) == size + runtimes.append(runtime) + deploys.append( + Transaction( + sender=sender, + to=None, + data=Initcode(deploy_code=runtime), + gas_limit=15_000_000, + ) + ) + + deployed = [tx.created_contract for tx in deploys] + calls = [ + Transaction(sender=sender, to=address, gas_limit=200_000) + for address in deployed + ] + + blocks = [Block(txs=[tx]) for tx in deploys] + blocks.append(Block(txs=calls)) + + post = { + address: Account(code=runtime, storage={marker_slot: index + 1}) + for index, (address, runtime) in enumerate( + zip(deployed, runtimes, strict=True) + ) + } + blockchain_test(pre=pre, blocks=blocks, post=post) From 70635173e0bda204a5eb95b7e12991034246d1cc Mon Sep 17 00:00:00 2001 From: awskii Date: Thu, 6 Aug 2026 13:40:13 +0700 Subject: [PATCH 2/2] tests(binary_tree): size the deploys without CODE_OFFSET EIP-8297 moved every code chunk into the code zone (#3310), removing CODE_OFFSET. Sizing by chunk count instead leaves the test valid on either side of that change. --- .../test_multi_block.py | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py b/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py index 024d70ffd0..6856ff23ad 100644 --- a/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py +++ b/tests/binary_tree/eip8297_partitioned_binary_tree/test_multi_block.py @@ -321,27 +321,24 @@ def test_consecutive_deploys_share_the_code_zone( pre: Alloc, ) -> None: """ - Deploy three contracts that each overflow the account header, one - per block, then call all three. - - Header code chunks are keyed by address, so they never meet. Chunks - past the header are content-addressed and land in one zone shared by - every contract on the chain, so each deploy after the first inserts - beside stems that are already there. The first deploy is the only - one that reaches an empty zone, and it is the case a single-deploy - test covers; what these blocks add is every deploy after it. - - The three contracts differ only in the byte they store and in their - length, so their stems are distinct and cannot collide by accident. - Each writes its own marker on the final block, which fails if any - deploy disturbed the code of a contract deployed before it. + Deploy three contracts spanning several code stems, one per block, + then call all three. + + Code chunks are content-addressed, so every contract on the chain + shares one zone and each deploy after the first inserts beside stems + that are already there. A single-deploy test only ever reaches an + empty zone; what these blocks add is every deploy after it. + + The three differ in length, so they occupy distinct stems and cannot + coincide by accident, and each writes its own marker on the final + block, which fails if a later deploy disturbed the code of one + deployed before it. """ sender = pre.fund_eoa() marker_slot = 0 - header_chunks = Spec.STEM_SUBTREE_WIDTH - Spec.CODE_OFFSET sizes = tuple( - Spec.CODE_CHUNK_SIZE * (header_chunks + extra) - for extra in (1, 9, header_chunks) + Spec.CODE_CHUNK_SIZE * chunks + for chunks in (129, 137, Spec.STEM_SUBTREE_WIDTH) ) runtimes: list[Bytecode] = []