Skip to content

Commit a054a03

Browse files
authored
Merge pull request #2452 from eqlabs/sistemd/remove-storage-class-commitment
refactor(common): remove `storage_commitment` and `class_commitment` from `BlockHeader`
2 parents 2097a13 + b07d337 commit a054a03

File tree

26 files changed

+77
-210
lines changed

26 files changed

+77
-210
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## Unreleased
1111

12+
### Removed
13+
14+
- `storage_commitment` and `class_commitment` fields from the `pathfinder_subscribe_newHeads` method response.
15+
- `class_commitment` from the `pathfinder_getProof` and `pathfinder_getClassProof` method responses.
16+
1217
### Fixed
1318

1419
- `pathfinder_getProof`, `pathfinder_getClassProof` return `ProofMissing` (10001) when Pathfinder is in `archive` mode and queried block's tries are empty.

crates/common/src/header.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ pub struct BlockHeader {
1717
pub strk_l2_gas_price: GasPrice,
1818
pub sequencer_address: SequencerAddress,
1919
pub starknet_version: StarknetVersion,
20-
pub class_commitment: ClassCommitment,
2120
pub event_commitment: EventCommitment,
2221
pub state_commitment: StateCommitment,
23-
pub storage_commitment: StorageCommitment,
2422
pub transaction_commitment: TransactionCommitment,
2523
pub transaction_count: usize,
2624
pub event_count: usize,
@@ -88,11 +86,14 @@ impl BlockHeaderBuilder {
8886
self
8987
}
9088

91-
/// Sets the [StateCommitment] by calculating its value from the current
89+
/// Sets the [StateCommitment] by calculating its value from the passed
9290
/// [StorageCommitment] and [ClassCommitment].
93-
pub fn calculated_state_commitment(mut self) -> Self {
94-
self.0.state_commitment =
95-
StateCommitment::calculate(self.0.storage_commitment, self.0.class_commitment);
91+
pub fn calculated_state_commitment(
92+
mut self,
93+
storage_commitment: StorageCommitment,
94+
class_commitment: ClassCommitment,
95+
) -> Self {
96+
self.0.state_commitment = StateCommitment::calculate(storage_commitment, class_commitment);
9697
self
9798
}
9899

@@ -146,16 +147,6 @@ impl BlockHeaderBuilder {
146147
self
147148
}
148149

149-
pub fn storage_commitment(mut self, storage_commitment: StorageCommitment) -> Self {
150-
self.0.storage_commitment = storage_commitment;
151-
self
152-
}
153-
154-
pub fn class_commitment(mut self, class_commitment: ClassCommitment) -> Self {
155-
self.0.class_commitment = class_commitment;
156-
self
157-
}
158-
159150
pub fn starknet_version(mut self, starknet_version: StarknetVersion) -> Self {
160151
self.0.starknet_version = starknet_version;
161152
self

crates/p2p/src/client/peer_agnostic/fixtures.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ pub fn hdr(tag: i32) -> SignedBlockHeader {
149149
Tagged::get(format!("header {tag}"), || SignedBlockHeader {
150150
header: BlockHeader {
151151
number: BlockNumber::new_or_panic(tag as u64),
152-
// TODO Set storage and class commitment
153-
storage_commitment: Default::default(),
154-
class_commitment: Default::default(),
155152
..Faker.fake()
156153
},
157154
..Faker.fake()

crates/p2p/src/client/types.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use pathfinder_common::{
1111
BlockHeader,
1212
BlockNumber,
1313
BlockTimestamp,
14-
ClassCommitment,
1514
ClassHash,
1615
EventCommitment,
1716
Fee,
@@ -22,7 +21,6 @@ use pathfinder_common::{
2221
SignedBlockHeader,
2322
StateCommitment,
2423
StateDiffCommitment,
25-
StorageCommitment,
2624
TransactionCommitment,
2725
TransactionHash,
2826
TransactionIndex,
@@ -118,8 +116,6 @@ impl TryFromDto<p2p_proto::header::SignedBlockHeader> for SignedBlockHeader {
118116
l1_da_mode: TryFromDto::try_from_dto(dto.l1_data_availability_mode)?,
119117
state_diff_commitment: StateDiffCommitment(dto.state_diff_commitment.root.0),
120118
state_diff_length: dto.state_diff_commitment.state_diff_length,
121-
class_commitment: ClassCommitment::ZERO,
122-
storage_commitment: StorageCommitment::ZERO,
123119
},
124120
signature,
125121
})

crates/pathfinder/examples/compute_pre0132_hashes.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use pathfinder_common::{
88
ReceiptCommitment,
99
StarknetVersion,
1010
StateCommitment,
11-
StorageCommitment,
1211
};
1312
use pathfinder_lib::state::block_hash::{
1413
calculate_event_commitment,
@@ -119,10 +118,6 @@ fn main() -> anyhow::Result<()> {
119118
header.state_commitment != StateCommitment::ZERO,
120119
"state_commitment missing"
121120
);
122-
ensure!(
123-
header.storage_commitment != StorageCommitment::ZERO,
124-
"storage_commitment missing"
125-
);
126121

127122
// Compute the block hash in the 0.13.2 style
128123
let header_data = get_header_data(&header);

crates/pathfinder/src/p2p_network/sync_handlers/tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ mod prop {
185185
let expected = overlapping::get(in_db, start_block, limit, step, num_blocks, direction)
186186
.into_iter().map(|Block { header, .. }| pathfinder_common::SignedBlockHeader {
187187
header: pathfinder_common::BlockHeader {
188-
// TODO Set the storage and class commitment
189-
storage_commitment: Default::default(),
190-
class_commitment: Default::default(),
191188
..header.header
192189
},
193190
signature: header.signature,

crates/pathfinder/src/state/sync.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,10 +912,8 @@ async fn l2_update(
912912
.sequencer_address
913913
.unwrap_or(SequencerAddress(Felt::ZERO)),
914914
starknet_version: block.starknet_version,
915-
class_commitment,
916915
event_commitment,
917916
state_commitment,
918-
storage_commitment,
919917
transaction_commitment,
920918
transaction_count,
921919
event_count,

crates/pathfinder/src/state/sync/revert.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use pathfinder_common::{
44
BlockNumber,
55
ClassCommitment,
66
ClassCommitmentLeafHash,
7+
StateCommitment,
78
StorageCommitment,
89
};
910
use pathfinder_merkle_tree::{ClassCommitmentTree, StorageCommitmentTree};
@@ -37,31 +38,30 @@ pub fn revert_starknet_state(
3738
target_block: BlockNumber,
3839
target_header: BlockHeader,
3940
) -> Result<(), anyhow::Error> {
40-
revert_contract_updates(
41-
transaction,
42-
head,
43-
target_block,
44-
target_header.storage_commitment,
45-
)?;
46-
revert_class_updates(
47-
transaction,
48-
head,
49-
target_block,
50-
target_header.class_commitment,
51-
)?;
41+
let storage_commitment = revert_contract_updates(transaction, head, target_block)?;
42+
let class_commitment = revert_class_updates(transaction, head, target_block)?;
43+
44+
let state_commitment = StateCommitment::calculate(storage_commitment, class_commitment);
45+
if state_commitment != target_header.state_commitment {
46+
anyhow::bail!(
47+
"State commitment mismatch: expected {}, calculated {}",
48+
target_header.state_commitment,
49+
state_commitment,
50+
);
51+
}
52+
5253
transaction.coalesce_trie_removals(target_block)
5354
}
5455

5556
/// Revert all contract/global storage trie updates.
5657
///
5758
/// Fetches reverse updates from the database and updates all tries, returning
58-
/// the storage commitment and the storage root node index.
59+
/// the [`StorageCommitment`].
5960
fn revert_contract_updates(
6061
transaction: &Transaction<'_>,
6162
head: BlockNumber,
6263
target_block: BlockNumber,
63-
expected_storage_commitment: StorageCommitment,
64-
) -> anyhow::Result<()> {
64+
) -> anyhow::Result<StorageCommitment> {
6565
let updates = transaction.reverse_contract_updates(head, target_block)?;
6666

6767
let mut global_tree =
@@ -91,14 +91,6 @@ fn revert_contract_updates(
9191
.commit()
9292
.context("Committing global state tree")?;
9393

94-
if expected_storage_commitment != storage_commitment {
95-
anyhow::bail!(
96-
"Storage commitment mismatch: expected {}, calculated {}",
97-
expected_storage_commitment,
98-
storage_commitment
99-
);
100-
}
101-
10294
let root_idx = transaction
10395
.insert_storage_trie(&trie_update, target_block)
10496
.context("Persisting storage trie")?;
@@ -108,16 +100,18 @@ fn revert_contract_updates(
108100
.context("Inserting storage root index")?;
109101
tracing::debug!(%target_block, %storage_commitment, "Committed global state tree");
110102

111-
Ok(())
103+
Ok(storage_commitment)
112104
}
113105

114106
/// Revert all class trie updates.
107+
///
108+
/// Fetches reverse updates from the database and updates all tries, returning
109+
/// the [`ClassCommitment`].
115110
fn revert_class_updates(
116111
transaction: &Transaction<'_>,
117112
head: BlockNumber,
118113
target_block: BlockNumber,
119-
expected_class_commitment: ClassCommitment,
120-
) -> anyhow::Result<()> {
114+
) -> anyhow::Result<ClassCommitment> {
121115
let updates = transaction.reverse_sierra_class_updates(head, target_block)?;
122116

123117
let mut class_tree =
@@ -143,14 +137,6 @@ fn revert_class_updates(
143137

144138
let (class_commitment, trie_update) = class_tree.commit().context("Committing class trie")?;
145139

146-
if expected_class_commitment != class_commitment {
147-
anyhow::bail!(
148-
"Storage commitment mismatch: expected {}, calculated {}",
149-
expected_class_commitment,
150-
class_commitment
151-
);
152-
}
153-
154140
let root_idx = transaction
155141
.insert_class_trie(&trie_update, target_block)
156142
.context("Persisting class trie")?;
@@ -161,5 +147,5 @@ fn revert_class_updates(
161147

162148
tracing::debug!(%target_block, %class_commitment, "Committed class trie");
163149

164-
Ok(())
150+
Ok(class_commitment)
165151
}

crates/pathfinder/src/sync/checkpoint.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,6 @@ mod tests {
785785
eth_l2_gas_price: GasPrice(0),
786786
strk_l2_gas_price: GasPrice(0),
787787
l1_da_mode: L1DataAvailabilityMode::Calldata,
788-
class_commitment: ClassCommitment::ZERO,
789-
storage_commitment: StorageCommitment::ZERO,
790788
},
791789
signature: BlockCommitmentSignature {
792790
r: dto.signature[0],

crates/pathfinder/src/sync/state_updates.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,6 @@ pub async fn batch_update_starknet_state(
303303
"State root mismatch");
304304
return Err(SyncError::StateRootMismatch(peer));
305305
}
306-
db.update_storage_and_class_commitments(tail, storage_commitment, class_commitment)
307-
.context("Updating storage and class commitments")?;
308306
db.commit().context("Committing db transaction")?;
309307

310308
Ok(PeerData::new(peer, tail))

0 commit comments

Comments
 (0)