Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly handle get_proof for contract without a root index #5

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions crates/merkle-tree/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,8 @@ impl<'tx> ContractsStorageTree<'tx> {
contract: ContractAddress,
block: BlockNumber,
key: &BitSlice<u8, Msb0>,
root: u64,
) -> anyhow::Result<Option<Vec<TrieNode>>> {
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),
Expand Down
41 changes: 25 additions & 16 deletions crates/rpc/src/pathfinder/methods/get_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down