Skip to content

Commit 3aa3849

Browse files
committed
fix: serialise wsdb node-delete key as canonical uint256
decrement_node_reference_count passed the raw fr nodeHash to delete_value, while write_node/read_node wrap it in FrKeyType (uint256). In bb the raw fr went through serialise_key's explicit uint256_t overload (implicit fr->uint256 conversion), so all three agreed. The extracted lmdblib replaced that overload with a generic serialise_key<T> template, which binds fr exactly and emits the field's Montgomery-form bytes instead of canonical uint256 bytes. Node deletes then targeted the wrong key, collaterally deleting retained nodes during unwind and corrupting the tree (the l1_to_l2 cross_chain e2e regression). Wrap the key in FrKeyType at the delete site so all node ops serialise the key identically. Also add native-packages/.clang-format (copied from barretenberg/cpp) so the new C++ packages format to bb's style.
1 parent d5700c2 commit 3aa3849

2 files changed

Lines changed: 35 additions & 5 deletions

File tree

native-packages/.clang-format

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
PointerAlignment: Left
2+
ColumnLimit: 120
3+
IndentWidth: 4
4+
BinPackArguments: false
5+
BinPackParameters: false
6+
Cpp11BracedListStyle: false
7+
AlwaysBreakAfterReturnType: None
8+
AlwaysBreakAfterDefinitionReturnType: None
9+
PenaltyReturnTypeOnItsOwnLine: 1000000
10+
BreakConstructorInitializers: BeforeComma
11+
BreakBeforeBraces: Custom
12+
BraceWrapping:
13+
AfterClass: false
14+
AfterEnum: false
15+
AfterFunction: true
16+
AfterNamespace: false
17+
AfterStruct: false
18+
AfterUnion: false
19+
AfterExternBlock: false
20+
BeforeCatch: false
21+
BeforeElse: false
22+
SplitEmptyFunction: false
23+
SplitEmptyRecord: false
24+
SplitEmptyNamespace: false
25+
AllowShortFunctionsOnASingleLine : Inline
26+
SortIncludes: true

native-packages/wsdb/cpp/src/merkle_tree/lmdb_store/lmdb_tree_store.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
// =====================
66

77
#include "merkle_tree/lmdb_store/lmdb_tree_store.hpp"
8-
#include "merkle_tree/tree_db_stats.hpp"
98
#include "barretenberg/common/serialize.hpp"
109
#include "barretenberg/crypto/merkle_tree/indexed_leaf.hpp"
1110
#include "barretenberg/crypto/merkle_tree/types.hpp"
1211
#include "barretenberg/ecc/curves/bn254/fr.hpp"
13-
#include "lmdblib/lmdb_db_transaction.hpp"
14-
#include "lmdblib/lmdb_helpers.hpp"
15-
#include "lmdblib/lmdb_store_base.hpp"
1612
#include "barretenberg/numeric/uint128/uint128.hpp"
1713
#include "barretenberg/numeric/uint256/uint256.hpp"
1814
#include "barretenberg/serialize/msgpack_impl.hpp"
1915
#include "lmdb_tree_store.hpp"
16+
#include "lmdblib/lmdb_db_transaction.hpp"
17+
#include "lmdblib/lmdb_helpers.hpp"
18+
#include "lmdblib/lmdb_store_base.hpp"
19+
#include "merkle_tree/tree_db_stats.hpp"
2020
#include <cstddef>
2121
#include <cstdint>
2222
#include <cstring>
@@ -283,7 +283,11 @@ void LMDBTreeStore::decrement_node_reference_count(const fr& nodeHash, NodePaylo
283283
}
284284
if (--nodeData.ref == 0) {
285285
// std::cout << "Deleting node at " << nodeHash << std::endl;
286-
tx.delete_value(nodeHash, *_nodeDatabase);
286+
// Wrap in FrKeyType so the node key is serialised identically to write_node/read_node
287+
// (canonical uint256 bytes). Passing the raw fr would bind serialise_key's generic
288+
// template and emit Montgomery-form bytes, deleting the wrong node.
289+
FrKeyType key(nodeHash);
290+
tx.delete_value(key, *_nodeDatabase);
287291
return;
288292
}
289293
// std::cout << "Updating node at " << nodeHash << " ref is now " << nodeData.ref << std::endl;

0 commit comments

Comments
 (0)