ECIP 1028: Private Sidechain checkpoints Source

AuthorIgor Artamonov
StatusDraft
TypeStandards Track
CategoryInterface
Created2017-07-18

Abstract

This proposal is a part of Multi Chain proposal defined by ECIP-1027. It provides a solution for a Private Chain based on Proof of Authority [1] connected to ETC Main Chain.

Motivation

Private Chains with PoS or PoA consensus algorithms are common solution for global business that needs a distributed way of processing data on blockchain. This types of blockchain are executed in trusted environment in a private network, and don’t need any communication with external entities. PoS/PoA are able to provide most of functionality required for such processing, but lack of security and data immutability usually provided by PoW.

Checkpoints proposed in ECIP-1027 are able to improve security and data immutability of such Private Chains.

Specification

  • Network has a custom Private Chain working under Proof-of-Authority
  • Network has a Checkpoint Contract in public ETC mainnet with methods makeCheckpoint and getLastCheckpoint
  • Network has set of trusted nodes with access to external network to make checkpoint, this can be same nodes as PoA or different set of nodes. Checkpoint is made every N blocks, where N can reflect from 1 minute to few hours of blockchain time and it does not affect Private Chain performance under normal conditions.
  • Checkpoint Contract has list of addresses with granted access to make checkpoints
  • Only one possible checkpoint is possible per Block Height, and height of a new checkpoint must be higher that existing checkpoint. Otherwise Trusted Nodes should come to agreement about Correct Fork if a network split is observed, this logic can be implemented in the Checkpoint Contract as well.
  • A checkpoint is a Hash of State Root + Block Height in the Private Chain, which does not leak any internal data to public chain (Hash(StateRoot | BlockHeight))
  • A Private Chain peer periodical check Checkpoint Contract and in case of chain split chooses chain cornered to that contract most recently.

Implementation

WARNING: following code is is for illustrative purpose only. It’s a very simplified implementation, should not be used in a production system.

Contract

contract Checkpoint {

   address historian;

   uint64 height;
   uint256 stateHash;

   function Checkpoint() {
       historian = msg.sender;
   }

   function makeCheckpoint(uint64 _height, uint256 _a, uint256 _b, uint256 _c, uint256 _stateHash) {
       if (historian != msg.sender) {
           throw;
       }
       if (_height <= height) {
           throw;
       }
       height = _height;
       stateHash = _stateHash;
   }

   function getLastCheckpoint() returns (uint64, uint256, uint256, uint256, uint256) {
       return (height, 0, 0, 0, stateHash);
   }

}

Consensus:


func MakeCheckpoint(contract *CheckpointContract, chain *BlockChain) {
      height := chain.height()
      block := chain.get(height)
      hash := sha3(block.stateRoot, checkpointHeight)
      contract.makeCheckpoint(height, nil, nil, nil, hash)
}

func (self *Checkpoint) FollowsCheckpoint(chain *BlockChain) bool {
      checkpointHeight := self.height() //height at latest Checkpoint
      checkpointHash := self.hash() //hash at latest Checkpoint
      if (chain.height() < checkpointHeight) {
             //chain is not fully synced yet, so maybe
             return true
      }
      blockAtCheckpoint := chain.get(checkpointHeight)
      chainHash := sha3(blockAtCheckpoint.stateRoot, checkpointHeight)
      return chainHash == checkpointHash
}

func (self *Checkpoint) SelectFork(left *BlockChain, right *BlockChain) *BlockChain {
      followLeft := self.FollowsCheckpoint(left)
      followRight := self.FollowsCheckpoint(right)
      if (followLeft && followRight) {
             // Recent Split
             return left.height() > right.height() ? left : right
      }
      if (followRight) {
             return followRight
      }
      if (followLeft) {
             return followRight
      }
      return nil
}

References

  1. Proof of Authority Chains - https://github.com/paritytech/parity/wiki/Proof-of-Authority-Chains
  2. Factom - Business Processes Secured by Immutable Audit Trails on the Blockchain (Paul Snow, Brian Deery, Jack Lu, David Johnston, Peter Kirby)