-
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
SnarkVerifierPoseidonWriter
rust binding
- Loading branch information
Showing
5 changed files
with
197 additions
and
0 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
38 changes: 38 additions & 0 deletions
38
halo2_proofs/include/bn254_snark_verifier_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,38 @@ | ||
#ifndef HALO2_PROOFS_INCLUDE_BN254_SNARK_VERIFIER_POSEIDON_WRITER_H_ | ||
#define HALO2_PROOFS_INCLUDE_BN254_SNARK_VERIFIER_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 SnarkVerifierPoseidonWriter { | ||
public: | ||
SnarkVerifierPoseidonWriter(); | ||
SnarkVerifierPoseidonWriter(const SnarkVerifierPoseidonWriter& other) = | ||
delete; | ||
SnarkVerifierPoseidonWriter& operator=( | ||
const SnarkVerifierPoseidonWriter& other) = delete; | ||
~SnarkVerifierPoseidonWriter(); | ||
|
||
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<SnarkVerifierPoseidonWriter> | ||
new_snark_verifier_poseidon_writer(); | ||
|
||
} // namespace tachyon::halo2_api::bn254 | ||
|
||
#endif // HALO2_PROOFS_INCLUDE_BN254_SNARK_VERIFIER_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
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,44 @@ | ||
#include "halo2_proofs/include/bn254_snark_verifier_poseidon_writer.h" | ||
|
||
namespace tachyon::halo2_api::bn254 { | ||
|
||
SnarkVerifierPoseidonWriter::SnarkVerifierPoseidonWriter() | ||
: writer_(tachyon_halo2_bn254_transcript_writer_create( | ||
TACHYON_HALO2_SNARK_VERIFIER_POSEIDON_TRANSCRIPT)) {} | ||
|
||
SnarkVerifierPoseidonWriter::~SnarkVerifierPoseidonWriter() { | ||
tachyon_halo2_bn254_transcript_writer_destroy(writer_); | ||
} | ||
|
||
void SnarkVerifierPoseidonWriter::update(rust::Slice<const uint8_t> data) { | ||
tachyon_halo2_bn254_transcript_writer_update(writer_, data.data(), | ||
data.size()); | ||
} | ||
|
||
rust::Box<Fr> SnarkVerifierPoseidonWriter::squeeze() { | ||
tachyon_bn254_fr* ret = new tachyon_bn254_fr; | ||
*ret = tachyon_halo2_bn254_transcript_writer_squeeze(writer_); | ||
return rust::Box<Fr>::from_raw(reinterpret_cast<Fr*>(ret)); | ||
} | ||
|
||
rust::Vec<uint8_t> SnarkVerifierPoseidonWriter::state() const { | ||
size_t state_size; | ||
tachyon_halo2_bn254_transcript_writer_get_state(writer_, nullptr, | ||
&state_size); | ||
rust::Vec<uint8_t> ret; | ||
// NOTE(chokobole): |rust::Vec<uint8_t>| doesn't have |resize()|. | ||
ret.reserve(state_size); | ||
for (size_t i = 0; i < state_size; ++i) { | ||
ret.push_back(0); | ||
} | ||
tachyon_halo2_bn254_transcript_writer_get_state(writer_, ret.data(), | ||
&state_size); | ||
return ret; | ||
} | ||
|
||
std::unique_ptr<SnarkVerifierPoseidonWriter> | ||
new_snark_verifier_poseidon_writer() { | ||
return std::make_unique<SnarkVerifierPoseidonWriter>(); | ||
} | ||
|
||
} // namespace tachyon::halo2_api::bn254 |
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ pub enum TranscriptType { | |
Blake2b, | ||
Poseidon, | ||
Sha256, | ||
SnarkVerifierPoseidon, | ||
} | ||
|
||
#[derive(Debug)] | ||
|