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.

ERC7615 proposes a way for publisher contracts to push data to subscriber contracts, allowing subscribers to receive notifications of data updates on-chain.

This article translates, summarizes, and expands on the proposal below.

I have also covered a range of other EIPs.

Overview

This standard proposes a data push mechanism for Ethereum smart contracts. A publisher contract (the source of the data) can automatically push specific data to a subscriber contract (the recipient).

The proposal defines interfaces for two types of contracts. The publisher checks whether any subscriber contracts are associated with the function that has been called. If so, it pushes data to those subscribers.

  • Publisher contract
    • A contract responsible for sending data.
  • Subscriber contract
    • A contract responsible for receiving data.

Motivation

Many keepers (entities responsible for monitoring data) currently rely on off-chain data or separate data collection processes to monitor on-chain events. This proposal aims to establish a system in which publisher contracts notify subscriber contracts of data updates. Direct on-chain communication between publishers and subscribers can make the system more reliable and efficient.

The mechanism can also make DeFi applications easier to extend. Publishers can deliver relevant data to subscribers immediately, enabling faster and more efficient financial transactions. It can also improve governance in decentralized autonomous organizations (DAOs). Publishers can notify subscribers of important updates promptly, enabling DAO members to make decisions based on up-to-date information. Other potential applications include the following.

Lending Protocol

In this example, an oracle acts as the publisher contract. The oracle provides market price information. When the oracle updates a price, it automatically sends the new information to the lending protocol, which acts as the subscriber contract. The lending protocol automatically liquidates lending positions based on the received price information. This allows price updates to be reflected promptly and positions to be managed efficiently.

Automatic Payment

In this example, a service provider acts as the publisher contract. When a user calls the service provider's contract, the publisher pushes information to the subscriber contract. The subscriber may be the user's wallet, such as an ERC6551 NFT-bound account or another smart contract wallet. The user's wallet then automatically executes the payment operation. Compared with conventional approval-based approaches, this allows more complex logic, such as a spending limit.

ERC6551 is a standard that associates a contract called a TBA (Token Bound Account) with each tokenId of an ERC721 NFT. Because a TBA is a contract, it can receive other NFTs, fungible tokens (FTs), and native tokens. An NFT can therefore hold other NFTs, FTs, and native tokens through its TBA. Authority over the assets held in the TBA belongs to the address that owns the associated NFT (tokenId). When the associated NFT is transferred via transfer, control passes to the recipient of the NFT. For more details, see the following article.

[ERC6551] Understanding Token Bound Accounts: Giving NFTs Smart Contract Accounts

PoS Without Transferring Assets

This example concerns NFT staking. The proof-of-stake (PoS) contract acts as the subscriber, and the NFT contract acts as the publisher. Users can earn staking rewards without calling transfer on their assets. When an NFT transfer occurs, the NFT contract pushes the information to the PoS contract. The PoS contract performs unstaking or other operations based on the information received.

DAO Voting

In this example, the DAO governance contract acts as the publisher. Once voting concludes, it automatically triggers the push mechanism and calls the relevant subscriber contracts to implement the voting result directly. For example, funds can be allocated to a particular account or pool automatically. This streamlines DAO governance and enables prompt execution.

Specification

Overview

The push mechanism consists of four steps.

  1. The publisher contract is called.
  2. The publisher looks up the subscriber list using the called function's selector.
    • The subscriber contract stores selected data in the inbox.
  3. The publisher calls the subscriber contract's exec function, pushing the selector and data.
  4. The subscriber executes based on the pushed selector and data or, if necessary, retrieves information from the publisher contract's inbox.

In the second step, the publisher looks up the subscriber list based on the selector of the function that was called. The subscriber contract stores the selected data in the inbox. The relationship between a called function and its corresponding subscribers can be configured within the publisher contract in two ways.

  • Unconditional push
    • A push occurs whenever the configured selector is called.
  • Conditional push
    • A push occurs when a call to the configured selector meets the specified conditions.

The publisher then invokes the subscriber's exec function to push the selector and data. A single selector can have several different types of subscriber contracts. The publisher calls each subscriber's exec function to push the request. When removing a subscriber from a selector, the publisher must check whether the subscriber's isLocked function returns true.

In the fourth step, the subscriber's implementation of exec should process the selector request and data as far as possible. In some cases, exec may call the publisher's inbox to obtain the complete pushed data.

ERC7615 push mechanism Source: https://eips.ethereum.org/EIPS/eip-7615

The original diagram is retained; any Japanese labels remain unchanged.

Contract Interfaces

There are two implementation types: unconditional push and conditional push.

Unconditional Push

js
interface IPushForce {
    event ForceApprove(bytes4 indexed selector, address indexed target);
    event ForceCancel(bytes4 indexed selector, address indexed target);
    event RenounceForceApprove();
    event RenounceForceCancel();

    error MustRenounce();
    error ForceApproveRenounced();
    error ForceCancelRenounced();

    function isForceApproved(bytes4 selector, address target) external returns (bool);
    function forceApprove(bytes4 selector, address target) external;
    function forceCancel(bytes4 selector, address target) external;
    function isRenounceForceApprove() external returns (bool);
    function isRenounceForceCancel() external returns (bool);
    function renounceForceApprove(bytes memory) external;
    function renounceForceCancel(bytes memory) external;
}
  • isForceApproved
    • Checks whether a selector is unconditionally bound to the target subscriber.
  • forceApprove
    • Binds a selector to the target subscriber.
  • forceCancel
    • Removes the binding between a selector and the target.
    • The original explanation states that the target's isLocked function must return true. However, the reference implementation below requires the opposite for cancellation; verify this condition against the specification before implementing it.
  • renounceForceApprove
    • Renounces the authority to call forceApprove.
    • After this function is called, forceApprove can no longer be called successfully.
  • renounceForceCancel
    • Renounces the authority to call forceCancel.
    • After this function is called, forceCancel can no longer be called successfully.

Conditional Push

js
interface IPushFree {
    event Approve(bytes4 indexed selector, address indexed target, bytes data);
    event Cancel(bytes4 indexed selector, address indexed target, bytes data);

    function inbox(bytes4 selector) external returns (bytes memory);
    function isApproved(bytes4 selector, address target, bytes calldata data) external returns (bool);
    function approve(bytes4 selector, address target, bytes calldata data) external;
    function cancel(bytes4 selector, address target, bytes calldata data) external;
}
  • isApproved
    • Checks whether a push is required based on the selector, target, and data.
  • approve
    • Approves a binding based on the selector, target, and data.
  • cancel
    • Removes a binding based on the selector, target, and data.
  • inbox
    • Stores data for retrieval by the subscriber contract.

Publisher Contract

The publisher contract must implement the following internal function.

js
function _push(bytes4 selector, bytes calldata data) internal;

This function is called from every function that needs to implement the push mechanism. It looks up unconditional and conditional subscriber contracts based on the selector and data, then invokes the subscriber's exec function.

Subscriber Contract

js
interface IExec {
    function isLocked(bytes4 selector, bytes calldata data) external returns (bool);
    function exec(bytes4 selector, bytes calldata data) external;
}

The exec function receives and executes requests from the publisher contract. isLocked checks whether the subscriber contract's subscription to the publisher can be removed, based on the selector and data. It is called when an unsubscribe request is received.

Additional Considerations

Unconditional and Conditional Configuration

A push can be triggered when the publisher contract is called, with payment of gas fees requested as part of the operation. Unconditional pushes may be necessary in some cases, such as pushing price changes to a lending protocol. Conditional pushes, by contrast, help reduce unnecessary gas consumption.

Checking isLocked Before Unsubscribing

Before calling forceCancel or cancel, the publisher must call the subscriber's isLocked function to prevent unilateral cancellation. A subscriber may depend heavily on the publisher, and unsubscribing could cause serious problems. Subscribers must therefore implement isLocked with care.

Unsubscribing means stopping a subscriber contract from receiving push notifications from a publisher contract.

The inbox Mechanism

In certain scenarios, the publisher may push only essential data together with the selector, while storing the complete data in the inbox. After receiving a push from the publisher, the subscriber can optionally call inbox. The inbox mechanism reduces gas consumption by keeping push messages small while making the complete data available.

Using the Function Selector as a Parameter

Using a function selector to look up subscriber contract addresses allows more granular configuration. The subscriber can identify the specific function that originated the request from the pushed information, allowing it to process the message more accurately.

Improving Security by Renouncing Authority

Authority to call forceApprove or forceCancel can be relinquished through the renounce functions. Once renounceForceApprove or renounceForceCancel is called, the corresponding ability to change registered push targets is removed, improving security.

Reference Implementation

js
pragma solidity ^0.8.24;

import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IPushFree, IPushForce} from "./interfaces/IPush.sol";
import {IExec} from "./interfaces/IExec.sol";

contract Foo is IPushFree, IPushForce {
    using EnumerableSet for EnumerableSet.AddressSet;

    bool public override isRenounceForceApprove;
    bool public override isRenounceForceCancel;

    mapping(bytes4 selector => mapping(uint256 tokenId => EnumerableSet.AddressSet targets)) private _registry;
    mapping(bytes4 selector => EnumerableSet.AddressSet targets) private _registryOfAll;
    // mapping(bytes4 => bytes) public inbox;

    modifier notLock(bytes4 selector, address target, bytes memory data) {
        require(!IExec(target).isLocked(selector, data), "Foo: lock");
        _;
    }

    function inbox(bytes4 selector) public view returns (bytes memory data) {
        uint256 loadData;
        assembly {
            loadData := tload(selector)
        }

        data = abi.encode(loadData);
    }

    function isApproved(bytes4 selector, address target, bytes calldata data) external view override returns (bool) {
        uint256 tokenId = abi.decode(data, (uint256));
        return _registry[selector][tokenId].contains(target);
    }

    function isForceApproved(bytes4 selector, address target) external view override returns (bool) {
        return _registryOfAll[selector].contains(target);
    }

    function approve(bytes4 selector, address target, bytes calldata data) external override {
        uint256 tokenId = abi.decode(data, (uint256));
        _registry[selector][tokenId].add(target);
    }

    function cancel(bytes4 selector, address target, bytes calldata data)
        external
        override
        notLock(selector, target, data)
    {
        uint256 tokenId = abi.decode(data, (uint256));
        _registry[selector][tokenId].remove(target);
    }

    function forceApprove(bytes4 selector, address target) external override {
        if (isRenounceForceApprove) revert ForceApproveRenounced();
        _registryOfAll[selector].add(target);
    }

    function forceCancel(bytes4 selector, address target) external override notLock(selector, target, "") {
        if (isRenounceForceCancel) revert ForceCancelRenounced();
        _registryOfAll[selector].remove(target);
    }

    function renounceForceApprove(bytes memory data) external override {
        (bool burn) = abi.decode(data, (bool));
        if (burn != true) {
            revert MustRenounce();
        }

        isRenounceForceApprove = true;
        emit RenounceForceApprove();
    }

    function renounceForceCancel(bytes memory data) external override {
        (bool burn) = abi.decode(data, (bool));
        if (burn != true) {
            revert MustRenounce();
        }

        isRenounceForceCancel = true;
        emit RenounceForceCancel();
    }

    function send(uint256 message) external {
        _push(this.send.selector, message);
    }

    function _push(bytes4 selector, uint256 message) internal {
        assembly {
            tstore(selector, message)
        }

        address[] memory targets = _registry[selector][message].values();
        for (uint256 i = 0; i < targets.length; i++) {
            IExec(targets[i]).exec(selector, abi.encode(message));
        }

        targets = _registryOfAll[selector].values();
        for (uint256 i = 0; i < targets.length; i++) {
            IExec(targets[i]).exec(selector, abi.encode(message));
        }
    }
}

contract Bar is IExec {
    event Log(bytes4 indexed selector, bytes data, bytes inboxData);

    function isLocked(bytes4, bytes calldata) external pure override returns (bool) {
        return true;
    }

    function exec(bytes4 selector, bytes calldata data) external {
        bytes memory inboxData = IPushFree(msg.sender).inbox(selector);

        emit Log(selector, data, inboxData);
    }
}

Security

exec Attacks

Because the exec function is publicly accessible, malicious calls could introduce arbitrary push information. An implementation of exec must validate every exec call.

Reentrancy Attacks

A publisher calling a subscriber's exec function creates a potential reentrancy risk. A malicious subscriber may reenter the publisher from inside exec, so implementations must account for this possibility.

Approval of Arbitrary Targets

Implementations of forceApprove and approve require appropriate access control to prevent unnecessary gas expenditure.

Implementing isLocked

Subscribers must implement isLocked to avoid potential losses arising from unsubscription. This is particularly important for lending protocols. Improper unsubscription can cause abnormal liquidations and lead to losses.

Similarly, when establishing a subscription, the publisher must verify that isLocked is properly implemented to avoid subscriptions that cannot be canceled.

Citation

Elaine Zhang (@lanyinzly) lz8aj@virginia.edu, Jerry jerrymindflow@gmail.com, Amandafanny amandafanny200@gmail.com, Shouhao Wong (@wangshouh) wongshouhao@outlook.com, Doris Che (@Cheyukj) dorischeyy@gmail.com, Henry Yuan (@onehumanbeing) hy2878@nyu.edu, "ERC-7615: Atomic Push-based Data Feed Among Contracts [DRAFT]," Ethereum Improvement Proposals, no. 7615, February 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7615.

Conclusion

This article covered ERC7615, a proposal for pushing data between publisher contracts and subscriber contracts so that contracts can receive on-chain notifications of data updates. I hope it helped explain the mechanism.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also share technical content on the following platforms.

https://chaldene.net/