Skip to content

AutoKey produces inconsistent values #1825

Open
@SkymanOne

Description

@SkymanOne

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ink_metadata[ink_metadata] Work itemC-bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions