Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paul's Doppelganger Protection Updates #16

Merged
merged 53 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
1668933
Change break -> continue
paulhauner May 5, 2021
60a7376
Change logs for global consistency
paulhauner May 5, 2021
02e61c3
Add incomplete progress
paulhauner May 5, 2021
3bd276c
Restrict signing based on doppelganger
paulhauner May 7, 2021
f9473d2
Add comments, fix violator detection
paulhauner May 7, 2021
604a551
Merge branch 'unstable' into sean-dopple
paulhauner Jun 9, 2021
93e3b32
Add comment
paulhauner Jun 10, 2021
9b77a31
Further tidying
paulhauner Jun 10, 2021
814e96b
Introduce VotingPubkey enum
paulhauner Jun 11, 2021
5471973
Rename function
paulhauner Jun 11, 2021
18e0284
Fix test compile error
paulhauner Jun 11, 2021
90317e9
Tidy
paulhauner Jun 11, 2021
138ddba
Rename VotingPubkey -> DoppelgangerStatus
paulhauner Jun 11, 2021
6d156a9
Add doppelganger protection comment
paulhauner Jun 11, 2021
a4216c3
Rename DoppelgangerStatus fns
paulhauner Jun 11, 2021
c0c859c
Tidy comments
paulhauner Jun 11, 2021
568670d
Skip validators with inconsistencies, tidy
paulhauner Jun 15, 2021
b146c27
Don't exit if BN returns nothing for liveness
paulhauner Jun 15, 2021
91e182d
Appease clippy
paulhauner Jun 15, 2021
589477e
Refactor to smaller functions
paulhauner Jun 15, 2021
b5fe24e
Make `detect_doppelgangers` more generic
paulhauner Jun 15, 2021
ff22c03
Use generic shutdown signal
paulhauner Jun 16, 2021
eb5e9c9
Add first tests
paulhauner Jun 16, 2021
521eb70
Add more testing
paulhauner Jun 16, 2021
a78cc52
More testing
paulhauner Jun 16, 2021
d73b9dd
Add success scenario test
paulhauner Jun 16, 2021
002c9e6
Add skip forward test
paulhauner Jun 16, 2021
00813e1
Add time skip backwards test
paulhauner Jun 16, 2021
7c9ec9f
Add staggered entry test
paulhauner Jun 16, 2021
8304496
Remove slot clock from doppelganger
paulhauner Jun 17, 2021
10bec29
Update comment
paulhauner Jun 17, 2021
a3d9854
Allow selection proof signing
paulhauner Jun 17, 2021
fc451bd
Add comment
paulhauner Jun 17, 2021
284ee60
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jun 17, 2021
1bac50f
fix duplicate `Cargo.toml` entry
realbigsean Jun 17, 2021
d48f84e
- move `DetectionState` mutation to method.
realbigsean Jun 29, 2021
70a4e5a
fix comments, set `DEFAULT_REMAINING_DETECTION_EPOCHS` to 1
realbigsean Jun 29, 2021
0d9c187
Disable doppelganger detection by default
realbigsean Jun 29, 2021
7e7dcb6
Add doppelganger status endpoint
realbigsean Jul 2, 2021
59f272a
Add doppelganger protection enabled method
realbigsean Jul 2, 2021
c3e8585
Add docs, fix tests and some comments
realbigsean Jul 2, 2021
88b7de7
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jul 2, 2021
72b5f88
Merge branch 'unstable' of https://github.com/sigp/lighthouse into pa…
realbigsean Jul 7, 2021
a35bf31
- And an `Arc` around the `ValidatorStore`
realbigsean Jul 7, 2021
ce55743
- Add local testnet test for successful doppelganger protection period
realbigsean Jul 8, 2021
f4aee3c
remove unncessary `mut`
realbigsean Jul 8, 2021
08e67f4
update doppelganger test in ci
realbigsean Jul 8, 2021
a9283a3
Merge branch 'doppleganger-detection' of https://github.com/realbigse…
realbigsean Jul 12, 2021
56b921d
Add a timeout for the liveness request
realbigsean Jul 12, 2021
e786eb7
fix test compilation after merge
realbigsean Jul 12, 2021
b213f1b
Use Option instead of enabled bool
paulhauner Jul 13, 2021
2bf2860
fix typo and add fork slot to test `.env` files
realbigsean Jul 13, 2021
6e2484c
fix tests
realbigsean Jul 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ jobs:
run: sudo npm install -g ganache-cli
- name: Run the syncing simulator
run: cargo run --release --bin simulator syncing-sim
doppelganger-detection-test:
name: doppelganger-detection-test
doppelganger-protection-test:
name: doppelganger-protection-test
runs-on: ubuntu-latest
needs: cargo-fmt
steps:
Expand All @@ -160,10 +160,14 @@ jobs:
run: |
make
make install-lcli
- name: Run the doppelganger detection test script
- name: Run the doppelganger protection success test script
run: |
cd scripts/tests
./doppelganger_detection.sh
./doppelganger_protection.sh success
- name: Run the doppelganger protection failure test script
run: |
cd scripts/tests
./doppelganger_protection.sh failure
check-benchmarks:
name: check-benchmarks
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2152,13 +2152,13 @@ impl ApiTester {
pub async fn test_post_lighthouse_liveness(self) -> Self {
let epoch = self.chain.epoch().unwrap();
let head_state = self.chain.head_beacon_state().unwrap();
let indices = (0..head_state.validators.len())
let indices = (0..head_state.validators().len())
.map(|i| i as u64)
.collect::<Vec<_>>();

// Construct the expected response
let expected: Vec<LivenessResponseData> = head_state
.validators
.validators()
.iter()
.enumerate()
.map(|(index, _)| LivenessResponseData {
Expand Down
46 changes: 45 additions & 1 deletion book/src/api-vc-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ HTTP Path | Description |
[`GET /lighthouse/spec`](#get-lighthousespec) | Get the Eth2 specification used by the validator
[`GET /lighthouse/validators`](#get-lighthousevalidators) | List all validators
[`GET /lighthouse/validators/:voting_pubkey`](#get-lighthousevalidatorsvoting_pubkey) | Get a specific validator
[`GET /lighthouse/validators/doppelganger_status`](#get-lighthousevalidatorsdoppelganger_status) | Check the doppelganger protection check status of all validators.
[`PATCH /lighthouse/validators/:voting_pubkey`](#patch-lighthousevalidatorsvoting_pubkey) | Update a specific validator
[`POST /lighthouse/validators`](#post-lighthousevalidators) | Create a new validator and mnemonic.
[`POST /lighthouse/validators/keystore`](#post-lighthousevalidatorskeystore) | Import a keystore.
Expand Down Expand Up @@ -220,6 +221,49 @@ localhost:5062/lighthouse/validators/0xb0148e6348264131bf47bcd1829590e870c836dc8
}
```

## `GET /lighthouse/validators/doppelganger_status`

Get the doppelganger protection check status of all validators managed by this validator client.

If doppelganger protection is disabled, this endpoint will return an empty array.

### HTTP Specification

| Property | Specification |
| --- |--- |
Path | `/lighthouse/validators/doppelganger_status`
Method | GET
Required Headers | [`Authorization`](./api-vc-auth-header.md)
Typical Responses | 200, 400

### Example Path

```
localhost:5062/lighthouse/validators/doppelganger_status
```

### Example Response Body

```json
{
"data":
[
{
"pubkey": "0xb0148e6348264131bf47bcd1829590e870c836dc893050fd0dadc7a28949f9d0a72f2805d027521b45441101f0cc1cde",
"status": "signing_enabled"
},
{
"pubkey": "0xb0148e6348264131bf47bcd1829590e870c836dc893050fd0dadc7a28949f9d0a72f2805d027521b45441101f0cc1cde",
"status": "signing_disabled"
},
{
"pubkey": "0xb0148e6348264131bf47bcd1829590e870c836dc893050fd0dadc7a28949f9d0a72f2805d027521b45441101f0cc1cde",
"status": "unknown"
}
]
}
```

## `PATCH /lighthouse/validators/:voting_pubkey`

Update some values for the validator with `voting_pubkey`.
Expand Down Expand Up @@ -351,7 +395,7 @@ Typical Responses | 200
"checksum": {
"function": "sha256",
"params": {

},
"message": "abadc1285fd38b24a98ac586bda5b17a8f93fc1ff0778803dc32049578981236"
},
Expand Down
5 changes: 4 additions & 1 deletion common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl fmt::Display for Error {
pub struct Timeouts {
pub attestation: Duration,
pub attester_duties: Duration,
pub liveness: Duration,
pub proposal: Duration,
pub proposer_duties: Duration,
}
Expand All @@ -92,6 +93,7 @@ impl Timeouts {
Timeouts {
attestation: timeout,
attester_duties: timeout,
liveness: timeout,
proposal: timeout,
proposer_duties: timeout,
}
Expand Down Expand Up @@ -1116,12 +1118,13 @@ impl BeaconNodeHttpClient {
.push("lighthouse")
.push("liveness");

self.post_with_response(
self.post_with_timeout_and_response(
path,
&LivenessRequestData {
indices: ids.to_vec(),
epoch,
},
self.timeouts.liveness,
)
.await
}
Expand Down
15 changes: 15 additions & 0 deletions common/eth2/src/lighthouse_vc/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,21 @@ impl ValidatorClientHttpClient {
self.get_opt(path).await
}

/// `GET lighthouse/validators/doppelganger_status`
pub async fn get_lighthouse_validators_doppelganger(
&self,
) -> Result<GenericResponse<Vec<DoppelgangerData>>, Error> {
let mut path = self.server.full.clone();

path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("lighthouse")
.push("validators")
.push("doppelganger_status");

self.get(path).await
}

/// `POST lighthouse/validators`
pub async fn post_lighthouse_validators(
&self,
Expand Down
14 changes: 14 additions & 0 deletions common/eth2/src/lighthouse_vc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@ pub struct KeystoreValidatorsPostRequest {
pub keystore: Keystore,
pub graffiti: Option<GraffitiString>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DoppelgangerData {
pub pubkey: PublicKeyBytes,
pub status: DoppelgangerStatus,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DoppelgangerStatus {
SigningEnabled,
SigningDisabled,
Unknown,
}
72 changes: 0 additions & 72 deletions scripts/tests/doppelganger_detection.sh

This file was deleted.

102 changes: 102 additions & 0 deletions scripts/tests/doppelganger_protection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash

BEHAVIOR=$1

if [[ "$BEHAVIOR" != "success" ]] && [[ "$BEHAVIOR" != "failure" ]]; then
echo "Usage: doppelganger_protection.sh [success|failure]"
exit 1
fi

cp ./vars_$BEHAVIOR.env ./vars.env

../local_testnet/clean.sh

echo "Starting ganache"

../local_testnet/ganache_test_node.sh &> /dev/null &
GANACHE_PID=$!

# wait for ganache to start
sleep 5

echo "Setting up local testnet"

../local_testnet/setup.sh

# Duplicate this directory so slashing protection doesn't keep us from re-using validator keys
cp -R $HOME/.lighthouse/local-testnet/node_1 $HOME/.lighthouse/local-testnet/node_1_doppelganger

echo "Starting bootnode"

../local_testnet/bootnode.sh &> /dev/null &
BOOT_PID=$!

# wait for the bootnode to start
sleep 5

echo "Starting local beacon nodes"

../local_testnet/beacon_node.sh $HOME/.lighthouse/local-testnet/node_1 9000 8000 &> /dev/null &
BEACON_PID=$!
../local_testnet/beacon_node.sh $HOME/.lighthouse/local-testnet/node_2 9100 8100 &> /dev/null &
BEACON2_PID=$!
../local_testnet/beacon_node.sh $HOME/.lighthouse/local-testnet/node_3 9200 8200 &> /dev/null &
BEACON3_PID=$!

echo "Starting local validator clients"

../local_testnet/validator_client.sh $HOME/.lighthouse/local-testnet/node_1 http://localhost:8000 &> /dev/null &
VALIDATOR_1_PID=$!
../local_testnet/validator_client.sh $HOME/.lighthouse/local-testnet/node_2 http://localhost:8100 &> /dev/null &
VALIDATOR_2_PID=$!
../local_testnet/validator_client.sh $HOME/.lighthouse/local-testnet/node_3 http://localhost:8200 &> /dev/null &
VALIDATOR_3_PID=$!

echo "Waiting an epoch before starting the next validator client"
sleep 64

if [ "$BEHAVIOR" == "failure" ]; then

echo "Starting the doppelganger validator client"

# Use same keys as keys from VC1, but connect to BN2
# This process should not last longer than 2 epochs
timeout 128 ../local_testnet/validator_client.sh $HOME/.lighthouse/local-testnet/node_1_doppelganger http://localhost:8100
DOPPELGANGER_EXIT=$?

echo "Shutting down"

# Cleanup
kill $BOOT_PID $BEACON_PID $BEACON2_PID $GANACHE_PID $VALIDATOR_1_PID $VALIDATOR_2_PID $VALIDATOR_3_PID $BEACON3_PID
rm ./vars.env

echo "Done"

if [ $DOPPELGANGER_EXIT -eq 124 ]; then
exit 1
fi
fi

if [ "$BEHAVIOR" == "success" ]; then

echo "Starting the last validator client"

# This process should last longer than 3 epochs
timeout 192 ../local_testnet/validator_client.sh $HOME/.lighthouse/local-testnet/node_4 http://localhost:8100

DOPPELGANGER_EXIT=$?

echo "Shutting down"

# Cleanup
kill $BOOT_PID $BEACON_PID $BEACON2_PID $GANACHE_PID $VALIDATOR_1_PID $VALIDATOR_2_PID $VALIDATOR_3_PID $BEACON3_PID
rm ./vars.env

echo "Done"

if [ $DOPPELGANGER_EXIT -ne 124 ]; then
exit 1
fi
fi

exit 0
5 changes: 4 additions & 1 deletion scripts/tests/vars.env → scripts/tests/vars_failure.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ BOOTNODE_PORT=4242
# Network ID and Chain ID of local eth1 test network
NETWORK_ID=4242

# Hard fork configuration
ALTAIR_FORK_EPOCH=18446744073709551615

SECONDS_PER_SLOT=2
SECONDS_PER_ETH1_BLOCK=1

# Enable doppelganger detection
VC_ARGS=
VC_ARGS=" --enable-doppelganger-protection "
Loading