Remove output statement logic in middleware (#199)
This commit is contained in:
parent
c232c8dae5
commit
0b5d4dd802
1 changed files with 0 additions and 174 deletions
|
|
@ -262,180 +262,6 @@ impl Operation {
|
|||
OperationType::Custom(cpr) => Self::Custom(cpr, args.to_vec()),
|
||||
})
|
||||
}
|
||||
/// Gives the output statement of the given operation, where determined
|
||||
/// A ValueOf statement is not determined by the NewEntry operation, so returns Ok(None)
|
||||
/// The outer Result is error handling
|
||||
pub fn output_statement(&self) -> Result<Option<Statement>> {
|
||||
use Statement::*;
|
||||
let pred: Option<Predicate> = self.op_type().output_predicate();
|
||||
|
||||
let st_args: Option<Vec<StatementArg>> = match self {
|
||||
Self::None => Some(vec![]),
|
||||
Self::NewEntry => Option::None,
|
||||
Self::CopyStatement(s1) => Some(s1.args()),
|
||||
Self::EqualFromEntries(ValueOf(ak1, v1), ValueOf(ak2, v2)) => {
|
||||
if v1 == v2 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::EqualFromEntries(_, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::NotEqualFromEntries(ValueOf(ak1, v1), ValueOf(ak2, v2)) => {
|
||||
if v1 != v2 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::NotEqualFromEntries(_, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::GtFromEntries(ValueOf(ak1, v1), ValueOf(ak2, v2)) => {
|
||||
if v1 > v2 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::GtFromEntries(_, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::LtFromEntries(ValueOf(ak1, v1), ValueOf(ak2, v2)) => {
|
||||
if v1 < v2 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::LtFromEntries(_, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::TransitiveEqualFromStatements(Equal(ak1, ak2), Equal(ak3, ak4)) => {
|
||||
if ak2 == ak3 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak4.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::TransitiveEqualFromStatements(_, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::GtToNotEqual(Gt(ak1, ak2)) => Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
]),
|
||||
Self::GtToNotEqual(_) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::LtToNotEqual(Gt(ak1, ak2)) => Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
]),
|
||||
Self::LtToNotEqual(_) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::ContainsFromEntries(ValueOf(ak1, v1), ValueOf(ak2, v2), ValueOf(ak3, v3), pf)
|
||||
if MerkleTree::verify(pf.siblings.len(), v1.into(), pf, &v2.raw(), &v3.raw())
|
||||
.is_ok() =>
|
||||
{
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
StatementArg::Key(ak3.clone()),
|
||||
])
|
||||
}
|
||||
Self::ContainsFromEntries(_, _, _, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::NotContainsFromEntries(ValueOf(ak1, v1), ValueOf(ak2, v2), pf)
|
||||
if MerkleTree::verify_nonexistence(pf.siblings.len(), v1.into(), pf, &v2.raw())
|
||||
.is_ok() =>
|
||||
{
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
])
|
||||
}
|
||||
Self::NotContainsFromEntries(_, _, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::SumOf(ValueOf(ak1, v1), ValueOf(ak2, v2), ValueOf(ak3, v3)) => {
|
||||
let v1: i64 = v1.typed().try_into()?;
|
||||
let v2: i64 = v2.typed().try_into()?;
|
||||
let v3: i64 = v3.typed().try_into()?;
|
||||
if v1 == v2 + v3 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
StatementArg::Key(ak3.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::SumOf(_, _, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::ProductOf(ValueOf(ak1, v1), ValueOf(ak2, v2), ValueOf(ak3, v3)) => {
|
||||
let v1: i64 = v1.typed().try_into()?;
|
||||
let v2: i64 = v2.typed().try_into()?;
|
||||
let v3: i64 = v3.typed().try_into()?;
|
||||
if v1 == v2 * v3 {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
StatementArg::Key(ak3.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::ProductOf(_, _, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::MaxOf(ValueOf(ak1, v1), ValueOf(ak2, v2), ValueOf(ak3, v3)) => {
|
||||
let v1: i64 = v1.typed().try_into()?;
|
||||
let v2: i64 = v2.typed().try_into()?;
|
||||
let v3: i64 = v3.typed().try_into()?;
|
||||
if v1 == std::cmp::max(v2, v3) {
|
||||
Some(vec![
|
||||
StatementArg::Key(ak1.clone()),
|
||||
StatementArg::Key(ak2.clone()),
|
||||
StatementArg::Key(ak3.clone()),
|
||||
])
|
||||
} else {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
}
|
||||
Self::MaxOf(_, _, _) => {
|
||||
return Err(anyhow!("Invalid operation"));
|
||||
}
|
||||
Self::Custom(_, _) => todo!(),
|
||||
};
|
||||
|
||||
let x: Option<Result<Statement>> = pred
|
||||
.zip(st_args)
|
||||
.map(|(pred, st_args)| Statement::from_args(pred, st_args));
|
||||
x.transpose()
|
||||
}
|
||||
/// Checks the given operation against a statement, and prints information if the check does not pass
|
||||
pub fn check_and_log(&self, params: &Params, output_statement: &Statement) -> Result<bool> {
|
||||
let valid: bool = self.check(params, output_statement)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue