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.
This article covers ERC-7412, a proposal for secure and efficient interactions across multiple blockchains and oracle networks using multicall.
This article translates, summarizes, and expands on the following specification.
Overview
ERC-7412 proposes a solution for smart contracts that require off-chain data (data from outside the blockchain). Specifically, it describes how to retrieve such data through oracles and make it available on-chain. The process works as follows.
1. Off-chain data is needed during contract execution
A smart contract may need data from outside the blockchain, such as weather information or stock prices, to execute its logic.
2. Proposed error
Under the proposed standard, the smart contract raises an OracleDataRequired(address oracleContract, bytes oracleQuery) error to indicate that it needs off-chain data.
This is an explicit notification from the contract that off-chain data is required.
3. The client's role
A client receiving this error, such as a user's wallet or application, queries the specified oracle network to obtain the required off-chain data.
4. Data retrieval and verification
The client supplies the data obtained from the oracle network to the smart contract in a form that can be verified on-chain, allowing the contract to check that the data has not been tampered with.
5. Using multicall
The client uses multicall to execute off-chain data verification and the original smart contract function call consecutively within a single transaction. This allows the contract's logic to execute successfully immediately after the data is verified.
6. Writing off-chain data on-chain
Through this process, off-chain data is written to the blockchain, where the smart contract can read and use it.
The proposal describes a way to retrieve and use the off-chain data required by smart contracts efficiently and securely. Retrieving data through oracles and recording it on-chain for contracts to access enables more flexible and practical smart contract implementations.
Motivation
Ethereum's scaling roadmap introduces multiple execution contexts for running smart contract code, including Layer 2 and Layer 3 scaling solutions. The ability to read data across multiple chains therefore becomes important when building scalable applications. In decentralized finance (DeFi) protocols that rely on price data, in particular, it is impractical for oracle networks to continuously push fresh data to countless Layer 2 and Layer 3 networks.
Cross-chain bridges are being developed to address this problem by allowing smart contract functions to write data to other chains. A corresponding standard is also needed to make it possible to read data from other chains. Such a standard can be generalized to read arbitrary off-chain data, including price feeds, from decentralized oracle networks.
With standards for both writing and reading cross-chain data, protocol developers can build abstractions around asynchrony, a subject that has been extensively explored in other areas of software engineering. This makes it possible to develop sophisticated protocols without being hindered by scaling constraints.
ERC-3668 introduced the use of a revert when off-chain data is required.
The standard proposed here can overcome some of its limitations by using multicall instead of callback functions.
This section describes the need for standards for reading and writing data across multiple chains to address Ethereum's scaling challenges. These standards open the way to sophisticated protocols that can operate without being constrained by scaling limitations.
Specification
This section describes the standard that smart contracts requiring off-chain data should follow. It provides guidelines for constructing a process to request and verify specific off-chain data.
OracleDataRequired error
error OracleDataRequired(address oracleContract, bytes oracleQuery)- Error raised when off-chain data is required
- When the contract needs off-chain data, it returns an
OracleDataRequired(address oracleContract, bytes oracleQuery)error.
- When the contract needs off-chain data, it returns an
- oracleQuery
- Specifies the requested off-chain data.
- Its format depends on the oracle ID specified by the oracle contract.
- It may include a chain ID, contract address, function signature, payload, timestamp, or a request for the latest data.
- oracleContract
- Address of the contract that verifies off-chain data and supplies the data needed to avoid the
OracleDataRequirederror.
- Address of the contract that verifies off-chain data and supplies the data needed to avoid the
IERC7412 interface
interface IERC7412 {
function oracleId() view external returns (bytes32 oracleId);
function fulfillOracleQuery(bytes signedOffchainData) payable external;
}- IERC7412
- The interface that must be implemented to fulfill off-chain data queries.
- oracleId() function
- Returns a unique identifier (oracle ID) referencing a decentralized oracle network.
- This ID is analogous to a chain ID in the Ethereum ecosystem.
- fulfillOracleQuery(bytes signedOffchainData) function
- Executes to verify off-chain data and fulfill the query. This function may require payment.
FeeRequired error
error FeeRequired(uint amount)- FeeRequired(uint amount)
- Specifies the fee (described here as a gas fee) required to execute
fulfillOracleQuery. - The caller resolves this error by supplying a sufficient fee through
msg.value.
- Specifies the fee (described here as a gas fee) required to execute
Key points
The standard provides a clear framework for handling off-chain data securely and efficiently. Smart contracts can specify the off-chain data they require and request it from oracle contracts capable of verifying and making it available. The oracle contract verifies the data and provides it upon payment of any required fee. This enables smart contracts to access off-chain data and perform operations using it.
The standard defines how smart contracts can securely and efficiently retrieve and use external data, such as price information, when they need it.
The specification also describes how clients should construct a multicall (multiple function calls executed in one transaction) for smart contract operations that require off-chain data.
Constructing a multicall
- Client responsibility
- The client is responsible for constructing a multicall that executes
fulfillOracleQueryto verify off-chain data before the intended function call, within an atomic transaction.
- The client is responsible for constructing a multicall that executes
- Atomic transaction
- Executes multiple operations in a single transaction, ensuring that either all operations succeed or all are rolled back if any fails.
Account abstraction and EOA support
- Account abstraction
- Wallets compliant with ERC-4337 should already be capable of generating atomic multi-operation transactions.
For more on ERC-4337, see the following article.
[ERC-4337] Implementing account abstraction without protocol changes
- Externally owned account (EOA) support
- Protocols can implement ERC-2771 to support this standard for EOAs.
For more on ERC-2771, see the following article.
[ERC-2771] Meta-transactions that let another address pay gas fees
Maintaining data freshness
- Emitting an OracleDataUsed event
- Ideally, the contract would emit an
OracleDataUsedevent to prevent the data from becoming too stale between the request and execution. - This event would include
oracleContract,oracleQuery, andexpirationTime, which indicates when the data becomes stale.
- Ideally, the contract would emit an
- Lack of a practical mechanism
- At the time of writing, most JSON-RPC APIs do not provide a practical way to retrieve event data during transaction simulation, so this feature was omitted from the standard.
Using URIs
- oracleId as a URI
- By using a URI for
oracleIdand specifying a particular URI asoracleQuery, the standard can accommodate arbitrary on-chain URIs without requiring client library updates. - This resembles the approach used in ERC-3668.
- By using a URI for
This section covers how to construct multicall transactions for efficient off-chain data retrieval, a proposal to emit events for tracking data freshness, and a flexible way to specify oracle IDs through URIs. These mechanisms provide a foundation for smart contracts to execute operations that depend on off-chain data more efficiently and securely.
Additional considerations
This proposal offers an alternative to the existing ERC-3668 standard that differs in several respects.
Differences from ERC-3668
On-chain URI encoding
ERC-3668 requires URIs to be encoded on-chain, which works well for static assets, such as NFT-related assets and IPFS hashes of Merkle trees. It is less suitable when fresh data is required, such as cross-chain data or price feeds. HTTP URLs can reference dynamic data, but this increases centralization and maintenance risks.
Using multicall
This proposal relies on multicall rather than callbacks. That substantially simplifies nested calls requiring different pieces of off-chain data. With the proposed standard, end users, including those using clients that implement account abstraction, need only sign a transaction regardless of the complexity of its internal call structure. The client can automatically add the off-chain data needed for the calls to succeed.
Simpler error construction
Developers implementing this standard need to know only their chosen oracle network, the query format accepted by that network, and the contract from which they intend to retrieve data.
Oracle provider scalability and compatibility
Under this standard, oracle providers can scale to support an unlimited number of networks while remaining compatible with local or forked networks used for protocol development.
Additional benefits
Oracles can charge fees in the native gas token during on-chain data verification. This creates an economic incentive to collect fees from data consumers and distribute them to node operators in decentralized oracle networks.
The proposal offers an alternative to ERC-3668 intended to make the implementation and operation of smart contracts requiring off-chain data more flexible and efficient.
Implementation
prepareTransaction function
function prepareTransaction(originalTx) {
let multicallTx = [originalTx];
while (true) {
try {
const simulationResult = simulateTx(multicallTx);
return multicallTx;
} catch (error) {
if (error instanceof OracleDataRequired) {
const signedRequiredData = fetchOffchainData(
error.oracleContract,
error.oracleQuery
);
const dataVerificationTx = generateDataVerificationTx(
error.oracleContract,
signedRequiredData
);
multicallTx.unshift(dataVerificationTx);
}
}
}
}This pseudocode illustrates a simplified version of a client SDK.
Ideally, this functionality would be implemented in wallets, although it could also be integrated at the application layer.
The function accepts the desired transaction and converts it into a multicall.
It prepends the data verification transactions needed to avoid the OracleDataRequired error.
How the function works
- prepareTransaction function
- Accepts the original transaction (
originalTx) as an argument.
- Accepts the original transaction (
- Initialize multicallTx
- First, create the multicall transaction array
multicallTxcontaining the original transaction.
- First, create the multicall transaction array
- Start an infinite loop
- Attempt transaction simulation and continue looping until the necessary off-chain data has been retrieved.
- Run the simulation
- Use
simulateTxto simulatemulticallTx. - If the simulation succeeds, return
multicallTxand exit.
- Use
- Handle errors
- If an
OracleDataRequirederror occurs during simulation, extract the oracle contract address (error.oracleContract) and required query (error.oracleQuery) from the error.
- If an
- Retrieve off-chain data
- Use
fetchOffchainDatato obtain the required off-chain data.
- Use
- Generate a data verification transaction
- Use
generateDataVerificationTxto generate a transaction that verifies the retrieved off-chain data.
- Use
- Add to the multicall transaction
- Prepend the generated data verification transaction to the
multicallTxarray.
- Prepend the generated data verification transaction to the
- Continue the loop
- Repeat this process until
multicallTxsucceeds.
- Repeat this process until
Purpose and benefits
The process retrieves the off-chain data required by a smart contract efficiently and verifies that data to avoid the OracleDataRequired error in advance, allowing the transaction to succeed.
End users can submit transactions without having to manage complex data dependencies themselves.
OracleContract
contract OracleContract is IERC7412 {
address public constant VERIFIER_CONTRACT = 0x0000;
uint public constant STALENESS_TOLERANCE = 86400; // One day
mapping(bytes32 => bytes) public latestVerifiedData;
function oracleId() external pure returns (bytes32){
return bytes32(abi.encodePacked("MY_ORACLE_ID"));
}
function fulfillOracleQuery(bytes calldata signedOffchainData) payable external {
bytes memory oracleQuery = _verify(signedOffchainData);
latestVerifiedData[keccak256(oracleQuery)] = signedOffchainData;
}
function retrieveCrossChainData(uint chainId, address contractAddress, bytes payload) internal returns (bytes) {
bytes memory oracleQuery = abi.encode(chainId, contractAddress, payload);
(uint timestamp, bytes response) = abi.decode(latestVerifiedData[oracleQuery], (uint, bytes));
if(timestamp < block.timestamp - STALENESS_TOLERANCE){
revert OracleDataRequired(address(this), oracleQuery);
}
return response;
}
function _verify(bytes memory signedOffchainData) payable internal returns (bytes oracleQuery) {
// Insert verification code here
// This may revert with error FeeRequired(uint amount)
}
}This code illustrates a smart contract that requests, verifies, and stores off-chain data.
The contract implements the IERC7412 interface and can be used by oracle providers.
Contract variables and functions
- VERIFIER_CONTRACT
- Defines the verifier contract address. This example uses the placeholder address
0x0000.
- Defines the verifier contract address. This example uses the placeholder address
- STALENESS_TOLERANCE
- Defines how recent data must be.
- In this example, data older than 24 hours (86,400 seconds) is considered stale.
- latestVerifiedData
- A mapping storing the latest verified off-chain data.
- Its keys are query hashes and its values are signed off-chain data.
Interface implementation
- oracleId function
- Returns a unique oracle ID.
- The ID is uniquely defined by the oracle provider.
- fulfillOracleQuery function
- Receives and verifies off-chain data, then stores it in the
latestVerifiedDatamapping. - It accepts signed off-chain data as an argument and verifies the query associated with that data.
- Receives and verifies off-chain data, then stores it in the
Retrieving cross-chain data
- retrieveCrossChainData function
- Retrieves cross-chain data based on a specified chain ID, contract address, and payload.
- Checks whether the verified data is fresh and raises an
OracleDataRequirederror if it is stale. - If fresh data is available, returns it.
Data verification
- _verify function
- An internal function for verifying signed off-chain data.
- Performs verification and returns the query if verification succeeds.
- May raise a
FeeRequirederror if verification incurs a fee.
This contract provides a way to automate the retrieval, verification, and use of off-chain data. It is useful for applications that need to obtain fresh data securely, such as cross-chain data or price feeds. The mechanism is intended to ensure that smart contracts operate correctly using fresh data.
ICrosschainContract
interface ICrosschainContract {
function functionA(uint x) external returns (uint y);
function functionB(uint x) external returns (uint y);
}
contract CrosschainAdder {
IERC7412 oracleContract = 0x0000;
function add(uint chainIdA, address contractAddressA, uint chainIdB, address contractAddressB) external returns (uint sum){
sum = abi.decode(oracleContract.retrieveCrossChainData(chainIdA, contractAddressA, abi.encodeWithSelector(ICrosschainContract.functionA.selector,1)), (uint)) + abi.decode(oracleContract.retrieveCrossChainData(chainIdB, contractAddressB, abi.encodeWithSelector(ICrosschainContract.functionB.selector,2)),(uint));
}
}This code example illustrates how to implement a top-level protocol smart contract that uses cross-chain data.
Specifically, it presents a contract called CrosschainAdder that retrieves data from two contracts on different blockchains and adds their values together.
ICrosschainContract interface
An interface with two functions, functionA and functionB.
Both can be called externally, accept a uint argument, and return a uint value.
CrosschainAdder contract
References an instance of the IERC7412 oracle contract.
The oracle contract provides functionality for retrieving and verifying off-chain data.
add function
The add function accepts two chain IDs (chainIdA and chainIdB) and the addresses of the contracts on the respective chains (contractAddressA and contractAddressB).
It calls oracleContract.retrieveCrossChainData to retrieve data from the specified chains and contract addresses.
It uses abi.encodeWithSelector to encode the target function selectors and arguments.
The retrieved data (the return values of functionA and functionB) is decoded and added together.
The sum is the return value of add.
Developer perspective
Developers implementing CrosschainAdder do not need to concern themselves with the implementation of the standard for retrieving and verifying off-chain data.
Retrieving data through oracleContract is as straightforward as retrieving ordinary on-chain data.
Use cases
Cross-chain functions of this kind can also be used to avoid loops with O(n) or greater complexity on-chain.
For example, if chainIdA and chainIdB refer to the same chain and functionA and functionB are view functions containing computationally expensive loops, the computations can be performed efficiently off-chain, with only their results handled on-chain.
This code example demonstrates how to retrieve cross-chain data through oracles and build smart contracts that use it, enabling efficient data exchange and processing across blockchains.
Security
This section describes the potential risks and responsibilities associated with the proposed standard for handling off-chain data, including its use of multicall.
Risks associated with multicall
Opaque transaction data
Reliance on multicall can make transaction data opaque, particularly in wallet applications that lack more advanced transaction decoding capabilities. This can make it difficult for users to understand what a transaction does.
Challenges for wallet developers
Multicall is becoming increasingly common in protocol development beyond this standard, and wallet developers are addressing the resulting challenges. More sophisticated transaction decoding is needed to improve transaction transparency.
Data verification and responsibility
Responsibility of the verifier contract
Under this standard, responsibility for checking the validity of data supplied by an oracle network lies with the verifier contract. In other words, the verifier contract checks the data before it is supplied to the smart contract.
No new avenue for invalid data
The standard does not introduce new opportunities for invalid data to be supplied to smart contracts. It provides an additional mechanism for ensuring accuracy and reliability within the existing process of supplying data from oracle networks.
The proposed standard provides a way to improve smart contract functionality and scalability while recognizing the risks and responsibilities involved in handling off-chain data. As wallet applications evolve, users are expected to gain a better understanding of transaction details. Processes that ensure data accuracy will continue to play an important role.
Citation
Noah Litvin (@noahlitvin), db (@dbeal-eth), "ERC-7412: On-Demand Off-Chain Data Retrieval [DRAFT]," Ethereum Improvement Proposals, no. 7412, July 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7412.
Conclusion
This article covered ERC-7412, a proposal for secure and efficient interactions across multiple blockchains and oracle networks using multicall.

