Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Aug 14, 2024
1 parent 711e301 commit 8bec961
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 37 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ IF (BUILD_PROOF_OF_SPACE_STATICALLY)
target_link_libraries(ProofOfSpace PUBLIC -static -Wl,--whole-archive -lrt -lpthread -Wl,--no-whole-archive)
ENDIF()

option(BUILD_STATIC_CHIAPOS_LIBRARY "Build chiapos library statically" OFF)
option(BUILD_STATIC_CHIAPOS_LIBRARY "Build chiapos static library (verify-only)" OFF)
IF (BUILD_STATIC_CHIAPOS_LIBRARY)
message("Statically build chiapos library")
add_library(chiapos_static STATIC src/chacha8.c src/verifier.hpp c-bindings/wrapper.cpp)
message("Build chiapos static library (verify-only)")
add_library(chiapos_static STATIC src/chacha8.c c-bindings/wrapper.cpp)
target_link_libraries(chiapos_static PUBLIC blake3)
target_include_directories(chiapos_static PUBLIC lib/include)
ENDIF()
Expand Down
13 changes: 4 additions & 9 deletions c-bindings/wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#include "wrapper.h"
#include "verifier.hpp"

extern "C" {
ByteArray validate_proof(const uint8_t* seed, uint8_t k, const uint8_t* challenge, const uint8_t* proof, uint16_t proof_len) {
bool validate_proof(uint8_t* seed, uint8_t k, uint8_t* challenge, 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) {
return ByteArray { nullptr, 0 };
return false;
}
uint8_t *quality_buf = new uint8_t[32];
quality.ToBytes(quality_buf);
delete[] quality_buf;
return ByteArray { quality_buf, 32 };
}

void delete_byte_array(ByteArray array) {
delete[] array.data;
return true;
}
}
10 changes: 1 addition & 9 deletions c-bindings/wrapper.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#include "picosha2.hpp"
#include "../src/verifier.hpp"

extern "C" {
typedef struct {
uint8_t* data;
size_t length;
} ByteArray;

ByteArray validate_proof(const uint8_t* seed, uint8_t k, const uint8_t* challenge, const uint8_t* proof, uint16_t proof_len);

void delete_byte_array(ByteArray array);
bool validate_proof(uint8_t* seed, uint8_t k, uint8_t* challenge, uint8_t* proof, uint16_t proof_len, uint8_t* quality_buf);
}
2 changes: 0 additions & 2 deletions rust-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ fn main() {
.clang_arg(format!("-I{}", blake3_include_path.to_str().unwrap()))
.clang_arg("-std=c++14")
.allowlist_function("validate_proof")
.allowlist_function("delete_byte_array")
.allowlist_type("ByteArray")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");
Expand Down
20 changes: 6 additions & 14 deletions rust-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ pub fn validate_proof(
};

unsafe {
let array = bindings::validate_proof(
seed.as_ptr(),
bindings::validate_proof(
seed.as_ptr() as *mut u8,
k,
challenge.as_ptr(),
proof.as_ptr(),
challenge.as_ptr() as *mut u8,
proof.as_ptr() as *mut u8,
proof_len,
);

if array.data.is_null() {
false
} else {
let data = std::slice::from_raw_parts(array.data, array.length);
quality.copy_from_slice(data);
bindings::delete_byte_array(array);
true
}
quality.as_mut_ptr(),
)
}
}

Expand Down

0 comments on commit 8bec961

Please sign in to comment.