mirror of
https://github.com/logos-storage/proof-aggregation.git
synced 2026-01-03 22:33:08 +00:00
add circuit with pub input
This commit is contained in:
parent
9b7a551543
commit
cf75968473
@ -21,7 +21,7 @@ use crate::circuits::sponge::{hash_n_no_padding, hash_n_with_padding};
|
|||||||
use crate::circuits::utils::{assign_hash_out_targets, ceiling_log2};
|
use crate::circuits::utils::{assign_hash_out_targets, ceiling_log2};
|
||||||
|
|
||||||
/// circuit for sampling a slot in a dataset merkle tree
|
/// circuit for sampling a slot in a dataset merkle tree
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SampleCircuit<
|
pub struct SampleCircuit<
|
||||||
F: RichField + Extendable<D> + Poseidon2,
|
F: RichField + Extendable<D> + Poseidon2,
|
||||||
const D: usize,
|
const D: usize,
|
||||||
@ -44,7 +44,7 @@ impl<
|
|||||||
|
|
||||||
/// struct of input to the circuit as targets
|
/// struct of input to the circuit as targets
|
||||||
/// used to build the circuit and can be assigned after building
|
/// used to build the circuit and can be assigned after building
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SampleTargets {
|
pub struct SampleTargets {
|
||||||
|
|
||||||
pub entropy: HashOutTarget, // public input
|
pub entropy: HashOutTarget, // public input
|
||||||
@ -112,8 +112,22 @@ impl<
|
|||||||
const D: usize,
|
const D: usize,
|
||||||
> SampleCircuit<F, D> {
|
> SampleCircuit<F, D> {
|
||||||
|
|
||||||
// in-circuit sampling
|
/// samples and registers the public input
|
||||||
// TODO: make it more modular
|
pub fn sample_slot_circuit_with_public_input(
|
||||||
|
&self,
|
||||||
|
builder: &mut CircuitBuilder::<F, D>,
|
||||||
|
)-> SampleTargets {
|
||||||
|
let targets = self.sample_slot_circuit(builder);
|
||||||
|
let mut pub_targets = vec![];
|
||||||
|
pub_targets.push(targets.slot_index);
|
||||||
|
pub_targets.extend_from_slice(&targets.dataset_root.elements);
|
||||||
|
pub_targets.extend_from_slice(&targets.entropy.elements);
|
||||||
|
builder.register_public_inputs(&pub_targets);
|
||||||
|
targets
|
||||||
|
}
|
||||||
|
|
||||||
|
/// in-circuit sampling
|
||||||
|
/// WARNING: no public input are registered when calling this function
|
||||||
pub fn sample_slot_circuit(
|
pub fn sample_slot_circuit(
|
||||||
&self,
|
&self,
|
||||||
builder: &mut CircuitBuilder::<F, D>,
|
builder: &mut CircuitBuilder::<F, D>,
|
||||||
@ -136,7 +150,8 @@ impl<
|
|||||||
|
|
||||||
// Create virtual target for slot root and index
|
// Create virtual target for slot root and index
|
||||||
let slot_root = builder.add_virtual_hash();
|
let slot_root = builder.add_virtual_hash();
|
||||||
let slot_index = builder.add_virtual_public_input();// public input
|
let slot_index = builder.add_virtual_target();// public input
|
||||||
|
// let slot_index = builder.add_virtual_public_input();// public input
|
||||||
|
|
||||||
// dataset path bits (binary decomposition of leaf_index)
|
// dataset path bits (binary decomposition of leaf_index)
|
||||||
let d_path_bits = builder.split_le(slot_index,max_log2_n_slots);
|
let d_path_bits = builder.split_le(slot_index,max_log2_n_slots);
|
||||||
@ -167,7 +182,8 @@ impl<
|
|||||||
MerkleTreeCircuit::<F,D>::reconstruct_merkle_root_circuit_with_mask(builder, &mut d_targets, max_log2_n_slots);
|
MerkleTreeCircuit::<F,D>::reconstruct_merkle_root_circuit_with_mask(builder, &mut d_targets, max_log2_n_slots);
|
||||||
|
|
||||||
// expected Merkle root
|
// expected Merkle root
|
||||||
let d_expected_root = builder.add_virtual_hash_public_input(); // public input
|
let d_expected_root = builder.add_virtual_hash(); // public input
|
||||||
|
// let d_expected_root = builder.add_virtual_hash_public_input(); // public input
|
||||||
|
|
||||||
// check equality with expected root
|
// check equality with expected root
|
||||||
for i in 0..NUM_HASH_OUT_ELTS {
|
for i in 0..NUM_HASH_OUT_ELTS {
|
||||||
@ -178,7 +194,8 @@ impl<
|
|||||||
|
|
||||||
let mut data_targets =vec![];
|
let mut data_targets =vec![];
|
||||||
let mut slot_sample_proofs = vec![];
|
let mut slot_sample_proofs = vec![];
|
||||||
let entropy_target = builder.add_virtual_hash_public_input(); // public input
|
let entropy_target = builder.add_virtual_hash(); // public input
|
||||||
|
// let entropy_target = builder.add_virtual_hash_public_input(); // public input
|
||||||
|
|
||||||
// virtual target for n_cells_per_slot
|
// virtual target for n_cells_per_slot
|
||||||
let n_cells_per_slot = builder.add_virtual_target();
|
let n_cells_per_slot = builder.add_virtual_target();
|
||||||
@ -310,8 +327,8 @@ impl<
|
|||||||
pub fn sample_slot_assign_witness(
|
pub fn sample_slot_assign_witness(
|
||||||
&self,
|
&self,
|
||||||
pw: &mut PartialWitness<F>,
|
pw: &mut PartialWitness<F>,
|
||||||
targets: &mut SampleTargets,
|
targets: &SampleTargets,
|
||||||
witnesses: SampleCircuitInput<F, D>,
|
witnesses: &SampleCircuitInput<F, D>,
|
||||||
){
|
){
|
||||||
// circuit params
|
// circuit params
|
||||||
let CircuitParams {
|
let CircuitParams {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user