Skip to content

Commit

Permalink
Merge pull request #2485 from eqlabs/chris/storage_root
Browse files Browse the repository at this point in the history
feat: add storage_root in starknet_getStorageProof
  • Loading branch information
CHr15F0x authored Jan 14, 2025
2 parents 98aa806 + ea13cbc commit e3c7647
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Graceful shutdown upon SIGINT and SIGTERM with a default grace period of 10 seconds, configurable via `--shutdown.grace-period`.
- `storage_root` along `nonce` and `class_hash` in `contracts_proof/contract_leaves_data` for `starknet_getStorageProof`.

### Removed

Expand Down
22 changes: 18 additions & 4 deletions crates/rpc/src/method/get_storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use pathfinder_common::{
ClassHash,
ContractAddress,
ContractNonce,
ContractRoot,
StorageAddress,
};
use pathfinder_crypto::Felt;
Expand Down Expand Up @@ -172,6 +173,7 @@ impl SerializeForVersion for &NodeHashToNodeMappings {
struct ContractLeafData {
nonce: ContractNonce,
class_hash: ClassHash,
storage_root: ContractRoot,
}

impl SerializeForVersion for &ContractLeafData {
Expand All @@ -182,6 +184,7 @@ impl SerializeForVersion for &ContractLeafData {
let mut s = serializer.serialize_struct()?;
s.serialize_field("nonce", &self.nonce)?;
s.serialize_field("class_hash", &self.class_hash)?;
s.serialize_field("storage_root", &self.storage_root)?;
s.end()
}
}
Expand Down Expand Up @@ -439,7 +442,16 @@ fn get_contract_proofs(
.context("Querying contract's nonce")?
.unwrap_or_default();

Ok(ContractLeafData { nonce, class_hash })
let storage_root = tx
.contract_root(block_number, address)
.context("Querying contract's storage root")?
.unwrap_or_default();

Ok(ContractLeafData {
nonce,
class_hash,
storage_root,
})
})
.collect::<Result<Vec<_>, Error>>()?;
Ok((
Expand Down Expand Up @@ -670,6 +682,7 @@ mod tests {
contract_leaves_data: vec![ContractLeafData {
nonce: ContractNonce::ZERO,
class_hash: ClassHash(Felt::from_hex_str("0x123").unwrap()),
storage_root: ContractRoot(Felt::from_hex_str("0x234").unwrap()),
}],
},
contracts_storage_proofs: vec![NodeHashToNodeMappings(vec![NodeHashToNodeMapping {
Expand Down Expand Up @@ -702,14 +715,15 @@ mod tests {
"node": {
"child": "0x123",
"length": 8,
"path": "0x0",
"path": "0x0"
}
}
],
"contract_leaves_data": [
{
"nonce": "0x0",
"class_hash": "0x123"
"class_hash": "0x123",
"storage_root": "0x234"
}
]
},
Expand All @@ -734,7 +748,7 @@ mod tests {
fn serialization_output(#[case] output: Output, #[case] expected: serde_json::Value) {
let output = output.serialize(crate::dto::Serializer::default()).unwrap();

assert_eq!(output, expected);
pretty_assertions_sorted::assert_eq!(output, expected);
}
}

Expand Down
5 changes: 4 additions & 1 deletion doc/rpc/v08/starknet_api_openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,9 @@
},
"class_hash": {
"$ref": "#/components/schemas/FELT"
},
"storage_root": {
"$ref": "#/components/schemas/FELT"
}
},
"required": ["nonce", "class_hash"]
Expand Down Expand Up @@ -3877,4 +3880,4 @@
}
}
}
}
}

0 comments on commit e3c7647

Please sign in to comment.