From 43c3c631458b2f938276e5a28ea824b56a87b609 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 6 Nov 2025 17:36:44 +0100 Subject: [PATCH] [CHIA-3793] after the hard fork, disallow block references (#20218) * after the hard fork, disallow block references * disable hard-fork 2 tests until we have a new test cache * fix rate limits test --- chia/consensus/block_body_validation.py | 6 +++++- chia/consensus/blockchain.py | 13 +++++++++---- chia/simulator/block_tools.py | 4 ++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/chia/consensus/block_body_validation.py b/chia/consensus/block_body_validation.py index c113184cf9..6506e3b051 100644 --- a/chia/consensus/block_body_validation.py +++ b/chia/consensus/block_body_validation.py @@ -341,10 +341,14 @@ async def validate_block_body( # the generator ref list for this block (or 'one' bytes [0x01] if no generator) # 8b. The generator ref list length must be less than or equal to MAX_GENERATOR_REF_LIST_SIZE entries # 8c. The generator ref list must not point to a height >= this block's height - if block.transactions_generator_ref_list in (None, []): + if block.transactions_generator_ref_list == []: if block.transactions_info.generator_refs_root != bytes([1] * 32): return Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT else: + # With hard fork 2 we ban transactions_generator_ref_list. + if prev_transaction_block_height >= constants.HARD_FORK2_HEIGHT: + return Err.TOO_MANY_GENERATOR_REFS + # If we have a generator reference list, we must have a generator if block.transactions_generator is None: return Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT diff --git a/chia/consensus/blockchain.py b/chia/consensus/blockchain.py index 00d9df5d1a..34e3252e4e 100644 --- a/chia/consensus/blockchain.py +++ b/chia/consensus/blockchain.py @@ -33,6 +33,7 @@ from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_dif from chia.consensus.find_fork_point import lookup_fork_chain from chia.consensus.full_block_to_block_record import block_to_block_record from chia.consensus.generator_tools import get_block_header +from chia.consensus.get_block_challenge import prev_tx_block from chia.consensus.get_block_generator import get_block_generator from chia.consensus.multiprocess_validation import PreValidationResult from chia.full_node.block_store import BlockStore @@ -698,12 +699,16 @@ class Blockchain: if len(block.transactions_generator_ref_list) > self.constants.MAX_GENERATOR_REF_LIST_SIZE: return None, Err.TOO_MANY_GENERATOR_REFS - if ( - self.try_block_record(block.prev_header_hash) is None - and block.prev_header_hash != self.constants.GENESIS_CHALLENGE - ): + prev_b = self.try_block_record(block.prev_header_hash) + if prev_b is None and block.prev_header_hash != self.constants.GENESIS_CHALLENGE: return None, Err.INVALID_PREV_BLOCK_HASH + prev_tx_height = prev_tx_block(self, prev_b) + + # With hard fork 2 we ban transactions_generator_ref_list. + if prev_tx_height >= self.constants.HARD_FORK2_HEIGHT and block.transactions_generator_ref_list != []: + return None, Err.TOO_MANY_GENERATOR_REFS + if block.transactions_info is not None: if block.transactions_generator is not None: if std_hash(bytes(block.transactions_generator)) != block.transactions_info.generator_root: diff --git a/chia/simulator/block_tools.py b/chia/simulator/block_tools.py index 51fd40a1a0..8ff75d44e5 100644 --- a/chia/simulator/block_tools.py +++ b/chia/simulator/block_tools.py @@ -387,6 +387,10 @@ class BlockTools: transaction_data: Optional[SpendBundle], block_refs: list[uint32], ) -> Optional[NewBlockGenerator]: + if prev_tx_height >= self.constants.HARD_FORK2_HEIGHT: + assert block_refs == [], "block references are not allowed after hard fork 2" + dummy_block_references = False + # we don't know if the new block will be a transaction # block or not, so even though we prepare a block # generator, we can't update our state (like,