-
Notifications
You must be signed in to change notification settings - Fork 101
Description
The insert_value and remove_value methods perform read-modify-write operations on leaf_count and entry_count metadata without proper synchronization. Concurrent modifications can cause these counters to become corrupted through lost updates.
The root cause is using separate read and write operations instead of atomic transactions. In miden-crypto/src/merkle/smt/large/storage/rocksdb.rs:318-360, the code reads current counts (lines 318-319), modifies them locally (lines 335, 345-347), and writes them back in a batch (lines 356-357). If two threads execute concurrently:
- Thread A reads
entry_count = 5 - Thread B reads
entry_count = 5 - Thread A increments to 6 and writes
- Thread B increments to 6 and writes (should be 7)
Result: entry_count = 6 instead of the correct value 7.
Fixing this requires investigation of RocksDB's synchronization and concurrency primitives to determine the right approach. Options include merge operators for atomic counter updates, compare-and-swap operations, RocksDB transactions, or external synchronization if the storage is shared across threads. The investigation should clarify the intended concurrency model and select appropriate RocksDB features.