11import enum
22import logging
33import time
4+ from typing import Self
45
56import requests
67from attrs import define
8+ from eth_account ._utils .signing import to_standard_v
9+ from eth_keys .datatypes import Signature as EthSignature
710from py_flare_common .fsp .epoch .epoch import RewardEpoch
811from py_flare_common .fsp .messaging import (
912 parse_generic_tx ,
1316)
1417from py_flare_common .fsp .messaging .byte_parser import ByteParser
1518from py_flare_common .fsp .messaging .types import ParsedPayload
19+ from py_flare_common .fsp .messaging .types import Signature as SSignature
1620from py_flare_common .ftso .commit import commit_hash
1721from web3 import AsyncWeb3
1822from web3 ._utils .events import get_event_data
4145LOGGER .info ("initialized" )
4246
4347
48+ class Signature (EthSignature ):
49+ @classmethod
50+ def from_vrs (cls , s : SSignature ) -> Self :
51+ return cls (
52+ vrs = (
53+ to_standard_v (int (s .v , 16 )),
54+ int (s .r , 16 ),
55+ int (s .s , 16 ),
56+ )
57+ )
58+
59+
4460def notify_discord (config : Configuration , message : str ) -> None :
4561 if config .discord_webhook is None :
4662 return
63+
4764 requests .post (
4865 config .discord_webhook ,
4966 headers = {"Content-Type" : "application/json" },
@@ -242,7 +259,7 @@ def validate_ftso(round: VotingRound, entity: Entity):
242259 issues .append (
243260 Issue (
244261 IssueLevel .INFO ,
245- f"no submit1 transaction for ftso in round { round . voting_epoch .id } " ,
262+ f"no submit1 transaction for ftso in round { epoch .id } " ,
246263 )
247264 )
248265
@@ -270,7 +287,7 @@ def validate_ftso(round: VotingRound, entity: Entity):
270287 IssueLevel .INFO ,
271288 (
272289 "submit 2 had 'None' value for feeds on indices "
273- f"{ ', ' .join (indices )} in round { round . voting_epoch .id } "
290+ f"{ ', ' .join (indices )} in round { epoch .id } "
274291 ),
275292 ),
276293 )
@@ -290,7 +307,7 @@ def validate_ftso(round: VotingRound, entity: Entity):
290307 IssueLevel .INFO ,
291308 (
292309 "commit hash and reveal didn't match in round "
293- f"{ round . voting_epoch .id } , causing reveal offence"
310+ f"{ epoch .id } , causing reveal offence"
294311 ),
295312 ),
296313 )
@@ -300,23 +317,34 @@ def validate_ftso(round: VotingRound, entity: Entity):
300317 Issue (
301318 # TODO:(matej) change level to warning
302319 IssueLevel .INFO ,
303- (
304- "no submit signatures transaction for ftso in round "
305- f"{ round .voting_epoch .id } "
306- ),
320+ ("no submit signatures transaction for ftso in round " f"{ epoch .id } " ),
307321 ),
308322 )
309323
310324 if finalization and ss :
311- # TODO:(matej) check for correct signature
312- ...
325+ s = Signature .from_vrs (submit_sig [0 ].payload .signature )
326+ addr = s .recover_public_key_from_msg_hash (
327+ finalization .to_message ()
328+ ).to_checksum_address ()
329+
330+ if addr != entity .signing_policy_address :
331+ issues .append (
332+ Issue (
333+ # TODO:(matej) change level to warning
334+ IssueLevel .INFO ,
335+ (
336+ "submit signatures signature doesn't match finalization for "
337+ f"ftso in round { epoch .id } "
338+ ),
339+ ),
340+ )
313341
314342 return issues
315343
316344
317345def validate_fdc (round : VotingRound , entity : Entity ):
318346 epoch = round .voting_epoch
319- fdc = round .ftso
347+ fdc = round .fdc
320348 finalization = fdc .finalization
321349
322350 _submit1 = fdc .submit_1 .by_identity .get (entity .identity_address , [])
@@ -379,16 +407,27 @@ def validate_fdc(round: VotingRound, entity: Entity):
379407 Issue (
380408 # TODO:(matej) change level to critical
381409 IssueLevel .INFO ,
382- (
383- "no submit signatures transaction for fdc in round "
384- f"{ round .voting_epoch .id } "
385- ),
410+ ("no submit signatures transaction for fdc in round " f"{ epoch .id } " ),
386411 ),
387412 )
388413
389414 if finalization and ss :
390- # TODO:(matej) check for correct signature
391- ...
415+ s = Signature .from_vrs (submit_sig [0 ].payload .signature )
416+ addr = s .recover_public_key_from_msg_hash (
417+ finalization .to_message ()
418+ ).to_checksum_address ()
419+
420+ if addr != entity .signing_policy_address :
421+ issues .append (
422+ Issue (
423+ # TODO:(matej) change level to warning
424+ IssueLevel .INFO ,
425+ (
426+ "submit signatures signature doesn't match finalization for "
427+ f"fdc in round { epoch .id } "
428+ ),
429+ ),
430+ )
392431
393432 return issues
394433
0 commit comments