Small PoC to protect a validator client from signing slashable attestations. Please read this hackmd for more context.
Here's the idea:
- For every target epoch higher than the
new_attestationtarget epoch, check that the corresponding source epoch is higher than the
new_attestationsource epoch (checking that
new_attestationis not surrounded by any previous vote).
- If the
new_attestationtarget epoch is already in the historical attestation list, check that they have the same hash (checking for double votes).
- For every target epoch between the
new_attestationsource epoch and the
new_attestationtarget epoch, check that the corresponding source epoch is smaller than the
new_attestationsource epoch (checking we're not surrounding any previous votes).
By taking advantage of the fact that the attestation_history is already sorted, this algorithm should be near instantaneous in almost all normal cases. The complexity is a linear function of the number of target epochs in the attestation_history that are bigger than the
Here's a gif to visualize it better:
There are two PoC in this repo. The first is a Rust version and the second a Python version. The Python version needs revision, please look at the Rust one. To run Rust tests:
cd rust_poc; cargo test
To run Python tests:
cd python_poc; python3 tests.py