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 examines ERC-7774, a proposal for invalidating Web3 page caches using blockchain events.

This article translates, summarizes, and expands on the specification linked below.

I also cover a variety of EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.

Overview

ERC-7774 extends ERC-6944 resolve mode, a resolution mechanism for the web3:// protocol defined by ERC-6860, so that the standard HTTP caching specification, RFC 9111, can be used effectively.

For more information about ERC-6944, see the following article.

[ERC6944] Specifying How Contracts Handle Resource Requests

The web3:// protocol treats blockchain data as web content and aims to behave like conventional HTTP wherever possible. As part of this approach, ERC-6944 allows smart contracts to return HTTP response headers, including Cache-Control and ETag.

However, under ERC-6944, HTTP request headers sent by the client are not passed to the smart contract. As a result, the contract cannot handle the following validation headers used in conventional HTTP caching.

  • If-None-Match Used with an ETag to check whether the content has changed.
  • If-Modified-Since Uses the last modification time to check whether the content has changed since that time.

Because of this limitation, smart contracts cannot perform ordinary HTTP cache validation, such as returning 304 Not Modified when content has not changed. They can only use simple expiration-based controls such as Cache-Control: max-age.

Consequently, every cache expiration requires an RPC call and regeneration of the full response. This is inefficient given the goal of making web3:// behave like HTTP.

To address this problem, ERC-7774 uses smart contract events to notify external clients when a cache entry has become invalid. This works around the inability to handle HTTP request headers directly while providing a cache invalidation model consistent with RFC 9111.

Motivation

Ethereum RPC calls are expensive for several reasons.

Even with a local node, they consume considerable CPU and I/O resources. When using a paid external RPC provider, requests may be billed according to their number. Many providers also enforce rate limits, meaning that sending too many requests in a short period can result in access being blocked.

Loading a web3:// URL in a web browser requires several RPC calls just to display a page. If caching is ineffective, the following problems arise.

  • Retrieving the same data repeatedly unnecessarily increases RPC costs.
  • Rate limits can cause pages to fail to load.
  • Pages load more slowly, resulting in a worse experience than conventional websites.

As with HTTP, making effective use of caching to reduce RPC calls is therefore important.

ERC-6944 allows smart contracts to return HTTP caching headers such as the following.

Header Purpose
Cache-Control Specifies the lifetime of a cache entry and how it should be revalidated.
ETag A hash-like identifier for the contents of a response.

As discussed above, however, conditional requests cannot be used to check whether content has changed because If-None-Match and If-Modified-Since request headers never reach the contract. Consequently, checking whether a cache entry is still valid requires a full response to be generated and an RPC call to be executed each time.

ERC-7774 takes a different approach. Rather than validating cached content through HTTP requests, it uses the following model.

  • The smart contract emits an event only when data is updated.
  • Clients or gateways monitor that event and invalidate the corresponding cached content.
  • If no update occurs, the local cache can be reused without making an RPC call.

This approach has two advantages.

First, it works around the structural limitation of ERC-6944, which prevents HTTP request headers from reaching smart contracts. Second, it shifts cache invalidation decisions from contract execution to event subscriptions, substantially reducing computational costs and RPC load.

Accordingly, ERC-7774 can extend ERC-6944 resolve mode without modifying it. The same mechanism can also be used if a future resolve mode supports HTTP request headers.

Specification

The evm-events Cache-Control extension directive

ERC-7774 enables caches for pages served over web3:// to be invalidated through blockchain events. It does this by adding an extension directive named evm-events to the standard HTTP Cache-Control header.

A directive is a control instruction that specifies how an operation should behave.

In HTTP, directives such as max-age and no-cache in Cache-Control tell clients and intermediaries how to handle a response.

In ERC-7774, the evm-events directive indicates that the cached response is invalidated by blockchain events rather than ordinary revalidation.

In ERC-6944 resolve mode, this flag tells clients that the cache for this response will be invalidated by smart contract events rather than ordinary HTTP revalidation, such as If-None-Match.

When using event-based caching for a web3:// response, the smart contract must do the following.

  1. Include evm-events in the Cache-Control header.
  2. Also provide ordinary HTTP caching headers, such as ETag and max-age, in accordance with RFC 9111.
  3. Emit the corresponding cache invalidation event whenever the response content changes.

The important point is that the presence of evm-events instructs clients to switch to the following behavior.

  • Retain the cached page until an event arrives.
  • Discard the cached page immediately when the event arrives.

What the evm-events value means

An optional value can be assigned to evm-events. The value explicitly specifies the contracts and paths whose invalidation events should be monitored.

The syntax is defined as follows.

text
cache-directive-value = [ address-path-absolute *( " " address-path-absolute ) ]
address-path-absolute = [ address ] path-absolute [ "?" query ]
address               = "0x" 20( HEXDIG HEXDIG )
path-absolute         = <RFC 3986 のパス>
query                 = <RFC 3986 のクエリ>

The original ABNF example retains its Japanese explanatory placeholders.

Each set contains the following elements, and multiple sets can be separated by spaces.

  • Contract address (optional)
  • Path
  • Query

Omitting the address refers to the contract that returned the response.

Common examples and their meanings are shown below.

Example Meaning
Cache-Control: evm-events Discard the cached page when an invalidation event is emitted for its own path.
Cache-Control: evm-events="/path/path2" In addition to its own path, discard the cached page when /path/path2 on the same contract is updated.
Cache-Control: evm-events="0x.../path/path2" Also discard the cached page when /path/path2 on another contract is updated.
Cache-Control: evm-events="0x..." Discard the cached page when the same path on another contract is updated.
Cache-Control: evm-events="/path/path2 /path/path3" Monitor updates to multiple paths together.

This covers cases such as invalidating a listing page whenever one of its individual pages changes.

Cache invalidation events

To invalidate a cache, a smart contract emits the following event.

js
event ClearPathCache(string[] paths);

The paths specified here correspond to pathQuery in ERC-6860, that is, combinations of paths and queries such as the following.

text
/path
/path?key=value

Path equivalence is determined using the following rules.

  • Omit the trailing /, except for the root path /.
  • Ignore the order of query parameters.

Consequently, the following are treated as the same cache target.

text
/test?a=1&b=2
/test?b=2&a=1

Using wildcards

To invalidate many pages at once, paths can contain the * wildcard. However, only a very limited set of patterns is permitted for gas efficiency and implementation simplicity.

Wildcards in paths
  • * can be used only as an entire path segment.
  • Combining it with other characters makes the pattern invalid.
  • It does not match an empty string; at least one character is required.
Pattern Matches Does not match
/* /test /, /test/abc
/test/* /test/abc /test/, /test/abc/def
/*/abc /test/abc //abc
/t*t Invalid Always ignored
Wildcards in query values
  • Only a standalone * is permitted as a value.
  • Combining it with other characters makes the pattern invalid.
Pattern Matches Does not match
/abc?a=* /abc?a=zz /abc?a=, /abc?a=zz&b=cc
/abc?a=*&b=* /abc?a=1&b=2 None
/abc?a=z* Invalid Always ignored
Global wildcard

Specifying only * targets every path under that contract.

Cache behavior

web3:// client states

For each chain and contract, a client has two possible states.

State Description
Monitoring events Subscribe to ClearPathCache events and immediately discard cache entries for the relevant paths.
Not monitoring events Do not use events; execute an RPC call each time as before.

The ERC-7774 mechanism is active only while events are being monitored.

Cache keys and metadata

Clients manage their cache state using the following keys.

text
(<chain id>, <contract address>, <ERC-6860 pathQuery>)
  =>
(<最終更新時刻>, <ETag>)

The cache metadata in the original example retains its Japanese label for the last modification time.

If the response varies according to its compression scheme, as in ERC-7618, headers such as Accept-Encoding are also included in the key.

When event monitoring stops, the entire mapping is discarded.

Request handling while monitoring events

While events are being monitored, requests are handled as follows.

  1. No cache metadata exists yet. Call the contract through RPC and store evm-events along with the ETag, or timestamp information with max-age.
  2. A cache entry already exists. When the browser sends If-None-Match or If-Modified-Since, compare it with the locally stored ETag or modification time. If they match, return 304 without making an RPC call. If they do not match, discard the cache entry and fetch the content again.

Invalidation through blockchain events

A client monitoring events continuously watches for ClearPathCache events on the chain. If it finds a cache entry matching a specified path, it immediately removes that entry.

This establishes the following model.

  • Smart contracts do not need to read request headers.
  • Events need to be emitted only when changes occur.
  • Clients can maintain cache consistency comparable to HTTP caching.

Additional details

To preserve the behavior of conventional HTTP as closely as possible, ERC-7774 reuses the existing HTTP caching headers defined by RFC 9111, including Cache-Control, ETag, and Last-Modified. Bringing familiar web caching mechanisms directly into web3://, instead of inventing new proprietary cache controls, makes the system easier for implementers and users to understand and improves compatibility.

The evm-events directive added to Cache-Control is especially important here. Rather than merely providing an optimization, it explicitly declares that the response relies on event-based cache invalidation.

Consider a response that contains ordinary RFC 9111 headers but lacks evm-events.

  • The website considers its HTTP cache configuration valid.
  • However, the smart contract does not implement ERC-7774 and never emits ClearPathCache events.
  • Meanwhile, an ERC-7774-compatible web3:// client with event-driven caching enabled may interpret the absence of invalidation events as evidence that the content has never changed.

In this situation, even if the content changes, the client may never refresh its cache and may continue serving outdated content indefinitely.

As a safeguard, ERC-7774 requires the directive to be declared explicitly.

  • If event-based invalidation is intended, Cache-Control must include evm-events.
  • If it is absent, the client can determine that the response does not support event-based invalidation.

Security

Temporarily serving stale data because of event propagation delays

In ERC-7774, smart contract events notify clients when cached content must be invalidated. There is inevitably a delay between the execution of a user's transaction, the inclusion of the ClearPathCache event in a block, and the retrieval and processing of that event by the web3:// client.

The sequence is as follows.

  1. The user submits a transaction that changes state.
  2. The contract emits ClearPathCache based on the new state.
  3. The block is finalized.
  4. The web3:// client retrieves the block and detects the event.
  5. The corresponding cache entries are removed.

Until step 4, the client still holds the old cache and may briefly return the content from before the change. This is fundamentally the same problem as delayed revalidation in HTTP caching and cannot be completely avoided given the real-time nature and distributed architecture of the system.

Serving stale data indefinitely when invalidation events are not implemented

If the smart contract does not correctly emit ClearPathCache events for each page, its cache entry can remain indefinitely.

The website therefore has the following explicit responsibilities.

  • Identify every path whose response content can change.
  • Emit the corresponding invalidation event whenever that change occurs.

If it fails to do so, web3:// clients will continue to conclude that no change has occurred and may serve stale content indefinitely. This is not merely a performance problem; it is a security risk affecting information integrity.

Rolling back caches during chain reorganizations

Blockchains occasionally undergo chain reorganizations, in which blocks previously considered confirmed are removed and replaced with a different sequence of blocks.

In that case, the following problems may occur.

  • A ClearPathCache event is emitted in a block, and a client discards its cache entry.
  • The block is subsequently removed by a reorganization.
  • The event is now treated as though it never existed.
  • The client's cache state, however, has already changed.

The reverse scenario is also possible.

  • A block containing a change is removed.
  • The client has already cached the new content as valid.
  • Consequently, it continues serving content that no longer matches the actual chain state.

For this reason, ERC-7774 states that when a web3:// client detects a chain reorganization, its cache state must also be rolled back to match the blockchain state. Without this adjustment, the client may continue serving cached content based on reverted state until the next invalidation event arrives.

Citation

Nicolas Deschildre (@nand2), Sam Wilson (@SamWilsn), "ERC-7774: Cache invalidation in ERC-5219 mode Web3 URL [DRAFT]," Ethereum Improvement Proposals, no. 7774, September 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7774.

Conclusion

This article covered ERC-7774, a proposal for invalidating Web3 page caches using blockchain events. I hope this explanation was helpful.

If you have questions, feel free to reach out via direct message on Twitter.

Twitter @cardene777

I also publish content on other platforms, which you can find below.