Skip to content

Commit be53db8

Browse files
authored
chore!: use standard serialization order for public data hash inputs (#20291)
We normally use `hash(T::serialize())` to compute the hash of T. This pr updates the hash of `PublicDataLeafPreimage` to follow the same approach.
2 parents d8fecc4 + 46e7b35 commit be53db8

File tree

11 files changed

+1936
-1895
lines changed

11 files changed

+1936
-1895
lines changed

barretenberg/cpp/pil/vm2/trees/public_data_check.pil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,30 +216,30 @@ namespace public_data_check;
216216

217217
#[LOW_LEAF_POSEIDON2_0]
218218
sel {
219-
low_leaf_slot, low_leaf_value, low_leaf_next_index,
219+
low_leaf_slot, low_leaf_value, low_leaf_next_slot,
220220
low_leaf_hash, const_four
221221
} in poseidon2_hash.start {
222222
poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2,
223223
poseidon2_hash.output, poseidon2_hash.input_len
224224
};
225225

226226
#[LOW_LEAF_POSEIDON2_1]
227-
sel { low_leaf_next_slot, precomputed.zero, precomputed.zero, low_leaf_hash }
227+
sel { low_leaf_next_index, precomputed.zero, precomputed.zero, low_leaf_hash }
228228
in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output };
229229

230230
pol commit updated_low_leaf_hash;
231231

232232
#[UPDATED_LOW_LEAF_POSEIDON2_0]
233233
write {
234-
low_leaf_slot, updated_low_leaf_value, updated_low_leaf_next_index,
234+
low_leaf_slot, updated_low_leaf_value, updated_low_leaf_next_slot,
235235
updated_low_leaf_hash, const_four
236236
} in poseidon2_hash.start {
237237
poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2,
238238
poseidon2_hash.output, poseidon2_hash.input_len
239239
};
240240

241241
#[UPDATED_LOW_LEAF_POSEIDON2_1]
242-
write { updated_low_leaf_next_slot, precomputed.zero, precomputed.zero, updated_low_leaf_hash }
242+
write { updated_low_leaf_next_index, precomputed.zero, precomputed.zero, updated_low_leaf_hash }
243243
in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output };
244244

245245
#[LOW_LEAF_MERKLE_CHECK]
@@ -262,14 +262,14 @@ namespace public_data_check;
262262

263263
#[NEW_LEAF_POSEIDON2_0]
264264
should_insert {
265-
leaf_slot, value, low_leaf_next_index,
265+
leaf_slot, value, low_leaf_next_slot,
266266
new_leaf_hash, const_four
267267
} in poseidon2_hash.start {
268268
poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2,
269269
poseidon2_hash.output, poseidon2_hash.input_len
270270
};
271271
#[NEW_LEAF_POSEIDON2_1]
272-
should_insert { low_leaf_next_slot, precomputed.zero, precomputed.zero, new_leaf_hash }
272+
should_insert { low_leaf_next_index, precomputed.zero, precomputed.zero, new_leaf_hash }
273273
in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output };
274274

275275
#[NEW_LEAF_MERKLE_CHECK]

barretenberg/cpp/src/barretenberg/crypto/merkle_tree/indexed_tree/indexed_leaf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ struct PublicDataLeafValue {
118118

119119
bool is_empty() const { return slot == fr::zero() && value == fr::zero(); }
120120

121-
std::vector<fr> get_hash_inputs(fr nextValue, fr nextIndex) const
121+
std::vector<fr> get_hash_inputs(fr nextSlot, fr nextIndex) const
122122
{
123-
return std::vector<fr>({ slot, value, nextIndex, nextValue });
123+
return std::vector<fr>({ slot, value, nextSlot, nextIndex });
124124
}
125125

126126
operator uint256_t() const { return get_key(); }

barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_public_data_check.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct lookup_public_data_check_low_leaf_poseidon2_0_settings_ {
152152
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
153153
ColumnAndShifts::public_data_check_low_leaf_slot,
154154
ColumnAndShifts::public_data_check_low_leaf_value,
155-
ColumnAndShifts::public_data_check_low_leaf_next_index,
155+
ColumnAndShifts::public_data_check_low_leaf_next_slot,
156156
ColumnAndShifts::public_data_check_low_leaf_hash,
157157
ColumnAndShifts::public_data_check_const_four
158158
};
@@ -182,7 +182,7 @@ struct lookup_public_data_check_low_leaf_poseidon2_1_settings_ {
182182
static constexpr Column COUNTS = Column::lookup_public_data_check_low_leaf_poseidon2_1_counts;
183183
static constexpr Column INVERSES = Column::lookup_public_data_check_low_leaf_poseidon2_1_inv;
184184
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
185-
ColumnAndShifts::public_data_check_low_leaf_next_slot,
185+
ColumnAndShifts::public_data_check_low_leaf_next_index,
186186
ColumnAndShifts::precomputed_zero,
187187
ColumnAndShifts::precomputed_zero,
188188
ColumnAndShifts::public_data_check_low_leaf_hash
@@ -214,7 +214,7 @@ struct lookup_public_data_check_updated_low_leaf_poseidon2_0_settings_ {
214214
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
215215
ColumnAndShifts::public_data_check_low_leaf_slot,
216216
ColumnAndShifts::public_data_check_updated_low_leaf_value,
217-
ColumnAndShifts::public_data_check_updated_low_leaf_next_index,
217+
ColumnAndShifts::public_data_check_updated_low_leaf_next_slot,
218218
ColumnAndShifts::public_data_check_updated_low_leaf_hash,
219219
ColumnAndShifts::public_data_check_const_four
220220
};
@@ -244,7 +244,7 @@ struct lookup_public_data_check_updated_low_leaf_poseidon2_1_settings_ {
244244
static constexpr Column COUNTS = Column::lookup_public_data_check_updated_low_leaf_poseidon2_1_counts;
245245
static constexpr Column INVERSES = Column::lookup_public_data_check_updated_low_leaf_poseidon2_1_inv;
246246
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
247-
ColumnAndShifts::public_data_check_updated_low_leaf_next_slot,
247+
ColumnAndShifts::public_data_check_updated_low_leaf_next_index,
248248
ColumnAndShifts::precomputed_zero,
249249
ColumnAndShifts::precomputed_zero,
250250
ColumnAndShifts::public_data_check_updated_low_leaf_hash
@@ -309,7 +309,7 @@ struct lookup_public_data_check_new_leaf_poseidon2_0_settings_ {
309309
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
310310
ColumnAndShifts::public_data_check_leaf_slot,
311311
ColumnAndShifts::public_data_check_value,
312-
ColumnAndShifts::public_data_check_low_leaf_next_index,
312+
ColumnAndShifts::public_data_check_low_leaf_next_slot,
313313
ColumnAndShifts::public_data_check_new_leaf_hash,
314314
ColumnAndShifts::public_data_check_const_four
315315
};
@@ -339,7 +339,7 @@ struct lookup_public_data_check_new_leaf_poseidon2_1_settings_ {
339339
static constexpr Column COUNTS = Column::lookup_public_data_check_new_leaf_poseidon2_1_counts;
340340
static constexpr Column INVERSES = Column::lookup_public_data_check_new_leaf_poseidon2_1_inv;
341341
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
342-
ColumnAndShifts::public_data_check_low_leaf_next_slot,
342+
ColumnAndShifts::public_data_check_low_leaf_next_index,
343343
ColumnAndShifts::precomputed_zero,
344344
ColumnAndShifts::precomputed_zero,
345345
ColumnAndShifts::public_data_check_new_leaf_hash
Binary file not shown.

barretenberg/cpp/src/barretenberg/world_state/world_state.test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ TEST_F(WorldStateTest, SyncExternalBlockFromEmpty)
592592
{ MerkleTreeId::NOTE_HASH_TREE,
593593
{ fr("0x2496ae3983b59733967ef32aecb041134d5f17bd2b040def30e699432dcc8967"), 1 } },
594594
{ MerkleTreeId::PUBLIC_DATA_TREE,
595-
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
595+
{ fr("0x0cef6cc2f1127a3f0e87e391b283f77e7d9e2c4843ca817fd5d62928bf08f719"), 129 } },
596596
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
597597
{ fr("0x149be5d1559bbefa0006c5e55ed982c43a1db53848e2f59385523d0c40d74a94"), 1 } },
598598
};
@@ -637,7 +637,7 @@ TEST_F(WorldStateTest, SyncBlockFromDirtyState)
637637
{ MerkleTreeId::NOTE_HASH_TREE,
638638
{ fr("0x2496ae3983b59733967ef32aecb041134d5f17bd2b040def30e699432dcc8967"), 1 } },
639639
{ MerkleTreeId::PUBLIC_DATA_TREE,
640-
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
640+
{ fr("0x0cef6cc2f1127a3f0e87e391b283f77e7d9e2c4843ca817fd5d62928bf08f719"), 129 } },
641641
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
642642
{ fr("0x149be5d1559bbefa0006c5e55ed982c43a1db53848e2f59385523d0c40d74a94"), 1 } },
643643
};
@@ -680,7 +680,7 @@ TEST_F(WorldStateTest, SyncCurrentBlock)
680680
{ MerkleTreeId::NOTE_HASH_TREE,
681681
{ fr("0x2496ae3983b59733967ef32aecb041134d5f17bd2b040def30e699432dcc8967"), 1 } },
682682
{ MerkleTreeId::PUBLIC_DATA_TREE,
683-
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
683+
{ fr("0x0cef6cc2f1127a3f0e87e391b283f77e7d9e2c4843ca817fd5d62928bf08f719"), 129 } },
684684
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
685685
{ fr("0x149be5d1559bbefa0006c5e55ed982c43a1db53848e2f59385523d0c40d74a94"), 1 } },
686686
};
@@ -718,7 +718,7 @@ TEST_F(WorldStateTest, RejectSyncBlockWithBadPublicWriteBatches)
718718
{ MerkleTreeId::NOTE_HASH_TREE,
719719
{ fr("0x2496ae3983b59733967ef32aecb041134d5f17bd2b040def30e699432dcc8967"), 1 } },
720720
{ MerkleTreeId::PUBLIC_DATA_TREE,
721-
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
721+
{ fr("0x0cef6cc2f1127a3f0e87e391b283f77e7d9e2c4843ca817fd5d62928bf08f719"), 129 } },
722722
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
723723
{ fr("0x149be5d1559bbefa0006c5e55ed982c43a1db53848e2f59385523d0c40d74a94"), 1 } },
724724
};
@@ -745,7 +745,7 @@ TEST_F(WorldStateTest, RejectSyncBlockWithInvalidStateRef)
745745
{ MerkleTreeId::NOTE_HASH_TREE,
746746
{ fr("0x2496ae3983b59733967ef32aecb041134d5f17bd2b040def30e699432dcc8967"), 1 } },
747747
{ MerkleTreeId::PUBLIC_DATA_TREE,
748-
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
748+
{ fr("0x0cef6cc2f1127a3f0e87e391b283f77e7d9e2c4843ca817fd5d62928bf08f719"), 129 } },
749749
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
750750
{ fr("0x149be5d1559bbefa0006c5e55ed982c43a1db53848e2f59385523d0c40d74a94"), 1 } },
751751
};
@@ -906,7 +906,7 @@ TEST_F(WorldStateTest, GetBlockForIndex)
906906
{ MerkleTreeId::NOTE_HASH_TREE,
907907
{ fr("0x2496ae3983b59733967ef32aecb041134d5f17bd2b040def30e699432dcc8967"), 1 } },
908908
{ MerkleTreeId::PUBLIC_DATA_TREE,
909-
{ fr("0x0278dcf9ff541da255ee722aecfad849b66af0d42c2924d949b5a509f2e1aec9"), 129 } },
909+
{ fr("0x0cef6cc2f1127a3f0e87e391b283f77e7d9e2c4843ca817fd5d62928bf08f719"), 129 } },
910910
{ MerkleTreeId::L1_TO_L2_MESSAGE_TREE,
911911
{ fr("0x149be5d1559bbefa0006c5e55ed982c43a1db53848e2f59385523d0c40d74a94"), 1 } },
912912
};

0 commit comments

Comments
 (0)