eq_common/
lib.rs

1use alloy::sol;
2use celestia_types::nmt::{Namespace, NamespaceProof};
3use celestia_types::RowProof;
4use serde::{Deserialize, Serialize};
5
6#[cfg(feature = "utils")]
7mod error;
8#[cfg(feature = "utils")]
9pub use error::InclusionServiceError;
10
11#[cfg(feature = "grpc")]
12/// gRPC generated bindings
13pub mod eqs {
14    include!("generated/eqs.rs");
15}
16
17/*
18    The types of proofs we expect to support:
19    1. KeccakInclusionToDataRootProof
20    2. KeccakInclusionToBlockHashProof
21    3. PayyPoseidonToDataRootProof
22    4. PayyPoseidonToBlockHashProof
23*/
24
25#[derive(Serialize, Deserialize, Clone, Debug)]
26pub struct KeccakInclusionToDataRootProofInput {
27    pub data: Vec<u8>,
28    pub namespace_id: Namespace,
29    pub share_proofs: Vec<NamespaceProof>,
30    pub row_proof: RowProof,
31    pub data_root: [u8; 32],
32    pub keccak_hash: [u8; 32],
33}
34
35/// Expecting bytes:
36/// (keccak_hash: [u8; 32], pub data_root: [u8; 32])
37pub type KeccakInclusionToDataRootProofOutput = sol! {
38    tuple(bytes32, bytes32)
39};
40
41#[cfg(test)]
42mod test {
43    use super::*;
44
45    use alloy_primitives::FixedBytes;
46    use alloy_sol_types::{SolType, SolValue};
47
48    #[test]
49    fn test_abi_encoding() {
50        let f: FixedBytes<32> = FixedBytes::from([0; 32]);
51        let output = (
52            FixedBytes::<32>::from([0; 32]),
53            FixedBytes::<32>::from([0; 32]),
54        );
55        let encoded = output.abi_encode();
56        // Interestingly, this line doesn't work
57        // You can't get a KeccakInclusionToDataRootProofOutput by calling KeccakInclusionToDataRootProofOutput::abi_decode
58        // However, we can get a tuple of alloy_primitives::FixedBytes<32>
59        // which is weird but fine
60        /*let decoded: KeccakInclusionToDataRootProofOutput = KeccakInclusionToDataRootProofOutput::abi_decode(&encoded, false)
61        .unwrap();*/
62        let decoded: (FixedBytes<32>, FixedBytes<32>) =
63            KeccakInclusionToDataRootProofOutput::abi_decode(&encoded, true).unwrap();
64        assert_eq!(output, decoded);
65    }
66}