{"action":"created","issue":{"url":"https://api.github.com/repos/vyperlang/vyper/issues/1733","repository_url":"https://api.github.com/repos/vyperlang/vyper","labels_url":"https://api.github.com/repos/vyperlang/vyper/issues/1733/labels{/name}","comments_url":"https://api.github.com/repos/vyperlang/vyper/issues/1733/comments","events_url":"https://api.github.com/repos/vyperlang/vyper/issues/1733/events","html_url":"https://github.com/vyperlang/vyper/issues/1733","id":525114732,"node_id":"MDU6SXNzdWU1MjUxMTQ3MzI=","number":1733,"title":"VIP: Hash-based storage slots","user":{"login":"fubuloubu","id":3859395,"node_id":"MDQ6VXNlcjM4NTkzOTU=","avatar_url":"https://avatars3.githubusercontent.com/u/3859395?v=4","gravatar_id":"","url":"https://api.github.com/users/fubuloubu","html_url":"https://github.com/fubuloubu","followers_url":"https://api.github.com/users/fubuloubu/followers","following_url":"https://api.github.com/users/fubuloubu/following{/other_user}","gists_url":"https://api.github.com/users/fubuloubu/gists{/gist_id}","starred_url":"https://api.github.com/users/fubuloubu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fubuloubu/subscriptions","organizations_url":"https://api.github.com/users/fubuloubu/orgs","repos_url":"https://api.github.com/users/fubuloubu/repos","events_url":"https://api.github.com/users/fubuloubu/events{/privacy}","received_events_url":"https://api.github.com/users/fubuloubu/received_events","type":"User","site_admin":false},"labels":[{"id":751622094,"node_id":"MDU6TGFiZWw3NTE2MjIwOTQ=","url":"https://api.github.com/repos/vyperlang/vyper/labels/discussion","name":"discussion","color":"000000","default":false,"description":"Used to denote VIPs and more complex issues that are waiting discussion in a meeting"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":16,"created_at":"2019-11-19T16:19:51Z","updated_at":"2019-11-27T14:56:10Z","closed_at":null,"author_association":"MEMBER","body":"## Simple Summary\r\nChange the initial storage slot index of a variable from a compilation-specific ordering to a hash-based index based on variable name.\r\n\r\n## Motivation\r\nWe currently do not do any sort of tightly packing of storage slots in Vyper contracts. The original specification of Vyper's ordering-based indexing of variable storage slots is [adapted from Solidity](https://solidity.readthedocs.io/en/v0.5.13/miscellaneous.html#layout-of-state-variables-in-storage). Unfortunately, due to the compiler making decisions about the ordering of storage slots, there is [chaotic behavior](https://blog.trailofbits.com/2018/09/05/contract-upgrade-anti-patterns/) of storage slot indexes between versions of different contracts, leading to issues when using the Proxy pattern of upgradeable contracts between multiple versions of a Solidity contract.\r\n\r\nBy creating a predictable storage slot index strategy (based on a collision-resistant, cryptographic hash function such as `keccak256`), external tools can regenerate the entire symbol table of a Vyper contract from nothing else than analyzing source code directly. More importantly, the Proxy pattern would be more resilient with hash-based indexes because the variable name now determines it's location, and not it's ordering within a contract (or inherited system of contracts, a la Solidity)\r\n\r\n## Specification\r\nThe change asked for here is to change the storage slot index function `index(v+1) := prev_slot + sizeof(v.type) + 1` from a stateful function which auto-increments the storage slot based on variable size of the variables laid out before it, to a stateless function that computes it via the hash of the variables name e.g. `index(v) := keccak(v.name)`. This does not change how structs or arrays are currently laid out (as specified in #769), only the base index for storage of a particular type.\r\n\r\n## Backwards Compatibility\r\nThis VIP will change how storage slots are calculated, and will break any existing tools that rely on the assumption that storage slots are auto-incremented based on the contract's definitions. However, tools should appreciate that storage slots are now predictably obtained from their names only, without relying on internal compiler information such as how the compiler makes a determination of storage slots based on complex inheritance and compression rules.\r\n\r\n## Dependencies\r\nNo dependencies. Related to #769.\r\n\r\n## Copyright\r\nCopyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/)\r\n"},"comment":{"url":"https://api.github.com/repos/vyperlang/vyper/issues/comments/559121280","html_url":"https://github.com/vyperlang/vyper/issues/1733#issuecomment-559121280","issue_url":"https://api.github.com/repos/vyperlang/vyper/issues/1733","id":559121280,"node_id":"MDEyOklzc3VlQ29tbWVudDU1OTEyMTI4MA==","user":{"login":"fubuloubu","id":3859395,"node_id":"MDQ6VXNlcjM4NTkzOTU=","avatar_url":"https://avatars3.githubusercontent.com/u/3859395?v=4","gravatar_id":"","url":"https://api.github.com/users/fubuloubu","html_url":"https://github.com/fubuloubu","followers_url":"https://api.github.com/users/fubuloubu/followers","following_url":"https://api.github.com/users/fubuloubu/following{/other_user}","gists_url":"https://api.github.com/users/fubuloubu/gists{/gist_id}","starred_url":"https://api.github.com/users/fubuloubu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fubuloubu/subscriptions","organizations_url":"https://api.github.com/users/fubuloubu/orgs","repos_url":"https://api.github.com/users/fubuloubu/repos","events_url":"https://api.github.com/users/fubuloubu/events{/privacy}","received_events_url":"https://api.github.com/users/fubuloubu/received_events","type":"User","site_admin":false},"created_at":"2019-11-27T14:56:10Z","updated_at":"2019-11-27T14:56:10Z","author_association":"MEMBER","body":"> No, I wasn't thinking about hexadecimal encoding (but I did use that shorthand as a way to explain the issue). But rather than worry about the odds a hash will consist solely of valid characters for a variable identifier, it's probably better to just avoid the possibility of an _input_ collision altogether. It's easy to do via a prefix or separator that can't occur in identifiers, like \"#\" or \"\\0\".\r\n\r\nYes but the string version of the hash would not be `abc123...`, it would be `Iz@n;1yBzc&KnvY?D[F/...` which would not be a valid Vyper identifier"}}
{"actor":{"display_login":"fubuloubu"}}