ERC-7618 web3 URL compressed content delivery (Content encoding in ERC-5219 mode Web3 URL)
Draft · Other · created 2024-02-08
A standard for serving web resources stored in compressed form on the blockchain at a web3:// address, where the protocol first decompresses the content before delivering it if the client does not support that compression method.
Why it is needed
Because storing data on the blockchain is expensive, it is advantageous to compress resources such as website files before storing and serving them. On the regular web (HTTP), the client sends a list of compression methods it can decode (Accept-Encoding), and the server negotiates by compressing the response with one of them. However, the blockchain's constraints on storage and computation make it difficult to replicate this negotiation as is. On the other hand, if a contract always attaches a fixed compression indicator (Content-Encoding) and sends the compressed version unconditionally, an HTTP client that does not implement that method will be unable to decode the content. This standard defines a fixed list of compression methods the protocol supports and has the protocol decompress the content when necessary before delivering it to the client, making it possible to both store content compressed and serve it safely.
In depth
Extension of ERC-6944 resolve mode
This standard extends ERC-6944 resolve mode, a branch of the ERC-6860 web3:// standard. In ERC-6944, a contract's request() method returns a KeyValue array called headers along with the response data; if this array contains a Content-Encoding HTTP header, it is interpreted to mean that the returned data is compressed using that algorithm. Since it only adds a header interpretation rule without changing the existing interface, it can be layered directly onto ERC-6944 resolve mode.
Conditions under which the protocol must decode
If the request() return includes a Content-Encoding header whose value is not in the list of supported algorithms the client indicated via the Accept-Encoding header, or if the client did not send an Accept-Encoding header at all, the protocol MUST decode the content before delivering it to the web3:// client. In other words, the compressed version is passed through as is only when the client has indicated it can decompress it; otherwise the protocol always decompresses it.
Required supported algorithms and error handling
The protocol MUST support the two content encodings gzip and br (Brotli). If, in a situation where the protocol must decode, the Content-Encoding indicated by the contract is not in this list, the protocol MUST send the client an unsupported content encoding error. If decoding succeeds, the decompressed data is sent to the client.
Header removal rule when decoding
When the protocol has decoded the content, it MUST NOT pass the Content-Encoding header to the client. This rule prevents a situation where a client that receives already-decompressed data sees the header and tries to decompress it again. The actual state of the delivered data and the header will always match.
Why the HTTP approach was not replicated as is
Transplanting the standard HTTP Accept-Encoding and Content-Encoding negotiation structure directly onto the web3:// protocol is not optimal because of blockchain storage and computation constraints. On the other hand, unconditionally serving a compressed response with a fixed Content-Encoding causes problems for HTTP clients that do not implement that algorithm. So the protocol takes a middle ground: it defines a list of supported algorithms and lets the protocol layer decode when needed. It also reuses the existing Content-Encoding header rather than inventing a new HTTP header, to stay as close to standard HTTP as possible.
Proposal status
This ERC is currently in Draft status. Since it is still a proposal whose content may change, you should check the latest source text before implementing it. This standard presupposes ERC-5219 and ERC-6944.