Padding in set target (#200)
* feat: handle padding in set_target * remove enable from MerkleClaimAndProof * Update src/backends/plonky2/circuits/mainpod.rs Co-authored-by: Ahmad Afuni <root@ahmadafuni.com> --------- Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
This commit is contained in:
parent
17e6c2a092
commit
26a6b2d143
7 changed files with 87 additions and 143 deletions
|
|
@ -19,7 +19,7 @@ use crate::{
|
|||
backends::plonky2::{
|
||||
basetypes::{C, D},
|
||||
circuits::mainpod::{MainPodVerifyCircuit, MainPodVerifyInput},
|
||||
primitives::{merkletree, merkletree::MerkleClaimAndProof},
|
||||
primitives::merkletree::MerkleClaimAndProof,
|
||||
signedpod::SignedPod,
|
||||
},
|
||||
middleware::{
|
||||
|
|
@ -42,7 +42,7 @@ pub(crate) fn extract_merkle_proofs(
|
|||
params: &Params,
|
||||
operations: &[middleware::Operation],
|
||||
) -> Result<Vec<MerkleClaimAndProof>> {
|
||||
let mut merkle_proofs = operations
|
||||
let merkle_proofs: Vec<_> = operations
|
||||
.iter()
|
||||
.flat_map(|op| match op {
|
||||
middleware::Operation::ContainsFromEntries(
|
||||
|
|
@ -51,40 +51,32 @@ pub(crate) fn extract_merkle_proofs(
|
|||
middleware::Statement::ValueOf(_, value),
|
||||
pf,
|
||||
) => Some(MerkleClaimAndProof::new(
|
||||
params.max_depth_mt_gadget,
|
||||
Hash::from(root.raw()),
|
||||
key.raw(),
|
||||
Some(value.raw()),
|
||||
pf,
|
||||
pf.clone(),
|
||||
)),
|
||||
middleware::Operation::NotContainsFromEntries(
|
||||
middleware::Statement::ValueOf(_, root),
|
||||
middleware::Statement::ValueOf(_, key),
|
||||
pf,
|
||||
) => Some(MerkleClaimAndProof::new(
|
||||
params.max_depth_mt_gadget,
|
||||
Hash::from(root.raw()),
|
||||
key.raw(),
|
||||
None,
|
||||
pf,
|
||||
pf.clone(),
|
||||
)),
|
||||
_ => None,
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
.collect();
|
||||
if merkle_proofs.len() > params.max_merkle_proofs {
|
||||
Err(anyhow!(
|
||||
return Err(anyhow!(
|
||||
"The number of required Merkle proofs ({}) exceeds the maximum number ({}).",
|
||||
merkle_proofs.len(),
|
||||
params.max_merkle_proofs
|
||||
))
|
||||
} else {
|
||||
fill_pad(
|
||||
&mut merkle_proofs,
|
||||
MerkleClaimAndProof::empty(params.max_depth_mt_gadget),
|
||||
params.max_merkle_proofs,
|
||||
);
|
||||
Ok(merkle_proofs)
|
||||
));
|
||||
}
|
||||
Ok(merkle_proofs)
|
||||
}
|
||||
|
||||
/// Find the operation argument statement in the list of previous statements and return the index.
|
||||
|
|
@ -115,12 +107,7 @@ fn find_op_aux(
|
|||
middleware::OperationAux::MerkleProof(pf_arg) => merkle_proofs
|
||||
.iter()
|
||||
.enumerate()
|
||||
.find_map(|(i, pf)| {
|
||||
pf.clone()
|
||||
.try_into()
|
||||
.ok()
|
||||
.and_then(|mid_pf: merkletree::MerkleProof| (&mid_pf == pf_arg).then_some(i))
|
||||
})
|
||||
.find_map(|(i, pf)| (pf.proof == *pf_arg).then_some(i))
|
||||
.map(OperationAux::MerkleProofIndex)
|
||||
.ok_or(anyhow!(
|
||||
"Merkle proof corresponding to op arg {} not found",
|
||||
|
|
@ -293,7 +280,6 @@ pub(crate) fn process_public_statements_operations(
|
|||
pub struct Prover {}
|
||||
|
||||
impl PodProver for Prover {
|
||||
// TODO: Be consistent on where we apply the padding, here, or in the set_targets?
|
||||
fn prove(&mut self, params: &Params, inputs: MainPodInputs) -> Result<Box<dyn Pod>> {
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
|
|
|||
|
|
@ -74,16 +74,15 @@ impl Operation {
|
|||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
let deref_aux = match self.2 {
|
||||
OperationAux::None => Ok(crate::middleware::OperationAux::None),
|
||||
OperationAux::MerkleProofIndex(i) => merkle_proofs
|
||||
.get(i)
|
||||
.cloned()
|
||||
.ok_or(anyhow!("Missing Merkle proof index {}", i))
|
||||
.and_then(|mp| {
|
||||
mp.try_into()
|
||||
.map(crate::middleware::OperationAux::MerkleProof)
|
||||
}),
|
||||
}?;
|
||||
OperationAux::None => crate::middleware::OperationAux::None,
|
||||
OperationAux::MerkleProofIndex(i) => crate::middleware::OperationAux::MerkleProof(
|
||||
merkle_proofs
|
||||
.get(i)
|
||||
.ok_or(anyhow!("Missing Merkle proof index {}", i))?
|
||||
.proof
|
||||
.clone(),
|
||||
),
|
||||
};
|
||||
middleware::Operation::op(self.0.clone(), &deref_args, &deref_aux)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue