EIPs Explained

ERC-1154 · Withdrawn · ERC · 2018-06-13

ERC-1154: Oracle Interface

A withdrawn proposal for one minimal oracle interface, where an oracle pushes an (id, result) report into a consumer contract, so oracle providers could be swapped without rewriting the consumer.

What problem does it solve?

Smart contracts cannot see the outside world, so they rely on oracles to report things like match results, prices or votes. In 2018 every oracle system used its own callback name and semantics (for example Oraclize's __callback or Chainlink's arbitrary callback names). A contract written for one oracle could not easily switch to another without adapters.

ERC-1154 tried to standardise the part that is the same everywhere: an oracle delivering a result for a specific question. The value of each oracle system lies in how it reaches an answer, not in the function name used to deliver it.

How it works

The spec defines a few terms: an oracle (any Ethereum account that reports data), an oracle consumer (the contract receiving it), an ID (what is being asked) and a result (the answer, as raw bytes).

The main interface is push-based: the oracle calls the consumer.

  • receiveResult(bytes32 id, bytes result) is implemented by the consumer.
  • It must revert if the caller is not an oracle authorised for that id.
  • It must revert if a result for that id was already received, so results are immutable.
  • Oracle and consumer agree off-band on how result is encoded, for example with abi.encode / abi.decode.

The spec also documents an alternative pull-based interface, resultFor(bytes32 id), which must revert until a result exists and must then always return the same value. Either style can be adapted to the other with one extra contract and one extra transaction.

IDs and results are intentionally unstructured. For time-series data the ID can encode both "what" and "when".

Sample code

A consumer that accepts one result per question from a single trusted oracle:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface OracleConsumer {
    function receiveResult(bytes32 id, bytes calldata result) external;
}

contract BinaryMarket is OracleConsumer {
    address public immutable oracle;
    mapping(bytes32 => bool) public resolved;
    mapping(bytes32 => bool) public outcome;

    constructor(address _oracle) { oracle = _oracle; }

    function receiveResult(bytes32 id, bytes calldata result) external {
        require(msg.sender == oracle, "unauthorized oracle");
        require(!resolved[id], "already resolved");
        resolved[id] = true;
        outcome[id] = abi.decode(result, (bool)); // codec agreed with the oracle
    }
}

Things to know

  • Status is Withdrawn. It is not a standard to build against, though the push/pull discussion is still a useful reference.
  • Today most on-chain price data is read through provider-specific interfaces rather than a shared ERC; no common oracle standard replaced this one.
  • In the push model the consumer enforces immutability itself. In the pull model you must trust the oracle contract to never change an answer, or check it yourself.
  • When one account (or a multisig) alone decides an outcome, the spec notes that no separate oracle contract is needed: that account can call receiveResult directly.

#oracle #interface #prediction-markets #withdrawn

Details

Authors
Alan Lu (@cag)
Status
Withdrawn
Type
Standards Track / ERC
Created
2018-06-13

Machine-readable: Markdown · JSON