ERC-801 · Stagnant · ERC · 2017-12-16
ERC-801: Canary Standard
A minimal interface for on-chain "canary" contracts that stay alive only while someone keeps feeding them, so apps can detect when a warrant canary or heartbeat stops.
What problem does it solve?
A warrant canary is a statement such as "we have not received a secret subpoena" that an organization repeats on a schedule. If it stops, people can infer something happened, without the organization ever saying so. The same idea works for heartbeats: "this operator is still active", or "this device still checks in".
On Ethereum, a canary can be a contract that someone must "feed" with regular transactions. ERC-801 gives these contracts a common interface, so dashboards, alarm services, feeder apps and even insurance contracts can read any canary's state the same way.
How it works
The interface is intentionally tiny:
| Member | Meaning |
|---|---|
isAlive() |
true if the canary has been fed properly |
getBlockOfDeath() |
Block number at which it died. Throws while it is still alive |
getType() |
Kind of canary (see below) |
event RIP() |
Must be emitted on the first call after the canary died |
Proposed getType() values:
1Simple: just this interface2Single feeder3Single feeder with "bad food"4Multiple feeders5Multiple mandatory feeders6IoT
Types 2 to 6 point to follow-up ERCs ("ERC-TBD") that were never written. How a canary is fed, and how long it may go hungry, is left to the implementation.
Sample code
A single-feeder canary that dies if not fed within interval blocks:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract SimpleCanary {
event RIP();
address public immutable feeder;
uint256 public immutable interval; // max blocks between feedings
uint256 public lastFed;
bool private ripEmitted;
constructor(uint256 _interval) {
feeder = msg.sender;
interval = _interval;
lastFed = block.number;
}
function isAlive() public view returns (bool) {
return block.number <= lastFed + interval;
}
function getBlockOfDeath() external view returns (uint256) {
require(!isAlive(), "still alive");
return lastFed + interval + 1;
}
function getType() external pure returns (uint8) {
return 2; // single feeder
}
function feed() external {
require(msg.sender == feeder, "not feeder");
if (!isAlive()) {
if (!ripEmitted) { ripEmitted = true; emit RIP(); }
return; // a dead canary stays dead
}
lastFed = block.number;
}
}
Things to know
- This proposal is Stagnant and was never finalized. The spec's own implementation section still reads "TODO".
- The spec uses pre-0.5 Solidity (
constantfunctions). Modern code usesview. RIPcan only be emitted when someone calls the contract after death, because contracts cannot act on their own. Off-chain watchers should pollisAlive()rather than wait for the event.- A canary only proves that the feeder kept sending transactions. What a missed feeding means is a social or legal question, not something the contract can decide.