소스 검색

Fix NFT URI length and parsing (#628)

* Fix NFT bridge parsing and limit URI length

Change-Id: I71e728bbe35cfb8f10b86d53475f7e1c68b2866a

* Update NFTBridge.sol

* Update NFTBridge.sol
Hendrik Hofstadt 3 년 전
부모
커밋
e50541912b
1개의 변경된 파일14개의 추가작업 그리고 10개의 파일을 삭제
  1. 14 10
      ethereum/contracts/nft/NFTBridge.sol

+ 14 - 10
ethereum/contracts/nft/NFTBridge.sol

@@ -196,6 +196,9 @@ contract NFTBridge is NFTBridgeGovernance {
     }
 
     function encodeTransfer(NFTBridgeStructs.Transfer memory transfer) public pure returns (bytes memory encoded) {
+        // There is a global limit on 200 bytes of tokenURI in Wormhole due to Solana
+        require(bytes(transfer.uri).length <= 200, "tokenURI must not exceed 200 bytes");
+
         encoded = abi.encodePacked(
             uint8(1),
             transfer.tokenAddress,
@@ -232,20 +235,21 @@ contract NFTBridge is NFTBridgeGovernance {
 
         transfer.tokenID = encoded.toUint256(index);
         index += 32;
-
-        uint8 len_uri = encoded.toUint8(index);
+        
+        // Ignore length due to malformatted payload
         index += 1;
+        transfer.uri = string(encoded.slice(index, encoded.length - index - 34));
 
-        transfer.uri = string(encoded.slice(index, len_uri));
-        index += len_uri;
-
-        transfer.to = encoded.toBytes32(index);
-        index += 32;
+        // From here we read backwards due malformatted package
+        index = encoded.length;
 
+        index -= 2;
         transfer.toChain = encoded.toUint16(index);
-        index += 2;
 
-        require(encoded.length == index, "invalid Transfer");
+        index -= 32;
+        transfer.to = encoded.toBytes32(index);
+
+        //require(encoded.length == index, "invalid Transfer");
     }
 
     function onERC721Received(
@@ -269,4 +273,4 @@ contract NFTBridge is NFTBridgeGovernance {
         }
         return string(array);
     }
-}
+}