Skip to content

Commit

Permalink
feat(sp1): add rust binding for TwoAdicFriPcs::Open()
Browse files Browse the repository at this point in the history
  • Loading branch information
chokobole committed Sep 2, 2024
1 parent 42e0777 commit b355f40
Show file tree
Hide file tree
Showing 17 changed files with 503 additions and 8 deletions.
6 changes: 5 additions & 1 deletion Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "6c16348d55a87ca4413d24b5b1ac51b264753c57e71b39852453958374c695a3",
"checksum": "584d430c890fb87d6faa910e73d25cd0415701a78ebe6820a9d7127b70c16a2b",
"crates": {
"addchain 0.2.0": {
"name": "addchain",
Expand Down Expand Up @@ -18143,6 +18143,10 @@
"id": "p3-util 0.1.3-succinct",
"target": "p3_util"
},
{
"id": "serde 1.0.204",
"target": "serde"
},
{
"id": "sp1-core 1.0.1",
"target": "sp1_core"
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

33 changes: 33 additions & 0 deletions vendors/sp1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ tachyon_rust_library(
deps = all_crate_deps(normal = True) + [
":baby_bear_poseidon2_cxx_bridge",
":baby_bear_poseidon2_duplex_challenger",
":baby_bear_poseidon2_fri_proof",
":baby_bear_poseidon2_opening_points",
":baby_bear_poseidon2_opening_proof",
":baby_bear_poseidon2_prover_data",
":baby_bear_poseidon2_prover_data_vec",
":baby_bear_poseidon2_two_adic_fri_pcs",
Expand Down Expand Up @@ -64,6 +67,9 @@ tachyon_cc_library(
name = "baby_bear_poseidon2_api_hdrs",
hdrs = [
"include/baby_bear_poseidon2_duplex_challenger.h",
"include/baby_bear_poseidon2_fri_proof.h",
"include/baby_bear_poseidon2_opening_points.h",
"include/baby_bear_poseidon2_opening_proof.h",
"include/baby_bear_poseidon2_prover_data.h",
"include/baby_bear_poseidon2_prover_data_vec.h",
"include/baby_bear_poseidon2_two_adic_fri_pcs.h",
Expand All @@ -84,6 +90,33 @@ tachyon_cc_library(
],
)

tachyon_cc_library(
name = "baby_bear_poseidon2_fri_proof",
srcs = ["src/baby_bear_poseidon2_fri_proof.cc"],
deps = [
":baby_bear_poseidon2_api_hdrs",
":baby_bear_poseidon2_cxx_bridge/include",
],
)

tachyon_cc_library(
name = "baby_bear_poseidon2_opening_points",
srcs = ["src/baby_bear_poseidon2_opening_points.cc"],
deps = [
":baby_bear_poseidon2_api_hdrs",
":baby_bear_poseidon2_cxx_bridge/include",
],
)

tachyon_cc_library(
name = "baby_bear_poseidon2_opening_proof",
srcs = ["src/baby_bear_poseidon2_opening_proof.cc"],
deps = [
":baby_bear_poseidon2_api_hdrs",
":baby_bear_poseidon2_cxx_bridge/include",
],
)

tachyon_cc_library(
name = "baby_bear_poseidon2_prover_data",
srcs = ["src/baby_bear_poseidon2_prover_data.cc"],
Expand Down
4 changes: 4 additions & 0 deletions vendors/sp1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ p3-maybe-rayon = "0.1.3-succinct"
p3-poseidon2 = "0.1.3-succinct"
p3-symmetric = "0.1.3-succinct"
p3-util = "0.1.3-succinct"
serde = { version = "1.0", default-features = false, features = [
"derive",
"alloc",
] }
sp1-core = { git = "https://github.com/kroma-network/sp1.git", rev = "dd032eb" }
sp1-prover = { git = "https://github.com/kroma-network/sp1.git", rev = "dd032eb" }
sp1-primitives = { git = "https://github.com/kroma-network/sp1.git", rev = "dd032eb" }
Expand Down
4 changes: 4 additions & 0 deletions vendors/sp1/include/baby_bear_poseidon2_duplex_challenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class DuplexChallenger {
DuplexChallenger& operator=(const DuplexChallenger& other) = delete;
~DuplexChallenger();

tachyon_sp1_baby_bear_poseidon2_duplex_challenger* challenger() {
return challenger_;
}

void observe(const TachyonBabyBear& value);
rust::Box<TachyonBabyBear> sample();
std::unique_ptr<DuplexChallenger> clone() const;
Expand Down
28 changes: 28 additions & 0 deletions vendors/sp1/include/baby_bear_poseidon2_fri_proof.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_FRI_PROOF_H_
#define VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_FRI_PROOF_H_

#include <memory>

#include "rust/cxx.h"

#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof.h"

namespace tachyon::sp1_api::baby_bear_poseidon2 {

class FriProof {
public:
explicit FriProof(tachyon_sp1_baby_bear_poseidon2_fri_proof* proof)
: proof_(proof) {}
FriProof(const FriProof& other) = delete;
FriProof& operator=(const FriProof& other) = delete;
~FriProof();

std::unique_ptr<FriProof> clone() const;

private:
tachyon_sp1_baby_bear_poseidon2_fri_proof* proof_;
};

} // namespace tachyon::sp1_api::baby_bear_poseidon2

#endif // VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_FRI_PROOF_H_
41 changes: 41 additions & 0 deletions vendors/sp1/include/baby_bear_poseidon2_opening_points.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_OPENING_POINTS_H_
#define VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_OPENING_POINTS_H_

#include <stddef.h>

#include <memory>

#include "tachyon/c/math/finite_fields/baby_bear/baby_bear4.h"
#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_opening_points.h"

namespace tachyon::sp1_api::baby_bear_poseidon2 {

struct TachyonBabyBear4;

class OpeningPoints {
public:
explicit OpeningPoints(
tachyon_sp1_baby_bear_poseidon2_opening_points* opening_points)
: opening_points_(opening_points) {}
OpeningPoints(const OpeningPoints& other) = delete;
OpeningPoints& operator=(const OpeningPoints& other) = delete;
~OpeningPoints();

const tachyon_sp1_baby_bear_poseidon2_opening_points* opening_points() const {
return opening_points_;
}

std::unique_ptr<OpeningPoints> clone() const;
void allocate(size_t round, size_t rows, size_t cols);
void set_point(size_t round, size_t row, size_t col,
const TachyonBabyBear4& point);

private:
tachyon_sp1_baby_bear_poseidon2_opening_points* opening_points_ = nullptr;
};

std::unique_ptr<OpeningPoints> new_opening_points(size_t rounds);

} // namespace tachyon::sp1_api::baby_bear_poseidon2

#endif // VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_OPENING_POINTS_H_
37 changes: 37 additions & 0 deletions vendors/sp1/include/baby_bear_poseidon2_opening_proof.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_OPENING_PROOF_H_
#define VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_OPENING_PROOF_H_

#include <memory>

#include "rust/cxx.h"

#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof.h"
#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_opened_values.h"

namespace tachyon::sp1_api::baby_bear_poseidon2 {

class FriProof;

class OpeningProof {
public:
OpeningProof();
OpeningProof(const OpeningProof& other) = delete;
OpeningProof& operator=(const OpeningProof& other) = delete;
~OpeningProof();

tachyon_sp1_baby_bear_poseidon2_opened_values** opened_values_ptr() {
return &opened_values_;
}
tachyon_sp1_baby_bear_poseidon2_fri_proof** proof_ptr() { return &proof_; }

rust::Vec<uint8_t> serialize_to_opened_values() const;
std::unique_ptr<FriProof> take_fri_proof();

private:
tachyon_sp1_baby_bear_poseidon2_opened_values* opened_values_;
tachyon_sp1_baby_bear_poseidon2_fri_proof* proof_;
};

} // namespace tachyon::sp1_api::baby_bear_poseidon2

#endif // VENDORS_SP1_INCLUDE_BABY_BEAR_POSEIDON2_OPENING_PROOF_H_
7 changes: 7 additions & 0 deletions vendors/sp1/include/baby_bear_poseidon2_two_adic_fri_pcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
namespace tachyon::sp1_api::baby_bear_poseidon2 {

class CommitResult;
class DuplexChallenger;
class OpeningPoints;
class OpeningProof;
class ProverData;
class ProverDataVec;
struct TachyonBabyBear;
struct TachyonBabyBear4;

class TwoAdicFriPcs {
public:
Expand All @@ -31,6 +35,9 @@ class TwoAdicFriPcs {
const TachyonBabyBear& shift) const;
std::unique_ptr<ProverData> commit(
const ProverDataVec& prover_data_vec) const;
std::unique_ptr<OpeningProof> do_open(const ProverDataVec& prover_data_vec,
const OpeningPoints& opening_points,
DuplexChallenger& challenger) const;

private:
tachyon_sp1_baby_bear_poseidon2_two_adic_fri* pcs_;
Expand Down
Loading

0 comments on commit b355f40

Please sign in to comment.