Skip to content

Commit c5cff06

Browse files
Added vulture (#422)
* Add vulture * Excluded tests from coverage
1 parent 4476df8 commit c5cff06

File tree

8 files changed

+72
-92
lines changed

8 files changed

+72
-92
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ repos:
8282
files: no-files
8383
args: ["lock", "--check"]
8484
always_run: true
85+
86+
- repo: https://github.com/jendrikseipp/vulture
87+
rev: 'v2.13'
88+
hooks:
89+
- id: vulture
90+
args: ["src/"]
91+
files: no-files
92+
always_run: true

poetry.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,20 @@ exclude = '''
112112
'''
113113

114114
[tool.coverage.report]
115-
fail_under = 70
115+
omit = ["*/tests/*"]
116+
fail_under = 66
116117

117118
[tool.pytest.ini_options]
118119
asyncio_mode = "auto"
120+
121+
[tool.vulture]
122+
exclude = ["*/test*", "conftest.py", "networks.py"]
123+
ignore_names = [
124+
"default_account", # execution client
125+
"_async_session_pool", # credentials.py
126+
"eth_typing_metadata", "ssz_metadata", # pyinstaller
127+
"DATA_DIR", # settings
128+
"contract_event", "get_from_block", "process_events", # event processor
129+
"validators_root", # ApprovalRequest
130+
"previous_version", "current_version", "genesis_validators_root", "fork_info", "voluntary_exit" # remote.py
131+
]

src/common/contracts.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,6 @@ async def get_exit_signatures_updated_event(
245245

246246
return last_event
247247

248-
async def get_rewards_min_oracles(self) -> int:
249-
"""Fetches the last oracles config updated event."""
250-
return await self.contract.functions.rewardsMinOracles().call()
251-
252-
async def get_validators_min_oracles(self) -> int:
253-
"""Fetches the last oracles config updated event."""
254-
return await self.contract.functions.validatorsMinOracles().call()
255-
256248
async def can_harvest(self, vault_address: ChecksumAddress) -> bool:
257249
return await self.contract.functions.canHarvest(vault_address).call()
258250

@@ -261,10 +253,6 @@ class DepositDataRegistryContract(ContractWrapper):
261253
abi_path = 'abi/IDepositDataRegistry.json'
262254
settings_key = 'DEPOSIT_DATA_REGISTRY_CONTRACT_ADDRESS'
263255

264-
async def get_deposit_data_manager(self) -> ChecksumAddress:
265-
"""Fetches the vault deposit data manager address."""
266-
return await self.contract.functions.getDepositDataManager(settings.vault).call()
267-
268256
async def get_validators_root(self) -> Bytes32:
269257
"""Fetches vault's validators root."""
270258
return await self.contract.functions.depositDataRoots(settings.vault).call()

src/validators/signing/key_shares.py

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,13 @@
1313
from py_ecc.optimized_bls12_381.optimized_curve import (
1414
G1 as P1, # don't confuse group name (G1) with primitive element name (P1)
1515
)
16-
from py_ecc.optimized_bls12_381.optimized_curve import (
17-
Z1,
18-
Z2,
19-
add,
20-
curve_order,
21-
multiply,
22-
)
16+
from py_ecc.optimized_bls12_381.optimized_curve import add, curve_order, multiply
2317
from py_ecc.typing import Optimized_Field, Optimized_Point3D
24-
from py_ecc.utils import prime_field_inv
25-
26-
from src.validators.typings import BLSPrivkey
2718

2819
# element of G1 or G2
2920
G12: TypeAlias = Optimized_Point3D[Optimized_Field]
3021

3122

32-
def get_polynomial_points(coefficients: list[int], num_points: int) -> list[int]:
33-
"""Calculates polynomial points."""
34-
points = []
35-
for x in range(1, num_points + 1):
36-
# start with x=1 and calculate the value of y
37-
y = coefficients[0]
38-
# calculate each term and add it to y, using modular math
39-
for i in range(1, len(coefficients)):
40-
exponentiation = (x**i) % curve_order
41-
term = (coefficients[i] * exponentiation) % curve_order
42-
y = (y + term) % curve_order
43-
# add the point to the list of points
44-
points.append(y)
45-
return points
46-
47-
4823
def get_G12_polynomial_points(coefficients: list, num_points: int) -> list:
4924
"""Calculates polynomial points in G1 or G2."""
5025
points = []
@@ -62,21 +37,6 @@ def get_G12_polynomial_points(coefficients: list, num_points: int) -> list:
6237
return points
6338

6439

65-
def private_key_to_private_key_shares(
66-
private_key: BLSPrivkey,
67-
threshold: int,
68-
total: int,
69-
) -> list[BLSPrivkey]:
70-
coefficients: list[int] = [int.from_bytes(private_key, 'big')]
71-
72-
for _ in range(threshold - 1):
73-
coefficients.append(secrets.randbelow(curve_order))
74-
75-
points = get_polynomial_points(coefficients, total)
76-
77-
return [BLSPrivkey(p.to_bytes(32, 'big')) for p in points]
78-
79-
8040
def bls_signature_to_shares(
8141
bls_signature: BLSSignature,
8242
coefficients_G2: list[G12],
@@ -121,31 +81,3 @@ def bls_signature_and_public_key_to_shares(
12181
public_key_shards = bls_public_key_to_shares(public_key, coefficients_G1, total)
12282

12383
return bls_signature_shards, public_key_shards
124-
125-
126-
def reconstruct_shared_bls_signature(signatures: dict[int, BLSSignature]) -> BLSSignature:
127-
"""
128-
Reconstructs shared BLS private key signature.
129-
Copied from https://github.com/dankrad/python-ibft/blob/master/bls_threshold.py
130-
"""
131-
r = Z2
132-
for i, sig in signatures.items():
133-
sig_point = signature_to_G2(sig)
134-
coef = 1
135-
for j in signatures:
136-
if j != i:
137-
coef = -coef * (j + 1) * prime_field_inv(i - j, curve_order) % curve_order
138-
r = add(r, multiply(sig_point, coef))
139-
return G2_to_signature(r)
140-
141-
142-
def get_aggregate_key(keyshares: dict[int, BLSPubkey]) -> BLSPubkey:
143-
r = Z1
144-
for i, key in keyshares.items():
145-
key_point = pubkey_to_G1(key)
146-
coef = 1
147-
for j in keyshares:
148-
if j != i:
149-
coef = -coef * (j + 1) * prime_field_inv(i - j, curve_order) % curve_order
150-
r = add(r, multiply(key_point, coef))
151-
return G1_to_pubkey(r)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from eth_typing import BLSPubkey, BLSSignature
2+
from py_ecc.bls.g2_primitives import (
3+
G1_to_pubkey,
4+
G2_to_signature,
5+
pubkey_to_G1,
6+
signature_to_G2,
7+
)
8+
from py_ecc.optimized_bls12_381 import Z1, Z2, add, curve_order, multiply
9+
from py_ecc.utils import prime_field_inv
10+
11+
12+
def reconstruct_shared_bls_signature(signatures: dict[int, BLSSignature]) -> BLSSignature:
13+
"""
14+
Reconstructs shared BLS private key signature.
15+
Copied from https://github.com/dankrad/python-ibft/blob/master/bls_threshold.py
16+
"""
17+
r = Z2
18+
for i, sig in signatures.items():
19+
sig_point = signature_to_G2(sig)
20+
coef = 1
21+
for j in signatures:
22+
if j != i:
23+
coef = -coef * (j + 1) * prime_field_inv(i - j, curve_order) % curve_order
24+
r = add(r, multiply(sig_point, coef))
25+
return G2_to_signature(r)
26+
27+
28+
def get_aggregate_key(keyshares: dict[int, BLSPubkey]) -> BLSPubkey:
29+
r = Z1
30+
for i, key in keyshares.items():
31+
key_point = pubkey_to_G1(key)
32+
coef = 1
33+
for j in keyshares:
34+
if j != i:
35+
coef = -coef * (j + 1) * prime_field_inv(i - j, curve_order) % curve_order
36+
r = add(r, multiply(key_point, coef))
37+
return G1_to_pubkey(r)

src/validators/signing/tests/oracle_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from web3 import Web3
99

1010
from src.config.settings import settings
11-
from src.validators.signing.key_shares import (
11+
from src.validators.signing.tests.key_shares import (
1212
get_aggregate_key,
1313
reconstruct_shared_bls_signature,
1414
)

src/validators/typings.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from eth_typing import BlockNumber, BLSSignature, ChecksumAddress, HexStr
66
from multiproof import MultiProof, StandardMerkleTree
7-
from sw_utils.typings import Bytes32
87

98
BLSPrivkey = NewType('BLSPrivkey', bytes)
109

@@ -74,14 +73,6 @@ class ApprovalRequest:
7473
validators_manager_signature: HexStr | None = None
7574

7675

77-
@dataclass
78-
class KeeperApprovalParams:
79-
validatorsRegistryRoot: HexStr | Bytes32
80-
validators: HexStr | bytes
81-
signatures: HexStr | bytes
82-
exitSignaturesIpfsHash: str
83-
84-
8576
class ValidatorsRegistrationMode(Enum):
8677
"""
8778
AUTO mode: validators are registered automatically when vault assets are enough.

0 commit comments

Comments
 (0)