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: mintBatch() gas grief #27

Merged
merged 5 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
7 changes: 5 additions & 2 deletions src/NFTMint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract NFTMint is Ownable {
error NFTMint_InvalidPerWalletLimit();
error NFTMint_InvalidMaxMints();
error NFTMint_InvalidOwner();
error NFTMint_InsufficientGas();
error NFTMint_InsufficientFee();

event MintCreated(MintERC1155 indexed mint, MintArgs args);
Expand Down Expand Up @@ -288,8 +289,10 @@ contract NFTMint is Ownable {

delete orders[nextOrderIdToFill_];
nextOrderIdToFill_++;
// If the mint fails with 500_000 gas, the order is still marked as filled.
try currentOrder.mint.mintBatch{ gas: 500_000 }(currentOrder.to, ids, amounts) { } catch { }

if (gasleft() * 63 / 64 < 1_000_000) revert NFTMint_InsufficientGas();
// If the mint fails with 1_000_000 gas, the order is still marked as filled.
try currentOrder.mint.mintBatch{ gas: 1_000_000 }(currentOrder.to, ids, amounts) { } catch { }
}

nextOrderIdToFill = uint96(nextOrderIdToFill_);
Expand Down
16 changes: 16 additions & 0 deletions test/NFTMint.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,21 @@ contract NFTMintTest is TestBase {
assertEq(nftMint.nextOrderIdToFill(), 1);
}

function test_fillOrders_insufficientGas() external {
MintERC1155 mint = test_createMint();

address minter = _randomAddress();
vm.deal(minter, 10 ether);
vm.prank(minter);
nftMint.order{ value: 1.1 ether }(mint, 100, "Test order", new bytes32[](0));

skip(1 days);
// Simulate low gas scenario
vm.startPrank(address(this));
vm.expectRevert(NFTMint.NFTMint_InsufficientGas.selector);
nftMint.fillOrders{ gas: 500_000 }(0);
vm.stopPrank();
}

receive() external payable { }
}
Loading