-
Notifications
You must be signed in to change notification settings - Fork 0
Add deposit signature #21
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8360e88
Add deposit signature shares
evgeny-stakewise 987cd23
Add validator_type to validators response
evgeny-stakewise bf5d56f
Add public keys file
evgeny-stakewise 1ae1b31
Merge branch 'operator-v4' into deposit-sig
evgeny-stakewise 67e17dd
Rename endpoints, add is_deposit_signature_ready
evgeny-stakewise 2b3652e
Rework deposit signature from HexStr to BLSSignature
evgeny-stakewise e801723
Review fixes
evgeny-stakewise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,89 @@ | ||
| from eth_typing import BLSSignature, HexStr | ||
| from eth_typing import BLSSignature | ||
| from fastapi import APIRouter | ||
| from web3 import Web3 | ||
|
|
||
| from src.app_state import AppState | ||
| from src.config import settings | ||
| from src.validators.exit_signature import ( | ||
| get_oracles_exit_signature_shares, | ||
| validate_deposit_signature, | ||
| validate_exit_signature, | ||
| ) | ||
| from src.validators.key_shares import reconstruct_shared_bls_signature | ||
| from src.validators.schema import ( | ||
| ExitSignatureShareRequest, | ||
| ExitSignatureShareResponse, | ||
| ExitsResponse, | ||
| ExitsResponseItem, | ||
| SignatureShareRequest, | ||
| SignatureShareResponse, | ||
| ValidatorsResponse, | ||
| ValidatorsResponseItem, | ||
| ) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| @router.get('/exits') | ||
| async def get_exits() -> ExitsResponse: | ||
| @router.get('/validators') | ||
| async def get_validators() -> ValidatorsResponse: | ||
| app_state = AppState() | ||
| response = ExitsResponse(exits=[]) | ||
| response = ValidatorsResponse(validators=[]) | ||
|
|
||
| for validator in app_state.validators.values(): | ||
| response.exits.append(ExitsResponseItem.from_validator(validator)) | ||
| response.validators.append(ValidatorsResponseItem.from_validator(validator)) | ||
| return response | ||
|
|
||
|
|
||
| @router.post('/exit-signature') | ||
| async def create_exit_signature_shares( | ||
| request: ExitSignatureShareRequest, | ||
| ) -> ExitSignatureShareResponse: | ||
| @router.post('/signatures') | ||
| async def submit_signature_shares( | ||
| request: SignatureShareRequest, | ||
| ) -> SignatureShareResponse: | ||
| app_state = AppState() | ||
|
|
||
| for share in request.shares: | ||
| validator = app_state.validators.get(share.public_key) | ||
| if validator is None: | ||
| continue | ||
|
|
||
| current_share = validator.exit_signature_shares.get(request.share_index) | ||
| if current_share: | ||
| continue | ||
| # Handle exit signature shares | ||
| if not validator.exit_signature_shares.get(request.share_index): | ||
| validator.exit_signature_shares[request.share_index] = BLSSignature( | ||
| Web3.to_bytes(hexstr=share.exit_signature) | ||
| ) | ||
|
|
||
| validator.exit_signature_shares[request.share_index] = BLSSignature( | ||
| Web3.to_bytes(hexstr=HexStr(share.exit_signature)) | ||
| ) | ||
| if len(validator.exit_signature_shares) >= settings.signature_threshold: | ||
| # Reconstruct and validate exit signature | ||
| exit_signature = reconstruct_shared_bls_signature(validator.exit_signature_shares) | ||
| if not validate_exit_signature( | ||
| validator.public_key, validator.validator_index, exit_signature | ||
| ): | ||
| raise RuntimeError('invalid exit signature') | ||
|
|
||
| if len(validator.exit_signature_shares) < settings.signature_threshold: | ||
| continue | ||
| validator.exit_signature = exit_signature | ||
|
|
||
| # Split exit signature into shares for oracles | ||
| oracles_shares = await get_oracles_exit_signature_shares( | ||
| public_key=validator.public_key, | ||
| validator_index=validator.validator_index, | ||
| exit_signature=validator.exit_signature, | ||
| ) | ||
| validator.oracles_exit_signature_shares = oracles_shares | ||
|
|
||
| exit_signature = reconstruct_shared_bls_signature(validator.exit_signature_shares) | ||
| if not validate_exit_signature( | ||
| validator.public_key, validator.validator_index, exit_signature | ||
| ): | ||
| raise RuntimeError('invalid exit signature') | ||
| # Handle deposit signature shares | ||
| if not validator.deposit_signature_shares.get(request.share_index): | ||
| validator.deposit_signature_shares[request.share_index] = BLSSignature( | ||
| Web3.to_bytes(hexstr=share.deposit_signature) | ||
| ) | ||
|
|
||
| validator.exit_signature = exit_signature | ||
| if len(validator.deposit_signature_shares) >= settings.signature_threshold: | ||
| # Reconstruct and validate deposit signature | ||
| deposit_signature = reconstruct_shared_bls_signature( | ||
| validator.deposit_signature_shares | ||
| ) | ||
| if not validate_deposit_signature( | ||
| validator.public_key, | ||
| Web3.to_bytes(hexstr=validator.withdrawal_credentials), | ||
| validator.amount, | ||
| deposit_signature, | ||
| ): | ||
| raise RuntimeError('invalid deposit signature') | ||
|
|
||
| oracles_shares = await get_oracles_exit_signature_shares( | ||
| public_key=validator.public_key, | ||
| validator_index=validator.validator_index, | ||
| exit_signature=validator.exit_signature, | ||
| ) | ||
| validator.oracles_exit_signature_shares = oracles_shares | ||
| validator.deposit_signature = deposit_signature | ||
|
|
||
| return ExitSignatureShareResponse() | ||
| return SignatureShareResponse() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.