Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Migrate storage maps to use twox64_concat or blake2_128_concat #4917

Closed
2 tasks done
shawntabrizi opened this issue Feb 13, 2020 · 1 comment · Fixed by #5226
Closed
2 tasks done

Migrate storage maps to use twox64_concat or blake2_128_concat #4917

shawntabrizi opened this issue Feb 13, 2020 · 1 comment · Fixed by #5226
Assignees
Labels
I7-refactor Code needs refactoring.
Milestone

Comments

@shawntabrizi
Copy link
Member

shawntabrizi commented Feb 13, 2020

The various map pallets mostly use blake2_256 hashers and sometimes linked_maps and empty double maps. All linked maps should be removed. Double maps where the initial item is expected to be constant (e.g. pallet-session's NextKeys) should be altered to a simple map now. Hashers should be switched to either:

  • blake2_128_concat in the case that the user is able to place map items whose keys are entirely at their discretion.
  • twox64_concat in the case that the user cannot.

An example of the former would be the frame_system's Account storage item, since any address (even one without a known corresponding private key!) may be sent an existential deposit and therefore be created.

An example of the latter would be frame_system's BlockHash storage item, since its keys are limited to the block number integers. Users cannot populate it directly, nor can they influence the data.

A second example of the latter would be pallet-staking's Bonded item. Though this has a corresponding key type/value to frame_system's Account storage item, it has different semantics; no entry can be placed except through a valid signed transaction coming from the account of the key. As such its value is heavily constrained and cannot be selected at will (in general a public key would need to be known for the account and the distribution/correlation between public and secret keys are not such that a trie-imbalancing global griefing attack would be practical to execute).

Tasks

  • Remove all the superfluous double-maps from Session & migrate.
  • Replace all hasher(blake2_256)s with _concat hashers & provide either static or dynamic migration.
@shawntabrizi shawntabrizi added the I7-refactor Code needs refactoring. label Feb 13, 2020
@shawntabrizi shawntabrizi changed the title Account storage in Balances Pallet needs to be migrated Storage in Balances Pallet needs to be migrated to use twox64concat Feb 13, 2020
@shawntabrizi shawntabrizi mentioned this issue Feb 13, 2020
6 tasks
@shawntabrizi shawntabrizi added this to the 2.0 milestone Feb 14, 2020
@gavofyork gavofyork changed the title Storage in Balances Pallet needs to be migrated to use twox64concat Migrate storage maps to use twox64_concat or blake2_128_concat Feb 18, 2020
apopiak added a commit to apopiak/stablecoin that referenced this issue Mar 4, 2020
@kianenigma
Copy link
Contributor

related: #4610

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
I7-refactor Code needs refactoring.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants