Skip to content

Commit 192a5cc

Browse files
authored
SignatureMint zero address check (#258)
* (C-1) mintWithSignature() front-running vulnerability * (M-1) TokenERC20 charges price when quantity is 0
1 parent 69143d3 commit 192a5cc

11 files changed

+27
-43
lines changed

contracts/base/ERC1155SignatureMint.sol

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,7 @@ contract ERC1155SignatureMint is ERC1155Base, PrimarySale, SignatureMintERC1155
6969
// Verify and process payload.
7070
signer = _processRequest(_req, _signature);
7171

72-
/**
73-
* Get receiver of tokens.
74-
*
75-
* Note: If `_req.to == address(0)`, a `mintWithSignature` transaction sitting in the
76-
* mempool can be frontrun by copying the input data, since the minted tokens
77-
* will be sent to the `_msgSender()` in this case.
78-
*/
79-
address receiver = _req.to == address(0) ? msg.sender : _req.to;
72+
address receiver = _req.to;
8073

8174
// Collect price
8275
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);

contracts/base/ERC20SignatureMint.sol

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
5555
// Verify and process payload.
5656
signer = _processRequest(_req, _signature);
5757

58-
/**
59-
* Get receiver of tokens.
60-
*
61-
* Note: If `_req.to == address(0)`, a `mintWithSignature` transaction sitting in the
62-
* mempool can be frontrun by copying the input data, since the minted tokens
63-
* will be sent to the `_msgSender()` in this case.
64-
*/
65-
address receiver = _req.to == address(0) ? msg.sender : _req.to;
58+
address receiver = _req.to;
6659

6760
// Collect price
6861
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);

contracts/base/ERC721SignatureMint.sol

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,7 @@ contract ERC721SignatureMint is ERC721Base, PrimarySale, SignatureMintERC721 {
6161
// Verify and process payload.
6262
signer = _processRequest(_req, _signature);
6363

64-
/**
65-
* Get receiver of tokens.
66-
*
67-
* Note: If `_req.to == address(0)`, a `mintWithSignature` transaction sitting in the
68-
* mempool can be frontrun by copying the input data, since the minted tokens
69-
* will be sent to the `_msgSender()` in this case.
70-
*/
71-
address receiver = _req.to == address(0) ? msg.sender : _req.to;
64+
address receiver = _req.to;
7265

7366
// Collect price
7467
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);

contracts/extension/SignatureMintERC1155.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ abstract contract SignatureMintERC1155 is EIP712, ISignatureMintERC1155 {
4141
_req.validityStartTimestamp <= block.timestamp && block.timestamp <= _req.validityEndTimestamp,
4242
"Request expired"
4343
);
44+
require(_req.to != address(0), "recipient undefined");
45+
require(_req.quantity > 0, "0 qty");
4446

4547
minted[_req.uid] = true;
4648
}

contracts/extension/SignatureMintERC1155Upgradeable.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ abstract contract SignatureMintERC1155Upgradeable is Initializable, EIP712Upgrad
4747
_req.validityStartTimestamp <= block.timestamp && block.timestamp <= _req.validityEndTimestamp,
4848
"Request expired"
4949
);
50+
require(_req.to != address(0), "recipient undefined");
51+
require(_req.quantity > 0, "0 qty");
5052

5153
minted[_req.uid] = true;
5254
}

contracts/extension/SignatureMintERC20.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ abstract contract SignatureMintERC20 is EIP712, ISignatureMintERC20 {
4141
_req.validityStartTimestamp <= block.timestamp && block.timestamp <= _req.validityEndTimestamp,
4242
"Request expired"
4343
);
44+
require(_req.to != address(0), "recipient undefined");
45+
require(_req.quantity > 0, "0 qty");
4446

4547
minted[_req.uid] = true;
4648
}

contracts/extension/SignatureMintERC20Upgradeable.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ abstract contract SignatureMintERC20Upgradeable is Initializable, EIP712Upgradea
4747
_req.validityStartTimestamp <= block.timestamp && block.timestamp <= _req.validityEndTimestamp,
4848
"Request expired"
4949
);
50+
require(_req.to != address(0), "recipient undefined");
51+
require(_req.quantity > 0, "0 qty");
5052

5153
minted[_req.uid] = true;
5254
}

contracts/extension/SignatureMintERC721.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ abstract contract SignatureMintERC721 is EIP712, ISignatureMintERC721 {
4343
if (_req.validityStartTimestamp > block.timestamp || block.timestamp > _req.validityEndTimestamp) {
4444
revert("Req expired");
4545
}
46+
require(_req.to != address(0), "recipient undefined");
47+
require(_req.quantity > 0, "0 qty");
4648

4749
minted[_req.uid] = true;
4850
}

contracts/extension/SignatureMintERC721Upgradeable.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ abstract contract SignatureMintERC721Upgradeable is Initializable, EIP712Upgrade
4949
if (_req.validityStartTimestamp > block.timestamp || block.timestamp > _req.validityEndTimestamp) {
5050
revert("Req expired");
5151
}
52+
require(_req.to != address(0), "recipient undefined");
53+
require(_req.quantity > 0, "0 qty");
5254

5355
minted[_req.uid] = true;
5456
}

contracts/signature-drop/SignatureDrop.sol

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,7 @@ contract SignatureDrop is
190190
// Verify and process payload.
191191
signer = _processRequest(_req, _signature);
192192

193-
/**
194-
* Get receiver of tokens.
195-
*
196-
* Note: If `_req.to == address(0)`, a `mintWithSignature` transaction sitting in the
197-
* mempool can be frontrun by copying the input data, since the minted tokens
198-
* will be sent to the `_msgSender()` in this case.
199-
*/
200-
address receiver = _req.to == address(0) ? _msgSender() : _req.to;
193+
address receiver = _req.to;
201194

202195
// Collect price
203196
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);

0 commit comments

Comments
 (0)