slashing-protector
provides an HTTP API to protect Ethereum 2.0 validators from slashing.
Clone this repository:
git clone github.com/bloxapp/slashing-protector
Run with Docker:
cd slashing-protector
docker-compose up
API is ready for use at http://localhost:9369 🤙
Use the client
package to interact with the slashing-protector
API:
import (
"log"
"net/http"
sp "github.com/bloxapp/slashing-protector/http"
)
client := sp.NewClient(&http.Client{})
// Check if an attestation is slashable:
check, err := client.CheckAttestation(ctx, network, pubKey, signingRoot, &phase0.Attestation{...})
if err != nil {
return err
}
if check.Slashable {
return errors.New("slashable attestation: %s", check.Reason)
}
// <- Not slashable, can submit!
// Check if a proposal is slashable:
check, err := client.CheckProposal(ctx, network, pubKey, signingRoot, &altair.BeaconBlock{...})
if err != nil {
return err
}
if check.Slashable {
return errors.New("slashable proposal: %s", check.Reason)
}
// <- Not slashable, can submit!
slashing-protector
leverages Prysm's bbolt-based slashing protection. (See https://github.com/prysmaticlabs/prysm/tree/v2.0.4/validator/db/kv)
This means that when Prysm releases a version, the dependency might need to be updated. Specifically, if the release fixes a bug or implements a specification change regarding slashing protection, then the dependency must be updated.
A good practice would be to update the dependency with every Prysm stable release.
- #️⃣ Copy the commit hash of the Prysm release or hotfix
- 📁 Navigate to
slashing-protector
's directory - 📦 Edit
go.mod
and paste the first 12 characters of the commit hash in the Prysm dependency:replace github.com/prysmaticlabs/prysm v1.4.4 => github.com/prysmaticlabs/prysm v1.4.2-0.20211005004110-<short_hash>
- 🧹 Run
go mod tidy
and it'll tell you that the timestamp (right before the hash) is wrong and what it should be instead. Copy the correct timestamp and update it ingo.mod
. Rungo mod tidy
again to ensure everything's okay. - 🧪 Run the tests to ensure no breaking changes.