Skip to content

Commit

Permalink
add signature checks in authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
gurukamath committed Sep 19, 2024
1 parent 47c5a6b commit 188c9aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
20 changes: 12 additions & 8 deletions src/ethereum/prague/vm/eoa_delegation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from ethereum import rlp
from ethereum.base_types import U64, U256, Bytes, Uint
from ethereum.crypto import InvalidSignature
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
from ethereum.crypto.hash import keccak256
from ethereum.exceptions import InvalidBlock
Expand All @@ -15,7 +16,6 @@
from ..state import account_exists, get_account, increment_nonce, set_code
from ..vm.gas import GAS_COLD_ACCOUNT_ACCESS, GAS_WARM_ACCESS
from . import Environment, Evm, Message
from .exceptions import InvalidAuthorization

SET_CODE_TX_MAGIC = b"\x05"
EOA_DELEGATION_MARKER = b"\xEF\x01\x00"
Expand Down Expand Up @@ -57,16 +57,23 @@ def recover_authority(authorization: Authorization) -> Address:
authorization
The authorization to recover the authority from.
Raises
------
InvalidSignature
If the signature is invalid.
Returns
-------
authority : `Address`
The recovered authority address.
"""
y_parity, r, s = authorization.y_parity, authorization.r, authorization.s
if y_parity not in (0, 1):
raise InvalidSignature("Invalid y_parity in authorization")
if 0 >= r or r >= SECP256K1N:
raise InvalidAuthorization
raise InvalidSignature("Invalid r value in authorization")
if 0 >= s or s > SECP256K1N // 2:
raise InvalidAuthorization
raise InvalidSignature("Invalid s value in authorization")

signing_hash = keccak256(
SET_CODE_TX_MAGIC
Expand All @@ -79,10 +86,7 @@ def recover_authority(authorization: Authorization) -> Address:
)
)

try:
public_key = secp256k1_recover(r, s, y_parity, signing_hash)
except Exception as e:
raise InvalidAuthorization from e
public_key = secp256k1_recover(r, s, y_parity, signing_hash)
return Address(keccak256(public_key)[12:32])


Expand Down Expand Up @@ -142,7 +146,7 @@ def set_delegation(message: Message, env: Environment) -> U256:

try:
authority = recover_authority(auth)
except InvalidAuthorization:
except InvalidSignature:
continue

message.accessed_addresses.add(authority)
Expand Down
8 changes: 0 additions & 8 deletions src/ethereum/prague/vm/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,3 @@ class KZGProofError(ExceptionalHalt):
"""

pass


class InvalidAuthorization(ExceptionalHalt):
"""
Raised when the authorization is invalid.
"""

pass

0 comments on commit 188c9aa

Please sign in to comment.