Skip to content

Commit

Permalink
feat: update cyclo_at_gamma assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobottazzi committed May 2, 2024
1 parent 7ef4ffa commit eb96331
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/sk_encryption_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,25 @@ impl<F: ScalarField> RlcCircuitInstructions<F> for BfvSkEncryptionCircuit {
} = payload;

let (ctx_gate, ctx_rlc) = builder.rlc_ctx_pair();
let gamma = *rlc.gamma();
let gate = range.gate();

let mut qi_constants = vec![];
let mut k0i_constants = vec![];

for z in 0..ct0is_assigned.len() {

let qi_constant = Constant(F::from_str_vartime(QIS[z]).unwrap());
qi_constants.push(qi_constant);

let k0i_constant = Constant(F::from_str_vartime(K0IS[z]).unwrap());
k0i_constants.push(k0i_constant);
}

// cyclo poly is equal to x^N + 1
let cyclo_at_gamma = gamma.pow_vartime([N as u64]) + F::from(1);
let cyclo_at_gamma_assigned = ctx_gate.load_witness(cyclo_at_gamma);
let bits_used = usize::BITS as usize - N.leading_zeros() as usize;
rlc.load_rlc_cache((ctx_gate, ctx_rlc), gate, bits_used);
let cyclo_at_gamma_assigned = rlc.rlc_pow_fixed(ctx_gate, gate, N);
let cyclo_at_gamma_assigned =
gate.add(ctx_gate, cyclo_at_gamma_assigned, Constant(F::from(1)));

// RANGE CHECK
s_assigned.range_check(ctx_gate, range, S_BOUND);
e_assigned.range_check(ctx_gate, range, E_BOUND);
k1_assigned.range_check(ctx_gate, range, K1_BOUND);
Expand All @@ -225,8 +225,6 @@ impl<F: ScalarField> RlcCircuitInstructions<F> for BfvSkEncryptionCircuit {
let e_at_gamma = e_assigned.enforce_eval_at_gamma(ctx_rlc, rlc);
let k1_at_gamma = k1_assigned.enforce_eval_at_gamma(ctx_rlc, rlc);

let gate = range.gate();

// For each `i` Prove that LHS(gamma) = RHS(gamma)
// LHS = ct0i(gamma)
// RHS = ai(gamma) * s(gamma) + e(gamma) + k1(gamma) * k0i + r1i(gamma) * qi + r2i(gamma) * cyclo(gamma)
Expand Down

0 comments on commit eb96331

Please sign in to comment.