BlockstreamResearch / rust-simplicity

Creative Commons Zero v1.0 Universal
58 stars 12 forks source link

types: avoid accessing BoundMutex::inner in derived Debug #225

Closed apoelstra closed 2 months ago

apoelstra commented 2 months ago

We have a submodule bound_mutex whose purpose is to ensure that no deadlocks are possible. We do this by having a short submodule which only accesses the BoundMutex::inner member in the get and set methods. These methods lock the mutex and immediately unlock it. The member is never accessed by any other method. This is easy to check by searching the code for inner.

HOWEVER, there is actually a hidden access to inner in the #[derive(Debug)] line on BoundMutex, and this access is incorrect. Rather than locking the mutex, cloning the Arc within, unlocking, then processing the cloned Arc, it just locks the mutex and then recursively calls stuff while it's locked. Stupid.

Fix this by manually implementing fmt::Debug, calling get rather than directly accessing inner.

Fixes #224.