Skip to content
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

Update EIP-7201: Explain possibility to use different formulas #7760

Merged
merged 8 commits into from
Sep 22, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions EIPS/eip-7201.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@

A _namespace id_ is a string that uniquely identifies a namespace in a contract. It should not contain any whitespace characters.

The storage location for a namespace is defined as `ns_loc(id: string) = keccak256(keccak256(id) - 1) & ~0xff`.
The storage location for an ERC-7201 namespace is defined as `erc7201(id: string) = keccak256(keccak256(id) - 1) & ~0xff`. In Solidity, this corresponds to the expression `keccak256(abi.encode(uint256(keccak256(id)) - 1)) & ~bytes32(uint256(0xff))`.

Check failure on line 31 in EIPS/eip-7201.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> EIPS/eip-7201.md | 31 | The storage location for an ERC-7201 namespace is defined as `erc7201(id: string) = keccak256(keccak256(id) - 1) & ~0xff`. In Solidity, this corresponds to the expression `keccak256(abi.encode(uint256(keccak256(id)) - 1)) & ~bytes32(uint256(0xff))`. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+` = help: see https://ethereum.github.io/eipw/markdown-link-first/

A Solidity contract using namespaced storage can annotate a struct with the NatSpec tag `@custom:storage-location erc7201:<NAMESPACE_ID>` to identify it as a namespace with id `<NAMESPACE_ID>`. _(Note: The Solidity compiler includes this annotation in the AST since v0.8.20, so this is recommended as the minimum compiler version when using this pattern.)_ Structs with this annotation found outside of contracts are not considered to be namespaces for any contract in the source code.
A Solidity contract using namespaced storage can annotate a struct with the NatSpec tag `@custom:storage-location <FORMULA_ID>:<NAMESPACE_ID>` to identify it as a namespace. `<FORMULA_ID>` identifies the formula used to compute the location based on the namespace id. The formula specified in this ERC can be identified as `erc7201`. For example, an ERC-7201 namespace with id `foobar` would be annotated as `@custom:storage-location erc7201:foobar`. _(Note: The Solidity compiler includes this annotation in the AST since v0.8.20, so this is recommended as the minimum compiler version when using this pattern.)_ Structs with this annotation found outside of contracts are not considered to be namespaces for any contract in the source code.

Check failure on line 33 in EIPS/eip-7201.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> EIPS/eip-7201.md | 33 | A Solidity contract using namespaced storage can annotate a struct with the NatSpec tag `@custom:storage-location <FORMULA_ID>:<NAMESPACE_ID>` to identify it as a namespace. `<FORMULA_ID>` identifies the formula used to compute the location based on the namespace id. The formula specified in this ERC can be identified as `erc7201`. For example, an ERC-7201 namespace with id `foobar` would be annotated as `@custom:storage-location erc7201:foobar`. _(Note: The Solidity compiler includes this annotation in the AST since v0.8.20, so this is recommended as the minimum compiler version when using this pattern.)_ Structs with this annotation found outside of contracts are not considered to be namespaces for any contract in the source code. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+`

Future EIPs may define new formulas with unique formula identifiers. It is recommended to follow the convention set in this EIP and use an identifier of the format `erc1234`.

## Rationale

Expand Down Expand Up @@ -82,7 +84,7 @@

## Security Considerations

Needs discussion.
Namespaces should avoid collisions with other namespaces or with standard Solidity or Vyper storage layout. ERC-7201 guarantees this property for arbitrary namespace ids under the assumption of keccak256 collision resistance, as discussed in Rationale.

Check failure on line 87 in EIPS/eip-7201.md

View workflow job for this annotation

GitHub Actions / EIP Walidator

the first match of the given pattern must be a link

error[markdown-link-first]: the first match of the given pattern must be a link --> EIPS/eip-7201.md | 87 | Namespaces should avoid collisions with other namespaces or with standard Solidity or Vyper storage layout. ERC-7201 guarantees this property for arbitrary namespace ids under the assumption of keccak256 collision resistance, as discussed in Rationale. | = info: the pattern in question: `(?i)(?:eip|erc)-[0-9]+`

## Copyright

Expand Down