Skip to content

Commit 8479cf2

Browse files
authored
Merge branch 'main' into shutdownwjb
2 parents 4729914 + 5349251 commit 8479cf2

File tree

10 files changed

+174
-46
lines changed

10 files changed

+174
-46
lines changed

.github/workflows/build-c-libraries.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,9 @@ jobs:
139139

140140
- name: Notify new build
141141
if: env.RELEASE == 'true'
142-
run: |
143-
curl -s -XPOST -H "Authorization: Bearer ${{ env.JWT_TOKEN }}" --data '{"release_version":"${{ env.RELEASE_TAG }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/chiavdfc/trigger
142+
uses: Chia-Network/actions/github/glue@main
143+
with:
144+
json_data: '{"release_version":"${{ env.RELEASE_TAG }}"}'
145+
glue_url: ${{ secrets.GLUE_API_URL }}
146+
glue_project: "chiavdfc"
147+
glue_path: "trigger"

.github/workflows/hw-build.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ jobs:
108108

109109
- name: Trigger repo update
110110
if: env.RELEASE == 'true'
111-
run: |
112-
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
113-
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
111+
uses: Chia-Network/actions/github/glue@main
112+
with:
113+
json_data: '{"release_version":"${{ env.RELEASE_TAG }}"}'
114+
glue_url: ${{ secrets.GLUE_API_URL }}
115+
glue_project: "chiavdf-hw"
116+
glue_path: "trigger"

.github/workflows/rust.yml

+85-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
branches:
1111
- "**"
1212

13+
concurrency:
14+
group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }}
15+
cancel-in-progress: true
16+
1317
permissions:
1418
id-token: write
1519
contents: read
@@ -32,16 +36,11 @@ jobs:
3236
cd rust_bindings
3337
cargo fuzz list | xargs -I "%" sh -c "cargo +nightly fuzz run % -- -max_total_time=600 || exit 255"
3438
35-
build_crate:
36-
name: Build crate
39+
lint:
40+
name: Lint
3741
runs-on: ubuntu-latest
38-
strategy:
39-
fail-fast: false
40-
4142
steps:
4243
- uses: actions/checkout@v4
43-
with:
44-
fetch-depth: 0
4544

4645
- name: Set up Rust
4746
uses: dtolnay/rust-toolchain@stable
@@ -54,14 +53,92 @@ jobs:
5453
- name: Clippy
5554
run: cargo clippy
5655

56+
test:
57+
name: Test (${{ matrix.os.name }} ${{ matrix.arch.name }})
58+
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}
59+
60+
strategy:
61+
fail-fast: false
62+
matrix:
63+
os:
64+
- name: macOS
65+
matrix: macos
66+
runs-on:
67+
arm: [macos-13-arm64]
68+
intel: [macos-13]
69+
cibw-archs-macos:
70+
arm: arm64
71+
intel: x86_64
72+
- name: Ubuntu
73+
matrix: ubuntu
74+
runs-on:
75+
arm: [Linux, ARM64]
76+
intel: [ubuntu-latest]
77+
- name: Windows
78+
matrix: windows
79+
runs-on:
80+
intel: [windows-latest]
81+
82+
arch:
83+
- name: ARM
84+
matrix: arm
85+
- name: Intel
86+
matrix: intel
87+
88+
exclude:
89+
- os:
90+
name: Windows
91+
matrix: windows
92+
runs-on:
93+
intel: [windows-latest]
94+
arch:
95+
name: ARM
96+
matrix: arm
97+
98+
steps:
99+
- uses: actions/checkout@v4
100+
101+
- name: Setup library path on MacOS
102+
if: matrix.os.name == 'macOS'
103+
run: echo "LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH" >> $GITHUB_ENV
104+
105+
- name: Install MPIR on Windows
106+
if: matrix.os.name == 'Windows'
107+
run: |
108+
git clone https://github.com/Chia-Network/mpir_gc_x64.git
109+
"$(Get-Location)/mpir_gc_x64" | Out-File -Append -FilePath $env:GITHUB_PATH
110+
111+
- name: Install libclang-dev on Linux
112+
if: matrix.os.name == 'Ubuntu'
113+
run: sudo apt-get install libclang-dev -y
114+
115+
- name: Set up Rust
116+
uses: dtolnay/rust-toolchain@stable
117+
57118
- name: Tests
58119
run: cargo test && cargo test --release
59120

121+
build_crate:
122+
name: Build crate
123+
needs: [lint, test]
124+
runs-on: ubuntu-latest
125+
strategy:
126+
fail-fast: false
127+
128+
steps:
129+
- uses: actions/checkout@v4
130+
131+
- name: Set up Rust
132+
uses: dtolnay/rust-toolchain@stable
133+
60134
- name: Build
61135
run: cargo build --release
62136

63137
- name: Prepare for publish
64-
run: cp -r src rust_bindings/cpp
138+
run: |
139+
cd rust_bindings
140+
cp -r ../src cpp
141+
git clone https://github.com/Chia-Network/mpir_gc_x64.git
65142
66143
- name: Publish to crates.io (dry run)
67144
# We use `--allow-dirty` because the `cpp` folder is copied into the working directory.

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust_bindings/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chiavdf"
3-
version = "1.1.5"
3+
version = "1.1.8"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "Bindings to the chiavdf C++ library."

rust_bindings/build.rs

+40-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::env;
22
use std::path::PathBuf;
3-
use std::str::FromStr;
43

54
use cmake::Config;
65

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

30-
println!(
31-
"cargo:rustc-link-search=native={}",
32-
PathBuf::from_str(dst.display().to_string().as_str())
33-
.unwrap()
34-
.join("build")
35-
.join("lib")
36-
.join("static")
37-
.to_str()
38-
.unwrap()
39-
);
4029
println!("cargo:rustc-link-lib=static=chiavdfc");
41-
println!("cargo:rustc-link-lib=gmp");
30+
31+
if cfg!(target_os = "windows") {
32+
let build_type = if cfg!(debug_assertions) {
33+
"Debug"
34+
} else {
35+
"Release"
36+
};
37+
38+
println!(
39+
"cargo:rustc-link-search=native={}",
40+
dst.join("build")
41+
.join("lib")
42+
.join("static")
43+
.join(build_type)
44+
.to_str()
45+
.unwrap()
46+
);
47+
48+
println!("cargo:rustc-link-lib=static=mpir");
49+
println!(
50+
"cargo:rustc-link-search=native={}",
51+
src_dir
52+
.parent()
53+
.unwrap()
54+
.join("mpir_gc_x64")
55+
.to_str()
56+
.unwrap()
57+
);
58+
} else {
59+
println!(
60+
"cargo:rustc-link-search=native={}",
61+
dst.join("build")
62+
.join("lib")
63+
.join("static")
64+
.to_str()
65+
.unwrap()
66+
);
67+
68+
println!("cargo:rustc-link-lib=gmp");
69+
}
4270

4371
let bindings = bindgen::Builder::default()
4472
.header(manifest_dir.join("wrapper.h").to_str().unwrap())

src/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ if(BUILD_PYTHON)
7070
if(UNIX)
7171
target_link_libraries(chiavdf PRIVATE -pthread)
7272
endif()
73+
if (WIN32)
74+
# workaround for constexpr mutex constructor change in MSVC 2022
75+
# https://stackoverflow.com/questions/78598141/first-stdmutexlock-crashes-in-application-built-with-latest-visual-studio
76+
target_compile_definitions(chiavdf PUBLIC _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
77+
endif()
7378
endif()
7479

7580
add_executable(verifier_test

src/callback.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class OneWesolowskiCallback: public WesolowskiCallback {
7676
uint32_t k, l;
7777
this->wanted_iter = wanted_iter;
7878
if (wanted_iter >= (1 << 16)) {
79-
ApproximateParameters(wanted_iter, k, l);
79+
ApproximateParameters(wanted_iter, l, k);
8080
} else {
8181
k = 10;
8282
l = 1;

src/provers.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OneWesolowskiProver : public Prover {
1111
{
1212
this->intermediates = intermediates;
1313
if (num_iterations >= (1 << 16)) {
14-
ApproximateParameters(num_iterations, k, l);
14+
ApproximateParameters(num_iterations, l, k);
1515
} else {
1616
k = 10;
1717
l = 1;

src/python_bindings/fastvdf.cpp

+28-17
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ PYBIND11_MODULE(chiavdf, m) {
2525
const string& x_s, const string& y_s,
2626
const string& proof_s,
2727
uint64_t num_iterations) {
28-
py::gil_scoped_release release;
2928
integer D(discriminant);
30-
form x = DeserializeForm(D, (const uint8_t *)x_s.data(), x_s.size());
31-
form y = DeserializeForm(D, (const uint8_t *)y_s.data(), y_s.size());
32-
form proof = DeserializeForm(D, (const uint8_t *)proof_s.data(), proof_s.size());
29+
std::string x_s_copy(x_s);
30+
std::string y_s_copy(y_s);
31+
std::string proof_s_copy(proof_s);
32+
py::gil_scoped_release release;
33+
form x = DeserializeForm(D, (const uint8_t *)x_s_copy.data(), x_s_copy.size());
34+
form y = DeserializeForm(D, (const uint8_t *)y_s_copy.data(), y_s_copy.size());
35+
form proof = DeserializeForm(D, (const uint8_t *)proof_s_copy.data(), proof_s_copy.size());
3336

3437
bool is_valid = false;
3538
VerifyWesolowskiProof(D, x, y, proof, num_iterations, is_valid);
@@ -41,16 +44,19 @@ PYBIND11_MODULE(chiavdf, m) {
4144
const string& x_s,
4245
const string& proof_blob,
4346
const uint64_t num_iterations, const uint64_t disc_size_bits, const uint64_t recursion) {
47+
std::string discriminant_copy(discriminant);
48+
std::string x_s_copy(x_s);
49+
std::string proof_blob_copy(proof_blob);
4450
py::gil_scoped_release release;
45-
std::string proof_blob_str(proof_blob);
46-
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_str.data());
47-
int proof_blob_size = proof_blob.size();
51+
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_copy.data());
52+
int proof_blob_size = proof_blob_copy.size();
4853

49-
return CheckProofOfTimeNWesolowski(integer(discriminant), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
54+
return CheckProofOfTimeNWesolowski(integer(discriminant_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
5055
});
5156

5257
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) {
5358
std::string challenge_hash_str(challenge_hash);
59+
std::string x_s_copy(x_s);
5460
std::vector<uint8_t> result;
5561
{
5662
py::gil_scoped_release release;
@@ -59,7 +65,7 @@ PYBIND11_MODULE(chiavdf, m) {
5965
challenge_hash_bytes,
6066
discriminant_size_bits
6167
);
62-
form x = DeserializeForm(D, (const uint8_t *) x_s.data(), x_s.size());
68+
form x = DeserializeForm(D, (const uint8_t *) x_s_copy.data(), x_s_copy.size());
6369
result = ProveSlow(D, x, num_iterations, shutdown_file_path);
6470
}
6571
py::bytes ret = py::bytes(reinterpret_cast<char*>(result.data()), result.size());
@@ -74,11 +80,14 @@ PYBIND11_MODULE(chiavdf, m) {
7480
const uint64_t num_iterations, const uint64_t recursion) {
7581
std::pair<bool, std::vector<uint8_t>> result;
7682
{
83+
std::string discriminant_copy(discriminant);
84+
std::string B_copy(B);
85+
std::string x_s_copy(x_s);
86+
std::string proof_blob_copy(proof_blob);
7787
py::gil_scoped_release release;
78-
std::string proof_blob_str(proof_blob);
79-
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_str.data());
80-
int proof_blob_size = proof_blob.size();
81-
result = CheckProofOfTimeNWesolowskiWithB(integer(discriminant), integer(B), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
88+
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_copy.data());
89+
int proof_blob_size = proof_blob_copy.size();
90+
result = CheckProofOfTimeNWesolowskiWithB(integer(discriminant_copy), integer(B_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
8291
}
8392
py::bytes res_bytes = py::bytes(reinterpret_cast<char*>(result.second.data()), result.second.size());
8493
py::tuple res_tuple = py::make_tuple(result.first, res_bytes);
@@ -89,11 +98,13 @@ PYBIND11_MODULE(chiavdf, m) {
8998
const string& x_s,
9099
const string& proof_blob,
91100
const uint64_t num_iterations, const uint64_t recursion) {
101+
std::string discriminant_copy(discriminant);
102+
std::string x_s_copy(x_s);
103+
std::string proof_blob_copy(proof_blob);
92104
py::gil_scoped_release release;
93-
std::string proof_blob_str(proof_blob);
94-
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_str.data());
95-
int proof_blob_size = proof_blob.size();
96-
integer B = GetBFromProof(integer(discriminant), (const uint8_t *)x_s.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
105+
uint8_t *proof_blob_ptr = reinterpret_cast<uint8_t *>(proof_blob_copy.data());
106+
int proof_blob_size = proof_blob_copy.size();
107+
integer B = GetBFromProof(integer(discriminant_copy), (const uint8_t *)x_s_copy.data(), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
97108
return B.to_string();
98109
});
99110
}

0 commit comments

Comments
 (0)