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.

ERC-3234 proposes a mechanism for borrowing multiple tokens together through batch flash loans.

This article translates, summarizes, and expands on the following proposal.

More EIP explainers:

Overview

ERC-3234 proposes a common interface for batch flash loans, allowing borrowers to obtain multiple tokens within the same atomic transaction.

Motivation

Many flash-loan providers support borrowing multiple assets together. This is particularly useful when refinancing several positions across DeFi platforms within one transaction.

Batch flash loans are more complex than the single-asset flash loans standardized by ERC-3156. They also serve different users and applications. A dedicated batch interface can address these requirements while retaining consistency with the single-asset standard.

For ERC-3156, see the following article.

ERC-3156: Implementing flash loans on Ethereum

ERC-3234 uses a callback-based interaction between two smart contracts: the lender and the receiver.

Specification

Lender

IERC3234BatchFlashLender.sol
pragma solidity ^0.7.0 || ^0.8.0;
import "./IERC3234BatchFlashBorrower.sol";


interface IERC3234BatchFlashLender {

    /**
     * @dev The amount of currency available to be lended.
     * @param tokens The currency for each loan in the batch.
     * @return The maximum amount that can be borrowed for each loan in the batch.
     */
    function maxFlashLoan(
        address[] calldata tokens
    ) external view returns (uint256[]);

    /**
     * @dev The fees to be charged for a given batch loan.
     * @param tokens The loan currencies.
     * @param amounts The amounts of tokens lent.
     * @return The amount of each `token` to be charged for each loan, on top of the returned principal.
     */
    function flashFee(
        address[] calldata tokens,
        uint256[] calldata amounts
    ) external view returns (uint256[]);

    /**
     * @dev Initiate a batch flash loan.
     * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
     * @param tokens The loan currencies.
     * @param amounts The amount of tokens lent.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     */
    function batchFlashLoan(
        IERC3234BatchFlashBorrower receiver,
        address[] calldata tokens,
        uint256[] calldata amounts,
        bytes[] calldata data
    ) external returns (bool);
}

The lender implements the IERC3234BatchFlashLender interface, which defines three functions.

maxFlashLoan
js
function maxFlashLoan(address[] calldata tokens) external view returns (uint256[]);
  • Returns the maximum amount available to borrow for each specified token.
  • Returns zero for unsupported tokens.

flashFee

js
function flashFee(address[] calldata tokens, uint256[] calldata amounts) external view returns (uint256[]);
  • Returns the fee associated with each token and loan amount.
  • Reverts if an unsupported token is specified.

batchFlashLoan

js
function batchFlashLoan(
    IERC3234BatchFlashBorrower receiver,
    address[] calldata tokens,
    uint256[] calldata amounts,
    bytes[] calldata data
) external returns (bool);

Initiates a batch flash loan to the specified receiver.

Execution flow
  1. Transfer each requested token amount to the receiver.
  2. Invoke the receiver's onBatchFlashLoan() callback.
  3. Verify that the callback returns keccak256("ERC3234BatchFlashBorrower.onBatchFlashLoan").
  4. Revert the transaction if the principal and applicable fee for any loan cannot be collected.
  5. Return true if all operations complete successfully.
Callback arguments
  • Pass the original caller, msg.sender, as the initiator.
  • Preserve the requested tokens, amounts, and associated data when invoking the callback.
  • Calculate the fees consistently with the corresponding flashFee query.

The declarations reproduced in this article use an array of byte strings (bytes[]) for the lender's data argument, but a single byte string (bytes) for the receiver's callback. Likewise, the fee query accepts arrays, whereas the original explanatory shorthand describes a fee for an individual token and amount. These differences should be resolved against the authoritative specification before implementing the interface.

Receiver

The receiver implements IERC3234BatchFlashBorrower.

IERC3234BatchFlashBorrower.sol
pragma solidity ^0.7.0 || ^0.8.0;


interface IERC3234BatchFlashBorrower {

    /**
     * @dev Receive a flash loan.
     * @param initiator The initiator of the loan.
     * @param tokens The loan currency.
     * @param amounts The amount of tokens lent.
     * @param fees The additional amount of tokens to repay.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     * @return The keccak256 hash of "ERC3234BatchFlashBorrower.onBatchFlashLoan"
     */
    function onBatchFlashLoan(
        address initiator,
        address[] calldata tokens,
        uint256[] calldata amounts,
        uint256[] calldata fees,
        bytes calldata data
    ) external returns (bytes32);
}

onBatchFlashLoan

js
function onBatchFlashLoan(
    address initiator,
    address[] calldata tokens,
    uint256[] calldata amounts,
    uint256[] calldata fees,
    bytes calldata data
) external returns (bytes32);
  • Called when the receiver obtains a batch flash loan.
  • The initiator identifies the account that initiated the loan, normally the caller of the lender.
  • Before returning, the receiver must authorize repayment of each principal plus its associated fee to the lender, subject to the lender's repayment model.
  • Successful acceptance is indicated by returning keccak256("ERC3234BatchFlashBorrower.onBatchFlashLoan").

Rationale

Handling unsupported tokens

Returning a numerical fee for an unsupported token could be misleading. The fee query therefore reverts for unsupported tokens, whereas the availability query returns zero.

Function naming

The name batchFlashLoan describes the operation and reduces the likelihood of naming conflicts. The design accommodates lenders that transfer existing tokens as well as those that mint tokens for the duration of a loan.

Providing an explicit receiver argument separates the initiator from the contract that receives the assets and callback.

The name onBatchFlashLoan also follows the callback naming conventions discussed in the proposal.

Consistency with existing implementations

Existing protocols, including Aave, dYdX, and Uniswap, have provided mechanisms for obtaining multiple assets within atomic operations. ERC-3234 incorporates token arrays to accommodate multi-asset borrowing patterns through a common interface. The precise capabilities vary by protocol and version.

Arbitrary data

The callback data field allows applications to supply custom parameters without expanding the standard interface for every use case.

Explicit initiator and amounts

The lender already knows the initiator from its execution context. Passing that address explicitly is clearer than requiring the receiver to extract it from arbitrary data.

The loan amounts are also passed directly so they can be validated without parsing application-specific data.

Passing fees

Providing the fees as explicit callback arguments lets the receiver determine the amounts required for repayment.

Pull-based repayment

The proposed repayment design uses a pull mechanism: the lender collects the repayment from the receiver using token allowances.

A push-based model, in which the receiver transfers the repayment back directly, is also possible. The proposal favors pull-based repayment for consistency with existing interfaces and integration patterns.

Security

Validating onBatchFlashLoan arguments

The callback arguments describe the loan conditions but should not be trusted merely because they appear in a call.

Arguments describing the loan

  • Initiator.
  • Token addresses.
  • Loan amounts.
  • Fees.

A receiver should verify that the callback originates from an authorized lender and that the parameters match the intended loan.

Arbitrary data

Trusting application-specific data additionally requires validating the initiator and checking that the data corresponds to an authorized operation.

Risks of automatic approval

Automatically approving repayment in a callback creates risks when lenders or initiators are not properly authenticated. Receivers should restrict approvals to the intended loan and avoid leaving unnecessary allowances.

Lenders must validate the callback's prescribed return value. This check alone does not replace the receiver's own authentication and authorization requirements.

External risks of flash minting

Flash minting can temporarily increase token supply within a transaction. Applications integrating flash-mintable assets must consider how temporary liquidity and supply changes affect their security assumptions.

Example 1: Interest-rate manipulation

The original article discusses how temporary liquidity can distort a lending protocol's interest-rate calculations and produce loan terms inconsistent with its intended economic model. Such risks can be mitigated by designing rate calculations that account for transient liquidity, applying appropriate bounds, and testing economic invariants under adversarial conditions.

Example 2: Integer overflow and underflow

Unbounded flash minting can expose arithmetic to extreme values approaching the maximum uint256 value, 2^256 - 1.

Solidity versions predating 0.8 require appropriate checked arithmetic, for example through OpenZeppelin's SafeMath library.

Solidity 0.8 and later check ordinary arithmetic for overflow and underflow by default. Unchecked blocks and other arithmetic assumptions still require review.

Internal risks of flash minting

Combining flash minting with protocol-specific functionality can violate assumptions that appear safe when each feature is considered independently.

Example: Treasury exposure in Yield Protocol

The original article discusses an historical scenario involving fyDAI flash minting, redemption, and interactions with MakerDAO collateral and liquidation accounting. The underlying lesson is that temporary token supply changes can affect treasury solvency and collateralization across integrated protocols.

Developers should test these interactions together, establish solvency invariants, and account for temporary changes in supply and liquidity.

The code excerpts in this article are reproduced from the original and have not been independently compiled or audited.

Citation

Alberto Cuesta Cañada (@albertocuestacanada), Fiona Kobayashi (@fifikobayashi), fubuloubu (@fubuloubu), Austin Williams (@onewayfunction), "ERC-3234: Batch Flash Loans [DRAFT]," Ethereum Improvement Proposals, no. 3234, January 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3234.

Conclusion

ERC-3234 proposes a standardized callback-based interface for borrowing multiple tokens through batch flash loans within a single transaction.

Questions are welcome via Twitter @cardene777.

Other publications:

https://chaldene.net/