Skip to content

Commit df45f39

Browse files
authored
odd v2 plot k-sizes are not valid (#19933)
1 parent 71e1c7c commit df45f39

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

chia/_tests/core/custom_types/test_proof_of_space.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from chia.types.blockchain_format.proof_of_space import (
1515
calculate_plot_difficulty,
1616
calculate_prefix_bits,
17+
check_plot_size,
1718
passes_plot_filter,
1819
verify_and_get_quality_string,
1920
)
@@ -221,6 +222,34 @@ def test_calculate_plot_difficulty(height: uint32, difficulty: uint8) -> None:
221222
assert calculate_plot_difficulty(DEFAULT_CONSTANTS, height) == difficulty
222223

223224

225+
@pytest.mark.parametrize(
226+
"size, valid",
227+
[
228+
(PlotSize.make_v1(31), False), # too small
229+
(PlotSize.make_v1(32), True),
230+
(PlotSize.make_v1(33), True),
231+
(PlotSize.make_v1(34), True),
232+
(PlotSize.make_v1(35), True),
233+
(PlotSize.make_v1(36), True),
234+
(PlotSize.make_v1(37), True),
235+
(PlotSize.make_v1(49), True),
236+
(PlotSize.make_v1(50), True),
237+
(PlotSize.make_v1(51), False), # too large
238+
(PlotSize.make_v2(26), False), # too small
239+
(PlotSize.make_v2(27), False), # too small (and odd)
240+
(PlotSize.make_v2(28), True),
241+
(PlotSize.make_v2(29), False), # odd
242+
(PlotSize.make_v2(30), True),
243+
(PlotSize.make_v2(31), False), # odd
244+
(PlotSize.make_v2(32), True),
245+
(PlotSize.make_v2(33), False), # too large (and odd)
246+
(PlotSize.make_v2(34), False), # too large
247+
],
248+
)
249+
def test_check_plot_size(size: PlotSize, valid: bool) -> None:
250+
assert check_plot_size(DEFAULT_CONSTANTS, size) == valid
251+
252+
224253
class TestProofOfSpace:
225254
@pytest.mark.parametrize("prefix_bits", [DEFAULT_CONSTANTS.NUMBER_ZERO_BITS_PLOT_FILTER_V1, 8, 7, 6, 5, 1, 0])
226255
def test_can_create_proof(self, prefix_bits: int, seeded_random: random.Random) -> None:

chia/types/blockchain_format/proof_of_space.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def check_plot_size(constants: ConsensusConstants, ps: PlotSize) -> bool:
5050
if size_v2 > constants.MAX_PLOT_SIZE_V2:
5151
log.error("Plot size is higher than the maximum")
5252
return False
53+
if (size_v2 & 1) == 1:
54+
log.error("Plot size is odd")
55+
return False
5356
return True
5457

5558

0 commit comments

Comments
 (0)