Skip to content

Commit

Permalink
Local devnet: fix block less than 10 (#426)
Browse files Browse the repository at this point in the history
* handle when contract data is None

* handle empty contract_proof

---------

Co-authored-by: Herman Obst Demaestri <[email protected]>
  • Loading branch information
ftheirs and HermanObst authored Dec 27, 2024
1 parent fe27841 commit ba6ac98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 9 additions & 2 deletions crates/bin/prove_block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,15 @@ pub async fn prove_block(
let updated_root = block_hash_storage_proof.class_commitment.unwrap_or(Felt::ZERO);
let previous_root = previous_block_hash_storage_proof.class_commitment.unwrap_or(Felt::ZERO);

let previous_contract_trie_root = previous_block_hash_storage_proof.contract_proof[0].hash::<PedersenHash>();
let current_contract_trie_root = block_hash_storage_proof.contract_proof[0].hash::<PedersenHash>();
// On devnet and until block 10, the storage_root_idx might be None and that means that contract_proof is empty
let previous_contract_trie_root = match previous_block_hash_storage_proof.contract_proof.first() {
Some(proof) => proof.hash::<PedersenHash>(),
None => Felt252::ZERO,
};
let current_contract_trie_root = match block_hash_storage_proof.contract_proof.first() {
Some(proof) => proof.hash::<PedersenHash>(),
None => Felt252::ZERO,
};

let previous_contract_proofs: Vec<_> =
previous_storage_proofs.values().map(|proof| proof.contract_proof.clone()).collect();
Expand Down
9 changes: 6 additions & 3 deletions crates/bin/prove_block/src/reexecute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use blockifier::transaction::objects::TransactionExecutionInfo;
use blockifier::transaction::transaction_execution::Transaction;
use blockifier::transaction::transactions::ExecutableTransaction;
use cairo_vm::Felt252;
use rpc_client::pathfinder::proofs::{PathfinderProof, TrieNode};
use rpc_client::pathfinder::proofs::{ContractData, PathfinderProof, TrieNode};
use rpc_client::RpcClient;
use starknet::core::types::{BlockId, StarknetError};
use starknet::providers::{Provider as _, ProviderError};
Expand Down Expand Up @@ -163,8 +163,11 @@ pub(crate) fn format_commitment_facts<H: HashFunctionType>(
impl PerContractStorage for ProverPerContractStorage {
async fn compute_commitment(&mut self) -> Result<CommitmentInfo, CommitmentInfoError> {
// TODO: error code
let contract_data =
self.storage_proof.contract_data.as_ref().expect("storage proof should have a contract_data field");
let contract_data = match self.storage_proof.contract_data.as_ref() {
None => &ContractData::default(),
Some(data) => data,
};

let updated_root = contract_data.root;

let commitment_facts = format_commitment_facts::<PedersenHash>(&contract_data.storage_proofs);
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-client/src/pathfinder/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TrieNode {
}
}

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Default)]
pub struct ContractData {
/// Root of the Contract state tree
pub root: Felt,
Expand Down Expand Up @@ -75,7 +75,7 @@ impl ContractData {

#[derive(Debug, Clone, Deserialize)]
pub struct PathfinderProof {
pub state_commitment: Felt,
pub state_commitment: Option<Felt>,
pub class_commitment: Option<Felt>,
pub contract_proof: Vec<TrieNode>,
pub contract_data: Option<ContractData>,
Expand Down

0 comments on commit ba6ac98

Please sign in to comment.