Skip to content

Commit

Permalink
Add checksum address validation
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Jan 23, 2023
1 parent 3b7e144 commit 676279e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion staking_deposit/intl/en/utils/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"validate_eth1_withdrawal_address": {
"err_invalid_ECDSA_hex_addr": "The given Eth1 address is not in hexadecimal encoded form.",
"msg_ECDSA_addr_withdrawal": "**[Warning] you are setting an Eth1 address as your withdrawal address. Please ensure that you have control over this address.**"
"err_invalid_ECDSA_hex_addr_checksum": "The given Eth1 address is not in checksum form.",
"msg_ECDSA_hex_addr_withdrawal": "**[Warning] you are setting an Eth1 address as your withdrawal address. Please ensure that you have control over this address.**"
},
"validate_bls_withdrawal_credentials": {
"err_not_bls_form": "The given withdrawal credentials is not in BLS_WITHDRAWAL_PREFIX form."
Expand Down
2 changes: 1 addition & 1 deletion staking_deposit/intl/tr/utils/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
},
"validate_eth1_withdrawal_address": {
"err_invalid_ECDSA_hex_addr": "Girilen Eth1 adresi onaltılık sistemde kodlanmamıştır.",
"msg_ECDSA_addr_withdrawal": "**[Uyarı] bir Eth1 adresini varlık çekme adresi olarak giriyorsunuz. Lütfen bu adresin kontrolünün sizde olduğundan emin olun.**"
"msg_ECDSA_hex_addr_withdrawal": "**[Uyarı] bir Eth1 adresini varlık çekme adresi olarak giriyorsunuz. Lütfen bu adresin kontrolünün sizde olduğundan emin olun.**"
}
}
7 changes: 4 additions & 3 deletions staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
BLSSignature,
HexAddress,
)
from eth_utils import is_hex_address, to_normalized_address, decode_hex
from eth_utils import is_hex_address, is_checksum_address, to_normalized_address, decode_hex
from py_ecc.bls import G2ProofOfPossession as bls

from staking_deposit.exceptions import ValidationError
Expand Down Expand Up @@ -125,14 +125,15 @@ def validate_int_range(num: Any, low: int, high: int) -> int:


def validate_eth1_withdrawal_address(cts: click.Context, param: Any, address: str) -> HexAddress:
# TODO: checksum
if address is None:
return None
if not is_hex_address(address):
raise ValueError(load_text(['err_invalid_ECDSA_hex_addr']))
if not is_checksum_address(address):
raise ValueError(load_text(['err_invalid_ECDSA_hex_addr_checksum']))

normalized_address = to_normalized_address(address)
click.echo('\n%s\n' % load_text(['msg_ECDSA_addr_withdrawal']))
click.echo('\n%s\n' % load_text(['msg_ECDSA_hex_addr_withdrawal']))
return normalized_address

#
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_existing_menmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_existing_mnemonic_eth1_address_withdrawal() -> None:
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',
'2', '2', '5', 'mainnet', 'MyPassword', 'MyPassword']
data = '\n'.join(inputs)
eth1_withdrawal_address = '0x00000000219ab540356cbb839cbe05303d7705fa'
eth1_withdrawal_address = '0x00000000219ab540356cBB839Cbe05303d7705Fa'
arguments = [
'--language', 'english',
'existing-mnemonic',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_generate_bls_to_execution_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_existing_mnemonic_bls_withdrawal() -> None:
'--bls_withdrawal_credentials_list', '0x00bd0b5a34de5fb17df08410b5e615dda87caf4fb72d0aac91ce5e52fc6aa8de',
'--validator_start_index', '0',
'--validator_indices', '1',
'--execution_address', '3434343434343434343434343434343434343434',
'--execution_address', '0x3434343434343434343434343434343434343434',
]
result = runner.invoke(cli, arguments, input=data)
assert result.exit_code == 0
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli/test_new_mnemonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def mock_get_mnemonic(language, words_path, entropy=None) -> str:
inputs = ['english', '1', 'mainnet', 'MyPassword', 'MyPassword',
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about']
data = '\n'.join(inputs)
eth1_withdrawal_address = '0x00000000219ab540356cbb839cbe05303d7705fa'
eth1_withdrawal_address = '0x00000000219ab540356cBB839Cbe05303d7705Fa'
arguments = [
'--language', 'english',
'new-mnemonic',
Expand Down

0 comments on commit 676279e

Please sign in to comment.