From fa233972d3d5d644aa77c37a276b7782bd8ab5da Mon Sep 17 00:00:00 2001 From: Brian Le Date: Fri, 9 Aug 2024 17:14:01 -0400 Subject: [PATCH 1/2] check `onERC1155Received()` --- src/MintERC1155.sol | 37 +++++++++++++++++++++++++------------ src/NFTMint.sol | 2 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/MintERC1155.sol b/src/MintERC1155.sol index 0d247ef..0dbb541 100644 --- a/src/MintERC1155.sol +++ b/src/MintERC1155.sol @@ -199,25 +199,38 @@ contract MintERC1155 is ERC1155Upgradeable, OwnableUpgradeable, ERC2981Upgradeab * @notice Check if the given address can receive tokens from this contract * @param to Address to check if receiving tokens is safe */ - function safeBatchTransferAcceptanceCheckOnMint(address to) external view returns (bool) { + function safeTransferAcceptanceCheckOnMint(address to) external view returns (bool) { + if (to.code.length == 0) return true; + + (bool success, bytes memory res) = to.staticcall{ gas: 400_000 }( + abi.encodeCall(IERC1155Receiver.onERC1155Received, (MINTER, address(0), 1, 1, "")) + ); + if (success) { + bytes4 response = abi.decode(res, (bytes4)); + if (response != IERC1155Receiver.onERC1155Received.selector) { + return false; + } + } else { + return false; + } + uint256[] memory idOrAmountArray = new uint256[](1); idOrAmountArray[0] = 1; - bytes memory callData = abi.encodeCall( - IERC1155Receiver.onERC1155BatchReceived, (MINTER, address(0), idOrAmountArray, idOrAmountArray, "") + (bool success, bytes memory res) = to.staticcall{ gas: 400_000 }( + abi.encodeCall( + IERC1155Receiver.onERC1155BatchReceived, (MINTER, address(0), idOrAmountArray, idOrAmountArray, "") + ) ); - - if (to.code.length > 0) { - (bool success, bytes memory res) = to.staticcall{ gas: 400_000 }(callData); - if (success) { - bytes4 response = abi.decode(res, (bytes4)); - if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { - return false; - } - } else { + if (success) { + bytes4 response = abi.decode(res, (bytes4)); + if (response != IERC1155Receiver.onERC1155BatchReceived.selector) { return false; } + } else { + return false; } + return true; } diff --git a/src/NFTMint.sol b/src/NFTMint.sol index 77a7623..5151328 100644 --- a/src/NFTMint.sol +++ b/src/NFTMint.sol @@ -194,7 +194,7 @@ contract NFTMint is Ownable { } } - if (!mint.safeBatchTransferAcceptanceCheckOnMint(msg.sender)) { + if (!mint.safeTransferAcceptanceCheckOnMint(msg.sender)) { revert NFTMint_BuyerNotAcceptingERC1155(); } From 3fb5f8d1bf1bdbde46b94815e4130a62010106a0 Mon Sep 17 00:00:00 2001 From: Brian Le Date: Fri, 9 Aug 2024 17:21:08 -0400 Subject: [PATCH 2/2] fix redeclared vars --- src/MintERC1155.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MintERC1155.sol b/src/MintERC1155.sol index 0dbb541..7c404b0 100644 --- a/src/MintERC1155.sol +++ b/src/MintERC1155.sol @@ -217,7 +217,7 @@ contract MintERC1155 is ERC1155Upgradeable, OwnableUpgradeable, ERC2981Upgradeab uint256[] memory idOrAmountArray = new uint256[](1); idOrAmountArray[0] = 1; - (bool success, bytes memory res) = to.staticcall{ gas: 400_000 }( + (success, res) = to.staticcall{ gas: 400_000 }( abi.encodeCall( IERC1155Receiver.onERC1155BatchReceived, (MINTER, address(0), idOrAmountArray, idOrAmountArray, "") )