Open
Description
Background
I had been working on the example for delegate_call()
when stumbled across a "bug" that, given two identical storage layouts with the same field names and order, the automatically generated keys for Mapping
appear to be different.
Problem
Look at two different contracts with different names, but same storage layouts:
- https://github.com/paritytech/ink/blob/4843f45999f94b01cfe44937b946db801c0799c6/integration-tests/delegatecall-bug/lib.rs#L13
- https://github.com/paritytech/ink/blob/4843f45999f94b01cfe44937b946db801c0799c6/integration-tests/key-reproducer/lib.rs#L7
When compiling both contracts in release mode. The metadata shows that Mapping
have different keys:
From delegatecall-bug:
"storage": {
"root": {
"layout": {
"struct": {
"fields": [
{
"layout": {
"root": {
"layout": {
"leaf": {
"key": "0x9ac42f14",
"ty": 0
}
},
"root_key": "0x9ac42f14",
"ty": 1
}
},
"name": "values"
},
{
"layout": {
"leaf": {
"key": "0x00000000",
"ty": 9
}
},
"name": "value"
}
],
"name": "DelegateCallBug"
}
},
"root_key": "0x00000000",
"ty": 10
}
},
From key-reproducer:
"storage": {
"root": {
"layout": {
"struct": {
"fields": [
{
"layout": {
"root": {
"layout": {
"leaf": {
"key": "0xa06565a3",
"ty": 0
}
},
"root_key": "0xa06565a3",
"ty": 1
}
},
"name": "values"
},
{
"layout": {
"leaf": {
"key": "0x00000000",
"ty": 9
}
},
"name": "value"
}
],
"name": "KeyReproducer"
}
},
"root_key": "0x00000000",
"ty": 10
}
},
Potential Solutiom
My intuition is that the name of the storage plays a role in the auto key generation, but for Solidity devs this behaviour is unexpected and can be a footgun in the future.