ERC-7615 A standard for pushing data between contracts (Atomic Push-based Data Feed Among Contracts)

Draft · Other · created 2024-02-03

Defines a mechanism in which, the moment a publisher contract is called, data is automatically pushed within the same transaction to pre-registered subscriber contracts.

Why it is needed

Today, many automated services (keepers) rely on off-chain data or separate collection processes to learn what happened on chain. For example, to execute a loan liquidation when a price changes, someone outside the chain must watch for that change and then send a separate transaction. This approach requires trusting an intermediary, and delivery can be delayed or missed. This proposal aims to create a scheme in which, when a publisher contract is called, that fact and its data are reported to subscriber contracts immediately and atomically within the same transaction. Because publishers and subscribers interact directly on chain, less external trust is needed and the process is more efficient. The source explains that this structure helps with various applications, such as expanding DeFi and improving DAO governance.

What to implement

In depth

The four-stage push structure

A push happens in four stages. 1) The publisher contract is called. 2) The publisher looks up the subscriber list using the called function's selector, and may store selected data in the inbox. 3) The publisher calls each subscriber's exec function to push the selector and data. 4) The subscriber executes using the received selector and data, or, if needed, requests information via the publisher's inbox function. Multiple subscribers of different types can be registered under a single selector, and the publisher calls each subscriber's exec in turn. Use of the inbox is OPTIONAL.

The unconditional push interface, IPushForce

This mode always pushes as soon as the registered selector is called. isForceApproved checks whether a selector is bound to a target (subscriber), forceApprove creates the binding, and forceCancel removes it. On forceCancel, target's isLocked is REQUIRED to return true. Calling renounceForceApprove means forceApprove can no longer be called afterward, and calling renounceForceCancel means forceCancel can no longer be called afterward. The source explains that executing both renunciations makes it impossible to further change registered push targets, greatly strengthening security.

The conditional push interface, IPushFree

This mode pushes only for calls that match the data condition set at registration time. isApproved, approve, and cancel are similar to their counterparts in IPushForce, but add a data parameter that checks whether a push is needed. inbox(bytes4 selector) is used to hold data in case a subscriber calls it. Since the caller pays the gas incurred by the push, there are cases, such as notifying a lending protocol of a price change, where unconditional push is needed, while conditional push reduces unnecessary gas consumption.

The _push hook and selector-based design

The publisher contract SHOULD implement an internal function, _push(bytes4 selector, bytes calldata data), that acts as a hook, and every function that needs to push MUST call this internal function. This function MUST include a process that looks up both unconditional and conditional subscriber contracts based on selector and data, then calls each subscriber's exec. Using the function selector as a parameter allows finer-grained configuration, and lets subscribers know which function a request originated from, so they can handle the pushed information more precisely.

The subscriber interface, IExec and isLocked

A subscriber must implement two functions, exec and isLocked. exec receives and executes the publisher's request, and the implementation SHOULD handle requests and data for every possible selector, and MAY call the publisher's inbox to obtain the full data when needed. isLocked indicates whether the subscription is in a state where it may be canceled when an unsubscribe request arrives. The publisher MUST call isLocked before forceCancel or cancel to prevent unilateral unsubscription, because a subscriber may depend heavily on the publisher logically, and cancellation could cause serious problems on the subscriber's side.

The inbox mechanism

A publisher can push only the selector and the core data to subscribers while keeping the full data in an inbox. Subscribers that receive the push call the inbox only when needed to fetch the full data. The source text explains that this keeps the pushed information simple while still guaranteeing the availability of the complete data, reducing gas consumption. The reference implementation shows an example of using transient storage opcodes (tstore, tload) to keep the inbox data only within the same transaction.

Draft status

This proposal is in Draft status, created in February 2024. The content may change or progress may stall, so the latest source text should be checked before implementation.

Things to watch out for

Original ERC · ← ERCs