In Ethereum 2.0's data availability model, we have a need to be able to reconstruct chunks of data when up to half of that data has been lost or withheld. I recently implemented some code to do this, but I always like to understand what's really going on, so I put together this worked example.
This example is going to be super unambitious. We are going to start with two items of data. We will encode these into four items of data, and then throw two of them away. Finally we will recover the original two items.
At this scale, you don't need to be very sophisticated. If our data are $[a,b]$, we can extend it to $[a,b,a+b,a-b]$: now we can lose any two of these values and still recover the original numbers (try it!). But for much larger scales, we need a general technique that can be efficiently implemented.
Such a technique is described by Vitalik Buterin in a post Reed-Solomon erasure code recovery in n*log^2(n) time with FFTs. My example here essentially follows that description and notation. It will seem massively over-complex when applied to our meager two data, but remember that the method is both general and efficient.
If you would like to play with it yourself, I've coded up the toy example below in this repo.