-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Added EVMVerifier class that is used on all EVM chains. Also add…
…ed that chains to the SignatureVerifier as EVM chains.
- Loading branch information
Showing
4 changed files
with
70 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import functools | ||
import logging | ||
|
||
from eth_account import Account | ||
from eth_account.messages import encode_defunct | ||
|
||
from aleph.chains.common import get_verification_buffer | ||
from aleph.schemas.pending_messages import BasePendingMessage | ||
from aleph.utils import run_in_executor | ||
|
||
from .abc import Verifier | ||
|
||
LOGGER = logging.getLogger("chains.evm") | ||
CHAIN_NAME = "ETH" | ||
|
||
|
||
class EVMVerifier(Verifier): | ||
async def verify_signature(self, message: BasePendingMessage) -> bool: | ||
"""Verifies a signature of a message, return True if verified, false if not""" | ||
|
||
verification = get_verification_buffer(message) | ||
|
||
message_hash = await run_in_executor( | ||
None, functools.partial(encode_defunct, text=verification.decode("utf-8")) | ||
) | ||
|
||
verified = False | ||
try: | ||
# we assume the signature is a valid string | ||
address = await run_in_executor( | ||
None, | ||
functools.partial( | ||
Account.recover_message, message_hash, signature=message.signature | ||
), | ||
) | ||
if address == message.sender: | ||
verified = True | ||
else: | ||
LOGGER.warning( | ||
"Received bad signature from %s for %s" % (address, message.sender) | ||
) | ||
return False | ||
|
||
except Exception: | ||
LOGGER.exception("Error processing signature for %s" % message.sender) | ||
verified = False | ||
|
||
return verified |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters