Refactor Ethscription Content Handling and Metadata Storage#137
Conversation
- Updated content URI handling to use `contentUriSha` for protocol uniqueness checks. - Introduced `contentHash` for deduplication of content, replacing the previous `contentSha`. - Enhanced metadata storage with `MetaStoreLib` for efficient management of mimetype, protocol, and operation. - Updated relevant contracts and tests to reflect changes in content and metadata handling, ensuring consistency across the codebase.
There was a problem hiding this comment.
Pull Request Overview
This PR performs a systematic field renaming across the codebase to improve clarity and consistency. The main changes rename contentUriHash to contentUriSha (clarifying it uses SHA-256) and contentSha to contentHash (clarifying it uses keccak256). Additionally, the PR introduces new libraries for metadata storage (MetaStoreLib, DedupedBlobStore) that consolidate the storage of mimetype, protocol name, and operation into a deduplicated reference system.
- Renamed hash fields to clarify their hash algorithms:
contentUriSha(SHA-256) andcontentHash(keccak256) - Introduced deduplicated metadata storage system replacing direct mimetype string storage
- Updated all tests, contracts, and Ruby integration code to use the new field names
Reviewed Changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/integration/ethscriptions_creation_spec.rb | Updated test expectations to use content_uri_sha instead of content_uri_hash |
| lib/storage_reader.rb | Updated struct field names and comments to reflect renamed fields and new metadata fields |
| lib/event_decoder.rb | Updated decoded event field names to match contract changes |
| lib/block_validator.rb | Updated validation logic and error messages for renamed hash fields |
| contracts/src/Ethscriptions.sol | Core contract updated with renamed fields and new metadata storage system |
| contracts/src/libraries/MetaStoreLib.sol | New library for deduplicated metadata storage |
| contracts/src/libraries/DedupedBlobStore.sol | New library for generic blob storage with deduplication |
| contracts/src/libraries/BytePackLib.sol | Added memory variant of pack function |
| contracts/src/libraries/EthscriptionsRendererLib.sol | Updated to accept decoded metadata parameters and removed escapeJSON call |
| contracts/test/*.t.sol | Updated all test files to use contentUriSha instead of contentUriHash |
| contracts/script/process_genesis_json.rb | Updated to output content_uri_sha field name |
| contracts/script/L2Genesis.s.sol | Updated to read from genesis JSON and use new field names |
| app/models/ethscription_transaction.rb | Updated Ruby model to use content_uri_sha variable naming |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Ethscriptions.CreateEthscriptionParams memory params; | ||
| params.ethscriptionId = vm.parseJsonBytes32(json, string.concat(basePath, ".transaction_hash")); | ||
| params.contentUriHash = vm.parseJsonBytes32(json, string.concat(basePath, ".content_uri_hash")); | ||
| params.contentUriSha = vm.parseJsonBytes32(json, string.concat(basePath, ".content_uri_hash")); |
There was a problem hiding this comment.
The JSON field name is incorrect. The Ruby script process_genesis_json.rb writes the field as content_uri_sha (line 17), but this code is trying to read from content_uri_hash. This will cause the genesis script to fail. Change .content_uri_hash to .content_uri_sha to match the JSON output.
| params.contentUriSha = vm.parseJsonBytes32(json, string.concat(basePath, ".content_uri_hash")); | |
| params.contentUriSha = vm.parseJsonBytes32(json, string.concat(basePath, ".content_uri_sha")); |
| mediaType, | ||
| '":"', | ||
| mediaUri.escapeJSON(), | ||
| mediaUri, |
There was a problem hiding this comment.
Removed .escapeJSON() from mediaUri when constructing JSON. While data URIs with base64 encoding typically don't contain characters requiring JSON escaping, this removal could cause issues if the data URI contains quotes, backslashes, or other special characters. Consider restoring .escapeJSON() or documenting why it's safe to omit.
| mediaUri, | |
| mediaUri.escapeJSON(), |
| stored_sha = stored[:content_hash]&.downcase&.delete_prefix('0x') | ||
| expected_sha = creation[:content_hash].downcase.delete_prefix('0x') | ||
| content_hash_match = stored_sha == expected_sha | ||
| content_hash_check = record_comparison( |
There was a problem hiding this comment.
This assignment to content_hash_check is useless, since its value is never read.
contentUriShafor protocol uniqueness checks.contentHashfor deduplication of content, replacing the previouscontentSha.MetaStoreLibfor efficient management of mimetype, protocol, and operation.Note
Replaces contentUriHash/contentSha with contentUriSha/contentHash and introduces MetaStoreLib-based deduped metadata; updates contracts, scripts, validators/readers, and tests accordingly.
contentUriHash/contentShawithcontentUriSha(sha256 URI) andcontentHash(keccak256 content) across storage, events, proofs, and APIs inEthscriptions,EthscriptionsProver, andGenesisEthscriptions.MetaStoreLibandmetadataStorage; storemimetype/protocol/operationasmetaRef(bytes32), removing dynamicmimetypestorage andprotocolOfmapping.DedupedBlobStorefor shared inline/SSTORE2 deduped blob storage; update content retrieval/storage paths.EthscriptionsRendererLibto decode metadata viaMetaStoreLib, render new attributes (e.g.,Content Hash,Protocol,Operation), and adjust media URI handling.BytePackLibwithpack(bytes); minor interface/ABI changes for getters and pagination unchanged externally.L2Genesis.s.sol: usecontentUriShathroughout; storemetaRef; emit updated events; register protocols unchanged.process_genesis_json.rb: writecontent_uri_shafield.TestTokenUri.s.sol: test cases updated tocontentUriSha.storage_reader.rb: decode newEthscriptiontuple (addscontent_uri_sha,content_hash,protocol_name,operation).event_decoder.rb: parseEthscriptionCreatedwithcontent_uri_sha/content_hash.block_validator.rb: validatecontent_uri_shaandcontent_hashinstead of old fields; instrumentation keys updated.app/models/ethscription_transaction.rb: calldata builder now encodescontentUriSha.contentUriHash→contentUriSha,contentSha→contentHash; new assertions for renderer attributes and prover proof fields; addMetaStore.t.sol.Written by Cursor Bugbot for commit 847d5de. This will update automatically on new commits. Configure here.