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:
parent
af34f454ec
commit
e50541912b
|
@ -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,
|
||||
|
@ -233,19 +236,20 @@ 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(
|
||||
|
|
Loading…
Reference in New Issue