Feat/fst order pred part1 & part2 (#454)
Implement support for first order predicates in the backend. Now a statement template can have a predicate hash or a wildcard. ## predicate <-> predicate hash constraints To build the custom predicate table we need to calculate the custom predicate batch id, which uses the serialization of the statement templates before normalization. This serialization uses the predicate hash when the template uses a predicate (instead of a wildcard). Then in normalization we recalculate the predicate hash if it was a Batch Self. This means that the relation between hash and predicate must be checked before and after normalization when the template is not using a wildcard. How this is achieved: - Before normalization: the constructor of StatementTmplTarget forces that if we keep a predicate, it's hash must be equal to the pred_hash when the template has a predicate (and not a wildcard) - After normalization: the predicate hash is calculated in the normalization and replaced in the case of the template using a predicate and it being a BatchSelf. If it was a predicate but not batch self, the old value was used which was constrained via the constructor. See `CircuitBuilder::add_virtual_statement_tmpl` and `normalize_st_tmpl_circuit` ## Wildcard predicate resolution It is done via `make_predicate_from_template_circuit` and is fairly simple as it's contains similar logic to `make_statement_arg_from_template_circuit` but simpler.
This commit is contained in:
parent
1724e7b146
commit
9c9a2c454c
11 changed files with 569 additions and 240 deletions
|
|
@ -29,6 +29,8 @@ pub enum MiddlewareInnerError {
|
|||
MismatchedStatementTmplArg(StatementTmplArg, StatementArg),
|
||||
#[error("Expected a statement of type {0}, got {1}")]
|
||||
MismatchedStatementType(Predicate, Predicate),
|
||||
#[error("Expected a statement with hash(predicate) {0}, got {1} ({2})")]
|
||||
MismatchedStatementWildcardPredicate(Value, Value, Predicate),
|
||||
#[error("Value {0} does not match argument {1} with index {2} in the following custom predicate:\n{3}")]
|
||||
MismatchedWildcardValueAndStatementArg(Value, Value, usize, CustomPredicate),
|
||||
#[error(
|
||||
|
|
@ -111,6 +113,15 @@ impl Error {
|
|||
pub(crate) fn mismatched_statement_type(expected: Predicate, seen: Predicate) -> Self {
|
||||
new!(MismatchedStatementType(expected, seen))
|
||||
}
|
||||
pub(crate) fn mismatched_statement_wc_pred(
|
||||
expected: Value,
|
||||
seen: Value,
|
||||
seen_pred: Predicate,
|
||||
) -> Self {
|
||||
new!(MismatchedStatementWildcardPredicate(
|
||||
expected, seen, seen_pred
|
||||
))
|
||||
}
|
||||
pub(crate) fn mismatched_wildcard_value_and_statement_arg(
|
||||
wc_value: Value,
|
||||
st_arg: Value,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue