{"id":28458212,"url":"https://github.com/solidstate-network/diamond-proxy-storage-rewrite","last_synced_at":"2026-05-08T01:33:24.196Z","repository":{"id":289675562,"uuid":"800914040","full_name":"solidstate-network/diamond-proxy-storage-rewrite","owner":"solidstate-network","description":"🔧 Contract and scripts to fix corrupted EIP-2535 Diamond proxy storage layout","archived":false,"fork":false,"pushed_at":"2024-05-20T10:34:12.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-07T00:11:24.208Z","etag":null,"topics":["diamond","diamond-proxy","eip-2535","eth","ether","ethereum","fix","solidity","wow"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solidstate-network.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-15T08:39:23.000Z","updated_at":"2025-04-24T01:39:32.000Z","dependencies_parsed_at":"2025-04-24T14:12:58.068Z","dependency_job_id":null,"html_url":"https://github.com/solidstate-network/diamond-proxy-storage-rewrite","commit_stats":null,"previous_names":["solidstate-network/diamond-proxy-storage-rewrite"],"tags_count":0,"template":false,"template_full_name":"solidstate-network/hardhat-template","purl":"pkg:github/solidstate-network/diamond-proxy-storage-rewrite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidstate-network%2Fdiamond-proxy-storage-rewrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidstate-network%2Fdiamond-proxy-storage-rewrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidstate-network%2Fdiamond-proxy-storage-rewrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidstate-network%2Fdiamond-proxy-storage-rewrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solidstate-network","download_url":"https://codeload.github.com/solidstate-network/diamond-proxy-storage-rewrite/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidstate-network%2Fdiamond-proxy-storage-rewrite/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263081366,"owners_count":23410867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["diamond","diamond-proxy","eip-2535","eth","ether","ethereum","fix","solidity","wow"],"created_at":"2025-06-07T00:10:23.854Z","updated_at":"2026-05-08T01:33:19.177Z","avatar_url":"https://github.com/solidstate-network.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Diamond Proxy Storage Rewrite Tool\n\nThis repository exists to correct the effects a known issue in multiple EIP-2535 Diamond proxy implementations.\n\n## Issue\n\nThe issue in question manifests when a [zero-selector](https://www.4byte.directory/signatures/?bytes4_signature=0x00000000) is added to a diamond proxy at position `8n + 1`. If it is later removed, the `diamondCut` function treats it as an empty slot rather than a function signature and ignores it, corrupting the storage of the proxy.\n\n## Usage\n\nFollow the Development insructions below to setup the Hardhat environment.\n\nUse the included Hardhat tasks to correct the storage of an affected diamond proxy. It is recommended to use the high-level `repair` task.\n\n```bash\nyarn run hardhat repair TODO\n```\n\nThe `repair` task consists of multiple component tasks which can be run individually. See the Hardhat help menu for more information.\n\nAll tasks make use of the Solidstate [hardhat-txn-dot-xyz](https://github.com/solidstate-network/hardhat-txn-dot-xyz) plugin, which delegates transaction signing to a web browser. This is intended to make it easier for multisig account users to update their diamond proxies.\n\nThe following is a description of each of the arguments accepted by the tasks.\n\n| Argument                | Description                                                                                                                                               |\n| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `diamond`               | Address of the diamond proxy with corrupted storage.                                                                                                      |\n| `proxy`                 | Address of the `StorageRewrite` contract.                                                                                                                 |\n| `authorizedSender`      | Address of the account permitted to call the `rewrite` function on the `StorageRewrite` contract. Defaults to the EIP-173 `owner` of the `diamond` proxy. |\n| `storageLayoutSeed`     | String seed used to calculate slot of storage layout struct, where `slot = keccak256(seed)`                                                               |\n| `selectorMappingOffset` | Index within the storage struct where the `diamond` proxy's \"selectorSlots\" `mapping` is located.                                                         |\n| `facetsMappingOffset`   | Index within the storage struct where the `diamond` proxy's \"facets\" `mapping` is located.                                                                |\n| `selectorCountOffset`   | Index within the storage struct where the `diamond` proxy's total selector count is stored.                                                               |\n| `slots`                 | JSON array of the data to be written to storage, generated by the `storage-calculate-diff` task.                                                          |\n\nThe following are storage slot seeds and offset values for known common diamond implementations. Values for other implementations must be calculated manually.\n\n| Implementation          | `storageLayoutSeed`                        | `selectorMappingOffset` | `facetsMappingOffset` | `selectorCountOffset` |\n| ----------------------- | ------------------------------------------ | ----------------------- | --------------------- | --------------------- |\n| Solidstate              | `solidstate.contracts.storage.DiamondBase` | `2n`                    | `0n`                  | `1n`                  |\n| Reference (\"diamond-2\") | `diamond.standard.diamond.storage`         | `1n`                    | `0n`                  | `2n`                  |\n\n## Development\n\nInstall dependencies via Yarn:\n\n```bash\nyarn install\n```\n\nSetup Husky to format code on commit:\n\n```bash\nyarn prepare\n```\n\nCompile contracts via Hardhat:\n\n```bash\nyarn run hardhat compile\n```\n\nThe Hardhat environment relies on the following environment variables. The `dotenv` package will attempt to read them from the `.env` and `.env.secret` files, if they are present.\n\n| Key                 | Description                                                              |\n| ------------------- | ------------------------------------------------------------------------ |\n| `API_KEY_ETHERSCAN` | [Etherscan](https://etherscan.io//) API key for source code verification |\n| `NODE_URL_MAINNET`  | JSON-RPC node URL for `mainnet` network                                  |\n| `PKEY_MAINNET`      | private key for production use on `mainnet` network                      |\n| `REPORT_GAS`        | if `true`, a gas report will be generated after running tests            |\n\n### Networks\n\nBy default, Hardhat uses the Hardhat Network in-process. An additional network, `mainnet`, is available, and its behavior is determined by the configuration of environment variables.\n\n### Testing\n\nTest contracts via Hardhat:\n\n```bash\nyarn run hardhat test\n```\n\nActivate gas usage reporting by setting the `REPORT_GAS` environment variable to `\"true\"`:\n\n```bash\nREPORT_GAS=true yarn run hardhat test\n```\n\nGenerate a code coverage report using `solidity-coverage`:\n\n```bash\nyarn run hardhat coverage\n```\n\n### Documentation\n\nA static documentation site can be generated using `hardhat-docgen`:\n\n```bash\nyarn run hardhat docgen\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidstate-network%2Fdiamond-proxy-storage-rewrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidstate-network%2Fdiamond-proxy-storage-rewrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidstate-network%2Fdiamond-proxy-storage-rewrite/lists"}