Closed frol closed 9 months ago
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):
"~$141"
.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 https://github.com/near/near-sdk-rs/issues/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:https://github.com/near/near-sdk-contract-tools/blob/1efbd10059cb7472c80eac4b482c9d005d00af24/src/standard/nep171/mod.rs#L72-L75