Skip to main content

CCIP-Read: Secure Off-Chain Data Retrieval

EIP-3668, commonly known as CCIP-Read, is a proposed protocol aimed at providing secure off-chain data retrieval. CCIP-Read introduces a standard set of rules and protocols to create a trusted environment for off-chain data reading, delivering a solution for the data interoperability issues that plague blockchain environments.

How CCIP Works - Specifics and Implementation

The process of responding to a query via CCIP read is a three-step procedure:

  1. Querying the contract: You initiate the process by making a typical blockchain call operation to the contract. If the contract requires off-chain data, it will fail with an error that asserts that the data for the call can be found off-chain and provides a URL to a service (gateway) that can provide the necessary information. Additionally, it passes on any extra contextual information that might be needed for the further steps.

  2. Querying the gateway: The client then makes a call to the gateway service using the callData from the revert message from step 1. The gateway responds with an answer which is opaque to the client – that is, its content, by design, is not beneficial to the client.

  3. Making transaction to contract: In this final step, the client makes a call to the original contract, supplying the response from step 2 and the extraData returned in step 1. The contract decodes the information, validates the response and takes action – either returning information to the client or making changes in a transaction.

The contract interface for a CCIP read enabled contract has to adhere to some specifics. It has to fail with a specific error (OffchainLookup(address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData)) every time a function that requires off-chain data is called.

The OffchainLookup error returns various data, such as the contract sender, URL templates to services (gateways) implementing the CCIP read protocol, data to call the gateway with (callData), the function selector (callbackFunction) for a function on the contract where a callback will be sent, and extraData which MUST be retained and provided unmodified to the callback function.

The implementation will also involve a callback function on the original contract for decoding and validating the data returned by the gateway. If the chain of calls and callbacks is successfully implemented, the return data from the last call will be returned to the client as if it was returned by the function that was originally invoked.

In summary, ERC-3668 or CCIP-Read is a crucial building block for the future of decentralized applications. By establishing a secure bridge to off-chain data sources, it unlocks the ability to process large volumes of information without overloading the blockchain. This translates into increased efficiency, reduced costs, and enhanced scalability for blockchain applications, ultimately paving the way for a more robust and interconnected decentralized ecosystem.