-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calyptus422.sol
44 lines (35 loc) · 1.36 KB
/
Calyptus422.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier:MIT
pragma solidity ^0.8.24;
//FestivalCoin's new smart contract allows fans to buy event tickets in batches.
//The dev team is proud, but the security auditor is suspicious.
//Can you spot the flaw? 🤔
// import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
// import "@openzeppelin/contracts/access/Ownable.sol";
// import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";
contract TicketingSystem is ERC1155, Ownable, ERC1155Supply {
constructor() ERC1155("") {}
error MaxSupplyReached();
error InvalidPrice();
mapping(uint256 => uint256) ticketsWithMaxSupply;
mapping (uint256 => uint256) ticketsWithPrice;
function buyTicketsBatch(
address to,
uint256[] calldata ids,
uint256[] calldata quantities
) public payable {
uint256 overallPrice;
for (uint256 i; i < ids.length; ++i) {
uint256 ticketQuantity = quantities[i];
uint256 ticketId = ids[i];
overallPrice += ticketsWithPrice[ticketId] * ticketQuantity;
if (
ERC1155Supply.totalSupply(ticketId) + ticketQuantity >
ticketsWithMaxSupply[ticketId]
){
revert MaxSupplyReached();
}
}
if (msg.value != overallPrice) revert InvalidPrice();
_mintBatch(to, ids, quantities, "");
}
}