Skip to content

Commit

Permalink
feat(halo2_proofs): bump up tachyon api version
Browse files Browse the repository at this point in the history
`from_params()` method was added to `TachyonGWCProver` and `TachyonSHPlonkProver`.
  • Loading branch information
dongchangYoo committed Mar 19, 2024
1 parent 0918c29 commit a2a15ed
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions halo2_proofs/include/bn254_gwc_prover.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Poly;
class GWCProver {
public:
GWCProver(uint8_t transcript_type, uint32_t k, const Fr& s);
GWCProver(uint8_t transcript_type, uint32_t k, const uint8_t* params,
size_t params_len);
GWCProver(const GWCProver& other) = delete;
GWCProver& operator=(const GWCProver& other) = delete;
~GWCProver();
Expand Down Expand Up @@ -55,6 +57,9 @@ class GWCProver {
std::unique_ptr<GWCProver> new_gwc_prover(uint8_t transcript_type, uint32_t k,
const Fr& s);

std::unique_ptr<GWCProver> new_gwc_prover_from_params(
uint8_t transcript_type, uint32_t k, rust::Slice<const uint8_t> params);

} // namespace tachyon::halo2_api::bn254

#endif // HALO2_PROOFS_INCLUDE_BN254_GWC_PROVER_H_
5 changes: 5 additions & 0 deletions halo2_proofs/include/bn254_shplonk_prover.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Poly;
class SHPlonkProver {
public:
SHPlonkProver(uint8_t transcript_type, uint32_t k, const Fr& s);
SHPlonkProver(uint8_t transcript_type, uint32_t k, const uint8_t* params,
size_t params_len);
SHPlonkProver(const SHPlonkProver& other) = delete;
SHPlonkProver& operator=(const SHPlonkProver& other) = delete;
~SHPlonkProver();
Expand Down Expand Up @@ -55,6 +57,9 @@ class SHPlonkProver {
std::unique_ptr<SHPlonkProver> new_shplonk_prover(uint8_t transcript_type,
uint32_t k, const Fr& s);

std::unique_ptr<SHPlonkProver> new_shplonk_prover_from_params(
uint8_t transcript_type, uint32_t k, rust::Slice<const uint8_t> params);

} // namespace tachyon::halo2_api::bn254

#endif // HALO2_PROOFS_INCLUDE_BN254_SHPLONK_PROVER_H_
24 changes: 24 additions & 0 deletions halo2_proofs/src/bn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ pub mod ffi {
type GWCProver;

fn new_gwc_prover(transcript_type: u8, k: u32, s: &Fr) -> UniquePtr<GWCProver>;
fn new_gwc_prover_from_params(
transcript_type: u8,
k: u32,
params: &[u8],
) -> UniquePtr<GWCProver>;
fn k(&self) -> u32;
fn n(&self) -> u64;
fn commit(&self, poly: &Poly) -> Box<G1JacobianPoint>;
Expand Down Expand Up @@ -182,6 +187,11 @@ pub mod ffi {
type SHPlonkProver;

fn new_shplonk_prover(transcript_type: u8, k: u32, s: &Fr) -> UniquePtr<SHPlonkProver>;
fn new_shplonk_prover_from_params(
transcript_type: u8,
k: u32,
params: &[u8],
) -> UniquePtr<SHPlonkProver>;
fn k(&self) -> u32;
fn n(&self) -> u64;
fn commit(&self, poly: &Poly) -> Box<G1JacobianPoint>;
Expand Down Expand Up @@ -836,6 +846,13 @@ impl<Scheme: CommitmentScheme> GWCProver<Scheme> {
_marker: PhantomData,
}
}

pub fn from_params(transcript_type: u8, k: u32, params: &[u8]) -> GWCProver<Scheme> {
GWCProver {
inner: ffi::new_gwc_prover_from_params(transcript_type, k, params),
_marker: PhantomData,
}
}
}

impl<Scheme: CommitmentScheme> TachyonProver<Scheme> for GWCProver<Scheme> {
Expand Down Expand Up @@ -939,6 +956,13 @@ impl<Scheme: CommitmentScheme> SHPlonkProver<Scheme> {
_marker: PhantomData,
}
}

pub fn from_params(transcript_type: u8, k: u32, params: &[u8]) -> SHPlonkProver<Scheme> {
SHPlonkProver {
inner: ffi::new_shplonk_prover_from_params(transcript_type, k, params),
_marker: PhantomData,
}
}
}

impl<Scheme: CommitmentScheme> TachyonProver<Scheme> for SHPlonkProver<Scheme> {
Expand Down
11 changes: 11 additions & 0 deletions halo2_proofs/src/bn254_gwc_prover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ GWCProver::GWCProver(uint8_t transcript_type, uint32_t k, const Fr& s)
: prover_(tachyon_halo2_bn254_gwc_prover_create_from_unsafe_setup(
transcript_type, k, reinterpret_cast<const tachyon_bn254_fr*>(&s))) {}

GWCProver::GWCProver(uint8_t transcript_type, uint32_t k, const uint8_t* params,
size_t params_len)
: prover_(tachyon_halo2_bn254_gwc_prover_create_from_params(
transcript_type, k, params, params_len)) {}

GWCProver::~GWCProver() { tachyon_halo2_bn254_gwc_prover_destroy(prover_); }

uint32_t GWCProver::k() const {
Expand Down Expand Up @@ -180,6 +185,12 @@ std::unique_ptr<GWCProver> new_gwc_prover(uint8_t transcript_type, uint32_t k,
return std::make_unique<GWCProver>(transcript_type, k, s);
}

std::unique_ptr<GWCProver> new_gwc_prover_from_params(
uint8_t transcript_type, uint32_t k, rust::Slice<const uint8_t> params) {
return std::make_unique<GWCProver>(transcript_type, k, params.data(),
params.size());
}

rust::Box<Fr> ProvingKey::transcript_repr_gwc(const GWCProver& prover) {
tachyon_halo2_bn254_gwc_prover_set_transcript_repr(prover.prover(), pk_);
tachyon_bn254_fr* ret = new tachyon_bn254_fr;
Expand Down
11 changes: 11 additions & 0 deletions halo2_proofs/src/bn254_shplonk_prover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SHPlonkProver::SHPlonkProver(uint8_t transcript_type, uint32_t k, const Fr& s)
: prover_(tachyon_halo2_bn254_shplonk_prover_create_from_unsafe_setup(
transcript_type, k, reinterpret_cast<const tachyon_bn254_fr*>(&s))) {}

SHPlonkProver::SHPlonkProver(uint8_t transcript_type, uint32_t k,
const uint8_t* params, size_t params_len)
: prover_(tachyon_halo2_bn254_shplonk_prover_create_from_params(
transcript_type, k, params, params_len)) {}

SHPlonkProver::~SHPlonkProver() {
tachyon_halo2_bn254_shplonk_prover_destroy(prover_);
}
Expand Down Expand Up @@ -184,6 +189,12 @@ std::unique_ptr<SHPlonkProver> new_shplonk_prover(uint8_t transcript_type,
return std::make_unique<SHPlonkProver>(transcript_type, k, s);
}

std::unique_ptr<SHPlonkProver> new_shplonk_prover_from_params(
uint8_t transcript_type, uint32_t k, rust::Slice<const uint8_t> params) {
return std::make_unique<SHPlonkProver>(transcript_type, k, params.data(),
params.size());
}

rust::Box<Fr> ProvingKey::transcript_repr_shplonk(const SHPlonkProver& prover) {
tachyon_halo2_bn254_shplonk_prover_set_transcript_repr(prover.prover(), pk_);
tachyon_bn254_fr* ret = new tachyon_bn254_fr;
Expand Down

0 comments on commit a2a15ed

Please sign in to comment.