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-1106: Add Python bindings to chiavdf and chiapos #675

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 13 additions & 4 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,24 @@ jobs:
run: |
python -m pip install maturin

- name: Build MacOs with maturin on Python ${{ matrix.python }}
- name: Build MacOS with maturin on Python ${{ matrix.python.major-dot-minor }}
if: matrix.os.matrix == 'macos'
env:
MACOSX_DEPLOYMENT_TARGET: "11.0"
run: |
export LIBRARY_PATH=/opt/homebrew/lib:$LIBRARY_PATH
python${{ matrix.python.major-dot-minor }} -m venv venv
. venv/bin/activate
maturin build -i python --release -m wheel/Cargo.toml

- name: Build Linux with maturin on Python ${{ matrix.python }}
- name: Build Linux with maturin on Python ${{ matrix.python.major-dot-minor }}
if: matrix.os.matrix == 'ubuntu'
run: |
docker run --rm --pull always \
-v ${{ github.workspace }}:/ws --workdir=/ws \
${{ matrix.python.by-arch[matrix.arch.matrix].docker-url }} \
bash -exc '\
yum -y install openssl-devel && \
yum -y install openssl-devel gmp-devel clang && \
source $HOME/.cargo/env && \
rustup target add ${{ matrix.python.by-arch[matrix.arch.matrix].rustup-target }} && \
python${{ matrix.python.major-dot-minor }} -m venv /venv && \
Expand All @@ -172,7 +173,15 @@ jobs:
CC=gcc maturin build --release --manylinux ${{ matrix.python.by-arch[matrix.arch.matrix].manylinux-version }} -m wheel/Cargo.toml \
'

- name: Build Windows with maturin on Python ${{ matrix.python }}
- name: Checkout MPIR for Windows
if: matrix.os.matrix == 'windows'
uses: actions/checkout@v4
with:
repository: Chia-Network/mpir_gc_x64
fetch-depth: 1
path: mpir_gc_x64

- name: Build Windows with maturin on Python ${{ matrix.python.major-dot-minor }}
if: matrix.os.matrix == 'windows'
env:
CC: "clang"
Expand Down
173 changes: 173 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ zstd = "0.13.2"
blocking-threadpool = "1.0.1"
libfuzzer-sys = "0.4"
wasm-bindgen = "0.2.93"
chiavdf = "1.1.5"
chiapos = "2.0.6"
4 changes: 4 additions & 0 deletions crates/chia-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ workspace = true

[features]
py-bindings = ["dep:pyo3", "dep:chia_py_streamable_macro"]
chiavdf = ["dep:chiavdf"]
chiapos = ["dep:chiapos"]

[dependencies]
clvmr = { workspace = true }
Expand All @@ -29,6 +31,8 @@ chia-puzzles = { workspace = true }
chia-bls = { workspace = true }
hex-literal = { workspace = true }
thiserror = { workspace = true }
chiavdf = { workspace = true, optional = true }
chiapos = { workspace = true, optional = true }

[dev-dependencies]
num-traits = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions crates/chia-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ pub mod merkle_set;
pub mod merkle_tree;
pub mod spendbundle_conditions;
pub mod spendbundle_validation;

#[cfg(feature = "chiavdf")]
pub mod vdf;

#[cfg(feature = "chiapos")]
pub mod proof_of_space;
17 changes: 17 additions & 0 deletions crates/chia-consensus/src/proof_of_space.rs
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
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have a few test cases for this rust function, a few valid ones and a few invalid ones. Maybe some edge cases

Loading
Loading