expose some interfaces for external usage (from introduction-pods) (#256)
* expose some interfaces for external usage (from introduction-pods) * add From<MainPod> for OperationArg, add copy op! Co-authored-by: Eduard S. <eduardsanou@posteo.net> --------- Co-authored-by: Eduard S. <eduardsanou@posteo.net>
This commit is contained in:
parent
5d13ac32ce
commit
7bc0bd08d2
6 changed files with 54 additions and 22 deletions
|
|
@ -63,31 +63,31 @@ macro_rules! new {
|
|||
}
|
||||
use InnerError::*;
|
||||
impl Error {
|
||||
pub(crate) fn custom(s: String) -> Self {
|
||||
pub fn custom(s: String) -> Self {
|
||||
new!(Custom(s))
|
||||
}
|
||||
pub(crate) fn plonky2_proof_fail(e: anyhow::Error) -> Self {
|
||||
pub fn plonky2_proof_fail(e: anyhow::Error) -> Self {
|
||||
Self::Plonky2ProofFail(e)
|
||||
}
|
||||
pub(crate) fn key_not_found() -> Self {
|
||||
pub fn key_not_found() -> Self {
|
||||
new!(KeyNotFound)
|
||||
}
|
||||
pub(crate) fn statement_not_check() -> Self {
|
||||
pub fn statement_not_check() -> Self {
|
||||
new!(StatementNotCheck)
|
||||
}
|
||||
pub(crate) fn repeated_value_of() -> Self {
|
||||
pub fn repeated_value_of() -> Self {
|
||||
new!(RepeatedValueOf)
|
||||
}
|
||||
pub(crate) fn not_type_statement() -> Self {
|
||||
pub fn not_type_statement() -> Self {
|
||||
new!(NotTypeStatement)
|
||||
}
|
||||
pub(crate) fn pod_id_invalid() -> Self {
|
||||
pub fn pod_id_invalid() -> Self {
|
||||
new!(PodIdInvalid)
|
||||
}
|
||||
pub(crate) fn id_not_equal(expected: PodId, found: PodId) -> Self {
|
||||
pub fn id_not_equal(expected: PodId, found: PodId) -> Self {
|
||||
new!(IdNotEqual(expected, found))
|
||||
}
|
||||
pub(crate) fn type_not_equal(expected: PodType, found: Value) -> Self {
|
||||
pub fn type_not_equal(expected: PodType, found: Value) -> Self {
|
||||
new!(TypeNotEqual(expected, found))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ use crate::{
|
|||
/// `max_public_statements` only pay for `max_public_statements` by starting the poseidon state
|
||||
/// with a precomputed constant corresponding to the front-padding part:
|
||||
/// `id = hash(serialize(reverse(statements || none-statements)))`
|
||||
pub(crate) fn calculate_id(statements: &[Statement], params: &Params) -> middleware::Hash {
|
||||
pub fn calculate_id(statements: &[Statement], params: &Params) -> middleware::Hash {
|
||||
assert!(statements.len() <= params.num_public_statements_id);
|
||||
assert!(params.max_public_statements <= params.num_public_statements_id);
|
||||
|
||||
|
|
@ -409,7 +409,7 @@ impl Prover {
|
|||
fn _prove(&self, params: &Params, inputs: MainPodInputs) -> Result<MainPod> {
|
||||
let rec_circuit_data = &*STANDARD_REC_MAIN_POD_CIRCUIT_DATA;
|
||||
let (main_pod_target, circuit_data) =
|
||||
RecursiveCircuit::<MainPodVerifyTarget>::circuit_data_padded(
|
||||
RecursiveCircuit::<MainPodVerifyTarget>::target_and_circuit_data_padded(
|
||||
params.max_input_recursive_pods,
|
||||
&rec_circuit_data.common,
|
||||
params,
|
||||
|
|
@ -570,11 +570,12 @@ impl MainPod {
|
|||
let rec_circuit_data = &*STANDARD_REC_MAIN_POD_CIRCUIT_DATA;
|
||||
// TODO: cache these artefacts
|
||||
// https://github.com/0xPARC/pod2/issues/247
|
||||
let (_, circuit_data) = RecursiveCircuit::<MainPodVerifyTarget>::circuit_data_padded(
|
||||
self.params.max_input_recursive_pods,
|
||||
&rec_circuit_data.common,
|
||||
&self.params,
|
||||
)?;
|
||||
let (_, circuit_data) =
|
||||
RecursiveCircuit::<MainPodVerifyTarget>::target_and_circuit_data_padded(
|
||||
self.params.max_input_recursive_pods,
|
||||
&rec_circuit_data.common,
|
||||
&self.params,
|
||||
)?;
|
||||
let public_inputs = id
|
||||
.to_fields(&self.params)
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ pub fn new_params_padded<I: InnerCircuit>(
|
|||
inner_params: &I::Params,
|
||||
) -> Result<RecursiveParams> {
|
||||
let (_, circuit_data) =
|
||||
RecursiveCircuit::<I>::circuit_data_padded(arity, common_data, inner_params)?;
|
||||
RecursiveCircuit::<I>::target_and_circuit_data_padded(arity, common_data, inner_params)?;
|
||||
let common_data = circuit_data.common.clone();
|
||||
let verifier_data = circuit_data.verifier_data();
|
||||
Ok(RecursiveParams {
|
||||
|
|
@ -265,7 +265,7 @@ impl<I: InnerCircuit> RecursiveCircuit<I> {
|
|||
}
|
||||
|
||||
/// returns the full-recursive CircuitData padded to share the input `common_data`
|
||||
pub fn circuit_data_padded(
|
||||
pub fn target_and_circuit_data_padded(
|
||||
arity: usize,
|
||||
common_data: &CommonCircuitData<F, D>,
|
||||
inner_params: &I::Params,
|
||||
|
|
@ -688,7 +688,7 @@ mod tests {
|
|||
let common_data = &circuit_data_3.common;
|
||||
|
||||
let (_, circuit_data_1) =
|
||||
RC::<Circuit1>::circuit_data_padded(arity, &common_data, &inner_params)?;
|
||||
RC::<Circuit1>::target_and_circuit_data_padded(arity, &common_data, &inner_params)?;
|
||||
let params_1 = RecursiveParams {
|
||||
arity,
|
||||
common_data: circuit_data_1.common.clone(),
|
||||
|
|
@ -696,7 +696,7 @@ mod tests {
|
|||
};
|
||||
|
||||
let (_, circuit_data_2) =
|
||||
RC::<Circuit2>::circuit_data_padded(arity, &common_data, &inner_params)?;
|
||||
RC::<Circuit2>::target_and_circuit_data_padded(arity, &common_data, &inner_params)?;
|
||||
let params_2 = RecursiveParams {
|
||||
arity,
|
||||
common_data: circuit_data_2.common.clone(),
|
||||
|
|
|
|||
|
|
@ -645,6 +645,22 @@ impl MainPod {
|
|||
pub fn id(&self) -> PodId {
|
||||
self.pod.id()
|
||||
}
|
||||
|
||||
/// Returns the value of a ValueOf statement with self id that defines key if it exists.
|
||||
pub fn get(&self, key: impl Into<Key>) -> Option<Value> {
|
||||
let key: Key = key.into();
|
||||
self.public_statements
|
||||
.iter()
|
||||
.find_map(|st| match st {
|
||||
Statement::ValueOf(ak, value)
|
||||
if ak.pod_id == self.id() && ak.key.hash() == key.hash() =>
|
||||
{
|
||||
Some(value)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
struct MainPodCompilerInputs<'a> {
|
||||
|
|
@ -759,6 +775,9 @@ pub mod build_utils {
|
|||
(new_entry, ($key:expr, $value:expr)) => { $crate::frontend::Operation(
|
||||
$crate::middleware::OperationType::Native($crate::middleware::NativeOperation::NewEntry),
|
||||
$crate::op_args!(($key, $value)), $crate::middleware::OperationAux::None) };
|
||||
(copy, $($arg:expr),+) => { $crate::frontend::Operation(
|
||||
$crate::middleware::OperationType::Native($crate::middleware::NativeOperation::CopyStatement),
|
||||
$crate::op_args!($($arg),*), $crate::middleware::OperationAux::None) };
|
||||
(eq, $($arg:expr),+) => { $crate::frontend::Operation(
|
||||
$crate::middleware::OperationType::Native($crate::middleware::NativeOperation::EqualFromEntries),
|
||||
$crate::op_args!($($arg),*), $crate::middleware::OperationAux::None) };
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::{
|
||||
frontend::SignedPod,
|
||||
frontend::{MainPod, SignedPod},
|
||||
middleware::{AnchoredKey, OperationAux, OperationType, Statement, Value},
|
||||
};
|
||||
|
||||
|
|
@ -78,6 +78,18 @@ impl From<(&SignedPod, &str)> for OperationArg {
|
|||
))
|
||||
}
|
||||
}
|
||||
impl From<(&MainPod, &str)> for OperationArg {
|
||||
fn from((pod, key): (&MainPod, &str)) -> Self {
|
||||
// TODO: TryFrom.
|
||||
let value = pod
|
||||
.get(key)
|
||||
.unwrap_or_else(|| panic!("Key {} is not present in POD: {}", key, pod));
|
||||
Self::Statement(Statement::ValueOf(
|
||||
AnchoredKey::from((pod.id(), key)),
|
||||
value,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Statement> for OperationArg {
|
||||
fn from(s: Statement) -> Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue