Skip to content

Commit

Permalink
feat(c/zk): add c API for crypto::FRIProof
Browse files Browse the repository at this point in the history
  • Loading branch information
chokobole committed Aug 30, 2024
1 parent 3940b3c commit 25e9d94
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tachyon/c/zk/air/sp1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ filegroup(
"baby_bear_poseidon2_duplex_challenger.h",
"baby_bear_poseidon2_field_merkle_tree.h",
"baby_bear_poseidon2_field_merkle_tree_vec.h",
"baby_bear_poseidon2_fri_proof.h",
"baby_bear_poseidon2_opened_values.h",
"baby_bear_poseidon2_opening_points.h",
"baby_bear_poseidon2_two_adic_fri.h",
Expand Down Expand Up @@ -104,8 +105,13 @@ tachyon_cc_library(

tachyon_cc_library(
name = "baby_bear_poseidon2_two_adic_fri",
srcs = ["baby_bear_poseidon2_two_adic_fri.cc"],
srcs = [
"baby_bear_poseidon2_fri_proof.cc",
"baby_bear_poseidon2_two_adic_fri.cc",
],
hdrs = [
"baby_bear_poseidon2_fri_proof.h",
"baby_bear_poseidon2_fri_proof_type_traits.h",
"baby_bear_poseidon2_two_adic_fri.h",
"baby_bear_poseidon2_two_adic_fri_type_traits.h",
],
Expand Down
23 changes: 23 additions & 0 deletions tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof.h"

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

using namespace tachyon;

using Proof = crypto::FRIProof<c::zk::air::plonky3::baby_bear::PCS::Base>;

tachyon_sp1_baby_bear_poseidon2_fri_proof*
tachyon_sp1_baby_bear_poseidon2_fri_proof_create() {
return c::base::c_cast(new Proof());
}

tachyon_sp1_baby_bear_poseidon2_fri_proof*
tachyon_sp1_baby_bear_poseidon2_fri_proof_clone(
const tachyon_sp1_baby_bear_poseidon2_fri_proof* fri_proof) {
return c::base::c_cast(new Proof(c::base::native_cast(*fri_proof)));
}

void tachyon_sp1_baby_bear_poseidon2_fri_proof_destroy(
tachyon_sp1_baby_bear_poseidon2_fri_proof* fri_proof) {
delete c::base::native_cast(fri_proof);
}
54 changes: 54 additions & 0 deletions tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @file baby_bear_poseidon2_fri_proof.h
* @brief Defines the interface for the fri proof used within the
* SP1(BabyBear + Poseidon2) proof system.
*/

#ifndef TACHYON_C_ZK_AIR_SP1_BABY_BEAR_POSEIDON2_FRI_PROOF_H_
#define TACHYON_C_ZK_AIR_SP1_BABY_BEAR_POSEIDON2_FRI_PROOF_H_

#include <stddef.h>
#include <stdint.h>

#include "tachyon/c/export.h"

struct tachyon_sp1_baby_bear_poseidon2_fri_proof {};

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Creates a new fri proof.
*
* @return A pointer to the newly created fri proof.
*/
TACHYON_C_EXPORT tachyon_sp1_baby_bear_poseidon2_fri_proof*
tachyon_sp1_baby_bear_poseidon2_fri_proof_create();

/**
* @brief Clones an existing fri proof.
*
* Creates a deep copy of the given fri proof.
*
* @param fri_proof A const pointer to the fri proof to
* clone.
* @return A pointer to the cloned fri proof.
*/
TACHYON_C_EXPORT tachyon_sp1_baby_bear_poseidon2_fri_proof*
tachyon_sp1_baby_bear_poseidon2_fri_proof_clone(
const tachyon_sp1_baby_bear_poseidon2_fri_proof* fri_proof);

/**
* @brief Destroys a fri proof, freeing its resources.
*
* @param proof A pointer to the fri proof to destroy.
*/
TACHYON_C_EXPORT void tachyon_sp1_baby_bear_poseidon2_fri_proof_destroy(
tachyon_sp1_baby_bear_poseidon2_fri_proof* proof);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // TACHYON_C_ZK_AIR_SP1_BABY_BEAR_POSEIDON2_FRI_PROOF_H_
25 changes: 25 additions & 0 deletions tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof_type_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef TACHYON_C_ZK_AIR_SP1_BABY_BEAR_POSEIDON2_FRI_PROOF_TYPE_TRAITS_H_
#define TACHYON_C_ZK_AIR_SP1_BABY_BEAR_POSEIDON2_FRI_PROOF_TYPE_TRAITS_H_

#include "tachyon/c/base/type_traits_forward.h"
#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_fri_proof.h"
#include "tachyon/c/zk/air/sp1/baby_bear_poseidon2_two_adic_fri_type_traits.h"
#include "tachyon/crypto/commitments/fri/fri_proof.h"

namespace tachyon::c::base {

template <>
struct TypeTraits<
tachyon::crypto::FRIProof<zk::air::plonky3::baby_bear::PCS::Base>> {
using CType = tachyon_sp1_baby_bear_poseidon2_fri_proof;
};

template <>
struct TypeTraits<tachyon_sp1_baby_bear_poseidon2_fri_proof> {
using NativeType =
tachyon::crypto::FRIProof<zk::air::plonky3::baby_bear::PCS::Base>;
};

} // namespace tachyon::c::base

#endif // TACHYON_C_ZK_AIR_SP1_BABY_BEAR_POSEIDON2_FRI_PROOF_TYPE_TRAITS_H_

0 comments on commit 25e9d94

Please sign in to comment.