You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hard-coded Storage key is unsafe, this may lead to colliding key-values stored in collections if user has other collections and uses 0 storage key for something else. It can either fail or even go unnoticed if the schema is the same:
#[derive(BorshSerialize,BorshStorageKey)]enumStorageKey{MyKey{account_hash:Vec<u8>},// other variants}
First and foremost, this is a valid concern. Thank you for the report.
Here is how near-sdk-contract-tools currently handles storage keys for most components (e.g. NEP-141):
A default storage key prefix is defined here. In the case of NEP-141, this default prefix is "~$141".
All storage entries managed by a component use that prefix to construct their keys.
All components allow the user to override the default storage prefix. Here is a test that demonstrates that functionality.
With that being said, there are not currently any safeguards that prevent (or even warn a user against) duplicating/overloading a storage key. That seems like a difficult problem to solve, though, without creating a complex compile-time key management system and prohibiting the use of env::storage_* methods.
Ah, I see, near-sdk-contract-tools deals with the storage keys much better than near-contract-standards. Given that the chances are that there will be a collision with ~$141 prefix are much lower than a simple enum-index key, I believe this issue can be closed as resolving it, as was mentioned above, would require some generic solution on near-skd-rs side.
It was reported by @hanakannzashi to near/near-sdk-rs#1141, but I checked near-sdk-contract-tools and realized that it has the same issue:
Hard-coded Storage key is unsafe, this may lead to colliding key-values stored in collections if user has other collections and uses
0
storage key for something else. It can either fail or even go unnoticed if the schema is the same:near-sdk-contract-tools/src/standard/nep171/mod.rs
Lines 72 to 75 in 1efbd10
The text was updated successfully, but these errors were encountered: