Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHIA-193: Rust bindings to chiapos #439

Merged
merged 25 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions c-bindings/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include "verifier.hpp"

extern "C" {
bool validate_proof(const uint8_t* seed, uint8_t k, const uint8_t* challenge, const uint8_t* proof, uint16_t proof_len, uint8_t* quality_buf) {
bool validate_proof(const uint8_t* plot_id, uint8_t k, const uint8_t* challenge, const uint8_t* proof, uint16_t proof_len, uint8_t* quality_buf) {
Verifier v;
auto quality = v.ValidateProof(seed, k, challenge, proof, proof_len);
if (quality.GetSize() == 0) {
auto quality = v.ValidateProof(plot_id, k, challenge, proof, proof_len);
if (quality.GetSize() != 256) {
arvidn marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
quality.ToBytes(quality_buf);
Expand Down
2 changes: 1 addition & 1 deletion c-bindings/wrapper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "picosha2.hpp"

extern "C" {
bool validate_proof(const uint8_t* seed, uint8_t k, const uint8_t* challenge, const uint8_t* proof, uint16_t proof_len, uint8_t* quality_buf);
bool validate_proof(const uint8_t* plot_id, uint8_t k, const uint8_t* challenge, const uint8_t* proof, uint16_t proof_len, uint8_t* quality_buf);
}
20 changes: 10 additions & 10 deletions rust-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod bindings {
}

pub fn validate_proof(
seed: &[u8; 32],
plot_id: &[u8; 32],
k: u8,
challenge: &[u8; 32],
proof: &[u8],
Expand All @@ -22,7 +22,7 @@ pub fn validate_proof(

unsafe {
bindings::validate_proof(
seed.as_ptr(),
plot_id.as_ptr(),
k,
challenge.as_ptr(),
proof.as_ptr(),
Expand All @@ -48,7 +48,7 @@ mod tests {

for line in proofs.lines() {
let mut parts = line.split(", ");
let seed = hex::decode(parts.next().unwrap())
let plot_id = hex::decode(parts.next().unwrap())
.unwrap()
.try_into()
.unwrap();
Expand All @@ -63,7 +63,7 @@ mod tests {
// The test should pass with the initial data.
let mut actual_quality = [0; 32];
assert!(validate_proof(
&seed,
&plot_id,
k,
&challenge,
&proof,
Expand All @@ -73,10 +73,10 @@ mod tests {

// If you change the seed, the test should fail.
let mut actual_quality = [0; 32];
let mut new_seed = seed;
new_seed[0] = new_seed[0].wrapping_add(1);
let mut new_plot_id = plot_id;
new_plot_id[0] = new_plot_id[0].wrapping_add(1);
assert!(!validate_proof(
&new_seed,
&new_plot_id,
k,
&challenge,
&proof,
Expand All @@ -88,7 +88,7 @@ mod tests {
let mut actual_quality = [0; 32];
let new_k = k.wrapping_add(1);
assert!(!validate_proof(
&seed,
&plot_id,
new_k,
&challenge,
&proof,
Expand All @@ -100,7 +100,7 @@ mod tests {
let mut new_challenge = challenge;
new_challenge[0] = new_challenge[0].wrapping_add(1);
assert!(!validate_proof(
&seed,
&plot_id,
k,
&new_challenge,
&proof,
Expand All @@ -113,7 +113,7 @@ mod tests {
let mut new_proof = proof;
new_proof[0] = new_proof[0].wrapping_add(1);
assert!(!validate_proof(
&seed,
&plot_id,
k,
&challenge,
&new_proof,
Expand Down
Loading