@@ -4,6 +4,7 @@ pragma solidity 0.8.24;
44import "./ERC721EthscriptionsSequentialEnumerableUpgradeable.sol " ;
55import {LibString} from "solady/utils/LibString.sol " ;
66import "./libraries/SSTORE2Unlimited.sol " ;
7+ import "./libraries/BytePackLib.sol " ;
78import "./libraries/EthscriptionsRendererLib.sol " ;
89import "./EthscriptionsProver.sol " ;
910import "./libraries/Predeploys.sol " ;
@@ -75,8 +76,8 @@ contract Ethscriptions is ERC721EthscriptionsSequentialEnumerableUpgradeable {
7576 /// @dev Ethscription ID (L1 tx hash) => Ethscription data
7677 mapping (bytes32 => Ethscription) internal ethscriptions;
7778
78- /// @dev Content SHA => SSTORE2 pointer (single address, no array )
79- mapping (bytes32 => address ) public contentPointerBySha ;
79+ /// @dev Content SHA => packed content (for <32 bytes) or SSTORE2 pointer (for >=32 bytes )
80+ mapping (bytes32 => bytes32 ) public contentStorageBySha ;
8081
8182 /// @dev Content URI hash => first ethscription tx hash that used it (for protocol uniqueness check)
8283 /// @dev bytes32(0) means unused, non-zero means the content URI has been used
@@ -373,7 +374,16 @@ contract Ethscriptions is ERC721EthscriptionsSequentialEnumerableUpgradeable {
373374 /// @notice Get content for an ethscription
374375 function getEthscriptionContent (bytes32 ethscriptionId ) public view returns (bytes memory ) {
375376 Ethscription storage ethscription = _getEthscriptionOrRevert (ethscriptionId);
376- address pointer = contentPointerBySha[ethscription.contentSha];
377+ bytes32 ref = contentStorageBySha[ethscription.contentSha];
378+
379+ // Check if it's inline content using BytePackLib
380+ if (BytePackLib.isPacked (ref)) {
381+ return BytePackLib.unpack (ref);
382+ }
383+
384+ // It's a pointer to SSTORE2 contract
385+ address pointer = address (uint160 (uint256 (ref)));
386+
377387 return SSTORE2Unlimited.read (pointer);
378388 }
379389
@@ -496,14 +506,21 @@ contract Ethscriptions is ERC721EthscriptionsSequentialEnumerableUpgradeable {
496506 contentSha = sha256 (content);
497507
498508 // Check if content already exists
499- address existingPointer = contentPointerBySha [contentSha];
500- if (existingPointer != address (0 )) {
509+ bytes32 existing = contentStorageBySha [contentSha];
510+ if (existing != bytes32 (0 )) {
501511 // Content already stored, just return the SHA
502512 return contentSha;
503513 }
504514
505- // Content doesn't exist, store it using SSTORE2Unlimited (handles any size)
506- contentPointerBySha[contentSha] = SSTORE2Unlimited.write (content);
515+ // Store based on size
516+ if (content.length <= 31 ) {
517+ // Pack small content directly into bytes32 (0-31 bytes)
518+ contentStorageBySha[contentSha] = BytePackLib.packCalldata (content);
519+ } else {
520+ // Deploy via SSTORE2 for larger content (32+ bytes)
521+ address pointer = SSTORE2Unlimited.write (content);
522+ contentStorageBySha[contentSha] = bytes32 (uint256 (uint160 (pointer)));
523+ }
507524
508525 return contentSha;
509526 }
0 commit comments