Skip to content

Commit bc328c8

Browse files
fix decompress_G2 and use one BLSSignature only
1 parent f2ea28e commit bc328c8

File tree

11 files changed

+33
-36
lines changed

11 files changed

+33
-36
lines changed

eth/_utils/bls.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636
from eth.beacon.typing import (
3737
BLSPubkey,
38-
BLSSignatureBytes,
39-
BLSSignatureIntegers,
38+
BLSSignature,
4039
)
4140

4241
G2_cofactor = 305502333931268344200999753193121504214466019254188142667664032982267604182971884026507427359259977847832272839041616661285803823378372096355777062779109 # noqa: E501
@@ -139,7 +138,7 @@ def compress_G2(pt: Tuple[FQP, FQP, FQP]) -> Tuple[int, int]:
139138
)
140139

141140

142-
def decompress_G2(p: bytes) -> Tuple[FQP, FQP, FQP]:
141+
def decompress_G2(p: Tuple[int, int]) -> Tuple[FQP, FQP, FQP]:
143142
x1 = p[0] % 2**383
144143
y1_mod_2 = p[0] // 2**383
145144
x2 = p[1]
@@ -161,8 +160,8 @@ def decompress_G2(p: bytes) -> Tuple[FQP, FQP, FQP]:
161160
#
162161
def sign(message: bytes,
163162
privkey: int,
164-
domain: int) -> BLSSignatureIntegers:
165-
return BLSSignatureIntegers(
163+
domain: int) -> BLSSignature:
164+
return BLSSignature(
166165
compress_G2(
167166
multiply(
168167
hash_to_G2(message, domain),
@@ -175,7 +174,7 @@ def privtopub(k: int) -> BLSPubkey:
175174
return BLSPubkey(compress_G1(multiply(G1, k)))
176175

177176

178-
def verify(message: bytes, pubkey: BLSPubkey, signature: BLSSignatureBytes, domain: int) -> bool:
177+
def verify(message: bytes, pubkey: BLSPubkey, signature: BLSSignature, domain: int) -> bool:
179178
try:
180179
final_exponentiation = final_exponentiate(
181180
pairing(
@@ -194,11 +193,11 @@ def verify(message: bytes, pubkey: BLSPubkey, signature: BLSSignatureBytes, doma
194193
return False
195194

196195

197-
def aggregate_signatures(signatures: Sequence[BLSSignatureBytes]) -> BLSSignatureIntegers:
196+
def aggregate_signatures(signatures: Sequence[BLSSignature]) -> BLSSignature:
198197
o = Z2
199198
for s in signatures:
200199
o = FQP_point_to_FQ2_point(add(o, decompress_G2(s)))
201-
return BLSSignatureIntegers(compress_G2(o))
200+
return BLSSignature(compress_G2(o))
202201

203202

204203
def aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
@@ -210,7 +209,7 @@ def aggregate_pubkeys(pubkeys: Sequence[BLSPubkey]) -> BLSPubkey:
210209

211210
def verify_multiple(pubkeys: Sequence[BLSPubkey],
212211
messages: Sequence[bytes],
213-
signature: BLSSignatureBytes,
212+
signature: BLSSignature,
214213
domain: int) -> bool:
215214
len_msgs = len(messages)
216215

eth/beacon/aggregation.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
from eth.beacon.enums import SignatureDomain
1414
from eth.beacon.typing import (
1515
BLSPubkey,
16-
BLSSignatureBytes,
17-
BLSSignatureIntegers,
16+
BLSSignature,
1817
Bitfield,
1918
CommitteeIndex,
2019
)
2120

2221

2322
def verify_votes(
2423
message: bytes,
25-
votes: Iterable[Tuple[CommitteeIndex, BLSSignatureBytes, BLSPubkey]],
24+
votes: Iterable[Tuple[CommitteeIndex, BLSSignature, BLSPubkey]],
2625
domain: SignatureDomain
27-
) -> Tuple[Tuple[BLSSignatureBytes, ...], Tuple[CommitteeIndex, ...]]:
26+
) -> Tuple[Tuple[BLSSignature, ...], Tuple[CommitteeIndex, ...]]:
2827
"""
2928
Verify the given votes.
3029
@@ -47,10 +46,10 @@ def verify_votes(
4746

4847
def aggregate_votes(
4948
bitfield: Bitfield,
50-
sigs: Iterable[BLSSignatureBytes],
51-
voting_sigs: Iterable[BLSSignatureBytes],
49+
sigs: Iterable[BLSSignature],
50+
voting_sigs: Iterable[BLSSignature],
5251
voting_committee_indices: Iterable[CommitteeIndex]
53-
) -> Tuple[Bitfield, BLSSignatureIntegers]:
52+
) -> Tuple[Bitfield, BLSSignature]:
5453
"""
5554
Aggregate the votes.
5655
"""

eth/beacon/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from eth.beacon.typing import BLSSignatureIntegers
1+
from eth.beacon.typing import BLSSignature
22

33
#
44
# shuffle function
@@ -13,4 +13,4 @@
1313
# The highest possible result of the RNG.
1414
RAND_MAX = 2 ** (RAND_BYTES * 8) - 1
1515

16-
EMPTY_SIGNATURE = BLSSignatureIntegers((0, 0))
16+
EMPTY_SIGNATURE = BLSSignature((0, 0))

eth/beacon/deposit_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from eth.beacon.typing import (
3131
SlotNumber,
3232
BLSPubkey,
33-
BLSSignatureBytes,
33+
BLSSignature,
3434
ValidatorIndex,
3535
Gwei,
3636
)
@@ -52,7 +52,7 @@ def get_min_empty_validator_index(validators: Sequence[ValidatorRecord],
5252

5353
def validate_proof_of_possession(state: BeaconState,
5454
pubkey: BLSPubkey,
55-
proof_of_possession: BLSSignatureBytes,
55+
proof_of_possession: BLSSignature,
5656
withdrawal_credentials: Hash32,
5757
randao_commitment: Hash32) -> None:
5858
deposit_input = DepositInput(
@@ -116,7 +116,7 @@ def process_deposit(*,
116116
state: BeaconState,
117117
pubkey: BLSPubkey,
118118
deposit: Gwei,
119-
proof_of_possession: BLSSignatureBytes,
119+
proof_of_possession: BLSSignature,
120120
withdrawal_credentials: Hash32,
121121
randao_commitment: Hash32,
122122
zero_balance_validator_ttl: int) -> Tuple[BeaconState, ValidatorIndex]:

eth/beacon/types/attestations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from eth.beacon.typing import (
1717
Bitfield,
18-
BLSSignatureIntegers,
18+
BLSSignature,
1919
)
2020
from eth.beacon.constants import EMPTY_SIGNATURE
2121

@@ -38,7 +38,7 @@ def __init__(self,
3838
data: AttestationData,
3939
participation_bitfield: Bitfield,
4040
custody_bitfield: Bitfield,
41-
aggregate_signature: BLSSignatureIntegers=EMPTY_SIGNATURE) -> None:
41+
aggregate_signature: BLSSignature=EMPTY_SIGNATURE) -> None:
4242
super().__init__(
4343
data,
4444
participation_bitfield,

eth/beacon/types/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from eth.beacon._utils.hash import hash_eth2
2525
from eth.beacon.typing import (
2626
SlotNumber,
27-
BLSSignatureIntegers,
27+
BLSSignature,
2828
)
2929

3030

@@ -84,7 +84,7 @@ def __init__(self,
8484
randao_reveal: Hash32,
8585
candidate_pow_receipt_root: Hash32,
8686
body: BeaconBlockBody,
87-
signature: BLSSignatureIntegers=EMPTY_SIGNATURE) -> None:
87+
signature: BLSSignature=EMPTY_SIGNATURE) -> None:
8888
super().__init__(
8989
slot,
9090
parent_root,

eth/beacon/types/deposit_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from eth.beacon._utils.hash import hash_eth2
1414
from eth.beacon.typing import (
1515
BLSPubkey,
16-
BLSSignatureIntegers,
16+
BLSSignature,
1717
)
1818
from eth.beacon.constants import EMPTY_SIGNATURE
1919

@@ -37,7 +37,7 @@ def __init__(self,
3737
pubkey: BLSPubkey,
3838
withdrawal_credentials: Hash32,
3939
randao_commitment: Hash32,
40-
proof_of_possession: BLSSignatureIntegers=EMPTY_SIGNATURE) -> None:
40+
proof_of_possession: BLSSignature=EMPTY_SIGNATURE) -> None:
4141
super().__init__(
4242
pubkey=pubkey,
4343
withdrawal_credentials=withdrawal_credentials,

eth/beacon/types/exits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)
1010
from eth.beacon.typing import (
1111
SlotNumber,
12-
BLSSignatureIntegers,
12+
BLSSignature,
1313
)
1414
from eth.beacon.constants import EMPTY_SIGNATURE
1515

@@ -30,7 +30,7 @@ class Exit(rlp.Serializable):
3030
def __init__(self,
3131
slot: SlotNumber,
3232
validator_index: ValidatorIndex,
33-
signature: BLSSignatureIntegers=EMPTY_SIGNATURE) -> None:
33+
signature: BLSSignature=EMPTY_SIGNATURE) -> None:
3434
super().__init__(
3535
slot,
3636
validator_index,

eth/beacon/types/proposer_slashings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99
from .proposal_signed_data import ProposalSignedData
1010
from eth.beacon.typing import (
11-
BLSSignatureIntegers,
11+
BLSSignature,
1212
)
1313
from eth.beacon.constants import EMPTY_SIGNATURE
1414

@@ -32,8 +32,8 @@ def __init__(self,
3232
proposal_data_1: ProposalSignedData,
3333
proposal_data_2: ProposalSignedData,
3434
# default arguments follow non-default arguments
35-
proposal_signature_1: BLSSignatureIntegers = EMPTY_SIGNATURE,
36-
proposal_signature_2: BLSSignatureIntegers = EMPTY_SIGNATURE) -> None:
35+
proposal_signature_1: BLSSignature = EMPTY_SIGNATURE,
36+
proposal_signature_2: BLSSignature = EMPTY_SIGNATURE) -> None:
3737
super().__init__(
3838
proposer_index=proposer_index,
3939
proposal_data_1=proposal_data_1,

eth/beacon/types/slashable_vote_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
uint384,
1616
)
1717
from eth.beacon.typing import (
18-
BLSSignatureIntegers,
18+
BLSSignature,
1919
ValidatorIndex,
2020
)
2121
from eth.beacon.constants import EMPTY_SIGNATURE
@@ -42,7 +42,7 @@ def __init__(self,
4242
aggregate_signature_poc_0_indices: Sequence[ValidatorIndex],
4343
aggregate_signature_poc_1_indices: Sequence[ValidatorIndex],
4444
data: AttestationData,
45-
aggregate_signature: BLSSignatureIntegers = EMPTY_SIGNATURE) -> None:
45+
aggregate_signature: BLSSignature = EMPTY_SIGNATURE) -> None:
4646
super().__init__(
4747
aggregate_signature_poc_0_indices,
4848
aggregate_signature_poc_1_indices,

0 commit comments

Comments
 (0)