Skip to content

Commit

Permalink
Move signatures encryption out of keystore
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed Feb 14, 2024
1 parent 3bb87ec commit c7b47ec
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
7 changes: 6 additions & 1 deletion src/exits/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
send_signature_rotation_requests,
)
from src.validators.keystores.base import BaseKeystore
from src.validators.signing.common import encrypt_signatures_list

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -203,9 +204,13 @@ async def _get_oracles_request(
failed_indexes.append(validator_index)
continue

encrypted_exit_signature_shards = encrypt_signatures_list(
oracles.public_keys, shards.exit_signatures
)

request.public_keys.append(public_key)
request.public_key_shards.append(shards.public_keys)
request.exit_signature_shards.append(shards.exit_signatures)
request.exit_signature_shards.append(encrypted_exit_signature_shards)

if failed_indexes:
logger.warning(
Expand Down
18 changes: 4 additions & 14 deletions src/validators/keystores/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from src.config.settings import NETWORKS, settings
from src.validators.exceptions import KeystoreException
from src.validators.keystores.base import BaseKeystore
from src.validators.signing.common import encrypt_signature
from src.validators.signing.key_shares import (
bls_signature_and_public_key_to_shares,
private_key_to_private_key_shares,
Expand Down Expand Up @@ -102,11 +101,9 @@ async def get_exit_signature_shards(
threshold=oracles.exit_signature_recover_threshold,
total=len(oracles.public_keys),
)
exit_signature_shards: list[HexStr] = []
for bls_priv_key, oracle_pubkey in zip(private_key_shares, oracles.public_keys):
exit_signature_shards.append(
encrypt_signature(oracle_pubkey, bls.Sign(bls_priv_key, message))
)
exit_signature_shards: list[BLSSignature] = []
for bls_priv_key in private_key_shares:
exit_signature_shards.append(bls.Sign(bls_priv_key, message))

return ExitSignatureShards(
public_keys=[Web3.to_hex(bls.SkToPk(priv_key)) for priv_key in private_key_shares],
Expand Down Expand Up @@ -143,16 +140,9 @@ async def get_exit_signature_shards_without_keystore(
message, exit_signature, public_key_bytes, threshold, total
)

encrypted_exit_signature_shares: list[HexStr] = []

for exit_signature_share, oracle_pubkey in zip(exit_signature_shares, oracles.public_keys):
encrypted_exit_signature_shares.append(
encrypt_signature(oracle_pubkey, exit_signature_share)
)

return ExitSignatureShards(
public_keys=[Web3.to_hex(p) for p in public_key_shares],
exit_signatures=encrypted_exit_signature_shares,
exit_signatures=exit_signature_shares,
)

async def get_exit_signature(
Expand Down
10 changes: 1 addition & 9 deletions src/validators/keystores/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from src.config.networks import NETWORKS
from src.config.settings import REMOTE_SIGNER_TIMEOUT, settings
from src.validators.keystores.base import BaseKeystore
from src.validators.signing.common import encrypt_signature
from src.validators.signing.key_shares import bls_signature_and_public_key_to_shares
from src.validators.typings import ExitSignatureShards
from src.validators.utils import load_deposit_data
Expand Down Expand Up @@ -93,16 +92,9 @@ async def get_exit_signature_shards(
message, exit_signature, public_key_bytes, threshold, total
)

encrypted_exit_signature_shares: list[HexStr] = []

for exit_signature_share, oracle_pubkey in zip(exit_signature_shares, oracles.public_keys):
encrypted_exit_signature_shares.append(
encrypt_signature(oracle_pubkey, exit_signature_share)
)

return ExitSignatureShards(
public_keys=[Web3.to_hex(p) for p in public_key_shares],
exit_signatures=encrypted_exit_signature_shares,
exit_signatures=exit_signature_shares,
)

async def get_exit_signature(
Expand Down
9 changes: 9 additions & 0 deletions src/validators/signing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ def encrypt_signature(oracle_pubkey: HexStr, signature: BLSSignature) -> HexStr:
return Web3.to_hex(ecies.encrypt(oracle_pubkey, signature))


def encrypt_signatures_list(
oracle_pubkeys: list[HexStr], signatures: list[BLSSignature]
) -> list[HexStr]:
res: list[HexStr] = []
for signature, oracle_pubkey in zip(signatures, oracle_pubkeys):
res.append(encrypt_signature(oracle_pubkey, signature))
return res


def get_validators_proof(
tree: StandardMerkleTree,
validators: list[Validator],
Expand Down
7 changes: 5 additions & 2 deletions src/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
)
from src.validators.keystores.base import BaseKeystore
from src.validators.keystores.local import LocalKeystore
from src.validators.signing.common import get_validators_proof
from src.validators.signing.common import encrypt_signatures_list, get_validators_proof
from src.validators.typings import (
ApprovalRequest,
DepositData,
Expand Down Expand Up @@ -305,6 +305,9 @@ async def create_approval_request(
oracles=oracles,
fork=settings.network_config.SHAPELLA_FORK,
)
encrypted_exit_signature_shards = encrypt_signatures_list(
oracles.public_keys, shards.exit_signatures
)

if not shards:
logger.warning(
Expand All @@ -315,7 +318,7 @@ async def create_approval_request(
request.public_keys.append(validator.public_key)
request.deposit_signatures.append(validator.signature)
request.public_key_shards.append(shards.public_keys)
request.exit_signature_shards.append(shards.exit_signatures)
request.exit_signature_shards.append(encrypted_exit_signature_shards)

validator_index += 1
return request
Expand Down
2 changes: 1 addition & 1 deletion src/validators/typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def public_keys(self) -> list[HexStr]:
@dataclass
class ExitSignatureShards:
public_keys: list[HexStr]
exit_signatures: list[HexStr] # encrypted exit signature shards
exit_signatures: list[BLSSignature]


@dataclass
Expand Down

0 comments on commit c7b47ec

Please sign in to comment.