-
Notifications
You must be signed in to change notification settings - Fork 81
use a partial SMT to represent storage entries in accounts query #1167
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
Changes from all commits
0afaa48
1055f2a
3b25e65
9e9d59b
d18ac8e
76ce57f
b64093a
c5016c9
bb8a79a
4a469d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ use miden_objects::account::{ | |
| AccountStorageHeader, | ||
| }; | ||
| use miden_objects::block::{AccountWitness, BlockNumber}; | ||
| use miden_objects::crypto::merkle::{MerklePath, SmtProof}; | ||
| use miden_objects::crypto::merkle::{MerklePath, PartialSmt}; | ||
| use miden_tx::utils::{Deserializable, Serializable, ToHex}; | ||
| use thiserror::Error; | ||
|
|
||
|
|
@@ -175,16 +175,18 @@ impl proto::rpc_store::account_proofs::account_proof::AccountStateHeader { | |
| account_id: AccountId, | ||
| known_account_codes: &BTreeMap<Word, AccountCode>, | ||
| ) -> Result<StateHeaders, crate::rpc::RpcError> { | ||
| use miden_objects::crypto::merkle::PartialSmt; | ||
|
|
||
| use crate::rpc::RpcError; | ||
| use crate::rpc::domain::MissingFieldHelper; | ||
| use crate::rpc::generated::rpc_store::account_proofs::account_proof::account_state_header::StorageSlotMapProof; | ||
|
|
||
| let proto::rpc_store::account_proofs::account_proof::AccountStateHeader { | ||
| header, | ||
| storage_header, | ||
| account_code, | ||
| storage_maps, | ||
| partial_storage_smts, | ||
| } = self; | ||
|
|
||
| let account_header = header | ||
| .ok_or( | ||
| proto::rpc_store::account_proofs::account_proof::AccountStateHeader::missing_field( | ||
|
|
@@ -213,28 +215,28 @@ impl proto::rpc_store::account_proofs::account_proof::AccountStateHeader { | |
| } | ||
| }; | ||
|
|
||
| // Get map values into slot |-> (key, value, proof) mapping | ||
| let mut storage_slot_proofs: BTreeMap<u8, Vec<SmtProof>> = BTreeMap::new(); | ||
| for StorageSlotMapProof { storage_slot, smt_proof } in storage_maps { | ||
| let proof = SmtProof::read_from_bytes(&smt_proof)?; | ||
| match storage_slot_proofs | ||
| .get_mut(&(u8::try_from(storage_slot).expect("there are no more than 256 slots"))) | ||
| { | ||
| Some(list) => list.push(proof), | ||
| None => { | ||
| _ = storage_slot_proofs.insert( | ||
| u8::try_from(storage_slot).expect("only 256 storage slots"), | ||
| vec![proof], | ||
| ); | ||
| }, | ||
| let partial_storage_smts = Result::<BTreeMap<u8, PartialSmt>, _>::from_iter( | ||
| partial_storage_smts.into_iter().map(|entry| { | ||
| let slot = u8::try_from(entry.storage_slot) | ||
| .map_err(crate::rpc::RpcError::SlotOutOfBounds)?; | ||
| let partial_smt = PartialSmt::read_from_bytes(&entry.partial_smt)?; | ||
| Ok::<_, crate::rpc::RpcError>((slot, partial_smt)) | ||
| }), | ||
| )?; | ||
|
|
||
| partial_storage_smts.iter().try_for_each(|(_slot, partial_smt)| { | ||
| for (key, _value) in partial_smt.entries() { | ||
| // validate all required inner nodes of the merkle path for the specific leaf exist | ||
| let _proof = partial_smt.open(key)?; | ||
| } | ||
| } | ||
| Ok::<_, crate::rpc::RpcError>(()) | ||
| })?; | ||
|
Comment on lines
+227
to
+233
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? Checking the internal logic of |
||
|
|
||
| Ok(StateHeaders { | ||
| account_header, | ||
| storage_header, | ||
| code, | ||
| storage_slots: storage_slot_proofs, | ||
| storage_slots: partial_storage_smts, | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -252,7 +254,7 @@ pub struct StateHeaders { | |
| pub account_header: AccountHeader, | ||
| pub storage_header: AccountStorageHeader, | ||
| pub code: AccountCode, | ||
| pub storage_slots: BTreeMap<StorageSlotIndex, Vec<SmtProof>>, | ||
| pub storage_slots: BTreeMap<StorageSlotIndex, PartialSmt>, | ||
| } | ||
|
|
||
| /// Represents a proof of existence of an account's state at a specific block number. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.