delta_local_laws/macros.rs
1/// Define the entrypoint of a local laws proof program.
2///
3/// # Parameters
4///
5/// - `$local_laws`: Path to the local law type to execute. The type must
6/// implement [crate::LocalLaws].
7///
8/// # Requirements
9///
10/// - The `sp1-zkvm` crate must be available in the crate calling this macro.
11///
12/// # Example
13///
14/// The `main.rs` of a local laws proof program:
15/// ```ignore
16/// #![no_main]
17/// use delta_local_laws::example::MinMaxSpendingLocalLaw;
18/// delta_local_laws::entrypoint!(MinMaxSpendingLocalLaw);
19/// ```
20#[macro_export]
21macro_rules! entrypoint {
22 ($local_laws:path $(,)?) => {
23 ::sp1_zkvm::entrypoint!(main);
24
25 fn main() {
26 use ::sp1_zkvm::io::{
27 commit,
28 read,
29 };
30 use ::std::vec::Vec;
31 use $crate::{
32 verifiable::types::{
33 VerifiableWithDiffs,
34 VerificationContext,
35 },
36 LocalLaws,
37 };
38
39 // Read the standard inputs
40 let verifiables = read::<Vec<VerifiableWithDiffs>>();
41 let verification_context = read::<VerificationContext>();
42
43 // Read the custom input of the local laws
44 let input = read();
45
46 // Verify the local laws
47 <$local_laws as LocalLaws>::validate(&verifiables, &verification_context, &input)
48 .expect("The local laws are not satisfied by the verifiables.");
49
50 // Commit standard inputs
51 commit(&verifiables);
52 commit(&verification_context);
53 }
54 };
55}