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
event ForceApprove(bytes4 indexed selector, address indexed target);: An event emitted when a function selector is registered for unconditional push to a subscriber address, target.event ForceCancel(bytes4 indexed selector, address indexed target);: An event emitted when an unconditional push registration between a selector and a subscriber is canceled.event RenounceForceApprove();: An event emitted when the permission to make unconditional push registrations is permanently renounced.event RenounceForceCancel();: An event emitted when the permission to cancel unconditional push registrations is permanently renounced.function isForceApproved(bytes4 selector, address target) external returns (bool);: Checks whether the given selector is already bound to the subscriber contract target for unconditional push.function forceApprove(bytes4 selector, address target) external;: Binds a selector to the subscriber contract target so that a push occurs every time that function is called.function forceCancel(bytes4 selector, address target) external;: Unbinds the selector from target. This must verify that target's isLocked returns true.function isRenounceForceApprove() external returns (bool);: Checks whether the forceApprove permission has already been renounced.function isRenounceForceCancel() external returns (bool);: Checks whether the forceCancel permission has already been renounced.function renounceForceApprove(bytes memory) external;: Renounces the forceApprove permission. After this, forceApprove can no longer be called.function renounceForceCancel(bytes memory) external;: Renounces the forceCancel permission. After this, forceCancel can no longer be called.event Approve(bytes4 indexed selector, address indexed target, bytes data);: An event emitted when a conditional push registration is made.event Cancel(bytes4 indexed selector, address indexed target, bytes data);: An event emitted when a conditional push registration is canceled.function inbox(bytes4 selector) external returns (bytes memory);: Returns the data held on the publisher side, keyed by selector. Called when a subscriber needs to fetch the full data.function isApproved(bytes4 selector, address target, bytes calldata data) external returns (bool);: Checks whether a combination of selector, subscriber address, and condition data is registered for conditional push.function approve(bytes4 selector, address target, bytes calldata data) external;: Registers a selector with the subscriber target so that a push occurs only when the condition data, data, matches.function cancel(bytes4 selector, address target, bytes calldata data) external;: Cancels a conditional push registration.function isLocked(bytes4 selector, bytes calldata data) external returns (bool);: Indicates whether the subscriber contract is in a state that can accept unsubscription. Called when an unsubscribe request is made.function exec(bytes4 selector, bytes calldata data) external;: Receives the selector and data sent by the publisher contract and executes the corresponding follow-up action on the subscriber side.
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
- Arbitrary calls to the exec function: Since exec is a public function, anyone can call it and inject arbitrary push information. Implementations must carefully consider the arbitrariness of the call and must not use data passed to exec without validation.
- Reentrancy attack: In a structure where the publisher calls the subscriber's exec, a reentrancy attack can occur. A malicious subscriber contract could construct a reentrancy attack against the publisher contract from within exec.
- Registering arbitrary targets: The forceApprove and approve implementations must have reasonable access control. Otherwise, callers may incur unnecessary gas loss. The gas usage of the exec function should also be checked.
- isLocked implementation: Subscribers must implement isLocked to prevent losses from subscription cancellation. This is especially important for lending protocols that use this standard, since an improper cancellation can lead to abnormal liquidation and significant losses. Conversely, publishers should check that isLocked is properly implemented when subscribing, so that an uncancelable subscription does not arise.