From a2a15ed53cadda5dde557908ccda87f6a83a182c Mon Sep 17 00:00:00 2001 From: dongchangYoo Date: Tue, 19 Mar 2024 18:50:38 +0900 Subject: [PATCH] feat(halo2_proofs): bump up tachyon api version `from_params()` method was added to `TachyonGWCProver` and `TachyonSHPlonkProver`. --- halo2_proofs/include/bn254_gwc_prover.h | 5 +++++ halo2_proofs/include/bn254_shplonk_prover.h | 5 +++++ halo2_proofs/src/bn254.rs | 24 +++++++++++++++++++++ halo2_proofs/src/bn254_gwc_prover.cc | 11 ++++++++++ halo2_proofs/src/bn254_shplonk_prover.cc | 11 ++++++++++ 5 files changed, 56 insertions(+) diff --git a/halo2_proofs/include/bn254_gwc_prover.h b/halo2_proofs/include/bn254_gwc_prover.h index 4e111108..38bf7af9 100644 --- a/halo2_proofs/include/bn254_gwc_prover.h +++ b/halo2_proofs/include/bn254_gwc_prover.h @@ -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(); @@ -55,6 +57,9 @@ class GWCProver { std::unique_ptr new_gwc_prover(uint8_t transcript_type, uint32_t k, const Fr& s); +std::unique_ptr new_gwc_prover_from_params( + uint8_t transcript_type, uint32_t k, rust::Slice params); + } // namespace tachyon::halo2_api::bn254 #endif // HALO2_PROOFS_INCLUDE_BN254_GWC_PROVER_H_ diff --git a/halo2_proofs/include/bn254_shplonk_prover.h b/halo2_proofs/include/bn254_shplonk_prover.h index 60b539ca..f0da94a1 100644 --- a/halo2_proofs/include/bn254_shplonk_prover.h +++ b/halo2_proofs/include/bn254_shplonk_prover.h @@ -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(); @@ -55,6 +57,9 @@ class SHPlonkProver { std::unique_ptr new_shplonk_prover(uint8_t transcript_type, uint32_t k, const Fr& s); +std::unique_ptr new_shplonk_prover_from_params( + uint8_t transcript_type, uint32_t k, rust::Slice params); + } // namespace tachyon::halo2_api::bn254 #endif // HALO2_PROOFS_INCLUDE_BN254_SHPLONK_PROVER_H_ diff --git a/halo2_proofs/src/bn254.rs b/halo2_proofs/src/bn254.rs index 84fdd44c..1cf41cd4 100644 --- a/halo2_proofs/src/bn254.rs +++ b/halo2_proofs/src/bn254.rs @@ -151,6 +151,11 @@ pub mod ffi { type GWCProver; fn new_gwc_prover(transcript_type: u8, k: u32, s: &Fr) -> UniquePtr; + fn new_gwc_prover_from_params( + transcript_type: u8, + k: u32, + params: &[u8], + ) -> UniquePtr; fn k(&self) -> u32; fn n(&self) -> u64; fn commit(&self, poly: &Poly) -> Box; @@ -182,6 +187,11 @@ pub mod ffi { type SHPlonkProver; fn new_shplonk_prover(transcript_type: u8, k: u32, s: &Fr) -> UniquePtr; + fn new_shplonk_prover_from_params( + transcript_type: u8, + k: u32, + params: &[u8], + ) -> UniquePtr; fn k(&self) -> u32; fn n(&self) -> u64; fn commit(&self, poly: &Poly) -> Box; @@ -836,6 +846,13 @@ impl GWCProver { _marker: PhantomData, } } + + pub fn from_params(transcript_type: u8, k: u32, params: &[u8]) -> GWCProver { + GWCProver { + inner: ffi::new_gwc_prover_from_params(transcript_type, k, params), + _marker: PhantomData, + } + } } impl TachyonProver for GWCProver { @@ -939,6 +956,13 @@ impl SHPlonkProver { _marker: PhantomData, } } + + pub fn from_params(transcript_type: u8, k: u32, params: &[u8]) -> SHPlonkProver { + SHPlonkProver { + inner: ffi::new_shplonk_prover_from_params(transcript_type, k, params), + _marker: PhantomData, + } + } } impl TachyonProver for SHPlonkProver { diff --git a/halo2_proofs/src/bn254_gwc_prover.cc b/halo2_proofs/src/bn254_gwc_prover.cc index e181fb4b..a2751d9f 100644 --- a/halo2_proofs/src/bn254_gwc_prover.cc +++ b/halo2_proofs/src/bn254_gwc_prover.cc @@ -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(&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 { @@ -180,6 +185,12 @@ std::unique_ptr new_gwc_prover(uint8_t transcript_type, uint32_t k, return std::make_unique(transcript_type, k, s); } +std::unique_ptr new_gwc_prover_from_params( + uint8_t transcript_type, uint32_t k, rust::Slice params) { + return std::make_unique(transcript_type, k, params.data(), + params.size()); +} + rust::Box 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; diff --git a/halo2_proofs/src/bn254_shplonk_prover.cc b/halo2_proofs/src/bn254_shplonk_prover.cc index c8ca7502..36617323 100644 --- a/halo2_proofs/src/bn254_shplonk_prover.cc +++ b/halo2_proofs/src/bn254_shplonk_prover.cc @@ -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(&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_); } @@ -184,6 +189,12 @@ std::unique_ptr new_shplonk_prover(uint8_t transcript_type, return std::make_unique(transcript_type, k, s); } +std::unique_ptr new_shplonk_prover_from_params( + uint8_t transcript_type, uint32_t k, rust::Slice params) { + return std::make_unique(transcript_type, k, params.data(), + params.size()); +} + rust::Box 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;