substrate-developer-hub / substrate-cms

5 stars 5 forks source link

Document about choice of hashers #17

Closed xlc closed 4 years ago

xlc commented 5 years ago

Substrate offers few different hash algorithm, and for double_map, developer have to pick which one to use for first key and second key.

It will be good if there is a documentation on the pros and cons for each algorithm and how to decide which hasher to use.

I think this is all we have so far, which describes when to use blake2_256 but not other hashers.

/// If the first key is untrusted, a cryptographic hasher such as blake2_256 must be used. /// Otherwise, other values of all storage items can be compromised. /// /// If the second key is untrusted, a cryptographic hasher such as blake2_256 must be used. /// Otherwise, other items in storage with the same first key can be compromised. /// /// Supported hashers (ordered from least to best security): /// /// twox_64_concat - TwoX with 64bit + key concatenated. /// twox_128 - TwoX with 128bit. /// twox_256 - TwoX with with 256bit. /// blake2_128 - Blake2 with 128bit. /// * blake2_256 - Blake2 with 256bit.

https://github.com/paritytech/substrate/blob/8cbfc10a28aafb6aec5487eebca16116f45bbf84/srml/support/procedural/src/lib.rs#L88-L92

joepetrowski commented 4 years ago

Closing in favor of https://github.com/substrate-developer-hub/knowledgebase/issues/5