pessimistic_proof/
proof.rs1#[cfg(any(test, feature = "testutils"))]
2pub use pessimistic_proof_core::proof::zero_if_empty_local_exit_root;
3pub use pessimistic_proof_core::PessimisticProofOutput;
4#[cfg(any(test, feature = "testutils"))]
5use pessimistic_proof_core::{multi_batch_header::MultiBatchHeader, NetworkState};
6use serde::{Deserialize, Serialize};
7#[cfg(any(test, feature = "testutils"))]
8use sp1_sdk::{Prover, ProverClient, SP1Stdin};
9use sp1_sdk::{SP1Proof, SP1ProofWithPublicValues, SP1PublicValues};
10
11#[cfg(any(test, feature = "testutils"))]
12use crate::ELF;
13
14pub trait DisplayToHex {
15 fn display_to_hex(&self) -> String;
16}
17
18impl DisplayToHex for PessimisticProofOutput {
19 fn display_to_hex(&self) -> String {
20 format!(
21 "prev_local_exit_root: {}, prev_pessimistic_root: {}, l1_info_root: {}, \
22 origin_network: {}, aggchain_hash: {}, new_local_exit_root: {}, \
23 new_pessimistic_root: {}",
24 self.prev_local_exit_root,
25 self.prev_pessimistic_root,
26 self.l1_info_root,
27 self.origin_network,
28 self.aggchain_hash,
29 self.new_local_exit_root,
30 self.new_pessimistic_root,
31 )
32 }
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
38pub enum Proof {
39 SP1(SP1ProofWithPublicValues),
40}
41
42impl Proof {
43 pub fn dummy() -> Self {
44 Self::SP1(SP1ProofWithPublicValues {
45 proof: SP1Proof::Core(vec![]),
46 public_values: SP1PublicValues::new(),
47 sp1_version: "".to_string(),
48 tee_proof: None,
49 })
50 }
51
52 #[cfg(any(test, feature = "testutils"))]
53 pub fn new_for_test(state: &NetworkState, multi_batch_header: &MultiBatchHeader) -> Self {
54 let mock = ProverClient::builder().mock().build();
55 let (p, _v) = mock.setup(ELF);
56
57 let mut stdin = SP1Stdin::new();
58 stdin.write(state);
59 stdin.write(multi_batch_header);
60
61 let proof = mock.prove(&p, &stdin).plonk().run().unwrap();
62
63 Proof::SP1(proof)
64 }
65}
66
67#[cfg(test)]
68mod tests {
69 use agglayer_tries::roots::LocalExitRoot;
70 use pessimistic_proof_core::{
71 keccak::keccak256_combine,
72 proof::{EMPTY_LER, EMPTY_PP_ROOT_V2},
73 };
74
75 use crate::local_state::LocalNetworkState;
76
77 #[test]
78 fn empty_tree_roots() {
79 let empty_state = LocalNetworkState::default();
80
81 let ler = LocalExitRoot::new(empty_state.exit_tree.get_root());
82 let ppr = keccak256_combine([
83 empty_state.balance_tree.root.as_slice(),
84 empty_state.nullifier_tree.root.as_slice(),
85 empty_state.exit_tree.leaf_count().to_le_bytes().as_slice(),
86 ]);
87
88 assert_eq!(EMPTY_LER, ler);
89 assert_eq!(EMPTY_PP_ROOT_V2, ppr);
90 }
91}