Skip to content

Commit 6819df2

Browse files
committed
chore: switch to keystores
1 parent 399a0aa commit 6819df2

File tree

7 files changed

+129
-14
lines changed

7 files changed

+129
-14
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
VALIDATORS_PER_NODE=${VALIDATORS_PER_NODE:-1}
5+
6+
# We get the index in the config map from the pod name, which will have the service index within it
7+
# For multiple validators per node, we need to multiply the pod index by VALIDATORS_PER_NODE
8+
POD_INDEX=$(echo $K8S_POD_NAME | awk -F'-' '{print $NF}')
9+
KEY_INDEX=$((POD_INDEX * VALIDATORS_PER_NODE))
10+
# Add the index to the start index to get the private key index
11+
PRIVATE_KEY_INDEX=$((KEY_INDEX_START + KEY_INDEX))
12+
13+
WEB3_SIGNER_URL=${WEB3_SIGNER_URL:-""}
14+
15+
echo "POD_INDEX: $POD_INDEX"
16+
echo "KEY_INDEX: $KEY_INDEX"
17+
echo "KEY_INDEX_START: $KEY_INDEX_START"
18+
echo "PRIVATE_KEY_INDEX: $PRIVATE_KEY_INDEX"
19+
echo "WEB3_SIGNER_URL: ${WEB3_SIGNER_URL}"
20+
# Specific for validators that can hold multiple keys on one node
21+
echo "VALIDATORS_PER_NODE: ${VALIDATORS_PER_NODE}"
22+
echo "MNEMONIC: $(echo $MNEMONIC | cut -d' ' -f1-2)..."
23+
24+
private_keys=()
25+
addresses=()
26+
27+
for ((i = 0; i < VALIDATORS_PER_NODE; i++)); do
28+
current_index=$((PRIVATE_KEY_INDEX + i))
29+
private_key=$(cast wallet private-key "$MNEMONIC" --mnemonic-index $current_index)
30+
address=$(cast wallet address --private-key $private_key)
31+
32+
if [ -z "$WEB3_SIGNER_URL" ]; then
33+
private_keys+=("$private_key")
34+
fi
35+
addresses+=("$address")
36+
done
37+
38+
# Other services will use the first key
39+
private_key=$(cast wallet private-key "$MNEMONIC" --mnemonic-index $PRIVATE_KEY_INDEX)
40+
address=$(cast wallet address "$private_key")
41+
42+
remoteSigner=""
43+
attesters=()
44+
publisher=""
45+
coinbase=$address
46+
47+
if [ -n "$WEB3_SIGNER_URL" ]; then
48+
remoteSigner=$(jq -n '{remoteSignerUrl: $url}' --arg url "$WEB3_SIGNER_URL")
49+
attesters=(${addresses[*]})
50+
publisher=$address
51+
else
52+
remoteSigner="null"
53+
attesters=(${private_keys[*]})
54+
publisher=$private_key
55+
fi
56+
57+
export KEY_STORE_DIRECTORY="/shared/config/keys"
58+
mkdir -p "$KEY_STORE_DIRECTORY"
59+
60+
jq -n '
61+
{
62+
schemaVersion: 1,
63+
remoteSigner: $remoteSigner,
64+
validators: {
65+
attester: $ARGS.positional,
66+
coinbase: $coinbase,
67+
publisher: $publisher,
68+
feeRecipient: "0x0000000000000000000000000000000000000000000000000000000000000000"
69+
}
70+
}
71+
' --argjson remoteSigner "$remoteSigner" \
72+
--arg publisher "$publisher" \
73+
--arg coinbase "$coinbase" \
74+
--args ${attesters[*]} > "$KEY_STORE_DIRECTORY/attesters.json"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
4+
WEB3_SIGNER_URL=${WEB3_SIGNER_URL:-""}
5+
6+
echo "KEY_INDEX_START: $KEY_INDEX_START"
7+
echo "WEB3_SIGNER_URL: ${WEB3_SIGNER_URL}"
8+
echo "MNEMONIC: $(echo $MNEMONIC | cut -d' ' -f1-2)..."
9+
10+
private_key=$(cast wallet private-key "$MNEMONIC" --mnemonic-index $KEY_INDEX_START)
11+
address=$(cast wallet address "$private_key")
12+
13+
remoteSigner=""
14+
publisher=""
15+
proverId=$address
16+
17+
if [ -n "$WEB3_SIGNER_URL" ]; then
18+
remoteSigner=$(jq -n '{remoteSignerUrl: $url}' --arg url "$WEB3_SIGNER_URL")
19+
publisher=$address
20+
else
21+
remoteSigner="null"
22+
publisher=$private_key
23+
fi
24+
25+
export KEY_STORE_DIRECTORY="/shared/config/keys"
26+
mkdir -p "$KEY_STORE_DIRECTORY"
27+
28+
jq -n '
29+
{
30+
schemaVersion: 1,
31+
remoteSigner: $remoteSigner,
32+
prover: {
33+
id: $proverId,
34+
publisher: $publisher,
35+
}
36+
}
37+
' --argjson remoteSigner "$remoteSigner" \
38+
--arg publisher "$publisher" \
39+
--arg proverId "$proverId" > "$KEY_STORE_DIRECTORY/prover.json"
40+

spartan/aztec-network/templates/prover-node.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ spec:
7979
- |
8080
source /shared/config/service-addresses
8181
/scripts/configure-prover-env.sh ${BOOT_NODE_HOST:-""} ${FULL_NODE_HOST:-""}
82-
source /scripts/get-private-key.sh
83-
source /shared/config/keys.env
82+
source /scripts/setup-prover-keystore.sh
8483
source /shared/contracts/contracts.env
8584
source /shared/config/p2p-addresses
8685
source /shared/config/otel-resource

spartan/aztec-network/templates/validator.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ spec:
5353
- "/bin/bash"
5454
- "-c"
5555
- |
56-
# Get the private key from the mnemonic - based on the pod replica index
57-
source /scripts/get-private-key.sh && \
58-
source /shared/config/keys.env && \
56+
source /scripts/setup-attester-keystore.sh && \
5957
source /shared/contracts/contracts.env && \
6058
source /shared/config/p2p-addresses && \
6159
source /shared/config/service-addresses && \

spartan/aztec-network/templates/web3signer.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,26 @@ spec:
5555
- |
5656
set -euo pipefail
5757
KS_DIR=/shared/key-store
58-
KS_FILE=$KS_DIR/attesters.yaml
59-
mkdir -p "$KS_DIR"; : > "$KS_FILE"
58+
ATTESTER_KS=$KS_DIR/attester.yaml
59+
PROVER_KS=$KS_DIR/prover.yaml
60+
61+
mkdir -p "$KS_DIR"
62+
: > "$ATTESTER_KS"
63+
: > "$PROVER_KS"
64+
6065
for ((i=0;i<VALIDATORS;i++)); do
6166
idx=$((VALIDATOR_KEY_START + i))
6267
pk="$(cast wallet private-key "$MNEMONIC" --mnemonic-index "$idx")"
63-
[[ $i -gt 0 ]] && echo '---' >> "$KS_FILE"
64-
cat >> "$KS_FILE" <<EOF
68+
[[ $i -gt 0 ]] && echo '---' >> "$ATTESTER_KS"
69+
cat >> "$ATTESTER_KS" <<EOF
6570
type: file-raw
6671
keyType: SECP256K1
6772
privateKey: "$pk"
6873
EOF
6974
done
7075
7176
pk="$(cast wallet private-key "$MNEMONIC" --mnemonic-index "$PROVER_KEY_START")"
72-
cat >> "$KS_FILE" <<EOF
73-
---
77+
cat >> "$PROVER_KS" <<EOF
7478
type: file-raw
7579
keyType: SECP256K1
7680
privateKey: "$pk"

spartan/aztec-network/values/rc-1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ bot:
6060
cpu: 7
6161

6262
web3signer:
63-
enabled: false
63+
enabled: true

yarn-project/node-keystore/src/schemas.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const validatorKeyStoreSchema = z.object({
7171
coinbase: ethAddressSchema.optional(),
7272
publisher: ethAccountsSchema.optional(),
7373
feeRecipient: aztecAddressSchema,
74-
remoteSigner: remoteSignerConfigSchema.optional(),
74+
remoteSigner: remoteSignerConfigSchema.nullish(),
7575
});
7676

7777
// Main keystore schema
@@ -80,7 +80,7 @@ export const keystoreSchema = z
8080
schemaVersion: z.literal(1),
8181
validators: z.array(validatorKeyStoreSchema).optional(),
8282
slasher: ethAccountsSchema.optional(),
83-
remoteSigner: remoteSignerConfigSchema.optional(),
83+
remoteSigner: remoteSignerConfigSchema.nullish(),
8484
prover: proverKeyStoreSchema.optional(),
8585
})
8686
.refine(data => data.validators || data.prover, {

0 commit comments

Comments
 (0)