Skip to content

Commit

Permalink
Merge branch 'main' into shutdownwjb
Browse files Browse the repository at this point in the history
  • Loading branch information
wjblanke authored Oct 8, 2024
2 parents 4729914 + 5349251 commit 8479cf2
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 46 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build-c-libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,9 @@ jobs:

- name: Notify new build
if: env.RELEASE == 'true'
run: |
curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdfc/trigger
uses: Chia-Network/actions/github/glue@main
with:
json_data: '{"release_version":"${{ env.RELEASE_TAG }}"}'
glue_url: ${{ secrets.GLUE_API_URL }}
glue_project: "chiavdfc"
glue_path: "trigger"
9 changes: 6 additions & 3 deletions .github/workflows/hw-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ jobs:

- name: Trigger repo update
if: env.RELEASE == 'true'
run: |
curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdf-hw/${{ env.RELEASE_TAG }}/start
curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdf-hw/${{ env.RELEASE_TAG }}/success/release_hw
uses: Chia-Network/actions/github/glue@main
with:
json_data: '{"release_version":"${{ env.RELEASE_TAG }}"}'
glue_url: ${{ secrets.GLUE_API_URL }}
glue_project: "chiavdf-hw"
glue_path: "trigger"
93 changes: 85 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
branches:
- "**"

concurrency:
group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }}
cancel-in-progress: true

permissions:
id-token: write
contents: read
Expand All @@ -32,16 +36,11 @@ jobs:
cd rust_bindings
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=600 || exit 255"
build_crate:
name: Build crate
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
Expand All @@ -54,14 +53,92 @@ jobs:
- name: Clippy
run: cargo clippy

test:
name: Test (${{ matrix.os.name }} ${{ matrix.arch.name }})
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}

strategy:
fail-fast: false
matrix:
os:
- name: macOS
matrix: macos
runs-on:
arm: [macos-13-arm64]
intel: [macos-13]
cibw-archs-macos:
arm: arm64
intel: x86_64
- name: Ubuntu
matrix: ubuntu
runs-on:
arm: [Linux, ARM64]
intel: [ubuntu-latest]
- name: Windows
matrix: windows
runs-on:
intel: [windows-latest]

arch:
- name: ARM
matrix: arm
- name: Intel
matrix: intel

exclude:
- os:
name: Windows
matrix: windows
runs-on:
intel: [windows-latest]
arch:
name: ARM
matrix: arm

steps:
- uses: actions/checkout@v4

- name: Setup library path on MacOS
if: matrix.os.name == 'macOS'
run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV

- name: Install MPIR on Windows
if: matrix.os.name == 'Windows'
run: |
git clone https://github.com/Chia-Network/mpir_gc_x64.git
"$(Get-Location)/mpir_gc_x64" | Out-File -Append -FilePath $env:GITHUB_PATH
- name: Install libclang-dev on Linux
if: matrix.os.name == 'Ubuntu'
run: sudo apt-get install libclang-dev -y

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

- name: Tests
run: cargo test && cargo test --release

build_crate:
name: Build crate
needs: [lint, test]
runs-on: ubuntu-latest
strategy:
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable

- name: Build
run: cargo build --release

- name: Prepare for publish
run: cp -r src rust_bindings/cpp
run: |
cd rust_bindings
cp -r ../src cpp
git clone https://github.com/Chia-Network/mpir_gc_x64.git
- name: Publish to crates.io (dry run)
# We use `--allow-dirty` because the `cpp` folder is copied into the working directory.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust_bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chiavdf"
version = "1.1.5"
version = "1.1.8"
edition = "2021"
license = "Apache-2.0"
description = "Bindings to the chiavdf C++ library."
Expand Down
52 changes: 40 additions & 12 deletions rust_bindings/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::env;
use std::path::PathBuf;
use std::str::FromStr;

use cmake::Config;

Expand All @@ -27,18 +26,47 @@ fn main() {
.define("BUILD_PYTHON", "OFF")
.build();

println!(
"cargo:rustc-link-search=native={}",
PathBuf::from_str(dst.display().to_string().as_str())
.unwrap()
.join("build")
.join("lib")
.join("static")
.to_str()
.unwrap()
);
println!("cargo:rustc-link-lib=static=chiavdfc");
println!("cargo:rustc-link-lib=gmp");

if cfg!(target_os = "windows") {
let build_type = if cfg!(debug_assertions) {
"Debug"
} else {
"Release"
};

println!(
"cargo:rustc-link-search=native={}",
dst.join("build")
.join("lib")
.join("static")
.join(build_type)
.to_str()
.unwrap()
);

println!("cargo:rustc-link-lib=static=mpir");
println!(
"cargo:rustc-link-search=native={}",
src_dir
.parent()
.unwrap()
.join("mpir_gc_x64")
.to_str()
.unwrap()
);
} else {
println!(
"cargo:rustc-link-search=native={}",
dst.join("build")
.join("lib")
.join("static")
.to_str()
.unwrap()
);

println!("cargo:rustc-link-lib=gmp");
}

let bindings = bindgen::Builder::default()
.header(manifest_dir.join("wrapper.h").to_str().unwrap())
Expand Down
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ if(BUILD_PYTHON)
if(UNIX)
target_link_libraries(chiavdf PRIVATE -pthread)
endif()
if (WIN32)
# workaround for constexpr mutex constructor change in MSVC 2022
# https://stackoverflow.com/questions/78598141/first-stdmutexlock-crashes-in-application-built-with-latest-visual-studio
target_compile_definitions(chiavdf PUBLIC _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
endif()
endif()

add_executable(verifier_test
Expand Down
2 changes: 1 addition & 1 deletion src/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OneWesolowskiCallback: public WesolowskiCallback {
uint32_t k, l;
this->wanted_iter = wanted_iter;
if (wanted_iter >= (1 << 16)) {
ApproximateParameters(wanted_iter, k, l);
ApproximateParameters(wanted_iter, l, k);
} else {
k = 10;
l = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/provers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OneWesolowskiProver : public Prover {
{
this->intermediates = intermediates;
if (num_iterations >= (1 << 16)) {
ApproximateParameters(num_iterations, k, l);
ApproximateParameters(num_iterations, l, k);
} else {
k = 10;
l = 1;
Expand Down
45 changes: 28 additions & 17 deletions src/python_bindings/fastvdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ PYBIND11_MODULE(chiavdf, m) {
const string& x_s, const string& y_s,
const string& proof_s,
uint64_t num_iterations) {
py::gil_scoped_release release;
integer D(discriminant);
form x = DeserializeForm(D, (const uint8_t *)x_s.data(), x_s.size());
form y = DeserializeForm(D, (const uint8_t *)y_s.data(), y_s.size());
form proof = DeserializeForm(D, (const uint8_t *)proof_s.data(), proof_s.size());
std::string x_s_copy(x_s);
std::string y_s_copy(y_s);
std::string proof_s_copy(proof_s);
py::gil_scoped_release release;
form x = DeserializeForm(D, (const uint8_t *)x_s_copy.data(), x_s_copy.size());
form y = DeserializeForm(D, (const uint8_t *)y_s_copy.data(), y_s_copy.size());
form proof = DeserializeForm(D, (const uint8_t *)proof_s_copy.data(), proof_s_copy.size());

bool is_valid = false;
VerifyWesolowskiProof(D, x, y, proof, num_iterations, is_valid);
Expand All @@ -41,16 +44,19 @@ PYBIND11_MODULE(chiavdf, m) {
const string& x_s,
const string& proof_blob,
const uint64_t num_iterations, const uint64_t disc_size_bits, const uint64_t recursion) {
std::string discriminant_copy(discriminant);
std::string x_s_copy(x_s);
std::string proof_blob_copy(proof_blob);
py::gil_scoped_release release;
std::string proof_blob_str(proof_blob);
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_str.data());
int proof_blob_size = proof_blob.size();
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_copy.data());
int proof_blob_size = proof_blob_copy.size();

return CheckProofOfTimeNWesolowski(integer(discriminant), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
return CheckProofOfTimeNWesolowski(integer(discriminant_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
});

m.def("prove", [] (const py::bytes& challenge_hash, const string& x_s, int discriminant_size_bits, uint64_t num_iterations, const string& shutdown_file_path) {
std::string challenge_hash_str(challenge_hash);
std::string x_s_copy(x_s);
std::vector<uint8_t> result;
{
py::gil_scoped_release release;
Expand All @@ -59,7 +65,7 @@ PYBIND11_MODULE(chiavdf, m) {
challenge_hash_bytes,
discriminant_size_bits
);
form x = DeserializeForm(D, (const uint8_t *) x_s.data(), x_s.size());
form x = DeserializeForm(D, (const uint8_t *) x_s_copy.data(), x_s_copy.size());
result = ProveSlow(D, x, num_iterations, shutdown_file_path);
}
py::bytes ret = py::bytes(reinterpret_cast<char*>(result.data()), result.size());
Expand All @@ -74,11 +80,14 @@ PYBIND11_MODULE(chiavdf, m) {
const uint64_t num_iterations, const uint64_t recursion) {
std::pair<bool, std::vector<uint8_t>> result;
{
std::string discriminant_copy(discriminant);
std::string B_copy(B);
std::string x_s_copy(x_s);
std::string proof_blob_copy(proof_blob);
py::gil_scoped_release release;
std::string proof_blob_str(proof_blob);
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_str.data());
int proof_blob_size = proof_blob.size();
result = CheckProofOfTimeNWesolowskiWithB(integer(discriminant), integer(B), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_copy.data());
int proof_blob_size = proof_blob_copy.size();
result = CheckProofOfTimeNWesolowskiWithB(integer(discriminant_copy), integer(B_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
}
py::bytes res_bytes = py::bytes(reinterpret_cast<char*>(result.second.data()), result.second.size());
py::tuple res_tuple = py::make_tuple(result.first, res_bytes);
Expand All @@ -89,11 +98,13 @@ PYBIND11_MODULE(chiavdf, m) {
const string& x_s,
const string& proof_blob,
const uint64_t num_iterations, const uint64_t recursion) {
std::string discriminant_copy(discriminant);
std::string x_s_copy(x_s);
std::string proof_blob_copy(proof_blob);
py::gil_scoped_release release;
std::string proof_blob_str(proof_blob);
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_str.data());
int proof_blob_size = proof_blob.size();
integer B = GetBFromProof(integer(discriminant), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_copy.data());
int proof_blob_size = proof_blob_copy.size();
integer B = GetBFromProof(integer(discriminant_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
return B.to_string();
});
}

0 comments on commit 8479cf2

Please sign in to comment.