Skip to content

Commit 7f43610

Browse files
authored
Merge pull request #128 from ethereum/dev
dev -> master for Zinken
2 parents 1681a93 + 4362769 commit 7f43610

File tree

7 files changed

+57
-10
lines changed

7 files changed

+57
-10
lines changed

eth2deposit/credentials.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Keystore,
1111
ScryptKeystore,
1212
)
13+
from eth2deposit.settings import DEPOSIT_CLI_VERSION
1314
from eth2deposit.utils.constants import (
1415
BLS_WITHDRAWAL_PREFIX,
1516
ETH2GWEI,
@@ -90,6 +91,7 @@ def deposit_datum_dict(self) -> Dict[str, bytes]:
9091
datum_dict.update({'deposit_message_root': self.deposit_message.hash_tree_root})
9192
datum_dict.update({'deposit_data_root': signed_deposit_datum.hash_tree_root})
9293
datum_dict.update({'fork_version': self.fork_version})
94+
datum_dict.update({'deposit_cli_version': DEPOSIT_CLI_VERSION})
9395
return datum_dict
9496

9597
def signing_keystore(self, password: str) -> Keystore:

eth2deposit/settings.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from typing import Dict, NamedTuple
2+
import pkg_resources
3+
4+
5+
DEPOSIT_CLI_VERSION = pkg_resources.require("eth2deposit")[0].version
26

37

48
class BaseChainSetting(NamedTuple):
@@ -13,21 +17,25 @@ class BaseChainSetting(NamedTuple):
1317
AltonaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000121'))
1418
# Eth2 "official" public testnet (spec v0.12.2)
1519
MedallaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000001'))
16-
# Eth2 "dress rehearsal_" testnet (spec v0.12.3)
20+
# Eth2 "dress rehearsal" testnet (spec v0.12.3)
1721
SpadinaSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000002'))
22+
# Eth2 "dress rehearsal" testnet (spec v0.12.3)
23+
ZinkenSetting = BaseChainSetting(GENESIS_FORK_VERSION=bytes.fromhex('00000003'))
1824

1925

2026
MAINNET = 'mainnet'
2127
WITTI = 'witti'
2228
ALTONA = 'altona'
2329
MEDALLA = 'medalla'
2430
SPADINA = 'spadina'
31+
ZINKEN = 'zinken'
2532
ALL_CHAINS: Dict[str, BaseChainSetting] = {
2633
MAINNET: MainnetSetting,
2734
WITTI: WittiSetting,
2835
ALTONA: AltonaSetting,
2936
MEDALLA: MedallaSetting,
3037
SPADINA: SpadinaSetting,
38+
ZINKEN: ZinkenSetting,
3139
}
3240

3341

eth2deposit/utils/crypto.py

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def SHA256(x: bytes) -> bytes:
1919

2020

2121
def scrypt(*, password: str, salt: str, n: int, r: int, p: int, dklen: int) -> bytes:
22+
if n * r * p < 2**20: # 128 MB memory usage
23+
raise ValueError("The Scrypt parameters chosen are not secure.")
2224
if n >= 2**(128 * r / 8):
2325
raise ValueError("The given `n` should be less than `2**(128 * r / 8)`."
2426
f"\tGot `n={n}`, r={r}, 2**(128 * r / 8)={2**(128 * r / 8)}")
@@ -29,6 +31,14 @@ def scrypt(*, password: str, salt: str, n: int, r: int, p: int, dklen: int) -> b
2931
def PBKDF2(*, password: bytes, salt: bytes, dklen: int, c: int, prf: str) -> bytes:
3032
if 'sha' not in prf:
3133
raise ValueError(f"String 'sha' is not in `prf`({prf})")
34+
if 'sha256' in prf and c < 2**18:
35+
'''
36+
Verify the number of rounds of SHA256-PBKDF2. SHA512 not checked as use in BIP39
37+
does not require, and therefore doesn't use, safe parameters (c=2048).
38+
39+
Ref: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed
40+
'''
41+
raise ValueError("The PBKDF2 parameters chosen are not secure.")
3242
_hash = _sha256 if 'sha256' in prf else _sha512
3343
res = _PBKDF2(password=password, salt=salt, dkLen=dklen, count=c, hmac_hash_module=_hash) # type: ignore
3444
return res if isinstance(res, bytes) else res[0] # PyCryptodome can return Tuple[bytes]

requirements.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
py-ecc==4.0.0 \
2-
--hash=sha256:0712a1ebc2d45417088aa613f28518c1714c99d023998e50244c91e3acbb0d6c \
3-
--hash=sha256:a637edcce7e31ddefae0a3c1018f16e25c9428fcd524b1ac5ceeb2adfc433276
1+
py-ecc==5.0.0 \
2+
--hash=sha256:67a6b944722408c75bb630617dfbd8062c45b72d154ed3a6891c833717c87638 \
3+
--hash=sha256:9d3c7ba607ef36d7f8af9944d702799014b27fc77b385d14024f96f9f610ad0a
44
pycryptodome==3.9.8 \
55
--hash=sha256:02e51e1d5828d58f154896ddfd003e2e7584869c275e5acbe290443575370fba \
66
--hash=sha256:03d5cca8618620f45fd40f827423f82b86b3a202c8d44108601b0f5f56b04299 \

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="eth2deposit",
9-
version='0.3.0',
9+
version='0.4.0',
1010
py_modules=["eth2deposit"],
1111
packages=find_packages(exclude=('tests', 'docs')),
1212
python_requires=">=3.7,<4",

tests/test_key_handling/test_key_derivation/test_tree.py

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
test_vectors = json.load(f)['kdf_tests']
1818

1919

20-
@pytest.mark.skip(reason="py_ecc doesn't support BLS v4 yet")
2120
@pytest.mark.parametrize(
2221
'test',
2322
test_vectors
@@ -27,7 +26,6 @@ def test_hkdf_mod_r(test) -> None:
2726
assert bls.KeyGen(seed) == _HKDF_mod_r(IKM=seed)
2827

2928

30-
@pytest.mark.skip(reason="py_ecc doesn't support BLS v4 yet")
3129
@pytest.mark.parametrize(
3230
'seed',
3331
[b'\x00' * 32]

tests/test_utils/test_crypto.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
@pytest.mark.parametrize(
1111
'n, r, valid',
1212
[
13-
(int(2**(128 * 1 / 8)) // 2, 1, True),
14-
(int(2**(128 * 1 / 8)), 1, False),
13+
(int(2**(128 * 1 / 8)) * 2, 8, True),
14+
(int(2**(128 * 1 / 8)) * 1, 8, False), # Unsafe Parameters
15+
(int(2**(128 * 1 / 8)) * 1, 1, False), # Invalid n
1516
]
1617
)
17-
def test_scrypt_invalid_n(n, r, valid):
18+
def test_scrypt_invalid_params(n, r, valid):
1819
if valid:
1920
scrypt(
2021
password="mypassword",
@@ -63,6 +64,34 @@ def test_PBKDF2_invalid_prf(prf, valid):
6364
)
6465

6566

67+
@pytest.mark.parametrize(
68+
'count, prf, valid',
69+
[
70+
(2**18, "sha256", True),
71+
(2**17, "sha256", False),
72+
(2**11, "sha512", True),
73+
]
74+
)
75+
def test_PBKDF2_invalid_count(count, prf, valid):
76+
if valid:
77+
PBKDF2(
78+
password="mypassword",
79+
salt="mysalt",
80+
dklen=64,
81+
c=count,
82+
prf=prf
83+
)
84+
else:
85+
with pytest.raises(ValueError):
86+
PBKDF2(
87+
password="mypassword",
88+
salt="mysalt",
89+
dklen=64,
90+
c=2048,
91+
prf=prf,
92+
)
93+
94+
6695
@pytest.mark.parametrize(
6796
'key, iv, valid',
6897
[

0 commit comments

Comments
 (0)