Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRI Implementation: frontend + CPU Backend + GPU Backend #795

Open
wants to merge 135 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
b848b0e
add sumcheck frontend
mickeyasa Dec 11, 2024
92f3579
format
mickeyasa Dec 11, 2024
d6a9c59
strange compilation err
mickeyasa Dec 11, 2024
e6672ff
added test for kickoff
mickeyasa Dec 12, 2024
bb3b1d5
small fixes to sumcheck frontend compilation
yshekel Dec 15, 2024
46b4d72
fix rust warppers
yshekel Dec 15, 2024
563694d
enable sumcheck for all fields and curves
yshekel Dec 15, 2024
ee5b5de
removed Sumcheck test from field api
mickeyasa Dec 15, 2024
aa68bb5
dummy backend added
mickeyasa Dec 16, 2024
ffae6b4
compilation fix
yshekel Dec 16, 2024
f3331cc
test fix
mickeyasa Dec 19, 2024
6cdcee8
format
mickeyasa Dec 19, 2024
9e9ca5a
changinf sumcheck without hash compilatio to warning
mickeyasa Dec 19, 2024
766dbe9
removed sumcheck file duplication
mickeyasa Dec 22, 2024
588a84c
default hash on for cargo
mickeyasa Dec 22, 2024
1a83ec2
cmake fix
mickeyasa Dec 22, 2024
e7ed244
removed commented code
mickeyasa Dec 23, 2024
7248477
format
mickeyasa Dec 23, 2024
4a22355
review
mickeyasa Dec 23, 2024
a9b6256
added comment to the MLE polynomial
mickeyasa Dec 24, 2024
b989711
review fixes
mickeyasa Dec 24, 2024
6a71b95
format
mickeyasa Dec 24, 2024
44663c1
mle polynomials is a vector of pointers
mickeyasa Dec 25, 2024
85de44d
format
mickeyasa Dec 25, 2024
01b7137
cpu backend inplementation start
mickeyasa Dec 25, 2024
d61ca9e
nackend implementation
mickeyasa Dec 31, 2024
d8abe7a
backend implementation
mickeyasa Dec 31, 2024
6550860
Merge remote-tracking branch 'origin/main' into add-sumcheck-frontend
mickeyasa Jan 12, 2025
30fc2bb
compilation start
mickeyasa Jan 12, 2025
1628b52
compile, fail on verification test
mickeyasa Jan 12, 2025
3b1165e
verification failed on round 1
mickeyasa Jan 12, 2025
698fb7e
test pass
mickeyasa Jan 12, 2025
b2b5ff1
format
mickeyasa Jan 12, 2025
3928fd9
spell check
mickeyasa Jan 12, 2025
8cc6078
test fix
mickeyasa Jan 12, 2025
a00a1d1
format
mickeyasa Jan 12, 2025
17fb2d1
adjusting sumcheck test to all fields
mickeyasa Jan 13, 2025
d7673f6
format
mickeyasa Jan 13, 2025
3cb70fa
reduce alpha feet small and large fields
mickeyasa Jan 13, 2025
07c1e85
format
mickeyasa Jan 13, 2025
9e60bb9
documentation
mickeyasa Jan 13, 2025
53dd569
format
mickeyasa Jan 13, 2025
b7d5ddc
go comp issue
mickeyasa Jan 13, 2025
d94ebec
remove prints
mickeyasa Jan 13, 2025
7b06f73
return the std::
mickeyasa Jan 13, 2025
2840f91
name fix
mickeyasa Jan 13, 2025
c22d38e
include added for compilation
mickeyasa Jan 13, 2025
48f30df
review fixes
mickeyasa Jan 13, 2025
81d870f
format
mickeyasa Jan 13, 2025
5baee05
removed OR HASH
mickeyasa Jan 13, 2025
ae57939
review fixes
mickeyasa Jan 15, 2025
7956576
format
mickeyasa Jan 15, 2025
51d6e8d
spell
mickeyasa Jan 15, 2025
5bd4e56
added use_extension_field for Sumcheckconfig
mickeyasa Jan 15, 2025
6d20856
format
mickeyasa Jan 15, 2025
9ea4eea
enlarging the sumcheck test to 8k
mickeyasa Jan 15, 2025
a9da45d
fiat shamir moved to frontend
mickeyasa Jan 19, 2025
17a659e
format
mickeyasa Jan 19, 2025
12469fb
another format
mickeyasa Jan 19, 2025
bc5e639
Fix/release script (#721)
LeonHibnik Jan 13, 2025
8447e1a
Fix bug in CPU vec ops regarding nof workers (#731)
yshekel Jan 13, 2025
db78555
Support android and vulkan (#735)
yshekel Jan 14, 2025
28cab47
Parallelize-vecop-program-execution (#736)
mickeyasa Jan 14, 2025
31dbb47
Create docs for program & program execution (#722)
idanfr-ingo Jan 14, 2025
64767a6
Feat: Blake3 (#733)
aviadingo Jan 14, 2025
be8cd4c
Bump rust crates' version
Jan 14, 2025
7f98ad6
Bump docs version
Jan 14, 2025
8a02604
Update sidebars.ts (#729)
ShaniBabayoff Jan 14, 2025
752dc93
Update documentation for v3.4 (#738)
ShaniBabayoff Jan 14, 2025
87677d0
Deprecated icicle/api headers and updated examples/docs (#740)
yshekel Jan 15, 2025
31a5efb
avoid warning
mickeyasa Jan 20, 2025
430afc1
fri_cpu initial implementation
ShanieWinitz Feb 11, 2025
b478aa6
When creating FRI without a given MerkleTree vector, generate it in t…
ShanieWinitz Feb 11, 2025
9ee1b8d
basic test added, api fix
ShanieWinitz Feb 11, 2025
7e3dbd5
merkle_trees passed by value (only holds std::shared_ptr<MerkleTreeBa…
ShanieWinitz Feb 12, 2025
c35f823
merge main to fri_cpu branch
ShanieWinitz Feb 13, 2025
a334b0e
fri_transcript moved to frontend
ShanieWinitz Feb 13, 2025
1b1fc4e
verifier added
ShanieWinitz Feb 16, 2025
c4122f1
Change create_fri API to accept separate hash functions for Merkle tr…
ShanieWinitz Feb 24, 2025
c06a038
FIXMEs and TODOs fixed and removed
ShanieWinitz Feb 25, 2025
c2953a1
merge with main
ShanieWinitz Feb 25, 2025
2efd9ae
FRI: ext_field support added. F::from() function added for ext_field
ShanieWinitz Mar 2, 2025
40392af
format
ShanieWinitz Mar 2, 2025
1048dfb
Merge remote-tracking branch 'origin/main' into swinitz/fri_cpu
ShanieWinitz Mar 2, 2025
d11f03a
Fixed fri_transcript_config: using the same instance for both prover …
ShanieWinitz Mar 2, 2025
e503dd8
format
ShanieWinitz Mar 2, 2025
b4b2d1d
format
ShanieWinitz Mar 2, 2025
59b0e72
format
ShanieWinitz Mar 2, 2025
dc3f2bf
format
ShanieWinitz Mar 2, 2025
0b4dafe
format
ShanieWinitz Mar 2, 2025
cdbe020
format
ShanieWinitz Mar 2, 2025
0e8670a
debug function removed
ShanieWinitz Mar 2, 2025
13ef0f0
remove code in comment, fri test under ifdef
ShanieWinitz Mar 2, 2025
00a5ef3
format
ShanieWinitz Mar 2, 2025
518318d
Remove unnecessary files
ShanieWinitz Mar 3, 2025
a9bce88
asserts replaced with errors
ShanieWinitz Mar 3, 2025
77f2646
merkle_trees is now moved into CpuFriBackend when calling create_fri.…
ShanieWinitz Mar 3, 2025
907abbf
Replaced assertions with error logs, applied additional code review f…
ShanieWinitz Mar 4, 2025
627947b
rand_query_indicies function update
ShanieWinitz Mar 4, 2025
42fa634
Removed fri_c_api.cpp. It will be added back in the next PR
ShanieWinitz Mar 4, 2025
1569b2a
m_first_round removed
ShanieWinitz Mar 4, 2025
02a39f5
refactored verify method with smaller calls
ShanieWinitz Mar 4, 2025
7205dbe
Pass fri_transcript_config by reference, and test for non-default config
ShanieWinitz Mar 4, 2025
f5cefa1
FriProof init: Added description and error handling for invalid argum…
ShanieWinitz Mar 4, 2025
755b0f5
format
ShanieWinitz Mar 4, 2025
9b2a900
revert MerkleTree build method to use sizeof(T)
ShanieWinitz Mar 4, 2025
366f1b8
Removed for this PR: create_fri frontend for the case where merkle_tr…
ShanieWinitz Mar 5, 2025
f092a76
added test for cases where fri should fail. The basic test is now wit…
ShanieWinitz Mar 5, 2025
881f0cb
format
ShanieWinitz Mar 5, 2025
20585e6
minor
ShanieWinitz Mar 5, 2025
48da21b
minor
ShanieWinitz Mar 6, 2025
9ab1880
Merge branch 'main' into swinitz/fri_cpu
ShanieWinitz Mar 6, 2025
f4fc903
Merge remote-tracking branch 'origin/main' into swinitz/fri_cpu
ShanieWinitz Mar 6, 2025
4cefe5d
Merge branch 'swinitz/fri_cpu' of github.com:ingonyama-zk/icicle into…
ShanieWinitz Mar 6, 2025
bd238aa
FRI frontend and cpu changes (#803)
jeremyfelder Mar 9, 2025
6319dee
Formatting
jeremyfelder Mar 9, 2025
01893ed
added documentation, removed debug prints
ShanieWinitz Mar 9, 2025
5f49f36
api update - creat_fri() removed, now just calling get_proof or verify
ShanieWinitz Mar 11, 2025
14db388
format
ShanieWinitz Mar 11, 2025
2f16963
Changed FriShouldFailCases test to be deterministic. Removed redundan…
ShanieWinitz Mar 11, 2025
2d792dc
format
ShanieWinitz Mar 11, 2025
fafb40d
Uncommented CUDA tests
ShanieWinitz Mar 12, 2025
c1eb318
Added more cases to FriShouldFailCases test. + some more code review …
ShanieWinitz Mar 12, 2025
0746e1b
format
ShanieWinitz Mar 12, 2025
6f6435b
Merge remote-tracking branch 'origin/main' into swinitz/fri_cpu
ShanieWinitz Mar 12, 2025
19abf19
update documentation
ShanieWinitz Mar 12, 2025
c205291
copy MerkleTree instead of using a reference (The MerkleTree class on…
ShanieWinitz Mar 12, 2025
39ab65f
format
ShanieWinitz Mar 12, 2025
d69b33e
FRI struct replaced with fri_merkle_tree namespace. const added to Fr…
ShanieWinitz Mar 12, 2025
4da615c
"output_store_min_layer" removed from verify
ShanieWinitz Mar 12, 2025
56ed067
change names to get_fri_proof_merkle_tree, fri_merkle_tree::prove, ve…
ShanieWinitz Mar 12, 2025
d80d180
moved Fri class from fri.h to fri.cpp.
ShanieWinitz Mar 12, 2025
414b7dc
format
ShanieWinitz Mar 12, 2025
d3789cb
removed S from template
ShanieWinitz Mar 12, 2025
58a8cc7
format
ShanieWinitz Mar 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions icicle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ option(HASH "Build hashes and tree builders" ON)
option(POSEIDON "Build poseidon hash" ON)
option(POSEIDON2 "Build poseidon2 hash" ON)
option(SUMCHECK "Build sumcheck" ON)
option(FRI "Build fri" ON)
option(SANITIZE "Enable memory address sanitizer" OFF)

# address sanitizer
Expand Down
3 changes: 3 additions & 0 deletions icicle/backend/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ if (FIELD)
if(SUMCHECK)
target_sources(icicle_field PRIVATE src/field/cpu_sumcheck.cpp)
endif()
if(FRI)
target_sources(icicle_field PRIVATE src/field/cpu_fri.cpp)
endif()
target_include_directories(icicle_field PRIVATE include)
endif() # FIELD

Expand Down
190 changes: 190 additions & 0 deletions icicle/backend/cpu/include/cpu_fri_backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#pragma once

#include <cstddef>
#include <cstdint>
#include <vector>
#include <random>
#include "icicle/errors.h"
#include "icicle/fri/fri_transcript.h"
#include "icicle/backend/fri_backend.h"
#include "cpu_fri_rounds.h"
#include "cpu_ntt_domain.h"
#include "icicle/utils/log.h"

namespace icicle {
template <typename S, typename F>
class CpuFriBackend : public FriBackend<S, F>
{
public:
/**
* @brief Constructor that accepts an existing array of Merkle trees.
*
* @param folding_factor The factor by which the codeword is folded each round.
* @param stopping_degree Stopping degree threshold for the final polynomial.
* @param merkle_trees A vector of MerkleTrees, tree per FRI round.
*/
CpuFriBackend(const size_t folding_factor, const size_t stopping_degree, std::vector<MerkleTree> merkle_trees)
: FriBackend<S, F>(folding_factor, stopping_degree, std::move(merkle_trees)),
m_nof_fri_rounds(this->m_merkle_trees.size()),
m_log_input_size(this->m_merkle_trees.size() + std::log2(static_cast<double>(stopping_degree + 1))),
m_input_size(pow(2, m_log_input_size)), m_fri_rounds(this->m_merkle_trees, m_log_input_size)
{
}

eIcicleError get_proof(
const FriConfig& fri_config,
const FriTranscriptConfig<F>& fri_transcript_config,
const F* input_data,
FriProof<F>& fri_proof /*out*/) override
Comment on lines +37 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is probably better to get the size of input_data here as another parameter. You assume it is valid but maybe it's not. If not, you need to identify and log an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new API its not relevant right?

{
if (__builtin_expect(fri_config.nof_queries <= 0, 0)) { ICICLE_LOG_ERROR << "Number of queries must be > 0"; }

FriTranscript<F> transcript(fri_transcript_config, m_log_input_size);

// Initialize the proof
eIcicleError err = fri_proof.init(fri_config.nof_queries, m_nof_fri_rounds, this->m_stopping_degree + 1);
if (err != eIcicleError::SUCCESS) { return err; }

// commit fold phase
err = commit_fold_phase(input_data, transcript, fri_config, fri_proof);
if (err != eIcicleError::SUCCESS) { return err; }

// proof of work
if (fri_config.pow_bits != 0) {
err = proof_of_work(transcript, fri_config.pow_bits, fri_proof);
if (err != eIcicleError::SUCCESS) { return err; }
}

// query phase
err = query_phase(transcript, fri_config, fri_proof);

return err;
}

private:
const size_t m_nof_fri_rounds;
const size_t m_log_input_size;
const size_t m_input_size;
FriRounds<F> m_fri_rounds; // Holds intermediate rounds

/**
* @brief Perform the commit-fold phase of the FRI protocol.
*
* @param input_data The initial polynomial evaluations.
* @param fri_proof The proof object to update.
* @param transcript The transcript to generate challenges.
* @return eIcicleError Error code indicating success or failure.
*/
eIcicleError commit_fold_phase(
const F* input_data, FriTranscript<F>& transcript, const FriConfig& fri_config, FriProof<F>& fri_proof)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should accept the size and not assume it it valid when you take a pointer like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new API its not relevant right?

{
if (this->m_folding_factor != 2) {
ICICLE_LOG_ERROR
<< "Currently only folding factor of 2 is supported"; // TODO SHANIE - remove when supporting other folding
// factors
}
const S* twiddles = ntt_cpu::CpuNttDomain<S>::s_ntt_domain.get_twiddles();
uint64_t domain_max_size = ntt_cpu::CpuNttDomain<S>::s_ntt_domain.get_max_size();
if (m_input_size > domain_max_size) {
ICICLE_LOG_ERROR << "Size is too large for domain. size = " << m_input_size
<< ", domain_max_size = " << domain_max_size;
}

// Retrieve pre-allocated memory for the round from m_fri_rounds.
// The instance of FriRounds has already allocated a vector for each round with
// a capacity of 2^(m_log_input_size - round_idx).
F* round_evals = m_fri_rounds.get_round_evals(0);
std::copy(input_data, input_data + m_input_size, round_evals);

size_t current_size = m_input_size;
size_t current_log_size = m_log_input_size;

for (size_t round_idx = 0; round_idx < m_nof_fri_rounds; ++round_idx) {
// Merkle tree for the current round_idx
MerkleTree* current_round_tree = m_fri_rounds.get_merkle_tree(round_idx);
current_round_tree->build(round_evals, current_size, MerkleTreeConfig());
auto [root_ptr, root_size] = current_round_tree->get_merkle_root();
if (root_ptr == nullptr || root_size <= 0) {
ICICLE_LOG_ERROR << "Failed to retrieve Merkle root for round " << round_idx;
}
// Add root to transcript and get alpha
std::vector<std::byte> merkle_commit(root_size);
std::memcpy(merkle_commit.data(), root_ptr, root_size);

F alpha = transcript.get_alpha(merkle_commit, round_idx == 0);

// Fold the evaluations
size_t half = current_size >> 1;
std::vector<F> peven(half);
std::vector<F> podd(half);

for (size_t i = 0; i < half; ++i) {
peven[i] = (round_evals[i] + round_evals[i + half]) * S::inv_log_size(1);
uint64_t tw_idx = domain_max_size - ((domain_max_size >> current_log_size) * i);
podd[i] = ((round_evals[i] - round_evals[i + half]) * S::inv_log_size(1)) * twiddles[tw_idx];
}

if (round_idx == m_nof_fri_rounds - 1) {
round_evals = fri_proof.get_final_poly();
} else {
round_evals = m_fri_rounds.get_round_evals(round_idx + 1);
}

for (size_t i = 0; i < half; ++i) {
round_evals[i] = peven[i] + (alpha * podd[i]);
}

current_size >>= 1;
current_log_size--;
}
return eIcicleError::SUCCESS;
}

eIcicleError proof_of_work(FriTranscript<F>& transcript, const size_t pow_bits, FriProof<F>& fri_proof)
{
for (uint64_t nonce = 0; nonce < UINT64_MAX; nonce++) {
if (transcript.hash_and_get_nof_leading_zero_bits(nonce) == pow_bits) {
transcript.set_pow_nonce(nonce);
fri_proof.set_pow_nonce(nonce);
return eIcicleError::SUCCESS;
}
}
ICICLE_LOG_ERROR << "Failed to find a proof-of-work nonce";
return eIcicleError::UNKNOWN_ERROR;
}

/**
* @brief Perform the query phase of the FRI protocol.
*
* @param transcript The transcript object.
* @param fri_config The FRI configuration object.
* @param fri_proof (OUT) The proof object where we store the resulting Merkle proofs.
* @return eIcicleError
*/
eIcicleError query_phase(FriTranscript<F>& transcript, const FriConfig& fri_config, FriProof<F>& fri_proof)
{
std::vector<size_t> queries_indicies =
transcript.rand_queries_indicies(fri_config.nof_queries, (this->m_stopping_degree + 1), m_input_size);
for (size_t query_idx = 0; query_idx < fri_config.nof_queries; query_idx++) {
size_t query = queries_indicies[query_idx];
for (size_t round_idx = 0; round_idx < m_nof_fri_rounds; round_idx++) {
size_t round_size = (1ULL << (m_log_input_size - round_idx));
size_t leaf_idx = query % round_size;
size_t leaf_idx_sym = (query + (round_size >> 1)) % round_size;
F* round_evals = m_fri_rounds.get_round_evals(round_idx);

MerkleProof& proof_ref = fri_proof.get_query_proof(2 * query_idx, round_idx);
eIcicleError err = m_fri_rounds.get_merkle_tree(round_idx)->get_merkle_proof(
round_evals, round_size, leaf_idx, false /* is_pruned */, MerkleTreeConfig(), proof_ref);
if (err != eIcicleError::SUCCESS) return err;
MerkleProof& proof_ref_sym = fri_proof.get_query_proof(2 * query_idx + 1, round_idx);
eIcicleError err_sym = m_fri_rounds.get_merkle_tree(round_idx)->get_merkle_proof(
round_evals, round_size, leaf_idx_sym, false /* is_pruned */, MerkleTreeConfig(), proof_ref_sym);
if (err_sym != eIcicleError::SUCCESS) return err_sym;
}
}
return eIcicleError::SUCCESS;
}
};

} // namespace icicle
68 changes: 68 additions & 0 deletions icicle/backend/cpu/include/cpu_fri_rounds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace icicle {

template <typename F>
class FriRounds
{
public:
/**
* @brief Constructor that accepts an already-existing array of Merkle trees.
* Ownership is transferred from the caller.
*
* @param merkle_trees A vector of MerkleTrees.
* @param log_input_size The log of the input size.
*/
FriRounds(std::vector<MerkleTree>& merkle_trees, const size_t log_input_size) : m_merkle_trees(merkle_trees)
{
size_t fold_rounds = m_merkle_trees.size();
m_rounds_evals.resize(fold_rounds);
for (size_t i = 0; i < fold_rounds; i++) {
m_rounds_evals[i] = std::make_unique<F[]>(1ULL << (log_input_size - i));
}
}

/**
* @brief Get the Merkle tree for a specific fri round.
*
* @param round_idx The index of the fri round.
* @return A pointer to the Merkle tree backend for the specified fri round.
*/
MerkleTree* get_merkle_tree(size_t round_idx)
{
if (round_idx >= m_merkle_trees.size()) {
ICICLE_LOG_ERROR << "round index out of bounds";
return nullptr;
}
return &m_merkle_trees[round_idx];
}

F* get_round_evals(size_t round_idx)
{
if (round_idx >= m_merkle_trees.size()) {
ICICLE_LOG_ERROR << "round index out of bounds";
return nullptr;
}
return m_rounds_evals[round_idx].get();
}

/**
* @brief Retrieve the Merkle root for a specific fri round.
*
* @param round_idx The index of the round.
* @return A pair containing a pointer to the Merkle root bytes and its size.
*/
std::pair<const std::byte*, size_t> get_merkle_root_for_round(size_t round_idx) const
{
if (round_idx >= m_merkle_trees.size()) { return {nullptr, 0}; }
return m_merkle_trees[round_idx].get_merkle_root();
}

private:
// Persistent polynomial evaluations for each round (heap allocated).
// For round i, the expected length is 2^(m_initial_log_size - i).
std::vector<std::unique_ptr<F[]>> m_rounds_evals;

// Holds MerkleTree for each round. m_merkle_trees[i] is the tree for round i.
std::vector<MerkleTree>& m_merkle_trees;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a bad idea to store a reference to another object like that since you don't control its lifetime and it may be released too soon (before the FriRounds object). In such cases you need to either pass by value, move or use a smart pointer. Even if this is not exposed to users, it still creates coupling and assumptions for code using this class and changes in other places may break this code.

};

} // namespace icicle
26 changes: 26 additions & 0 deletions icicle/backend/cpu/src/field/cpu_fri.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "icicle/backend/fri_backend.h"
#include "cpu_fri_backend.h"

using namespace field_config;
using namespace icicle;

namespace icicle {

template <typename S, typename F>
eIcicleError cpu_create_fri_backend(
const Device& device,
const size_t folding_factor,
const size_t stopping_degree,
std::vector<MerkleTree> merkle_trees,
std::shared_ptr<FriBackend<S, F>>& backend /*OUT*/)
{
backend = std::make_shared<CpuFriBackend<S, F>>(folding_factor, stopping_degree, std::move(merkle_trees));
return eIcicleError::SUCCESS;
}

REGISTER_FRI_FACTORY_BACKEND("CPU", (cpu_create_fri_backend<scalar_t, scalar_t>));
#ifdef EXT_FIELD
REGISTER_FRI_EXT_FACTORY_BACKEND("CPU", (cpu_create_fri_backend<scalar_t, extension_t>));
#endif // EXT_FIELD

} // namespace icicle
14 changes: 7 additions & 7 deletions icicle/cmake/features.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# Define available field libraries with an index and their supported features
# Format: index:field:features
set(ICICLE_FIELDS
1001:babybear:NTT,EXT_FIELD,POSEIDON,POSEIDON2,SUMCHECK
1002:stark252:NTT,POSEIDON,POSEIDON2,SUMCHECK
1001:babybear:NTT,EXT_FIELD,POSEIDON,POSEIDON2,SUMCHECK,FRI
1002:stark252:NTT,POSEIDON,POSEIDON2,SUMCHECK,FRI
1003:m31:EXT_FIELD,POSEIDON,POSEIDON2,SUMCHECK
1004:koalabear:NTT,EXT_FIELD,POSEIDON,POSEIDON2,SUMCHECK
1004:koalabear:NTT,EXT_FIELD,POSEIDON,POSEIDON2,SUMCHECK,FRI
)

# Define available curve libraries with an index and their supported features
# Format: index:curve:features
set(ICICLE_CURVES
1:bn254:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK
2:bls12_381:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK
3:bls12_377:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK
4:bw6_761:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK
1:bn254:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK,FRI
2:bls12_381:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK,FRI
3:bls12_377:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK,FRI
4:bw6_761:NTT,MSM,G2,ECNTT,POSEIDON,POSEIDON2,SUMCHECK,FRI
5:grumpkin:MSM,POSEIDON,POSEIDON2,SUMCHECK
)

Expand Down
1 change: 1 addition & 0 deletions icicle/cmake/field.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function(setup_field_target FIELD FIELD_INDEX FEATURES_STRING)
handle_poseidon(icicle_field "${FEATURES_LIST}")
handle_poseidon2(icicle_field "${FEATURES_LIST}")
handle_sumcheck(icicle_field "${FEATURES_LIST}")
handle_fri(icicle_field "${FEATURES_LIST}")
# Add additional feature handling calls here

set_target_properties(icicle_field PROPERTIES OUTPUT_NAME "icicle_field_${FIELD}")
Expand Down
11 changes: 11 additions & 0 deletions icicle/cmake/target_editor.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,14 @@ function(handle_sumcheck TARGET FEATURE_LIST)
set(SUMCHECK OFF CACHE BOOL "SUMCHECK not available for this field" FORCE)
endif()
endfunction()

function(handle_fri TARGET FEATURE_LIST)
if(FRI AND "FRI" IN_LIST FEATURE_LIST)
target_compile_definitions(${TARGET} PUBLIC FRI=${FRI})
target_sources(${TARGET} PRIVATE src/fri/fri.cpp)
target_link_libraries(${TARGET} PRIVATE icicle_hash)
set(FRI ON CACHE BOOL "Enable FRI feature" FORCE)
else()
set(FRI OFF CACHE BOOL "FRI not available for this field" FORCE)
endif()
endfunction()
Loading
Loading