Skip to content

Commit edd5b00

Browse files
authored
Merge pull request #1314 from Chia-Network/bump-chia-pos2
bump chia-pos2 to 0.1.6 along with updates for the new PoS
2 parents 1ce5e79 + 9bf0dd4 commit edd5b00

File tree

11 files changed

+70
-88
lines changed

11 files changed

+70
-88
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ dependencies = [
456456

457457
[[package]]
458458
name = "chia-pos2"
459-
version = "0.1.4"
459+
version = "0.1.6"
460460
source = "registry+https://github.com/rust-lang/crates.io-index"
461-
checksum = "3013a7003399d43ac66c231b08649a7fd97d4f6399dbbd356360e76b5359af01"
461+
checksum = "d6fffd6779c3200ebbd552ba79566f2ff2ef5bed4f8975d0026e981b87103328"
462462
dependencies = [
463463
"cc",
464464
"serde",
@@ -472,6 +472,7 @@ dependencies = [
472472
"anyhow",
473473
"arbitrary",
474474
"chia-bls 0.35.0",
475+
"chia-pos2",
475476
"chia-serde",
476477
"chia-sha2 0.35.0",
477478
"chia-traits 0.35.0",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ chia-serde = { path = "./crates/chia-serde", version = "0.35.0" }
131131
clvm-traits = { path = "./crates/clvm-traits", version = "0.35.0" }
132132
clvm-utils = { path = "./crates/clvm-utils", version = "0.35.0" }
133133
clvm-derive = { path = "./crates/clvm-derive", version = "0.35.0" }
134-
chia-pos2 = "0.1.4"
134+
chia-pos2 = "0.1.6"
135135
chia-consensus-fuzz = { path = "./crates/chia-consensus/fuzz", version = "0.35.0" }
136136
chia-bls-fuzz = { path = "./crates/chia-bls/fuzz", version = "0.35.0" }
137137
chia-datalayer-fuzz = { path = "./crates/chia-datalayer/fuzz", version = "0.35.0" }

crates/chia-consensus/src/consensus_constants.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ pub struct ConsensusConstants {
160160
min_plot_strength: u8,
161161
max_plot_strength: u8,
162162

163-
/// The quality proof scan filter for v2 plots
164-
quality_proof_scan_filter: u8,
165-
166163
plot_filter_v2_first_adjustment_height: u32,
167164
plot_filter_v2_second_adjustment_height: u32,
168165
plot_filter_v2_third_adjustment_height: u32,
@@ -241,8 +238,6 @@ pub const TEST_CONSTANTS: ConsensusConstants = ConsensusConstants {
241238
min_plot_strength: 2,
242239
max_plot_strength: 32,
243240

244-
quality_proof_scan_filter: 5,
245-
246241
plot_filter_v2_first_adjustment_height: 0xffff_ffff, // placeholder
247242
plot_filter_v2_second_adjustment_height: 0xffff_ffff, // placeholder
248243
plot_filter_v2_third_adjustment_height: 0xffff_ffff, // placeholder

crates/chia-protocol/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ chia_py_streamable_macro = { workspace = true, optional = true }
2727
clvmr = { workspace = true }
2828
chia-traits = { workspace = true }
2929
chia-sha2 = { workspace = true }
30+
chia-pos2 = { workspace = true }
3031
clvm-traits = { workspace = true, features = ["derive"] }
3132
clvm-utils = { workspace = true }
3233
chia-bls = { workspace = true }
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
use crate::Bytes32;
2+
use chia_pos2::serialize_quality;
3+
use chia_sha2::Sha256;
14
use chia_streamable_macro::streamable;
25

6+
#[cfg(feature = "py-bindings")]
7+
use pyo3::pymethods;
8+
39
#[streamable]
410
pub struct PartialProof {
511
#[cfg_attr(feature = "serde", serde(with = "serde_arrays"))]
6-
proof_fragments: [u64; 64],
12+
fragments: [u64; 16],
13+
}
14+
15+
impl PartialProof {
16+
pub fn get_string(&self, strength: u8) -> Bytes32 {
17+
let mut sha256 = Sha256::new();
18+
sha256.update(serialize_quality(&self.fragments, strength));
19+
sha256.finalize().into()
20+
}
21+
}
22+
23+
#[cfg(feature = "py-bindings")]
24+
#[pymethods]
25+
impl PartialProof {
26+
#[pyo3(name = "get_string")]
27+
fn py_get_string(&self, strength: u8) -> Bytes32 {
28+
self.get_string(strength)
29+
}
730
}

tests/run_gen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
PLOT_FILTER_32_HEIGHT=uint32(20643000),
8787
MIN_PLOT_STRENGTH=uint8(2),
8888
MAX_PLOT_STRENGTH=uint8(32),
89-
QUALITY_PROOF_SCAN_FILTER=uint8(5),
9089
PLOT_FILTER_V2_FIRST_ADJUSTMENT_HEIGHT=uint32(0xFFFFFFFF),
9190
PLOT_FILTER_V2_SECOND_ADJUSTMENT_HEIGHT=uint32(0xFFFFFFFF),
9291
PLOT_FILTER_V2_THIRD_ADJUSTMENT_HEIGHT=uint32(0xFFFFFFFF),

tests/test_consensus_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ def test_formatting() -> None:
55

66
assert (
77
f"{DEFAULT_CONSTANTS}"
8-
== "ConsensusConstants { SLOT_BLOCKS_TARGET: 32, MIN_BLOCKS_PER_CHALLENGE_BLOCK: 16, MAX_SUB_SLOT_BLOCKS: 128, NUM_SPS_SUB_SLOT: 64, SUB_SLOT_ITERS_STARTING: 134217728, DIFFICULTY_CONSTANT_FACTOR: 147573952589676412928, DIFFICULTY_STARTING: 7, DIFFICULTY_CHANGE_MAX_FACTOR: 3, SUB_EPOCH_BLOCKS: 384, EPOCH_BLOCKS: 4608, SIGNIFICANT_BITS: 8, DISCRIMINANT_SIZE_BITS: 1024, NUMBER_ZERO_BITS_PLOT_FILTER_V1: 9, NUMBER_ZERO_BITS_PLOT_FILTER_V2: 5, MIN_PLOT_SIZE_V1: 32, MAX_PLOT_SIZE_V1: 50, PLOT_SIZE_V2: 28, SUB_SLOT_TIME_TARGET: 600, NUM_SP_INTERVALS_EXTRA: 3, MAX_FUTURE_TIME2: 120, NUMBER_OF_TIMESTAMPS: 11, GENESIS_CHALLENGE: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, AGG_SIG_ME_ADDITIONAL_DATA: ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb, AGG_SIG_PARENT_ADDITIONAL_DATA: baf5d69c647c91966170302d18521b0a85663433d161e72c826ed08677b53a74, AGG_SIG_PUZZLE_ADDITIONAL_DATA: 284fa2ef486c7a41cc29fc99c9d08376161e93dd37817edb8219f42dca7592c4, AGG_SIG_AMOUNT_ADDITIONAL_DATA: cda186a9cd030f7a130fae45005e81cae7a90e0fa205b75f6aebc0d598e0348e, AGG_SIG_PUZZLE_AMOUNT_ADDITIONAL_DATA: 0f7d90dff0613e6901e24dae59f1e690f18b8f5fbdcf1bb192ac9deaf7de22ad, AGG_SIG_PARENT_AMOUNT_ADDITIONAL_DATA: 585796bd90bb553c0430b87027ffee08d88aba0162c6e1abbbcc6b583f2ae7f9, AGG_SIG_PARENT_PUZZLE_ADDITIONAL_DATA: 2ebfdae17b29d83bae476a25ea06f0c4bd57298faddbbc3ec5ad29b9b86ce5df, GENESIS_PRE_FARM_POOL_PUZZLE_HASH: d23da14695a188ae5708dd152263c4db883eb27edeb936178d4d988b8f3ce5fc, GENESIS_PRE_FARM_FARMER_PUZZLE_HASH: 3d8765d3a597ec1d99663f6c9816d915b9f68613ac94009884c4addaefcce6af, MAX_VDF_WITNESS_SIZE: 64, MEMPOOL_BLOCK_BUFFER: 10, MAX_COIN_AMOUNT: 18446744073709551615, MAX_BLOCK_COST_CLVM: 11000000000, COST_PER_BYTE: 12000, WEIGHT_PROOF_THRESHOLD: 2, WEIGHT_PROOF_RECENT_BLOCKS: 1000, MAX_BLOCK_COUNT_PER_REQUESTS: 32, BLOCKS_CACHE_SIZE: 5120, MAX_GENERATOR_REF_LIST_SIZE: 512, POOL_SUB_SLOT_ITERS: 37600000000, HARD_FORK_HEIGHT: 5496000, HARD_FORK2_HEIGHT: 4294967295, PLOT_V1_PHASE_OUT_EPOCH_BITS: 8, PLOT_FILTER_128_HEIGHT: 10542000, PLOT_FILTER_64_HEIGHT: 15592000, PLOT_FILTER_32_HEIGHT: 20643000, MIN_PLOT_STRENGTH: 2, MAX_PLOT_STRENGTH: 32, QUALITY_PROOF_SCAN_FILTER: 5, PLOT_FILTER_V2_FIRST_ADJUSTMENT_HEIGHT: 4294967295, PLOT_FILTER_V2_SECOND_ADJUSTMENT_HEIGHT: 4294967295, PLOT_FILTER_V2_THIRD_ADJUSTMENT_HEIGHT: 4294967295, }"
8+
== "ConsensusConstants { SLOT_BLOCKS_TARGET: 32, MIN_BLOCKS_PER_CHALLENGE_BLOCK: 16, MAX_SUB_SLOT_BLOCKS: 128, NUM_SPS_SUB_SLOT: 64, SUB_SLOT_ITERS_STARTING: 134217728, DIFFICULTY_CONSTANT_FACTOR: 147573952589676412928, DIFFICULTY_STARTING: 7, DIFFICULTY_CHANGE_MAX_FACTOR: 3, SUB_EPOCH_BLOCKS: 384, EPOCH_BLOCKS: 4608, SIGNIFICANT_BITS: 8, DISCRIMINANT_SIZE_BITS: 1024, NUMBER_ZERO_BITS_PLOT_FILTER_V1: 9, NUMBER_ZERO_BITS_PLOT_FILTER_V2: 5, MIN_PLOT_SIZE_V1: 32, MAX_PLOT_SIZE_V1: 50, PLOT_SIZE_V2: 28, SUB_SLOT_TIME_TARGET: 600, NUM_SP_INTERVALS_EXTRA: 3, MAX_FUTURE_TIME2: 120, NUMBER_OF_TIMESTAMPS: 11, GENESIS_CHALLENGE: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, AGG_SIG_ME_ADDITIONAL_DATA: ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb, AGG_SIG_PARENT_ADDITIONAL_DATA: baf5d69c647c91966170302d18521b0a85663433d161e72c826ed08677b53a74, AGG_SIG_PUZZLE_ADDITIONAL_DATA: 284fa2ef486c7a41cc29fc99c9d08376161e93dd37817edb8219f42dca7592c4, AGG_SIG_AMOUNT_ADDITIONAL_DATA: cda186a9cd030f7a130fae45005e81cae7a90e0fa205b75f6aebc0d598e0348e, AGG_SIG_PUZZLE_AMOUNT_ADDITIONAL_DATA: 0f7d90dff0613e6901e24dae59f1e690f18b8f5fbdcf1bb192ac9deaf7de22ad, AGG_SIG_PARENT_AMOUNT_ADDITIONAL_DATA: 585796bd90bb553c0430b87027ffee08d88aba0162c6e1abbbcc6b583f2ae7f9, AGG_SIG_PARENT_PUZZLE_ADDITIONAL_DATA: 2ebfdae17b29d83bae476a25ea06f0c4bd57298faddbbc3ec5ad29b9b86ce5df, GENESIS_PRE_FARM_POOL_PUZZLE_HASH: d23da14695a188ae5708dd152263c4db883eb27edeb936178d4d988b8f3ce5fc, GENESIS_PRE_FARM_FARMER_PUZZLE_HASH: 3d8765d3a597ec1d99663f6c9816d915b9f68613ac94009884c4addaefcce6af, MAX_VDF_WITNESS_SIZE: 64, MEMPOOL_BLOCK_BUFFER: 10, MAX_COIN_AMOUNT: 18446744073709551615, MAX_BLOCK_COST_CLVM: 11000000000, COST_PER_BYTE: 12000, WEIGHT_PROOF_THRESHOLD: 2, WEIGHT_PROOF_RECENT_BLOCKS: 1000, MAX_BLOCK_COUNT_PER_REQUESTS: 32, BLOCKS_CACHE_SIZE: 5120, MAX_GENERATOR_REF_LIST_SIZE: 512, POOL_SUB_SLOT_ITERS: 37600000000, HARD_FORK_HEIGHT: 5496000, HARD_FORK2_HEIGHT: 4294967295, PLOT_V1_PHASE_OUT_EPOCH_BITS: 8, PLOT_FILTER_128_HEIGHT: 10542000, PLOT_FILTER_64_HEIGHT: 15592000, PLOT_FILTER_32_HEIGHT: 20643000, MIN_PLOT_STRENGTH: 2, MAX_PLOT_STRENGTH: 32, PLOT_FILTER_V2_FIRST_ADJUSTMENT_HEIGHT: 4294967295, PLOT_FILTER_V2_SECOND_ADJUSTMENT_HEIGHT: 4294967295, PLOT_FILTER_V2_THIRD_ADJUSTMENT_HEIGHT: 4294967295, }"
99
)

tests/test_pos2.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from chia_rs import create_v2_plot, Prover, validate_proof_v2, solve_proof
22
from chia_rs.sized_bytes import bytes32
3+
from chia_rs.sized_ints import uint8
34
import random
45

56

@@ -10,7 +11,6 @@ def test_plot_roundtrip() -> None:
1011
)
1112
k = 18
1213
strength = 2
13-
proof_fragment_scan_filter = 4
1414

1515
create_v2_plot("k-18-test.plot", k, strength, plot_id, b" " * (64 + 48))
1616

@@ -36,24 +36,18 @@ def test_plot_roundtrip() -> None:
3636
challenge = bytes32.random(rng)
3737
num_challenges += 1
3838

39-
quality_proofs = prover.get_qualities_for_challenge(
40-
challenge, proof_fragment_scan_filter
41-
)
42-
if quality_proofs == []:
39+
partial_proofs = prover.get_qualities_for_challenge(challenge)
40+
if partial_proofs == []:
4341
continue
44-
for qp in quality_proofs:
45-
proof_fragments, s = prover.get_partial_proof(qp)
46-
assert s == strength
47-
full_proof = solve_proof(proof_fragments, plot_id, strength, k)
42+
for pp in partial_proofs:
43+
full_proof = solve_proof(pp, plot_id, strength, k)
4844

4945
num_proofs += 1
50-
quality = validate_proof_v2(
51-
plot_id, k, challenge, strength, proof_fragment_scan_filter, full_proof
52-
)
46+
quality = validate_proof_v2(plot_id, k, challenge, strength, full_proof)
5347
assert quality is not None
54-
assert quality == qp.serialize()
48+
assert quality == pp.get_string(uint8(strength))
5549

5650
print(f"challenges: {num_challenges}")
5751
print(f"proofs: {num_proofs}")
5852
assert num_challenges == 100
59-
assert num_proofs == 50
53+
assert num_proofs == 3

wheel/generate_type_stubs.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def parse_rust_source(filename: str, upper_case: bool) -> list[tuple[str, list[s
204204

205205

206206
extra_members = {
207+
"PartialProof": [
208+
"def get_string(self, strength: uint8) -> bytes32: ...",
209+
],
207210
"Coin": [
208211
"def name(self) -> bytes32: ...",
209212
],
@@ -502,16 +505,10 @@ def make_v2(s: int) -> PlotParam: ...
502505
size_v1: Optional[uint8]
503506
strength_v2: Optional[uint8]
504507
505-
# Proof-of-space 2
506-
@final
507-
class QualityProof:
508-
def serialize(self) -> bytes32: ...
509-
510508
@final
511509
class Prover:
512510
def __new__(cls, plot_path: str) -> Prover: ...
513-
def get_qualities_for_challenge(self, challenge: bytes32, proof_fragment_filter: int) -> list[QualityProof]: ...
514-
def get_partial_proof(self, quality: QualityProof) -> tuple[PartialProof, int]: ...
511+
def get_qualities_for_challenge(self, challenge: bytes32) -> list[PartialProof]: ...
515512
def size(self) -> int: ...
516513
def plot_id(self) -> bytes32: ...
517514
def get_strength(self) -> int: ...
@@ -528,7 +525,7 @@ def create_v2_plot(filename: str,
528525
memo: bytes,
529526
) -> None: ...
530527
531-
def validate_proof_v2(plot_id: bytes32, size: int, challenge: bytes32, required_plot_strength: int, proof_fragment_scan_filter: int, proof: bytes) -> Optional[bytes32]: ...
528+
def validate_proof_v2(plot_id: bytes32, size: int, challenge: bytes32, plot_strength: int, proof: bytes) -> Optional[bytes32]: ...
532529
533530
def solve_proof(fragments: PartialProof, plot_id: bytes32, strength: int, k: int) -> bytes: ...
534531

wheel/python/chia_rs/chia_rs.pyi

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,10 @@ class PlotParam:
200200
size_v1: Optional[uint8]
201201
strength_v2: Optional[uint8]
202202

203-
# Proof-of-space 2
204-
@final
205-
class QualityProof:
206-
def serialize(self) -> bytes32: ...
207-
208203
@final
209204
class Prover:
210205
def __new__(cls, plot_path: str) -> Prover: ...
211-
def get_qualities_for_challenge(self, challenge: bytes32, proof_fragment_filter: int) -> list[QualityProof]: ...
212-
def get_partial_proof(self, quality: QualityProof) -> tuple[PartialProof, int]: ...
206+
def get_qualities_for_challenge(self, challenge: bytes32) -> list[PartialProof]: ...
213207
def size(self) -> int: ...
214208
def plot_id(self) -> bytes32: ...
215209
def get_strength(self) -> int: ...
@@ -226,7 +220,7 @@ def create_v2_plot(filename: str,
226220
memo: bytes,
227221
) -> None: ...
228222

229-
def validate_proof_v2(plot_id: bytes32, size: int, challenge: bytes32, required_plot_strength: int, proof_fragment_scan_filter: int, proof: bytes) -> Optional[bytes32]: ...
223+
def validate_proof_v2(plot_id: bytes32, size: int, challenge: bytes32, plot_strength: int, proof: bytes) -> Optional[bytes32]: ...
230224

231225
def solve_proof(fragments: PartialProof, plot_id: bytes32, strength: int, k: int) -> bytes: ...
232226

@@ -2086,10 +2080,11 @@ class HeaderBlock:
20862080

20872081
@final
20882082
class PartialProof:
2089-
proof_fragments: list[uint64]
2083+
fragments: list[uint64]
2084+
def get_string(self, strength: uint8) -> bytes32: ...
20902085
def __new__(
20912086
cls,
2092-
proof_fragments: Sequence[uint64]
2087+
fragments: Sequence[uint64]
20932088
) -> PartialProof: ...
20942089
def __hash__(self) -> int: ...
20952090
def __repr__(self) -> str: ...
@@ -2108,7 +2103,7 @@ class PartialProof:
21082103
def to_json_dict(self) -> dict[str, Any]: ...
21092104
@classmethod
21102105
def from_json_dict(cls, json_dict: dict[str, Any]) -> Self: ...
2111-
def replace(self, *, proof_fragments: Union[ list[uint64], _Unspec] = _Unspec()) -> PartialProof: ...
2106+
def replace(self, *, fragments: Union[ list[uint64], _Unspec] = _Unspec()) -> PartialProof: ...
21122107

21132108
@final
21142109
class TimestampedPeerInfo:
@@ -4528,7 +4523,6 @@ class ConsensusConstants:
45284523
PLOT_FILTER_32_HEIGHT: uint32
45294524
MIN_PLOT_STRENGTH: uint8
45304525
MAX_PLOT_STRENGTH: uint8
4531-
QUALITY_PROOF_SCAN_FILTER: uint8
45324526
PLOT_FILTER_V2_FIRST_ADJUSTMENT_HEIGHT: uint32
45334527
PLOT_FILTER_V2_SECOND_ADJUSTMENT_HEIGHT: uint32
45344528
PLOT_FILTER_V2_THIRD_ADJUSTMENT_HEIGHT: uint32
@@ -4584,7 +4578,6 @@ class ConsensusConstants:
45844578
PLOT_FILTER_32_HEIGHT: uint32,
45854579
MIN_PLOT_STRENGTH: uint8,
45864580
MAX_PLOT_STRENGTH: uint8,
4587-
QUALITY_PROOF_SCAN_FILTER: uint8,
45884581
PLOT_FILTER_V2_FIRST_ADJUSTMENT_HEIGHT: uint32,
45894582
PLOT_FILTER_V2_SECOND_ADJUSTMENT_HEIGHT: uint32,
45904583
PLOT_FILTER_V2_THIRD_ADJUSTMENT_HEIGHT: uint32
@@ -4656,7 +4649,6 @@ class ConsensusConstants:
46564649
PLOT_FILTER_32_HEIGHT: Union[ uint32, _Unspec] = _Unspec(),
46574650
MIN_PLOT_STRENGTH: Union[ uint8, _Unspec] = _Unspec(),
46584651
MAX_PLOT_STRENGTH: Union[ uint8, _Unspec] = _Unspec(),
4659-
QUALITY_PROOF_SCAN_FILTER: Union[ uint8, _Unspec] = _Unspec(),
46604652
PLOT_FILTER_V2_FIRST_ADJUSTMENT_HEIGHT: Union[ uint32, _Unspec] = _Unspec(),
46614653
PLOT_FILTER_V2_SECOND_ADJUSTMENT_HEIGHT: Union[ uint32, _Unspec] = _Unspec(),
46624654
PLOT_FILTER_V2_THIRD_ADJUSTMENT_HEIGHT: Union[ uint32, _Unspec] = _Unspec()) -> ConsensusConstants: ...

0 commit comments

Comments
 (0)