New 'use' syntax with support for intro predicates (#431)

* New 'use' syntax with support for intro predicates

* Use empty statement in test

* Review feedback
This commit is contained in:
Rob Knight 2025-10-17 12:27:11 +02:00 committed by GitHub
parent ffed5b4fbd
commit aa4b531ac7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 118 additions and 13 deletions

View file

@ -34,6 +34,7 @@ mod tests {
middleware::{
CustomPredicate, CustomPredicateBatch, CustomPredicateRef, Key, NativePredicate,
Params, Predicate, RawValue, StatementTmpl, StatementTmplArg, Value, Wildcard,
EMPTY_HASH,
},
};
@ -687,7 +688,7 @@ mod tests {
let batch_id_str = available_batch.id().encode_hex::<String>();
let input = format!(
r#"
use imported_pred from 0x{}
use batch imported_pred from 0x{}
REQUEST(
imported_pred(Pod1, Pod2)
@ -738,7 +739,7 @@ mod tests {
let input = format!(
r#"
use pred_one, _, pred_three from 0x{}
use batch pred_one, _, pred_three from 0x{}
REQUEST(
pred_one(Pod1)
@ -796,7 +797,7 @@ mod tests {
let input = format!(
r#"
use imported_eq from 0x{}
use batch imported_eq from 0x{}
wrapper_pred(X, Y) = AND(
imported_eq(X, Y)
@ -836,6 +837,38 @@ mod tests {
Ok(())
}
#[test]
fn test_e2e_intro_import_parsing() -> Result<(), LangError> {
let params = Params::default();
let intro_hash = EMPTY_HASH.encode_hex::<String>();
let input = format!(
r#"
use intro empty() from 0x{intro_hash}
REQUEST(
empty()
)
"#,
);
let processed = parse(&input, &params, &[])?;
let request_templates = processed.request.templates();
assert_eq!(request_templates.len(), 1);
if let Predicate::Intro(intro_ref) = &request_templates[0].pred {
assert_eq!(intro_ref.name, "empty");
assert_eq!(intro_ref.args_len, 0);
assert_eq!(intro_ref.verifier_data_hash, EMPTY_HASH);
} else {
panic!("Expected Intro predicate");
}
assert!(request_templates[0].args.is_empty());
Ok(())
}
#[test]
fn test_e2e_literals() -> Result<(), LangError> {
let pk = crate::backends::plonky2::primitives::ec::curve::Point::generator();
@ -920,7 +953,7 @@ mod tests {
let input = format!(
r#"
use some_pred from {}
use batch some_pred from {}
"#,
unknown_batch_id
);