Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mitigation: check onERC1155Received() #28

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/MintERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,38 @@
* @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));

Check warning on line 209 in src/MintERC1155.sol

View check run for this annotation

Codecov / codecov/patch

src/MintERC1155.sol#L209

Added line #L209 was not covered by tests
if (response != IERC1155Receiver.onERC1155Received.selector) {
return false;

Check warning on line 211 in src/MintERC1155.sol

View check run for this annotation

Codecov / codecov/patch

src/MintERC1155.sol#L211

Added line #L211 was not covered by tests
}
} else {
return false;
}

uint256[] memory idOrAmountArray = new uint256[](1);
idOrAmountArray[0] = 1;

bytes memory callData = abi.encodeCall(
IERC1155Receiver.onERC1155BatchReceived, (MINTER, address(0), idOrAmountArray, idOrAmountArray, "")
(success, res) = to.staticcall{ gas: 400_000 }(

Check warning on line 220 in src/MintERC1155.sol

View check run for this annotation

Codecov / codecov/patch

src/MintERC1155.sol#L220

Added line #L220 was not covered by tests
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));

Check warning on line 226 in src/MintERC1155.sol

View check run for this annotation

Codecov / codecov/patch

src/MintERC1155.sol#L226

Added line #L226 was not covered by tests
if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
return false;
}
} else {
return false;

Check warning on line 231 in src/MintERC1155.sol

View check run for this annotation

Codecov / codecov/patch

src/MintERC1155.sol#L231

Added line #L231 was not covered by tests
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/NFTMint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ contract NFTMint is Ownable {
}
}

if (!mint.safeBatchTransferAcceptanceCheckOnMint(msg.sender)) {
if (!mint.safeTransferAcceptanceCheckOnMint(msg.sender)) {
revert NFTMint_BuyerNotAcceptingERC1155();
}

Expand Down
Loading