Return the encryption and Groth16 proof
(
rng: &mut R,
message: &E::ScalarField,
ek: &EncryptionKey<E>,
snark_pk: &saver_groth16::ProvingKey<E>,
chunk_bit_size: u8,
)
| 187 | |
| 188 | /// Return the encryption and Groth16 proof |
| 189 | pub fn encrypt_with_proof<R: RngCore>( |
| 190 | rng: &mut R, |
| 191 | message: &E::ScalarField, |
| 192 | ek: &EncryptionKey<E>, |
| 193 | snark_pk: &saver_groth16::ProvingKey<E>, |
| 194 | chunk_bit_size: u8, |
| 195 | ) -> crate::Result<(Ciphertext<E>, E::ScalarField, ark_groth16::Proof<E>)> { |
| 196 | let g_i = saver_groth16::get_gs_for_encryption(&snark_pk.pk.vk); |
| 197 | let (ct, r) = Encryption::encrypt(rng, message, ek, g_i, chunk_bit_size)?; |
| 198 | let decomposed_message = utils::decompose(message, chunk_bit_size)? |
| 199 | .into_iter() |
| 200 | .map(|m| E::ScalarField::from(m as u64)) |
| 201 | .collect::<Vec<_>>(); |
| 202 | let circuit = |
| 203 | BitsizeCheckCircuit::new(chunk_bit_size, None, Some(decomposed_message), true); |
| 204 | let proof = saver_groth16::create_proof(circuit, &r, snark_pk, ek, rng)?; |
| 205 | Ok((ct, r, proof)) |
| 206 | } |
| 207 | |
| 208 | pub fn rerandomize_ciphertext_and_proof<R: RngCore>( |
| 209 | ciphertext: Ciphertext<E>, |
nothing calls this directly
no test coverage detected