-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure generic values used with a StorageMap
are hashable
#5045
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add breaking label?
I don't really understand the security issue. I see it more as a potential compiler issue.
Don't really see an issue with this constraint though.
Perhaps not security concern, this has been corrected. But we still see the following: This compiles: struct MyStruct {
val: u64
}
abi MyContract {
#[storage(read, write)]
fn test_function();
}
storage {
my_map: StorageMap<MyStruct, u64> = StorageMap {},
}
impl MyContract for Contract {
#[storage(read, write)]
fn test_function() {
let my_struct = MyStruct { val: 1 };
storage.my_map.insert(my_struct, 2)
}
} When this does not, even though the use std::hash::sha256;
struct MyStruct {
val: u64
}
abi MyContract {
fn test_function();
}
impl MyContract for Contract {
fn test_function() {
let my_struct = MyStruct { val: 1 };
let result = sha256(my_struct);
}
} |
hm, strange. seems like a compiler issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue that reports the faulty behavior found in this PR. #5046
Although the added constraints are redundant because the impl self already contains them, because the compiler appears not to check the impl self constraints I think this is a good idea to add until the issue is fixed.
Description
Currently, any type may be included as a key value to the
StorageMap<K, V>
type. This presents an issue as the type must be hashable in order to generate the key.A where clause has been added to the function definition.
This should open the door for using heap types(
String
,Bytes
) as key values for theStorageMap
type however, this will require additional compiler changes.Checklist
Breaking*
orNew Feature
labels where relevant.