Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
Background
ERC-7399 proposes a common interface for flash loans. Its goal is to let applications borrow assets temporarily across different DeFi protocols without writing a separate integration for each lender.
This article explains the proposal linked below.
I also cover other EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.
Overview
A flash loan is a loan between smart contracts that begins and ends in one blockchain transaction. The borrower receives the funds during that transaction and must return the principal and any fee before it completes. If repayment fails, the transaction reverts and its effects are rolled back.
ERC-7399 defines how the lender accepts a loan request, how the borrower temporarily gains control through a callback, and how the lender verifies that the loan was repaid. A common interface lets applications use those operations across different services.
Motivation
Flash loan providers use different interfaces. Developers have to write provider-specific code for each integration. As adoption grows, maintaining compatibility across providers increases development costs and introduces more opportunities for mistakes.
Differences among existing implementations
| Area | Differences |
|---|---|
| Starting a loan | Providers use different calling conventions. |
| Borrower and callback receiver | Some providers require one address for both roles. Others let them be different. |
| Repayment | Some implementations pull repayment from the borrower. Others require payment to be pushed to the recipient. |
| Flash Minting | Some protocols can Mint their own token without a supply cap or fee. In those cases the limit may come from computation rather than available liquidity. |
These differences make it harder to integrate multiple flash loan providers.
What the proposal aims to improve
A shared interface lets borrowers reuse code across lenders. Lenders can accept requests in a common format and reduce integration work. Wider compatibility can also shorten development time and make it easier for teams to reuse reviewed integration code.
Specification
Basic structure
ERC-7399 defines a short-term loan of ERC-20 tokens. The borrower must repay the assets within the same call to flash() that initiated the loan.
Lifecycle of a flash loan
| Step | What happens |
|---|---|
① The initiator calls flash() |
The request specifies the loan receiver, callback, asset, and amount. |
| ② The lender sends the asset to the loan receiver | The specified amount is transferred temporarily. |
| ③ The lender invokes the callback receiver | The callback performs the operation that uses the loan. |
| ④ The callback arranges repayment | The principal and fee must reach the payment receiver. |
| ⑤ The callback result is returned | The return value of flash() is the return value of the callback. |
If the lender does not receive repayment, the transaction reverts. The fee may be zero.
Main participants
- Lender. The contract that provides the loan and chooses which assets to support.
- Initiator. The address that starts the loan.
- Loan receiver. The address that receives the funds.
- Callback receiver. The address whose function runs to use the borrowed funds.
- Payment receiver. The address that receives the principal and fee.
Lender interface
The lender implements the ERC-7399 interface. The following example is preserved from the original article.
// SPDX-License-Identifier: CC0-1.0
pragma solidity >=0.6.0 <0.9.0;
import { IERC20 } from "./IERC20.sol";
interface IERC7399 {
/// @dev 貸し出し可能な最大金額を返す
function maxFlashLoan(address asset) external view returns (uint256);
/// @dev 指定したローンに対する手数料を返す
function flashFee(IERC20 asset, uint256 amount) external view returns (uint256);
/// @dev フラッシュローンを実行する
function flash(
address loanReceiver,
ERC20 asset,
uint256 amount,
bytes calldata data,
function(address, address, IERC20, uint256, uint256, bytes memory) external returns (bytes memory) callback
)
external
returns (bytes memory);
}| Function | Purpose | Requirements |
|---|---|---|
maxFlashLoan(asset) |
Returns the maximum available amount for the asset. | Must not revert. Returns 0 if the asset is unavailable. |
flashFee(asset, amount) |
Quotes the fee for the specified asset and amount. | Must not revert. Returns type(uint256).max if the lender cannot provide the loan. |
flash() |
Executes the loan. | Invokes the callback and verifies repayment. |
How flash() works
- The lender sends the specified amount of the asset to the loan receiver.
- The lender invokes the callback with the parameters shown below. The example uses the lender itself as the payment receiver; an implementation can choose a separate recipient.
bytes memory result = callback(
msg.sender, // Initiator
address(this), // Lenderコントラクト
asset, // 貸し出すトークン
amount, // 金額
_fee, // 手数料(flashFee関数の結果)
data // エンコードされたユーザーデータ
);- After the callback, the lender checks that the payment receiver has received the principal and fee. In a balance-based check, the result must be at least the payment receiver's balance at the start of the callback, after the loan transfer, plus the amount borrowed and the fee.
flash()returns the callback's result unchanged.
Callback receiver interface
The receiver provides at least one external function with the following signature.
/// @dev コールバック関数の標準形式
/// @param initiator フラッシュローンを開始したアドレス
/// @param paymentReceiver 返済を受け取るアドレス
/// @param asset 借りたトークン
/// @param amount 借りた金額
/// @param fee 支払う手数料
/// @param data 任意のユーザーデータ
/// @return result コールバックの戻り値(ABIエンコード済み)
function(address, address, IERC20, uint256, uint256, bytes memory)
external
returns (bytes memory)
callback;The function can have any name and may be overloaded. Its return type must be bytes memory.
Safety and compatibility requirements
The loan and repayment complete in one transaction. If repayment fails, that transaction reverts. The lender chooses which assets to make available and may charge a fee of zero. The callback can run application-specific logic provided that repayment still succeeds.
Rationale
Why maxFlashLoan and flashFee use numeric return values
A common convention
Both methods return a numeric value even when the lender cannot provide the requested loan. This lets applications compare or sort providers without having to handle a revert for every unsupported request.
| Function | Result when supported | Result when unavailable |
|---|---|---|
maxFlashLoan(asset) |
Maximum amount available. | 0. |
flashFee(asset, amount) |
Fee for the requested asset and amount. | type(uint256).max. |
The application can use those values to determine whether a provider supports the loan.
Why the method is called flash
The verb reflects the fact that the operation starts and ends within a single transaction. It is also less likely to collide with existing function names and is broad enough to cover both lending existing balances and providing newly Minted units.
Why the interface identifies the asset
Flash loan protocols commonly support multiple tokens through a single contract. Passing asset to both flash() and the callback lets the parties handle each token using the same interface.
What data is for
The initiator can pass arbitrary bytes through data, typically after ABI encoding them. The callback can decode those bytes as needed. Because it returns bytes memory, it can send arbitrary information back to the initiator through the return value of flash().
How the callback gets the initiator
Many callbacks need to know who requested the loan. The lender already knows that address as msg.sender, so it supplies the value directly. Putting it only in data would leave the receiver to authenticate a value supplied by the initiator.
Why loanReceiver and callbackReceiver are separate
The explicit loanReceiver parameter lets an application use different addresses to request the loan, receive funds, and execute the callback. All three roles often use one address, so the callback does not receive the loan receiver as a separate parameter. Applications that need this detail can pass it through data.
The role of paymentReceiver
A separate payment receiver decouples the path the assets take from the order in which contracts are called. The contract initiating the loan and the one receiving repayment can be different. This gives implementations flexibility in areas such as repayment accounting and fee distribution.
Why amount and fee are explicit parameters
The callback needs the loan amount and fee to verify the terms and calculate repayment. Encoding them only in data would require the receiver to authenticate the values itself. A separate fee parameter also makes repayment and profitability calculations more straightforward.
Callback flexibility
The initiator can select any external function with the required signature. Different callbacks can perform different tasks, such as collateral swaps. A Solidity external function pointer occupies 24 bytes. The first 20 bytes identify the target address, and the last four identify the function selector.
Why repayment uses a push model
Repayment is pushed to the payment receiver. The lender can verify that the transfer arrived instead of pulling the amount from the borrower. A pull model can introduce extra risks when operations are composed. A push model also makes the repayment check explicit. A wrapper can expose the ERC-7399 interface for a lender that only supports pull repayment.
Compatibility
ERC-7399 is proposed as a successor to ERC-3156. The earlier standard defined the basic lending, repayment, and fee flow. Differences among implementations remained a challenge. ERC-7399 aims to make integrations more flexible through a common interface, but ERC-3156 integrations cannot call it unchanged.
For more on ERC-3156, see the accompanying article.
[ERC-3156] Implementing flash loans on Ethereum
Security considerations
Validating callback arguments
A receiver should authenticate the lender and initiator before relying on callback arguments. Values passed by a caller do not establish their own authenticity.
Argument groups and their validation requirements
| Group | Why validation matters | Main arguments |
|---|---|---|
| Loan terms | The values describe a prior request, but an arbitrary caller can supply different values. | initiator, asset, amount, and fee. |
| Additional data | The initiating caller can supply arbitrary bytes. | data. |
A callback therefore needs a way to check that the values belong to the intended operation.
Authenticating the lender and terms
Before trusting initiator, asset, amount, or fee, verify that the callback came from the lender approved for the operation. The lender that handles flash() commonly calls the receiver directly. For integrations that route through more than one lender or intermediary, restrict recognition to the intended trusted parties.
Validating data
data can contain arbitrary information. Authenticate the lender and establish that the initiator was authorized to supply the bytes before using them. The receiver can then validate their format and meaning against the expected operation.
Flash loan security considerations
Flash loans can move large balances temporarily within a transaction. Their scale makes it important to validate the callback and the requested repayment.
Automatic authorization
Contracts that repay a loan automatically should check that the lender and initiator are trusted for that operation.
| Approach | What it checks |
|---|---|
| Record the expected operation | Store the expected borrower, amount, and fee at initiation and compare them during the callback. |
| Apply application-specific checks | Check the amount sent to the loan receiver and verify the fee against the application's own rules. |
| Limit trusted callers | Restrict the initiators and lenders the contract recognizes. |
These checks reduce the possibility that an outside caller can arrange an unauthorized loan or repayment.
Risks flash Minting creates for other protocols
Flash Minting temporarily expands a token's supply. Other contracts that rely on that supply may observe values outside their normal operating range.
Spot oracle manipulation
An oracle that derives a price from current supply can give a misleading result when the supply includes a temporary flash Mint. Applications that consume that price may make decisions using a distorted value.
| Protection | Purpose |
|---|---|
| Exclude flash-Minted units | Calculate the reference supply without units created temporarily. |
| Use a time average | Reduce dependence on a short-lived fluctuation. |
| Add sanity checks | Detect abrupt supply changes and reject invalid observations. |
Arithmetic overflow and underflow
If a flash Mint has no effective issuance cap, other protocols may encounter values larger than they anticipated. Arithmetic outside the supported numeric range can cause incorrect calculations or losses.
| Protection | Purpose |
|---|---|
| Checked arithmetic | Use compiler support that detects overflow and underflow. |
| Explicit limits | Check the issuance cap and the allowed range of repayment amounts. |
Risks within the flash-Minting protocol
A contract that combines flash Minting with collateral management, borrowing, or redemption can create unintended interactions. A temporary change in internal token balances can affect treasury operations if the financial logic treats those balances as ordinary supply.
Example treasury-loss scenario
The Japanese article illustrates the risk with a contract that lends its own FOO token, borrows from a third party when users Burn FOO, and aggregates several users' obligations in one external account.
| Stage | System-level effect |
|---|---|
| ① Temporary issuance | Flash Minting greatly increases the FOO units in circulation. |
| ② External debt changes | A dependent funding path can increase the lending contract's third-party debt. |
| ③ Borrowing terms change | Greater utilization can raise the interest rate on the underlying platform. |
| ④ Collateral coverage falls | The aggregate position may become undercollateralized and subject to liquidation. |
| ⑤ Treasury losses arise | A liquidation can impose losses on the treasury and create gains elsewhere. |
The design should isolate temporary Minting from treasury funding and enforce independent limits on lending and collateral exposure.
Citation
Alberto Cuesta Cañada (@alcueca), Michael Amadi (@AmadiMichaels), Devtooligan (@devtooligan), Ultrasecr.eth (@ultrasecreth), Sam Bacha (@sambacha), “ERC-7399: ⚡ Flash Loans ⚡ [DRAFT],” Ethereum Improvement Proposals, no. 7399, July 2023. Available at https://eips.ethereum.org/EIPS/eip-7399.
Conclusion
ERC-7399 gives flash lenders and borrowers a shared interface for sending assets, running a callback, and verifying repayment within the same transaction across DeFi integrations.
Questions are welcome by direct message.
I also publish elsewhere.



