nervosnetwork / ckb-light-client

CKB light client reference implementation
MIT License
14 stars 16 forks source link

Should check whether a long fork is valid before trust it #122

Closed yangby-cryptape closed 1 year ago

yangby-cryptape commented 1 year ago

Issue

Let $N_{last}$ denote the constant LAST_N_BLOCKS.

Let $n{k}$ denote the block number of block $B{k}$.

Suppose there are follow steps:

When $n{1} \gt n{fork} + N{last}$, the client couldn't have the header of $B{fork}$.

Then we couldn't know whether the fork chain is valid, because the fork chain is not base on any known block.

So, a malicious node could send an invalid long fork chain to the light client easily, and it will cause the light client panics.

Solution

The light client has to do a full chain sampling for the long fork chain, before panics.