allow SELF in st_tmpl (#240)

* allow SELF in st_tmpl

* add some tests

* 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:
Eduard S. 2025-05-22 15:13:02 +02:00 committed by GitHub
parent b4a4c72328
commit 82481e88d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 178 additions and 87 deletions

View file

@ -8,8 +8,8 @@ use crate::{
backends::plonky2::primitives::merkletree::MerkleProof,
middleware::{
custom::KeyOrWildcard, AnchoredKey, CustomPredicate, CustomPredicateRef, Error,
NativePredicate, Params, Predicate, Result, Statement, StatementArg, StatementTmplArg,
ToFields, Wildcard, WildcardValue, F, SELF,
NativePredicate, Params, Predicate, Result, SelfOrWildcard, Statement, StatementArg,
StatementTmplArg, ToFields, Wildcard, WildcardValue, F, SELF,
},
};
@ -363,10 +363,15 @@ pub fn check_st_tmpl(
(StatementTmplArg::None, StatementArg::None) => true,
(StatementTmplArg::Literal(lhs), StatementArg::Literal(rhs)) if lhs == rhs => true,
(
StatementTmplArg::AnchoredKey(pod_id_wc, key_or_wc),
StatementTmplArg::AnchoredKey(self_or_wc, key_or_wc),
StatementArg::Key(AnchoredKey { pod_id, key }),
) => {
let pod_id_ok = check_or_set(WildcardValue::PodId(*pod_id), pod_id_wc, wildcard_map);
let pod_id_ok = match self_or_wc {
SelfOrWildcard::SELF => SELF == *pod_id,
SelfOrWildcard::Wildcard(pod_id_wc) => {
check_or_set(WildcardValue::PodId(*pod_id), pod_id_wc, wildcard_map)
}
};
let key_ok = match key_or_wc {
KeyOrWildcard::Key(tmpl_key) => tmpl_key == key,
KeyOrWildcard::Wildcard(key_wc) => {