remove NonePod and use dummy signed pods (#272)
* remove NonePod and use dummy signed pods * apply suggestion by @arnaucube
This commit is contained in:
parent
03485d6fd3
commit
3b4edab1f5
6 changed files with 54 additions and 49 deletions
|
|
@ -1464,12 +1464,9 @@ impl InnerCircuit for MainPodVerifyTarget {
|
|||
}
|
||||
// Padding
|
||||
if input.signed_pods.len() != self.params.max_input_signed_pods {
|
||||
// TODO: Instead of using an input for padding, use a canonical minimal SignedPod,
|
||||
// without it a MainPod configured to support input signed pods must have at least one
|
||||
// input signed pod :(
|
||||
let pad_pod = &input.signed_pods[0];
|
||||
let dummy = SignedPod::dummy();
|
||||
for i in input.signed_pods.len()..self.params.max_input_signed_pods {
|
||||
self.signed_pods[i].set_targets(pw, pad_pod)?;
|
||||
self.signed_pods[i].set_targets(pw, &dummy)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
use std::{collections::HashMap, sync::Mutex};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{LazyLock, Mutex},
|
||||
};
|
||||
|
||||
use itertools::Itertools;
|
||||
use plonky2::{
|
||||
|
|
@ -23,7 +26,7 @@ use crate::{
|
|||
error::{Error, Result},
|
||||
mainpod::{self, calculate_id},
|
||||
recursion::pad_circuit,
|
||||
serialize_proof, LazyLock, DEFAULT_PARAMS, STANDARD_REC_MAIN_POD_CIRCUIT_DATA,
|
||||
serialize_proof, DEFAULT_PARAMS, STANDARD_REC_MAIN_POD_CIRCUIT_DATA,
|
||||
},
|
||||
middleware::{
|
||||
self, AnchoredKey, DynError, Hash, Params, Pod, PodId, PodType, RecursivePod, Statement,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use crate::{
|
|||
deserialize_proof,
|
||||
emptypod::EmptyPod,
|
||||
error::{Error, Result},
|
||||
mock::emptypod::MockEmptyPod,
|
||||
mock::{emptypod::MockEmptyPod, signedpod::MockSignedPod},
|
||||
primitives::merkletree::MerkleClaimAndProof,
|
||||
recursion::{RecursiveCircuit, RecursiveParams},
|
||||
serialize_proof,
|
||||
|
|
@ -27,8 +27,8 @@ use crate::{
|
|||
},
|
||||
middleware::{
|
||||
self, resolve_wildcard_values, AnchoredKey, CustomPredicateBatch, DynError, Hash,
|
||||
MainPodInputs, NativeOperation, NonePod, OperationType, Params, Pod, PodId, PodProver,
|
||||
PodType, RecursivePod, StatementArg, ToFields, VDSet, F, KEY_TYPE, SELF,
|
||||
MainPodInputs, NativeOperation, OperationType, Params, Pod, PodId, PodProver, PodType,
|
||||
RecursivePod, StatementArg, ToFields, VDSet, F, KEY_TYPE, SELF,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -257,13 +257,16 @@ pub(crate) fn layout_statements(
|
|||
statements.push(middleware::Statement::None.into());
|
||||
|
||||
// Input signed pods region
|
||||
// TODO: Replace this with a dumb signed pod
|
||||
// https://github.com/0xPARC/pod2/issues/246
|
||||
let none_sig_pod_box: Box<dyn Pod> = Box::new(NonePod {});
|
||||
let none_sig_pod = none_sig_pod_box.as_ref();
|
||||
let dummy_signed_pod_box: Box<dyn Pod> =
|
||||
if mock || inputs.signed_pods.len() == params.max_input_signed_pods {
|
||||
Box::new(MockSignedPod::dummy())
|
||||
} else {
|
||||
Box::new(SignedPod::dummy())
|
||||
};
|
||||
let dummy_signed_pod = dummy_signed_pod_box.as_ref();
|
||||
assert!(inputs.signed_pods.len() <= params.max_input_signed_pods);
|
||||
for i in 0..params.max_input_signed_pods {
|
||||
let pod = inputs.signed_pods.get(i).unwrap_or(&none_sig_pod);
|
||||
let pod = inputs.signed_pods.get(i).unwrap_or(&dummy_signed_pod);
|
||||
let sts = pod.pub_statements();
|
||||
assert!(sts.len() <= params.max_signed_pod_values);
|
||||
for j in 0..params.max_signed_pod_values {
|
||||
|
|
|
|||
|
|
@ -120,6 +120,15 @@ impl MockSignedPod {
|
|||
kvs: data.kvs,
|
||||
}))
|
||||
}
|
||||
/// Generate a valid MockSignedPod with a public deterministic public key and no other
|
||||
/// key-values than the default ones. This is used for padding.
|
||||
pub fn dummy() -> MockSignedPod {
|
||||
MockSigner {
|
||||
pk: "dummy".to_string(),
|
||||
}
|
||||
._sign(&Params::default(), &HashMap::new())
|
||||
.expect("valid")
|
||||
}
|
||||
}
|
||||
|
||||
impl Pod for MockSignedPod {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, sync::LazyLock};
|
||||
|
||||
use itertools::Itertools;
|
||||
use num_bigint::RandBigInt;
|
||||
use num_bigint::{BigUint, RandBigInt};
|
||||
use rand::rngs::OsRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -28,7 +28,12 @@ use crate::{
|
|||
pub struct Signer(pub SecretKey);
|
||||
|
||||
impl Signer {
|
||||
fn _sign(&mut self, params: &Params, kvs: &HashMap<Key, Value>) -> Result<SignedPod> {
|
||||
fn sign_with_nonce(
|
||||
&mut self,
|
||||
params: &Params,
|
||||
nonce: BigUint,
|
||||
kvs: &HashMap<Key, Value>,
|
||||
) -> Result<SignedPod> {
|
||||
let mut kvs = kvs.clone();
|
||||
let pubkey = self.0.public_key();
|
||||
kvs.insert(Key::from(KEY_SIGNER), Value::from(pubkey));
|
||||
|
|
@ -37,7 +42,6 @@ impl Signer {
|
|||
let dict = Dictionary::new(params.max_depth_mt_containers, kvs)?;
|
||||
let id = RawValue::from(dict.commitment()); // PodId as Value
|
||||
|
||||
let nonce = OsRng.gen_biguint_below(&GROUP_ORDER);
|
||||
let signature: Signature = self.0.sign(id, &nonce);
|
||||
Ok(SignedPod {
|
||||
id: PodId(Hash::from(id)),
|
||||
|
|
@ -46,6 +50,10 @@ impl Signer {
|
|||
dict,
|
||||
})
|
||||
}
|
||||
fn _sign(&mut self, params: &Params, kvs: &HashMap<Key, Value>) -> Result<SignedPod> {
|
||||
let nonce = OsRng.gen_biguint_below(&GROUP_ORDER);
|
||||
self.sign_with_nonce(params, nonce, kvs)
|
||||
}
|
||||
|
||||
pub fn public_key(&self) -> Point {
|
||||
self.0.public_key()
|
||||
|
|
@ -77,6 +85,15 @@ struct Data {
|
|||
kvs: Dictionary,
|
||||
}
|
||||
|
||||
static DUMMY_POD: LazyLock<SignedPod> = LazyLock::new(dummy);
|
||||
|
||||
fn dummy() -> SignedPod {
|
||||
let nonce = BigUint::from(2u32);
|
||||
Signer(SecretKey(BigUint::from(1u32)))
|
||||
.sign_with_nonce(&Params::default(), nonce, &HashMap::new())
|
||||
.expect("valid")
|
||||
}
|
||||
|
||||
impl SignedPod {
|
||||
fn _verify(&self) -> Result<()> {
|
||||
// 1. Verify type
|
||||
|
|
@ -142,6 +159,12 @@ impl SignedPod {
|
|||
dict: data.kvs,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Generate a valid SignedPod with a public deterministic secret key and nonce and no other
|
||||
/// key-values than the default ones. This is used for padding.
|
||||
pub fn dummy() -> SignedPod {
|
||||
DUMMY_POD.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Pod for SignedPod {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue