mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-24 10:05:29 -05:00
[CHIA-3963 CHIA-3955] early check of proof of space in a few places (#20685)
early check of proof of space in a few places
This commit is contained in:
@@ -703,6 +703,9 @@ class Blockchain:
|
||||
async def validate_unfinished_block_header(
|
||||
self, block: UnfinishedBlock, skip_overflow_ss_validation: bool = True
|
||||
) -> tuple[uint64 | None, Err | None]:
|
||||
if len(block.reward_chain_block.proof_of_space.proof) >= 2000:
|
||||
return None, Err.INVALID_POSPACE
|
||||
|
||||
if len(block.transactions_generator_ref_list) > self.constants.MAX_GENERATOR_REF_LIST_SIZE:
|
||||
return None, Err.TOO_MANY_GENERATOR_REFS
|
||||
|
||||
|
||||
@@ -2062,6 +2062,9 @@ class FullNode:
|
||||
):
|
||||
# This is the case where we already had the unfinished block, and asked for this block without
|
||||
# the transactions (since we already had them). Therefore, here we add the transactions.
|
||||
pos = block.reward_chain_block.proof_of_space
|
||||
if pos.version == 1 and pos.quality_string() is None:
|
||||
raise ConsensusError(Err.INVALID_POSPACE)
|
||||
unfinished_rh: bytes32 = block.reward_chain_block.get_unfinished().get_hash()
|
||||
foliage_hash: bytes32 | None = block.foliage.foliage_transaction_block_hash
|
||||
assert foliage_hash is not None
|
||||
@@ -2327,6 +2330,10 @@ class FullNode:
|
||||
self.log.debug("Received a disconnected unfinished block")
|
||||
return None
|
||||
|
||||
pos = block.reward_chain_block.proof_of_space
|
||||
if pos.version == 1 and pos.quality_string() is None:
|
||||
raise ConsensusError(Err.INVALID_POSPACE)
|
||||
|
||||
# Adds the unfinished block to seen, and check if it's seen before, to prevent
|
||||
# processing it twice. This searches for the exact version of the unfinished block (there can be many different
|
||||
# foliages for the same trunk). This is intentional, to prevent DOS attacks.
|
||||
|
||||
@@ -1231,6 +1231,11 @@ def validate_recent_blocks(
|
||||
adjusted = False
|
||||
validated_block_count = 0
|
||||
for idx, block in enumerate(recent_chain.recent_chain_data):
|
||||
pos = block.reward_chain_block.proof_of_space
|
||||
if pos.version == 1 and pos.quality_string() is None:
|
||||
log.info(f"invalid proof of space in weight proof recent chain block {block.height}")
|
||||
return False, []
|
||||
|
||||
required_iters = uint64(0)
|
||||
overflow = False
|
||||
ses = False
|
||||
|
||||
@@ -168,6 +168,11 @@ def verify_and_get_quality_string(
|
||||
# === V1 plots ===
|
||||
assert plot_param.strength_v2 is None
|
||||
|
||||
if not height_agnostic and prev_transaction_block_height >= constants.SOFT_FORK9_HEIGHT:
|
||||
if len(pos.proof) >= 2000:
|
||||
log.error(f"Proof of space too large: {len(pos.proof)} bytes")
|
||||
return None
|
||||
|
||||
quality_str = Verifier().validate_proof(plot_id, plot_param.size_v1, pos.challenge, bytes(pos.proof))
|
||||
if not quality_str:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user