Closed ithinker1991 closed 6 years ago
There is a path that solidity uses to address storage variable. It is a 32-byte value that is defined by compiler for each storage variable. Storage key is not the same as storage variable path, it's a sha3 from that path, key = sha3(path)
. Thus lower 16 bytes of the key reflect whole path value whatever it is.
@mkalinin thank you for your reply. But
I have see sha3(path)
in class SecureTrie
. The class SecureTrie
is used in many scenarios.
Why uses SecureTrie
instead of TrieImp
?
@ithinker1991 because of Ethereum specification. Originally this was done to avoid malicious Trie manipulation. I.e. you may intentionally add such data to a contract that Trie depth becomes very large which causes significant performance degradation for Trie operations
32-bytes composed key should be [first 16-bytes of address hash:second 16-bytes of node key]
There seems a BIG problem. I noticed in solidity, for dynamic type such as
string
,bytes
first 16-bytes of node-key are same and second 16-bytes of node are different. So if one field has been encoded to many storage-key. the composed key will be same.For example s1 = "1111111111111111111111111111111111111112222222222222222222222222222222222222222333333333333333333333333333333333333";
encoded result: