From 9cb16d9a84e8d9f89f5f4a7fdfbf7ec39f1756b6 Mon Sep 17 00:00:00 2001 From: dcota <32775237+DaigaroCota@users.noreply.github.com> Date: Mon, 5 Feb 2024 22:22:49 -0800 Subject: [PATCH] fix: add token uri and memoir to release key --- src/MgdL2NFTEscrow.sol | 44 ++++++++++++++++++++++---------- src/voucher/Mgd1155L2Voucher.sol | 7 ++--- src/voucher/Mgd721L2Voucher.sol | 7 ++--- src/voucher/MgdL2BaseNFT.sol | 2 +- src/voucher/MgdL2BaseVoucher.sol | 15 +++++++++-- 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/MgdL2NFTEscrow.sol b/src/MgdL2NFTEscrow.sol index 1ca6307..bc24220 100644 --- a/src/MgdL2NFTEscrow.sol +++ b/src/MgdL2NFTEscrow.sol @@ -140,7 +140,7 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver { /// @param nft token address to redeem /// @param tokenId to redeeem /// @param amount to redeem - /// @param owner who will receive nft + /// @param receiver who will receive nft /// @param blockHash of tx in L2 where {MgdL2NFTVoucher.redeemVoucherToL1(...)} was called /// @param marketData status of voucher when redeem call was initiated in L2 function getRedeemClearanceKey( @@ -148,16 +148,19 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver { address nft, uint256 tokenId, uint256 amount, - address owner, + address receiver, bytes32 blockHash, - MgdL1MarketData calldata marketData + MgdL1MarketData calldata marketData, + string memory tokenURI, + bytes memory tokenIdMemoir ) external view returns (bool) { - uint256 key = - _generateL1RedeemKey(voucherId, nft, tokenId, amount, owner, blockHash, marketData); + uint256 key = _generateL1RedeemKey( + voucherId, nft, tokenId, amount, receiver, blockHash, marketData, tokenURI, tokenIdMemoir + ); return redeemClearance[key]; } @@ -180,13 +183,14 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver { address receiver, bytes32 blockHash, MgdL1MarketData calldata marketData, - string calldata tokenURI, - bytes calldata memoir + string memory tokenURI, + bytes memory memoir ) external { - uint256 key = - _generateL1RedeemKey(voucherId, nft, tokenId, amount, receiver, blockHash, marketData); + uint256 key = _generateL1RedeemKey( + voucherId, nft, tokenId, amount, receiver, blockHash, marketData, tokenURI, memoir + ); if (!redeemClearance[key]) { revert MgdL2NFTEscrow__releaseFromEscrow_notClearedOrAlreadyReleased(); } @@ -326,16 +330,30 @@ contract MgdL2NFTEscrow is Initializable, IERC721Receiver, IERC1155Receiver { address nft, uint256 tokenId, uint256 amount, - address owner, + address receiver, bytes32 blockHash, - MgdL1MarketData calldata marketData + MgdL1MarketData calldata marketData, + string memory tokenURI, + bytes memory tokenIdMemoir ) internal pure returns (uint256 key) { - key = - uint256(keccak256(abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData))); + if (tokenId == _REF_NUMBER) { + bytes32 hashedUriMemoir = keccak256(abi.encode(tokenURI, tokenIdMemoir)); + key = uint256( + keccak256( + abi.encode( + voucherId, nft, tokenId, amount, receiver, blockHash, marketData, hashedUriMemoir + ) + ) + ); + } else { + key = uint256( + keccak256(abi.encode(voucherId, nft, tokenId, amount, receiver, blockHash, marketData)) + ); + } } function _sendEscrowNoticeToL2(uint256 voucherId, bool state, TypeNFT nftType) internal { diff --git a/src/voucher/Mgd1155L2Voucher.sol b/src/voucher/Mgd1155L2Voucher.sol index c703a5e..a28889a 100644 --- a/src/voucher/Mgd1155L2Voucher.sol +++ b/src/voucher/Mgd1155L2Voucher.sol @@ -245,11 +245,12 @@ contract Mgd1155L2Voucher is MgdL2BaseVoucher, ERC1155Permit, Almost1155Upgradea _mint(owner, voucherId, representedAmount, ""); _voucherMarketData[voucherId] = marketData; - if (memoir.length > 0) { - _tokenIdMemoir[voucherId] = memoir; - } if (generatedL1VoucherId == 0) { + _tokenURIs[voucherId] = tokenURI; + if (memoir.length > 0) { + _tokenIdMemoir[voucherId] = memoir; + } emit MintGoldDustNFTMinted( voucherId, tokenURI, diff --git a/src/voucher/Mgd721L2Voucher.sol b/src/voucher/Mgd721L2Voucher.sol index 0d2983c..156d495 100644 --- a/src/voucher/Mgd721L2Voucher.sol +++ b/src/voucher/Mgd721L2Voucher.sol @@ -222,11 +222,12 @@ contract Mgd721L2Voucher is MgdL2BaseVoucher, ERC721Permit, Almost721Upgradeable _safeMint(owner, voucherId); _voucherMarketData[voucherId] = marketData; - if (memoir.length > 0) { - _tokenIdMemoir[voucherId] = memoir; - } if (generatedL1VoucherId == 0) { + _tokenURIs[voucherId] = tokenURI; + if (memoir.length > 0) { + _tokenIdMemoir[voucherId] = memoir; + } emit MintGoldDustNFTMinted( voucherId, tokenURI, diff --git a/src/voucher/MgdL2BaseNFT.sol b/src/voucher/MgdL2BaseNFT.sol index 47e93f6..36f4877 100644 --- a/src/voucher/MgdL2BaseNFT.sol +++ b/src/voucher/MgdL2BaseNFT.sol @@ -49,7 +49,7 @@ abstract contract MgdL2BaseNFT is Initializable, PausableUpgradeable, Reentrancy // voucherId => struct MgdL1MarketData mapping(uint256 => MgdL1MarketData) internal _voucherMarketData; - + mapping(uint256 => string) internal _tokenURIs; mapping(uint256 => bytes) internal _tokenIdMemoir; /** diff --git a/src/voucher/MgdL2BaseVoucher.sol b/src/voucher/MgdL2BaseVoucher.sol index 28882fe..44ee4a0 100644 --- a/src/voucher/MgdL2BaseVoucher.sol +++ b/src/voucher/MgdL2BaseVoucher.sol @@ -287,8 +287,19 @@ abstract contract MgdL2BaseVoucher is MgdL2BaseNFT { returns (uint256 key, bytes32 blockHash) { blockHash = blockhash(block.number); - key = - uint256(keccak256(abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData))); + if (tokenId == _REF_NUMBER) { + bytes32 hashedUriMemoir = + keccak256(abi.encode(_tokenURIs[voucherId], _tokenIdMemoir[voucherId])); + key = uint256( + keccak256( + abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData, hashedUriMemoir) + ) + ); + } else { + key = uint256( + keccak256(abi.encode(voucherId, nft, tokenId, amount, owner, blockHash, marketData)) + ); + } } function _clearVoucherData(uint256 voucherId) internal {