13
13
// limitations under the License.
14
14
15
15
use alloy:: {
16
- hex:: FromHex ,
17
- network:: EthereumWallet ,
18
- node_bindings:: Anvil ,
19
- primitives:: { FixedBytes , U256 } ,
20
- providers:: ProviderBuilder ,
16
+ network:: EthereumWallet , node_bindings:: Anvil , primitives:: U256 , providers:: ProviderBuilder ,
21
17
signers:: local:: PrivateKeySigner ,
22
18
} ;
23
19
use alloy_sol_types:: sol;
@@ -27,7 +23,7 @@ use reqwest::header;
27
23
use serde:: { Deserialize , Serialize } ;
28
24
use serde_with:: { base64:: Base64 , serde_as, DisplayFromStr } ;
29
25
use std:: sync:: Arc ;
30
- use tendermint_rpc:: HttpClient ;
26
+ use tendermint_rpc:: { Client , HttpClient } ;
31
27
32
28
sol ! (
33
29
#[ sol( rpc) ]
37
33
38
34
const CELESTIA_RPC_URL : & str = "https://celestia-testnet.brightlystake.com" ;
39
35
40
- const BATCH_START : u64 = 10 ;
41
- const BATCH_END : u64 = 42 ;
42
- const PROOF_HEIGHT : u64 = 15 ;
36
+ const BATCH_START : u32 = 2768370 ;
37
+ const BATCH_END : u32 = 2768400 ;
38
+ const PROOF_HEIGHT : u32 = 2768375 ;
43
39
44
40
/// Type matches Celestia API endpoint for generating proof.
45
41
/// https://docs.celestia.org/developers/blobstream-proof-queries#_1-data-root-inclusion-proof
@@ -78,27 +74,34 @@ async fn e2e_basic_range() -> anyhow::Result<()> {
78
74
79
75
let verifier = MockVerifier :: deploy ( & provider, [ 0 , 0 , 0 , 0 ] . into ( ) ) . await ?;
80
76
77
+ let tm_client = Arc :: new ( HttpClient :: new ( CELESTIA_RPC_URL ) ?) ;
78
+ let trusted_block_hash = tm_client
79
+ . header ( BATCH_START - 1 )
80
+ . await ?
81
+ . header
82
+ . hash ( )
83
+ . as_bytes ( )
84
+ . try_into ( )
85
+ . unwrap ( ) ;
86
+
81
87
// Deploy the contract.
82
88
let contract = IBlobstream :: deploy (
83
89
& provider,
84
90
anvil. addresses ( ) [ 0 ] ,
85
91
verifier. address ( ) . clone ( ) ,
86
92
// Uses Celestia block hash at height below proving range on Mocha
87
- FixedBytes :: < 32 > :: from_hex (
88
- "5C5451567973D8658A607D58F035BA9078291E33D880A0E6E67145C717E6B11B" ,
89
- ) ?,
90
- BATCH_START - 1 ,
93
+ trusted_block_hash,
94
+ BATCH_START as u64 - 1 ,
91
95
)
92
96
. await ?;
93
97
94
- let client = Arc :: new ( HttpClient :: new ( CELESTIA_RPC_URL ) ?) ;
95
-
96
- let receipt = prove_block_range ( client, BATCH_START ..BATCH_END ) . await ?;
98
+ let receipt =
99
+ prove_block_range ( tm_client. clone ( ) , BATCH_START as u64 ..BATCH_END as u64 ) . await ?;
97
100
98
101
post_batch ( & contract, & receipt) . await ?;
99
102
100
103
let height = contract. latestHeight ( ) . call ( ) . await ?;
101
- assert_eq ! ( height. _0, BATCH_END - 1 ) ;
104
+ assert_eq ! ( height. _0, BATCH_END as u64 - 1 ) ;
102
105
103
106
// Somewhat hacky to do this manually, seems no Rust tooling for this endpoint.
104
107
let http_client = reqwest:: Client :: new ( ) ;
@@ -115,16 +118,23 @@ async fn e2e_basic_range() -> anyhow::Result<()> {
115
118
let response: DataRootInclusionResponse =
116
119
serde_json:: from_value ( response[ "result" ] [ "proof" ] . clone ( ) ) ?;
117
120
121
+ let proof_data_root = tm_client
122
+ . header ( PROOF_HEIGHT )
123
+ . await ?
124
+ . header
125
+ . data_hash
126
+ . unwrap ( )
127
+ . as_bytes ( )
128
+ . try_into ( )
129
+ . unwrap ( ) ;
118
130
// Validate data root inclusion.
119
131
let is_valid = contract
120
132
. verifyAttestation (
121
133
U256 :: from ( 1 ) ,
122
134
DataRootTuple {
123
135
height : U256 :: from ( PROOF_HEIGHT ) ,
124
136
// TODO this is fixed from on chain, but could be pulled from node to be dynamic
125
- dataRoot : FixedBytes :: < 32 > :: from_hex (
126
- "3D96B7D238E7E0456F6AF8E7CDF0A67BD6CF9C2089ECB559C659DCAA1F880353" ,
127
- ) ?,
137
+ dataRoot : proof_data_root,
128
138
} ,
129
139
BinaryMerkleProof {
130
140
sideNodes : response
0 commit comments