a bit of blocky

This commit is contained in:
2023-09-01 23:24:51 +02:00
parent 8e3b1d93f9
commit 9621715a32
5 changed files with 206 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
/**
* ______ _ _ _ _ _
* | _ \ | | | | | | | | | |
* | | | |_____ ___ __ | | | |_ __ __| | ___ _ __| | __ _ _ __ __| |
* | | | / _ \ \ /\ / / '_ \| | | | '_ \ / _` |/ _ \ '__| | / _` | '_ \ / _` |
* | |/ / (_) \ V V /| | | | |_| | | | | (_| | __/ | | |___| (_| | | | | (_| |
* |___/ \___/ \_/\_/ |_| |_|\___/|_| |_|\__,_|\___|_| \_____/\__,_|_| |_|\__,_|
*/
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract AnotherPlease is ERC721Enumerable {
uint256 public constant TICKETS_TO_GIVE_AWAY = 10;
uint256 public constant PURCHASABLE_TICKETS = 20;
uint256 public constant TICKET_PRICE = 10000000000000 ether;
mapping(address => bool) public freeTicketReceivers;
uint256 public ticketsGivenAway;
error FreeTicketAlreadyClaimed();
error FreeTicketsExhausted();
error NotEnoughFunds();
error SoldOut();
constructor() ERC721("DownUnderLand Tickets", "DUCTF_ENTRY") {}
modifier ticketNotClaimed() {
if (freeTicketReceivers[msg.sender]) revert FreeTicketAlreadyClaimed();
_;
}
// The first 20 people to claim a ticket get it freeeeeeeeeeeeeeeee!
function claimFreeTicket() external ticketNotClaimed {
if (ticketsGivenAway >= TICKETS_TO_GIVE_AWAY) revert FreeTicketsExhausted();
_gibTicket(msg.sender);
ticketsGivenAway++;
freeTicketReceivers[msg.sender] = true;
}
// Buy a ticket to the exclusive DownUnderLand Party!!!!!
// Cheap price!
function buyATicket() external payable {
if (msg.value < TICKET_PRICE) revert NotEnoughFunds();
_gibTicket(msg.sender);
uint256 change = TICKET_PRICE - msg.value;
if (change > 0) {
(bool success,) = msg.sender.call{value: change}("");
require(success, "Bruh do u not want ur money back?");
}
}
function totalTicketsAvailable() public pure returns (uint256) {
return TICKETS_TO_GIVE_AWAY + PURCHASABLE_TICKETS;
}
function _gibTicket(address to) internal {
if (totalSupply() >= totalTicketsAvailable()) revert SoldOut();
_safeMint(to, totalSupply());
}
}

View File

@@ -0,0 +1,88 @@
# Another Please
```
A smart contract system is selling DownUnderLand tickets! Can you get them all?
Goal: Own all 30 tickets to DownUnderLand in your player wallet.
Author: BlueAlder
Estimated startup time: 90 seconds
```
# setup
Siehe "Eight Five Four Five"
# Source
```sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
/**
* ______ _ _ _ _ _
* | _ \ | | | | | | | | | |
* | | | |_____ ___ __ | | | |_ __ __| | ___ _ __| | __ _ _ __ __| |
* | | | / _ \ \ /\ / / '_ \| | | | '_ \ / _` |/ _ \ '__| | / _` | '_ \ / _` |
* | |/ / (_) \ V V /| | | | |_| | | | | (_| | __/ | | |___| (_| | | | | (_| |
* |___/ \___/ \_/\_/ |_| |_|\___/|_| |_|\__,_|\___|_| \_____/\__,_|_| |_|\__,_|
*/
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
contract AnotherPlease is ERC721Enumerable {
uint256 public constant TICKETS_TO_GIVE_AWAY = 10;
uint256 public constant PURCHASABLE_TICKETS = 20;
uint256 public constant TICKET_PRICE = 10000000000000 ether;
mapping(address => bool) public freeTicketReceivers;
uint256 public ticketsGivenAway;
error FreeTicketAlreadyClaimed();
error FreeTicketsExhausted();
error NotEnoughFunds();
error SoldOut();
constructor() ERC721("DownUnderLand Tickets", "DUCTF_ENTRY") {}
modifier ticketNotClaimed() {
if (freeTicketReceivers[msg.sender]) revert FreeTicketAlreadyClaimed();
_;
}
// The first 20 people to claim a ticket get it freeeeeeeeeeeeeeeee!
function claimFreeTicket() external ticketNotClaimed {
if (ticketsGivenAway >= TICKETS_TO_GIVE_AWAY) revert FreeTicketsExhausted();
_gibTicket(msg.sender);
ticketsGivenAway++;
freeTicketReceivers[msg.sender] = true;
}
// Buy a ticket to the exclusive DownUnderLand Party!!!!!
// Cheap price!
function buyATicket() external payable {
if (msg.value < TICKET_PRICE) revert NotEnoughFunds();
_gibTicket(msg.sender);
uint256 change = TICKET_PRICE - msg.value;
if (change > 0) {
(bool success,) = msg.sender.call{value: change}("");
require(success, "Bruh do u not want ur money back?");
}
}
function totalTicketsAvailable() public pure returns (uint256) {
return TICKETS_TO_GIVE_AWAY + PURCHASABLE_TICKETS;
}
function _gibTicket(address to) internal {
if (totalSupply() >= totalTicketsAvailable()) revert SoldOut();
_safeMint(to, totalSupply());
}
}
```
# Lösung
#TODO

View File

@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract EightFiveFourFive {
string private use_this;
bool public you_solved_it = false;
constructor(string memory some_string) {
use_this = some_string;
}
function readTheStringHere() external view returns (string memory) {
return use_this;
}
function solve_the_challenge(string memory answer) external {
you_solved_it = keccak256(bytes(answer)) == keccak256(bytes(use_this));
}
function isSolved() external view returns (bool) {
return you_solved_it;
}
}

View File

@@ -0,0 +1,30 @@
# Eight Five Four Five
```
Warming up, let's get you setup and make sure you can connect to the blockchain infra ok :). Your challenge is to ensure the isSolved() function returns true!
Author: Blue Alder
Estimated startup time: 90 seconds
```
# setup
1. Booten der Instanz
2. Installieren von Metamask im Browser
3. Konfigurieren des Netzes mit ID 31337 und der gelieferten RPC Url (es wird ein leerer Account erstellt der nicht gebraucht wird)
4. Instanz-Url folgen und warten bis fertig gebootet (nicht mehr "Service Unavailable")
5. Import des Account mit dem gelieferten private Key (Zugang zu Player Wallet)
6. Kopieren des Contract Codes in die online blockchain IDE remix.ethereum.org (leichtere Interaktion mit dem Contract, theoretisch auch mit web3js lösbar)
7. Im Seiten-Reiter "Deploy" vob remix die mitgelieferte Contract Adresse in das Feld eintragen und den Contract laden
=> Nun kann man mit dem Contract interagieren
Es wird das Player Wallet gebraucht, da bei der Methode "solve_the_challenge" eine Zustandsveränderung auf der chain erwirkt werden kann, dies kostet gas. Das Player Konto verfügt über genug dieser Währung um die challenge zu lösen. Theoretisch kann man ein eigenes Konto auch an einem faucet füllen.
# Lösung
1. Call "readTheString" => ```I can connect to the blockchain!```
2. Call "solve_the_challenge" mit return aus 1.
3. GetFlag auf der CTF-Seite
=> DUCTF{I_can_connect_to_8545_pretty_epic:)}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB