Creating a-Proof of-Stake Price Oracle

infernal_toast
3 min readDec 27, 2019

--

One short term goal of mine is to design a decentralized Medianizer.

A Medianizer is a smart contract that collects votes from Stakers. These votes reflect the price of an asset, and the contract uses the Median result and ignores outliers.

Maker DAO has a Medianizer. It accepts price data from multiple feeds and uses the median. The holders of MKR can vote in order to change the rules of the DAI Price Medianizer.

One of the most difficult engineering challenges for a Medianizer, as with all Ethereum applications, it to keep chainstate and gas costs to a minimum. One of the best ways to accomplish this is with off-chain signatures and small P2P networks that facilitate them.

In this proposed design, instead of using MKR as a governance structure, a staking contract will be used which will leverage the scarcity and distribution of 0xBTC for trustless consensus.

  1. The Staking Contract

A smart contract will exist with a method called ‘deposit’ which will allow the user to send their 0xBTC tokens into the contract and will record their new balance in a mapping array. Likewise, a method will allow the user to withdraw tokens and reduce their balance. A third method will be read-only and it will return an array of the ethereum addresses of the top 13 (subject to change) balances, or stakers.

2. The Medianizer

A smart contract will exist which has an interface to the 0xBTC contract so that it can monitor the current Epoch (block height). This contract also has an interface to The Staking Contract so that it can read the addresses of the top X stakers.

A read-only method will be available called getLastMedianPrice() which will return the last median price of 0xBTC/$ (in terms of satoastis per dollar) and the last 0xBTC epoch count at which this price was recorded.

A method called AddPriceVotes() will be available, callable by anyone. This method accepts an array of up to 13 votes from the 13 stakers. Each vote is comprized of [ThePriceOf0xBTC (in terms of satoastis per $1.00) , an ECRecovery Signature by the voter account whose address must be a top 13 staker]. These votes are added to a PendingVotes list.

A method called SubmitPriceVotes() will be available, callable by anyone to ‘flush’ the pending price votes through and to use the median of them to set the important LastMedianPrice variable. This can only be called after a grace period of 60(?) ethereum blocks in order to allow for all votes to be submitted. At least 7 of the 13 votes are needed to submit. When this occurs, some* 0xbtc belonging to this contract will be distributed equally to all nodes who voted with a bonus to the node who called SubmitPriceVotes. (Therefore, it will be the responsibility of other contracts to fill this contract with 0xbtc in order to improve the reliability and quality of the price data.)

3. The offchain network and oracle node

‘0xMedianizer’ Node software must be developed for the stakers to run which will

  1. connect to the other nodes and maintain a list of them
  2. collect price data from multiple feeds
  3. monitor The Staking Contract to maintain a local cache of the top stakers currently
  4. Each 0xBTC block, determine current 0xbtc/& price and create a ‘vote packet’ which is [ThePriceOf0xBTC (in terms of satoastis per $1.00) , an ECRecovery Signature by the voter account]
  5. Share this vote packet with the rest of the 0xMedianizer nodes
  6. Collect all of the vote packets from the other nodes and call the ‘AddPriceVotes’ & ‘SubmitPriceVotes’ methods of the Medianizer contract when appropriate

This system of contracts and software will establish a price oracle on the Ethereum Network for 0xBTC to $. Then, it will be possible to develop a ‘DAI-Like’ CDP loan system on top of that price oracle. Creating and closing CDPs will cost fees which would be sent to the Medianizer contract to then pay oracles (stakers) for their work.

Risks:

  • If one party were able to stake enough 0xBTC to control 7 of the 13 top staking slots, they could control the median price of the medianizer, thereby allowing them to lie about the price. This risk could be reduced by ‘slashing’ price votes that are too far from the winning median. This risk can be further reduced by rewarding stakers more, thereby incentivising more other people to become stakers and push the ‘staking cartel’ out. Finally, increasing the number of stakers to a higher number such as 25 would increase the cost required to gain majority. The downside is that total gas costs for voting rounds may also increase since there is more work -load for the EVM to tally more votes.

--

--

No responses yet