-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python bindings to chiavdf and chiapos
- Loading branch information
Showing
9 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use chia_protocol::{Bytes32, ProofOfSpace}; | ||
use chiapos::validate_proof; | ||
|
||
pub fn get_quality_string(pos: &ProofOfSpace, plot_id: Bytes32) -> Option<Bytes32> { | ||
let mut quality = [0; 32]; | ||
if validate_proof( | ||
&plot_id.to_bytes(), | ||
pos.size, | ||
&pos.challenge.to_bytes(), | ||
&pos.proof, | ||
&mut quality, | ||
) { | ||
Some(Bytes32::from(quality)) | ||
} else { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use chia_protocol::{ClassgroupElement, VDFInfo, VDFProof}; | ||
use chiavdf::{create_discriminant, verify_n_wesolowski}; | ||
|
||
use crate::consensus_constants::ConsensusConstants; | ||
|
||
pub fn validate_vdf_proof( | ||
proof: &VDFProof, | ||
input_el: &ClassgroupElement, | ||
info: &VDFInfo, | ||
constants: &ConsensusConstants, | ||
) -> bool { | ||
if proof.witness_type + 1 > constants.max_vdf_witness_size { | ||
return false; | ||
} | ||
|
||
let mut discriminant = vec![0; constants.discriminant_size_bits as usize / 8]; | ||
create_discriminant(&info.challenge, &mut discriminant); | ||
|
||
let proof_buf = [info.output.data.as_slice(), proof.witness.as_slice()].concat(); | ||
|
||
verify_n_wesolowski( | ||
&discriminant, | ||
&input_el.data, | ||
&proof_buf, | ||
info.number_of_iterations, | ||
proof.witness_type as u64, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.