Fix NFT URI length and parsing (#628)

* Fix NFT bridge parsing and limit URI length

Change-Id: I71e728bbe35cfb8f10b86d53475f7e1c68b2866a

* Update NFTBridge.sol

* Update NFTBridge.sol
This commit is contained in:
Hendrik Hofstadt 2021-12-21 14:36:00 +01:00 committed by GitHub
parent af34f454ec
commit e50541912b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 10 deletions

View File

@ -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);
}
}
}