Skip to content

Commit f643686

Browse files
authored
Zero value check when price is zero (#465)
* msg value should be zero if price is zero * fix size * add the check for base contracts too
1 parent 8d50a49 commit f643686

24 files changed

+80
-29
lines changed

contracts/LoyaltyCard.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ contract LoyaltyCard is
256256
uint256 _pricePerToken
257257
) internal {
258258
if (_pricePerToken == 0) {
259+
require(msg.value == 0, "!Value");
259260
return;
260261
}
261262

contracts/OpenEditionERC721.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ contract OpenEditionERC721 is
158158
uint256 _pricePerToken
159159
) internal override {
160160
if (_pricePerToken == 0) {
161+
require(msg.value == 0, "!Value");
161162
return;
162163
}
163164

contracts/base/ERC1155Drop.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,19 @@ contract ERC1155Drop is
289289
uint256 _pricePerToken
290290
) internal virtual override {
291291
if (_pricePerToken == 0) {
292+
require(msg.value == 0, "!Value");
292293
return;
293294
}
294295

295296
uint256 totalPrice = _quantityToClaim * _pricePerToken;
296297

298+
bool validMsgValue;
297299
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
298-
if (msg.value != totalPrice) {
299-
revert("Must send total price.");
300-
}
300+
validMsgValue = msg.value == totalPrice;
301+
} else {
302+
validMsgValue = msg.value == 0;
301303
}
304+
require(validMsgValue, "Invalid msg value");
302305

303306
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
304307
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);

contracts/base/ERC1155SignatureMint.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,19 @@ contract ERC1155SignatureMint is ERC1155Base, PrimarySale, SignatureMintERC1155
115115
uint256 _pricePerToken
116116
) internal virtual {
117117
if (_pricePerToken == 0) {
118+
require(msg.value == 0, "!Value");
118119
return;
119120
}
120121

121122
uint256 totalPrice = _quantityToClaim * _pricePerToken;
122123

124+
bool validMsgValue;
123125
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
124-
require(msg.value == totalPrice, "Must send total price.");
126+
validMsgValue = msg.value == totalPrice;
127+
} else {
128+
validMsgValue = msg.value == 0;
125129
}
130+
require(validMsgValue, "Invalid msg value");
126131

127132
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
128133
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);

contracts/base/ERC20Drop.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,20 @@ contract ERC20Drop is ContractMetadata, Multicall, Ownable, ERC20Permit, Primary
9292
uint256 _pricePerToken
9393
) internal virtual override {
9494
if (_pricePerToken == 0) {
95+
require(msg.value == 0, "!Value");
9596
return;
9697
}
9798

9899
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
99100
require(totalPrice > 0, "quantity too low");
100101

102+
bool validMsgValue;
101103
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
102-
require(msg.value == totalPrice, "Must send total price.");
104+
validMsgValue = msg.value == totalPrice;
105+
} else {
106+
validMsgValue = msg.value == 0;
103107
}
108+
require(validMsgValue, "Invalid msg value");
104109

105110
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
106111
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);

contracts/base/ERC20DropVote.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,20 @@ contract ERC20DropVote is ContractMetadata, Multicall, Ownable, ERC20Votes, Prim
7575
uint256 _pricePerToken
7676
) internal virtual override {
7777
if (_pricePerToken == 0) {
78+
require(msg.value == 0, "!Value");
7879
return;
7980
}
8081

8182
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
8283
require(totalPrice > 0, "quantity too low");
8384

85+
bool validMsgValue;
8486
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
85-
require(msg.value == totalPrice, "Must send total price.");
87+
validMsgValue = msg.value == totalPrice;
88+
} else {
89+
validMsgValue = msg.value == 0;
8690
}
91+
require(validMsgValue, "Invalid msg value");
8792

8893
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
8994
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);

contracts/base/ERC20SignatureMint.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
9090
uint256 _price
9191
) internal virtual {
9292
if (_price == 0) {
93+
require(msg.value == 0, "!Value");
9394
return;
9495
}
9596

contracts/base/ERC20SignatureMintVote.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ contract ERC20SignatureMintVote is ERC20Vote, PrimarySale, SignatureMintERC20 {
9797
uint256 _price
9898
) internal virtual {
9999
if (_price == 0) {
100+
require(msg.value == 0, "!Value");
100101
return;
101102
}
102103

contracts/base/ERC721Drop.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,19 @@ contract ERC721Drop is
261261
uint256 _pricePerToken
262262
) internal virtual override {
263263
if (_pricePerToken == 0) {
264+
require(msg.value == 0, "!Value");
264265
return;
265266
}
266267

267268
uint256 totalPrice = _quantityToClaim * _pricePerToken;
268269

270+
bool validMsgValue;
269271
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
270-
if (msg.value != totalPrice) {
271-
revert("Must send total price");
272-
}
272+
validMsgValue = msg.value == totalPrice;
273+
} else {
274+
validMsgValue = msg.value == 0;
273275
}
276+
require(validMsgValue, "Invalid msg value");
274277

275278
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
276279
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);

contracts/base/ERC721SignatureMint.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ contract ERC721SignatureMint is ERC721Base, PrimarySale, SignatureMintERC721 {
103103
uint256 _pricePerToken
104104
) internal virtual {
105105
if (_pricePerToken == 0) {
106+
require(msg.value == 0, "!Value");
106107
return;
107108
}
108109

109110
uint256 totalPrice = _quantityToClaim * _pricePerToken;
110111

112+
bool validMsgValue;
111113
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
112-
require(msg.value == totalPrice, "Must send total price.");
114+
validMsgValue = msg.value == totalPrice;
115+
} else {
116+
validMsgValue = msg.value == 0;
113117
}
118+
require(validMsgValue, "Invalid msg value");
114119

115120
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
116121
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);

0 commit comments

Comments
 (0)