dusk-network / rusk

The reference Dusk platform implementation and tools
Mozilla Public License 2.0
162 stars 60 forks source link

BTreeMap optimization for provisioners #2146

Open fed-franz opened 2 months ago

fed-franz commented 2 months ago

(See finding 9 of the Oak audit.)

The file consensus/src/user/provisioners.rs demonstrates a wise choice of data structure to track all available provisioners, namely BTreeMap. However, the structure is not utilized to the maximum of its capabilities. The set of provisioners eligible for participation in the current round committee is computed by iterating all provisioners (line 154), filtering them by round and minimum stake (line 155), cloning their stakes (line 245), comparing each public key with an excluded one (line 251) and, finally, constructing a new map from the iterator (line 252). These iterations are excessive and reduce tolerance to DoS attacks against the network.

Recommendation: We recommend utilizing standard functions retain and remove provided by the BTreeMap structure. The former can be used to filter the map in-place, while the latter will help remove the public key with asymptotic complexity O(log(N)) instead of O(N).

www-yaman88 commented 1 week ago

www-Yaman88 is a dynamic online platform that offers an extensive collection of interactive games, catering to all types of players. With its user-friendly design, www-Yaman88 allows for easy navigation through a variety of engaging options, from thrilling action games to strategic challenges.