Skip to content

Commit

Permalink
FRI x_indices, FRI round proof poly values ordering, lookup and permu…
Browse files Browse the repository at this point in the history
…tation argument partition products, copy_constraints, commitment_params #305
  • Loading branch information
ETatuzova committed Apr 8, 2024
1 parent fc284de commit b8dc491
Show file tree
Hide file tree
Showing 26 changed files with 1,833 additions and 868 deletions.
307 changes: 229 additions & 78 deletions include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,14 @@ namespace nil {
namespace crypto3 {
namespace zk {
namespace commitments {
template<typename TranscriptHashType, typename OutType = std::uint32_t, std::uint32_t MASK=0xFFFF0000>
template<typename TranscriptHashType, typename OutType = std::uint32_t>
class proof_of_work {
public:
using transcript_hash_type = TranscriptHashType;
using transcript_type = transcript::fiat_shamir_heuristic_sequential<transcript_hash_type>;
using output_type = OutType;

constexpr static std::uint32_t mask = MASK;

static inline boost::property_tree::ptree get_params() {
boost::property_tree::ptree params;
params.put("mask", mask);
return params;
}

static inline OutType generate(transcript_type &transcript) {
static inline OutType generate(transcript_type &transcript, OutType mask=0xFFFF) {
output_type proof_of_work = std::rand();
output_type result;
std::vector<std::uint8_t> bytes(4);
Expand All @@ -75,7 +67,7 @@ namespace nil {
return proof_of_work;
}

static inline bool verify(transcript_type &transcript, output_type proof_of_work) {
static inline bool verify(transcript_type &transcript, output_type proof_of_work, OutType mask=0xFFFF) {
std::vector<std::uint8_t> bytes(4);
bytes[0] = std::uint8_t((proof_of_work&0xFF000000)>>24);
bytes[1] = std::uint8_t((proof_of_work&0x00FF0000)>>16);
Expand All @@ -91,31 +83,25 @@ namespace nil {
// amount of bits for grinding instead of the mask.
// This was done because the actual mask is applied to the high bits instead of the low bits
// which makes manually setting the mask error-prone.
template<typename TranscriptHashType, typename FieldType, std::uint8_t GrindingBits=16>
template<typename TranscriptHashType, typename FieldType>
class field_proof_of_work {
public:
using transcript_hash_type = TranscriptHashType;
using transcript_type = transcript::fiat_shamir_heuristic_sequential<transcript_hash_type>;
using value_type = typename FieldType::value_type;
using integral_type = typename FieldType::integral_type;

constexpr static const integral_type mask =
(GrindingBits > 0 ?
((integral_type(2) << GrindingBits - 1) - 1) << (FieldType::modulus_bits - GrindingBits)
: 0);

static inline boost::property_tree::ptree get_params() {
boost::property_tree::ptree params;
params.put("mask", mask);
return params;
}

static inline value_type generate(transcript_type &transcript) {
static inline value_type generate(transcript_type &transcript, std::size_t GrindingBits=16) {
static boost::random::random_device dev;
static nil::crypto3::random::algebraic_engine<FieldType> random_engine(dev);
value_type proof_of_work = random_engine();
integral_type result;

integral_type mask =
(GrindingBits > 0 ?
((integral_type(1) << GrindingBits) - 1) << (FieldType::modulus_bits - GrindingBits)
: 0);

while( true ) {
transcript_type tmp_transcript = transcript;
tmp_transcript(proof_of_work);
Expand All @@ -129,8 +115,13 @@ namespace nil {
return proof_of_work;
}

static inline bool verify(transcript_type &transcript, value_type proof_of_work) {
static inline bool verify(transcript_type &transcript, value_type proof_of_work, std::size_t GrindingBits=16) {
transcript(proof_of_work);
integral_type mask =
(GrindingBits > 0 ?
((integral_type(1) << GrindingBits) - 1) << (FieldType::modulus_bits - GrindingBits)
: 0);

integral_type result = integral_type(transcript.template challenge<FieldType>().data);
return ((result & mask) == 0);
}
Expand Down
13 changes: 4 additions & 9 deletions include/nil/crypto3/zk/commitments/polynomial/fri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,18 @@ namespace nil {
template<typename FieldType,
typename MerkleTreeHashType,
typename TranscriptHashType,
std::size_t Lambda,
std::size_t M,
bool UseGrinding =false,
typename GrindingType = proof_of_work<TranscriptHashType>
>
struct fri : public detail::basic_batched_fri<FieldType,
MerkleTreeHashType,
TranscriptHashType,
Lambda, M,
UseGrinding, GrindingType
M, GrindingType
> {
using basic_fri = detail::basic_batched_fri<FieldType,
MerkleTreeHashType,
TranscriptHashType,
Lambda, M, UseGrinding, GrindingType>;
M, GrindingType>;
constexpr static const std::size_t m = basic_fri::m;
constexpr static const std::size_t batches_num = basic_fri::batches_num;

Expand All @@ -104,8 +101,7 @@ namespace nil {
typename std::enable_if<std::is_base_of<commitments::fri<typename FRI::field_type,
typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type,
FRI::lambda, FRI::m,
FRI::use_grinding,
FRI::m,
typename FRI::grinding_type
>,
FRI>::value,
Expand All @@ -129,8 +125,7 @@ namespace nil {
typename FRI::field_type,
typename FRI::merkle_tree_hash_type,
typename FRI::transcript_hash_type,
FRI::lambda, FRI::m,
FRI::use_grinding,
FRI::m,
typename FRI::grinding_type
>,
FRI>::value,
Expand Down
Loading

0 comments on commit b8dc491

Please sign in to comment.