-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(halo2_proofs): add
create_proof()
of tachyon
- Loading branch information
Showing
29 changed files
with
2,830 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_BLAKE2B_WRITER_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_BLAKE2B_WRITER_H_ | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#include <array> | ||
#include <memory> | ||
|
||
#include <tachyon/c/zk/plonk/halo2/bn254_transcript.h> | ||
|
||
#include "rust/cxx.h" | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
constexpr size_t kBlake2bDigestLength = 64; | ||
constexpr size_t kBlake2bStateLength = 216; | ||
|
||
class Blake2bWriter { | ||
public: | ||
Blake2bWriter(); | ||
Blake2bWriter(const Blake2bWriter& other) = delete; | ||
Blake2bWriter& operator=(const Blake2bWriter& other) = delete; | ||
~Blake2bWriter(); | ||
|
||
void update(rust::Slice<const uint8_t> data); | ||
void finalize(std::array<uint8_t, kBlake2bDigestLength>& result); | ||
rust::Vec<uint8_t> state() const; | ||
|
||
private: | ||
tachyon_halo2_bn254_transcript_writer* writer_; | ||
}; | ||
|
||
std::unique_ptr<Blake2bWriter> new_blake2b_writer(); | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_BLAKE2B_WRITER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_EVALS_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_EVALS_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include <tachyon/c/math/polynomials/univariate/bn254_univariate_evaluations.h> | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
struct Fr; | ||
|
||
class Evals { | ||
public: | ||
Evals(); | ||
explicit Evals(tachyon_bn254_univariate_evaluations* evals) : evals_(evals) {} | ||
Evals(const Evals& other) = delete; | ||
Evals& operator=(const Evals& other) = delete; | ||
~Evals(); | ||
|
||
tachyon_bn254_univariate_evaluations* evals() { return evals_; } | ||
const tachyon_bn254_univariate_evaluations* evals() const { return evals_; } | ||
|
||
tachyon_bn254_univariate_evaluations* release() { | ||
return std::exchange(evals_, nullptr); | ||
} | ||
|
||
size_t len() const; | ||
void set_value(size_t idx, const Fr& value); | ||
std::unique_ptr<Evals> clone() const; | ||
|
||
private: | ||
tachyon_bn254_univariate_evaluations* evals_; | ||
}; | ||
|
||
std::unique_ptr<Evals> zero_evals(); | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_EVALS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_GWC_PROVER_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_GWC_PROVER_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <memory> | ||
|
||
#include <tachyon/c/zk/plonk/halo2/bn254_gwc_prover.h> | ||
|
||
#include "rust/cxx.h" | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
struct Fr; | ||
struct G1JacobianPoint; | ||
struct InstanceSingle; | ||
struct AdviceSingle; | ||
class ProvingKey; | ||
class Evals; | ||
class RationalEvals; | ||
class Poly; | ||
|
||
class GWCProver { | ||
public: | ||
GWCProver(uint8_t transcript_type, uint32_t k, const Fr& s); | ||
GWCProver(const GWCProver& other) = delete; | ||
GWCProver& operator=(const GWCProver& other) = delete; | ||
~GWCProver(); | ||
|
||
const tachyon_halo2_bn254_gwc_prover* prover() const { return prover_; } | ||
|
||
uint32_t k() const; | ||
uint64_t n() const; | ||
rust::Box<G1JacobianPoint> commit(const Poly& poly) const; | ||
rust::Box<G1JacobianPoint> commit_lagrange(const Evals& evals) const; | ||
std::unique_ptr<Evals> empty_evals() const; | ||
std::unique_ptr<RationalEvals> empty_rational_evals() const; | ||
std::unique_ptr<Poly> ifft(const Evals& evals) const; | ||
void batch_evaluate( | ||
rust::Slice<const std::unique_ptr<RationalEvals>> rational_evals, | ||
rust::Slice<std::unique_ptr<Evals>> evals) const; | ||
void set_rng(rust::Slice<const uint8_t> state); | ||
void set_transcript(rust::Slice<const uint8_t> state); | ||
void set_extended_domain(const ProvingKey& pk); | ||
void create_proof(ProvingKey& key, | ||
rust::Slice<InstanceSingle> instance_singles, | ||
rust::Slice<AdviceSingle> advice_singles, | ||
rust::Slice<const Fr> challenges); | ||
rust::Vec<uint8_t> get_proof() const; | ||
|
||
private: | ||
tachyon_halo2_bn254_gwc_prover* prover_; | ||
}; | ||
|
||
std::unique_ptr<GWCProver> new_gwc_prover(uint8_t transcript_type, uint32_t k, | ||
const Fr& s); | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_GWC_PROVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_POLY_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_POLY_H_ | ||
|
||
#include <utility> | ||
|
||
#include <tachyon/c/math/polynomials/univariate/bn254_univariate_dense_polynomial.h> | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
class Poly { | ||
public: | ||
Poly(); | ||
explicit Poly(tachyon_bn254_univariate_dense_polynomial* poly) | ||
: poly_(poly) {} | ||
Poly(const Poly& other) = delete; | ||
Poly& operator=(const Poly& other) = delete; | ||
~Poly(); | ||
|
||
tachyon_bn254_univariate_dense_polynomial* poly() { return poly_; } | ||
const tachyon_bn254_univariate_dense_polynomial* poly() const { | ||
return poly_; | ||
} | ||
|
||
tachyon_bn254_univariate_dense_polynomial* release() { | ||
return std::exchange(poly_, nullptr); | ||
} | ||
|
||
private: | ||
tachyon_bn254_univariate_dense_polynomial* poly_; | ||
}; | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_POLY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_POSEIDON_WRITER_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_POSEIDON_WRITER_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <memory> | ||
|
||
#include <tachyon/c/zk/plonk/halo2/bn254_transcript.h> | ||
|
||
#include "rust/cxx.h" | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
struct Fr; | ||
|
||
class PoseidonWriter { | ||
public: | ||
PoseidonWriter(); | ||
PoseidonWriter(const PoseidonWriter& other) = delete; | ||
PoseidonWriter& operator=(const PoseidonWriter& other) = delete; | ||
~PoseidonWriter(); | ||
|
||
void update(rust::Slice<const uint8_t> data); | ||
rust::Box<Fr> squeeze(); | ||
rust::Vec<uint8_t> state() const; | ||
|
||
private: | ||
tachyon_halo2_bn254_transcript_writer* writer_; | ||
}; | ||
|
||
std::unique_ptr<PoseidonWriter> new_poseidon_writer(); | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_POSEIDON_WRITER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_PROVING_KEY_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_PROVING_KEY_H_ | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#include <memory> | ||
|
||
#include <tachyon/c/zk/plonk/keys/bn254_plonk_proving_key.h> | ||
|
||
#include "rust/cxx.h" | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
struct Fr; | ||
class GWCProver; | ||
class SHPlonkProver; | ||
|
||
class ProvingKey { | ||
public: | ||
explicit ProvingKey(rust::Slice<const uint8_t> pk_bytes); | ||
ProvingKey(const ProvingKey& other) = delete; | ||
ProvingKey& operator=(const ProvingKey& other) = delete; | ||
~ProvingKey(); | ||
|
||
const tachyon_bn254_plonk_proving_key* pk() const { return pk_; } | ||
tachyon_bn254_plonk_proving_key* pk() { return pk_; } | ||
|
||
rust::Vec<uint8_t> advice_column_phases() const; | ||
uint32_t blinding_factors() const; | ||
rust::Vec<uint8_t> challenge_phases() const; | ||
rust::Vec<size_t> constants() const; | ||
size_t num_advice_columns() const; | ||
size_t num_challenges() const; | ||
size_t num_instance_columns() const; | ||
rust::Vec<uint8_t> phases() const; | ||
rust::Box<Fr> transcript_repr_gwc(const GWCProver& prover); | ||
rust::Box<Fr> transcript_repr_shplonk(const SHPlonkProver& prover); | ||
|
||
private: | ||
const tachyon_bn254_plonk_verifying_key* GetVerifyingKey() const; | ||
const tachyon_bn254_plonk_constraint_system* GetConstraintSystem() const; | ||
|
||
tachyon_bn254_plonk_proving_key* pk_; | ||
}; | ||
|
||
std::unique_ptr<ProvingKey> new_proving_key( | ||
rust::Slice<const uint8_t> pk_bytes); | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_PROVING_KEY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_RATIONAL_EVALS_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_RATIONAL_EVALS_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include <tachyon/c/math/polynomials/univariate/bn254_univariate_rational_evaluations.h> | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
struct Fr; | ||
|
||
class RationalEvals { | ||
public: | ||
RationalEvals(); | ||
explicit RationalEvals(tachyon_bn254_univariate_rational_evaluations* evals) | ||
: evals_(evals) {} | ||
RationalEvals(const RationalEvals& other) = delete; | ||
RationalEvals& operator=(const RationalEvals& other) = delete; | ||
~RationalEvals(); | ||
|
||
tachyon_bn254_univariate_rational_evaluations* evals() { return evals_; } | ||
const tachyon_bn254_univariate_rational_evaluations* evals() const { | ||
return evals_; | ||
} | ||
|
||
tachyon_bn254_univariate_rational_evaluations* release() { | ||
return std::exchange(evals_, nullptr); | ||
} | ||
|
||
size_t len() const; | ||
void set_zero(size_t idx); | ||
void set_trivial(size_t idx, const Fr& numerator); | ||
void set_rational(size_t idx, const Fr& numerator, const Fr& denominator); | ||
std::unique_ptr<RationalEvals> clone() const; | ||
|
||
private: | ||
tachyon_bn254_univariate_rational_evaluations* evals_; | ||
}; | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_RATIONAL_EVALS_H_ |
Oops, something went wrong.