Skip to content

Commit 38c2213

Browse files
committed
v2 plots only support pool contract puzzle hash
1 parent e947dd1 commit 38c2213

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

chia/_tests/core/custom_types/test_proof_of_space.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,33 @@ def b32(key: str) -> bytes32:
114114
pos_challenge=bytes32(b"1" * 32),
115115
plot_size=PlotSize.make_v2(0),
116116
plot_public_key=G1Element(),
117-
pool_public_key=G1Element(),
117+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
118118
expected_error="Plot size is lower than the minimum",
119119
),
120120
ProofOfSpaceCase(
121121
id="v2 plot size 34",
122122
pos_challenge=bytes32(b"1" * 32),
123123
plot_size=PlotSize.make_v2(34),
124124
plot_public_key=G1Element(),
125-
pool_public_key=G1Element(),
125+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
126126
expected_error="Plot size is higher than the maximum",
127127
),
128128
ProofOfSpaceCase(
129-
id="Not passing the plot filter v2",
130-
pos_challenge=b32("3d29ea79d19b3f7e99ebf764ae53697cbe143603909873946af6ab1ece606861"),
129+
id="v2 Not passing the plot filter",
130+
pos_challenge=b32("8147a0c9f351fb654d5c0054d01bdd70e9def1b5c7b43212ff44acb4378956b3"),
131131
plot_size=PlotSize.make_v2(32),
132-
pool_public_key=g1(
133-
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
134-
),
135-
plot_public_key=g1(
136-
"879526b4e7b616cfd64984d8ad140d0798b048392a6f11e2faf09054ef467ea44dc0dab5e5edb2afdfa850c5c8b629cc"
137-
),
132+
plot_public_key=G1Element(),
133+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
138134
expected_error="Did not pass the plot filter",
139135
),
136+
ProofOfSpaceCase(
137+
id="v2 plot with pool pk",
138+
pos_challenge=bytes32(b"1" * 32),
139+
plot_size=PlotSize.make_v2(28),
140+
plot_public_key=G1Element(),
141+
pool_public_key=G1Element(),
142+
expected_error="v2 plots require pool_contract_puzzle_hash, pool public key is not supported",
143+
),
140144
)
141145
def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: ProofOfSpaceCase) -> None:
142146
pos = make_pos(
@@ -160,15 +164,13 @@ def test_verify_and_get_quality_string(caplog: pytest.LogCaptureFixture, case: P
160164

161165
@datacases(
162166
ProofOfSpaceCase(
163-
id="v2 plot are not implemented",
167+
id="v2 plot",
164168
plot_size=PlotSize.make_v2(30),
165-
pos_challenge=b32("47deb938e145d25d7b3b3c85ca9e3972b76c01aeeb78a02fe5d3b040d282317e"),
169+
pos_challenge=b32("a5fd5287b295a3748e8498be03c6ce3d0f682d19613c003911aa6a65527d3ba4"),
166170
plot_public_key=g1(
167171
"afa3aaf09c03885154be49216ee7fb2e4581b9c4a4d7e9cc402e27280bf0cfdbdf1b9ba674e301fd1d1450234b3b1868"
168172
),
169-
pool_public_key=g1(
170-
"b6449c2c68df97c19e884427e42ee7350982d4020571ead08732615ff39bd216bfd630b6460784982bec98b49fea79d0"
171-
),
173+
pool_contract_puzzle_hash=bytes32(b"1" * 32),
172174
expected_error="NotImplementedError",
173175
),
174176
)
@@ -189,7 +191,7 @@ def test_verify_and_get_quality_string_v2(caplog: pytest.LogCaptureFixture, case
189191
pos=pos,
190192
constants=DEFAULT_CONSTANTS,
191193
original_challenge_hash=b32("0x73490e166d0b88347c37d921660b216c27316aae9a3450933d3ff3b854e5831a"),
192-
signage_point=b32("0x7b3e23dbd438f9aceefa9827e2c5538898189987f49b06eceb7a43067e77b531"),
194+
signage_point=b32("0xf7c1bd874da5e709d4713d60c8a70639eb1167b367a9c3787c65c1e582e2e662"),
193195
height=case.height,
194196
)
195197
except NotImplementedError as e:

chia/consensus/block_header_validation.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,10 +756,15 @@ def validate_unfinished_header_block(
756756
!= constants.GENESIS_PRE_FARM_FARMER_PUZZLE_HASH
757757
):
758758
return None, ValidationError(Err.INVALID_PREFARM)
759-
# 20b. If pospace has a pool pk, heck pool target signature. Should not check this for genesis block.
759+
# 20b. If pospace has a pool pk, check pool target signature. Should not check this for genesis block.
760760
elif header_block.reward_chain_block.proof_of_space.pool_public_key is not None:
761761
assert header_block.reward_chain_block.proof_of_space.pool_contract_puzzle_hash is None
762762
assert header_block.foliage.foliage_block_data.pool_signature is not None
763+
764+
# v2 plots require pool contract puzzle hash, not pool pk
765+
if header_block.reward_chain_block.proof_of_space.size().size_v2 is not None:
766+
return None, ValidationError(Err.INVALID_POOL_SIGNATURE)
767+
763768
if not AugSchemeMPL.verify(
764769
header_block.reward_chain_block.proof_of_space.pool_public_key,
765770
bytes(header_block.foliage.foliage_block_data.pool_target),

chia/types/blockchain_format/proof_of_space.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def make_pos(
6464

6565

6666
def get_plot_id(pos: ProofOfSpace) -> bytes32:
67+
plot_size = pos.size()
68+
if plot_size.size_v2 is not None:
69+
assert pos.pool_contract_puzzle_hash is not None
70+
return calculate_plot_id_v2(pos.pool_contract_puzzle_hash, pos.plot_public_key, plot_size.size_v2)
71+
6772
assert pos.pool_public_key is None or pos.pool_contract_puzzle_hash is None
6873
if pos.pool_public_key is None:
6974
assert pos.pool_contract_puzzle_hash is not None
@@ -114,14 +119,18 @@ def verify_and_get_quality_string(
114119
return None
115120

116121
plot_size = pos.size()
122+
if plot_size.size_v2 is not None and pos.pool_contract_puzzle_hash is None:
123+
log.error("v2 plots require pool_contract_puzzle_hash, pool public key is not supported")
124+
return None
125+
117126
if not check_plot_size(constants, plot_size):
118127
return None
119128

120129
plot_id: bytes32 = get_plot_id(pos)
121130
new_challenge: bytes32 = calculate_pos_challenge(plot_id, original_challenge_hash, signage_point)
122131

123132
if new_challenge != pos.challenge:
124-
log.error("Calculated pos challenge doesn't match the provided one")
133+
log.error(f"Calculated pos challenge doesn't match the provided one {new_challenge}")
125134
return None
126135

127136
# we use different plot filter prefix sizes depending on v1 or v2 plots
@@ -204,6 +213,14 @@ def calculate_pos_challenge(plot_id: bytes32, challenge_hash: bytes32, signage_p
204213
return std_hash(calculate_plot_filter_input(plot_id, challenge_hash, signage_point))
205214

206215

216+
def calculate_plot_id_v2(
217+
pool_contract_puzzle_hash: bytes32,
218+
plot_public_key: G1Element,
219+
strength: uint8,
220+
) -> bytes32:
221+
return std_hash(bytes(pool_contract_puzzle_hash) + bytes(plot_public_key) + bytes(strength))
222+
223+
207224
def calculate_plot_id_pk(
208225
pool_public_key: G1Element,
209226
plot_public_key: G1Element,

0 commit comments

Comments
 (0)