diff --git a/crates/merkle-tree/src/contract.rs b/crates/merkle-tree/src/contract.rs index 638cb4327c..a07a8561b8 100644 --- a/crates/merkle-tree/src/contract.rs +++ b/crates/merkle-tree/src/contract.rs @@ -83,15 +83,8 @@ impl<'tx> ContractsStorageTree<'tx> { contract: ContractAddress, block: BlockNumber, key: &BitSlice, + root: u64, ) -> anyhow::Result>> { - let root = tx - .contract_root_index(block, contract) - .context("Querying contract root index")?; - - let Some(root) = root else { - return Ok(None); - }; - let storage = ContractStorage { tx, block: Some(block), diff --git a/crates/rpc/src/pathfinder/methods/get_proof.rs b/crates/rpc/src/pathfinder/methods/get_proof.rs index 96295d3fb6..f7c1388f8b 100644 --- a/crates/rpc/src/pathfinder/methods/get_proof.rs +++ b/crates/rpc/src/pathfinder/methods/get_proof.rs @@ -280,24 +280,33 @@ pub async fn get_proof( .context("Querying contract's nonce")? .unwrap_or_default(); + let root = tx + .contract_root_index(header.number, input.contract_address) + .context("Querying contract root index")?; + let mut storage_proofs = Vec::new(); for k in &input.keys { - let proof = ContractsStorageTree::get_proof( - &tx, - input.contract_address, - header.number, - k.view_bits(), - ) - .context("Get proof from contract state tree")? - .ok_or_else(|| { - let e = anyhow!( - "Storage proof missing for key {:?}, but should be present", - k - ); - tracing::warn!("{e}"); - e - })?; - storage_proofs.push(ProofNodes(proof)); + if let Some(root) = root { + let proof = ContractsStorageTree::get_proof( + &tx, + input.contract_address, + header.number, + k.view_bits(), + root, + ) + .context("Get proof from contract state tree")? + .ok_or_else(|| { + let e = anyhow!( + "Storage proof missing for key {:?}, but should be present", + k + ); + tracing::warn!("{e}"); + e + })?; + storage_proofs.push(ProofNodes(proof)); + } else { + storage_proofs.push(ProofNodes(vec![])); + } } let contract_data = ContractData {