Skip to content

Commit

Permalink
Arrange JSON fields by adding metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Jan 16, 2023
1 parent 1f8bab5 commit f5e2803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions staking_deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,14 @@ def get_bls_to_execution_change_dict(self, validator_index: int) -> Dict[str, by
result_dict.update({'message': message})
result_dict.update({'signature': '0x' + signed_bls_to_execution_change.signature.hex()})

# meta
result_dict.update({'network_name': self.chain_setting.NETWORK_NAME})
result_dict.update({'genesis_validators_root': '0x' + self.chain_setting.GENESIS_VALIDATORS_ROOT.hex()})
result_dict.update({'deposit_cli_version': DEPOSIT_CLI_VERSION})
# metadata
metadata: Dict[str, Any] = {
'network_name': self.chain_setting.NETWORK_NAME,
'genesis_validators_root': '0x' + self.chain_setting.GENESIS_VALIDATORS_ROOT.hex(),
'deposit_cli_version': DEPOSIT_CLI_VERSION,
}

result_dict.update({'metadata': metadata})
return result_dict


Expand Down
5 changes: 4 additions & 1 deletion staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def validate_bls_to_execution_change(btec_dict: Dict[str, Any],
from_bls_pubkey = BLSPubkey(decode_hex(btec_dict['message']['from_bls_pubkey']))
to_execution_address = decode_hex(btec_dict['message']['to_execution_address'])
signature = BLSSignature(decode_hex(btec_dict['signature']))
genesis_validators_root = decode_hex(btec_dict['metadata']['genesis_validators_root'])

if validator_index != input_validator_index:
return False
Expand All @@ -182,6 +183,8 @@ def validate_bls_to_execution_change(btec_dict: Dict[str, Any],
or to_execution_address != decode_hex(input_execution_address)
):
return False
if genesis_validators_root != chain_setting.GENESIS_VALIDATORS_ROOT:
return False

message = BLSToExecutionChange(
validator_index=validator_index,
Expand All @@ -190,7 +193,7 @@ def validate_bls_to_execution_change(btec_dict: Dict[str, Any],
)
domain = compute_bls_to_execution_change_domain(
fork_version=chain_setting.GENESIS_FORK_VERSION,
genesis_validators_root=chain_setting.GENESIS_VALIDATORS_ROOT,
genesis_validators_root=genesis_validators_root,
)
signing_root = compute_signing_root(message, domain)

Expand Down

0 comments on commit f5e2803

Please sign in to comment.