Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 8 additions & 9 deletions examples/CRISP/circuits/src/constants.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
// without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.

/// Half of the largest minimum degree used for vote encoding regions.
///
/// This constant defines the size of the coefficient region allocated for encoding vote amounts
/// in binary format within each half of the polynomial. Votes are encoded as binary numbers:
/// - NO votes: coefficients [0, HALF_LARGEST_MINIMUM_DEGREE)
/// - YES votes: coefficients [HALF_D, HALF_D + HALF_LARGEST_MINIMUM_DEGREE)
///
/// With a value of 50, each vote type can represent values up to 2^50 - 1.
pub global HALF_LARGEST_MINIMUM_DEGREE: u32 = 50;
/// Maximum number of options for a vote.
/// We need this value because we need a compile-time bound value
/// for looping.
pub global MAX_OPTIONS: u32 = 10;

// This constant defines the size of the coefficient region allocated for encoding vote amounts
/// in binary format within each half of the polynomial. Votes are encoded as binary numbers.
pub global MAX_VOTE_BITS: u32 = 50;
5 changes: 3 additions & 2 deletions examples/CRISP/circuits/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ fn main(
balance: Field,
is_first_vote: pub bool,
is_mask_vote: bool,
num_options: pub u32,
) -> pub Field {
// ============================================================================
// STEP 1: Eligibility - Merkle Tree Proof
Expand Down Expand Up @@ -176,15 +177,15 @@ fn main(
let ct_commitment = compute_ciphertext_commitment::<512, 2, 36>(ct0is, ct1is);

if is_mask_vote == false {
check_coefficient_values_with_balance(k1, USER_DATA_ENCRYPTION_Q_MOD_T_MOD_P, balance);
check_coefficient_values_with_balance(k1, USER_DATA_ENCRYPTION_Q_MOD_T_MOD_P, balance, num_options);
validate_signature(hashed_message, public_key_x, public_key_y, signature);

let voter_address = address_to_field(derive_address(public_key_x, public_key_y));
assert(slot_address == voter_address);

ct_commitment
} else {
check_coefficient_zero(k1);
check_coefficient_zero(k1, num_options);

if is_first_vote {
ct_commitment
Expand Down
Loading
Loading