Substrate: contracts: implement `ext_runtime_get_storage`

Created on 11 Oct 2019  路  2Comments  路  Source: paritytech/substrate

In order to allow smart contracts to query runtime storage, a new ext_ function is required:

fn ext_runtime_get_storage(key_ptr: u32, key_len: u32) -> u32

I've implemented a quick prototype: https://github.com/paritytech/substrate/compare/aj-contracts-get-storage.

However this is hard coded to hash the key twox_128(key)

Assuming we don't expect the contract itself to perform the key hashing, the remaining problem to solve is the API for correct hashing of keys for different storage types:

  • Value twox_128(key)
  • Map blake2_256(prefix + key)
  • Map2 twox_128(prefix + key)
  • LinkedMap blake2_256(prefix + key)
  • LinkedMap2 twox_128(prefix + key)
  • DoubleMap blake2_256(prefix + key) + blake2_256(key2)
  • DoubleMap2 twox_128(prefix + key) + twox_128(key2)

Rel: https://github.com/paritytech/ink/pull/204

All 2 comments

Related previous discussion: #2214

Access the storage directly will make it very hard / impossible to upgrade runtime module storage format because it means all the contracts have to upgrade as well, which is just not going to happen in a generic smart contract chain.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drozdziak1 picture drozdziak1  路  5Comments

gregdhill picture gregdhill  路  5Comments

AurevoirXavier picture AurevoirXavier  路  3Comments

pepyakin picture pepyakin  路  5Comments

xlc picture xlc  路  5Comments