diff --git a/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol b/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol index 6136f4cf1..dc82cb0e0 100644 --- a/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol +++ b/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721.sol @@ -102,15 +102,24 @@ abstract contract LSP8CompatibleERC721 is uint256 /* tokenId */ ) public view virtual returns (string memory) { bytes memory data = _getData(_LSP4_METADATA_KEY); - - // offset = bytes4(hashSig) + bytes32(contentHash) -> 4 + 32 = 36 - uint256 offset = 36; - - bytes memory uriBytes = BytesLib.slice( - data, - offset, - data.length - offset - ); + uint256 requiredLength = data.length - 36; + + bytes memory uriBytes; + assembly { + uriBytes := mload(0x40) + mstore(uriBytes, requiredLength) + for { + let i := 0 + } lt(i, requiredLength) { + i := add(i, 0x20) + } { + mstore( + add(uriBytes, add(i, 0x20)), + mload(add(data, add(i, 68))) + ) + } + mstore(0x40, add(uriBytes, add(0x20, requiredLength))) + } return string(uriBytes); } diff --git a/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol b/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol index 851a0e361..60ef44e97 100644 --- a/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol +++ b/contracts/LSP8IdentifiableDigitalAsset/extensions/LSP8CompatibleERC721InitAbstract.sol @@ -110,15 +110,24 @@ abstract contract LSP8CompatibleERC721InitAbstract is uint256 /* tokenId */ ) public view virtual returns (string memory) { bytes memory data = _getData(_LSP4_METADATA_KEY); - - // offset = bytes4(hashSig) + bytes32(contentHash) -> 4 + 32 = 36 - uint256 offset = 36; - - bytes memory uriBytes = BytesLib.slice( - data, - offset, - data.length - offset - ); + uint256 requiredLength = data.length - 36; + + bytes memory uriBytes; + assembly { + uriBytes := mload(0x40) + mstore(uriBytes, requiredLength) + for { + let i := 0 + } lt(i, requiredLength) { + i := add(i, 0x20) + } { + mstore( + add(uriBytes, add(i, 0x20)), + mload(add(data, add(i, 68))) + ) + } + mstore(0x40, add(uriBytes, add(0x20, requiredLength))) + } return string(uriBytes); }