From 025d7ba485709089fecd1e0052982e32c303cd38 Mon Sep 17 00:00:00 2001 From: gop Date: Thu, 16 Nov 2023 13:13:55 -0600 Subject: [PATCH] QIP5: Interlinks in Quai --- README.mediawiki | 7 +++ qip-0005.md | 119 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 qip-0005.md diff --git a/README.mediawiki b/README.mediawiki index 645db0c..169ba37 100644 --- a/README.mediawiki +++ b/README.mediawiki @@ -41,6 +41,13 @@ Those proposing changes should consider that ultimately consent may rest with th | wizeguyy | Standard | Draft +|- +| [[qip-0005.mediawiki|4]] +| Consensus (hard fork) +| Interlinks +| gameofpointers +| Standard +| Draft |} diff --git a/qip-0005.md b/qip-0005.md new file mode 100644 index 0000000..ab2c86f --- /dev/null +++ b/qip-0005.md @@ -0,0 +1,119 @@ + ``` + QIP: 5 + Layer: Consensus (hard fork) + Title: Interlink (NiPoPow) + Author: gameofpointers + Comments-Summary: No comments yet. + Comments-URI: https://github.com/quainetwork/qips/wiki/Comments:QIP-0005 + Status: Draft + Type: Standards Track + Created: 2023-11-16 + License: BSD-2-Clause + ``` + +## Abstract + +This QIP defines a block interlink structure to be used in Quai as described in +[1] with few changes. + +## Motivation + +To Prove/Verify the Proof Of Work done on Quai since the genesis using a +non-interactive proof of proof of work (NiPoPoW). This requires using only +O(log(N)) headers instead of the whole chain history. This enables a light +node(SPV client) to quickly verify the work done on the chain on a node with low +resource. Specifically in Quai, the plan is to use interlinks for work based +snap sync and to use nodes as trustless RPC providers. + +## Specification + +### Definitions +1. $Order(O)$ - Quai blockchain is organized into different levels, Prime, Region and Zone. Prime has a order of 0, Region has order of 1, Zone has order 2. Order of a Block(B) is defined as $O(B)$. $O(B_p)=0$, $O(B_r)=1$, and $O(B_z)=2$. + +### Overview + +Interlink data structure is a skip-list that helps a verifier to process a +sparse subset of the blockchain. + +Proof of Work function of a Valid Block in the blockchain satisfies the Mining Target(T) i.e $id \leq T$ . + +Traditional Interlinks are organized into different levels. If $id \leq +\frac{T}{2^{k \times \mu}}$ we say the block is of rank $\mu$. k is a compression +parameter and determines the range between interlinks. This is a small +deviation from the equation in [1] $id \leq \frac{T}{2^{\mu}}$. Having a bigger +range between interlink levels helps with proof compression while preserving +the security guarantees.Rank in Quai is analogous to Level in paper[1]. Since Quai has three layers namely Prime, Region, Zone. Prime chain acts as the base chain and has rank of 0. [1] defines $\mu$ for a block $B$ as $$\mu=\log(T)-\log(id(B))$$ +This changes for Quai to $$\mu=\frac{\log(T)-\log(id(B)}{k} $$ +In [1] the authors say that for genesis we set the $id=0$ and $\mu=\inf$. Lowest rank $mu=0$ represents every prime block in Quai. + +Now for the implemention of interlinks in Quai we have established that, +* Frequency of interlink computation will be on every Prime Block +* The Target used to calculate the Interlinks will be the $T_p$. ($T_p$ is the Target used to determine if the block is a prime block). All interlink hash calculations will be done on this Target. + +## Implementation + +Given the understanding of this theory, for a given k, and num of levels(L) the interlink data structure would look like this. + +```{go} +type InterLinks []Hash +``` + +I propose to add new field to the header: +* Merkle root of the interlink. This will be used to store/reference the interlink data structure. This will be stored in the body of the block. + +```{go} +type Header struct { + ... + ... + interlinkRootHash Hash + ... + ... +} +``` + +Logic to calculate the rank of a block +```{go} +func CalculateRank(block) int { + if Order(block) != 0 { + return + } + rank := 0 + primeTarget := 2^256/block.PrimeDifficultyThreshold + for i:=0;i rank { + rank = mu + } + } + return rank +} +``` + +Logic to calculate the Interlink root given a block +```{go} +func CalculateInterlinkRoot(block) Hash { + if Order(block) != 0 { + return + } + newInterLink = Copy(block.InterLink) + rank := CalculateRank(block) + for i:=0;i