Skip to content

Commit ac9f2d6

Browse files
committed
Fix 1271 signatures for delegates
1 parent 735a168 commit ac9f2d6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

safe_transaction_service/history/helpers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from eth_typing import ChecksumAddress, Hash32, HexStr
66
from eth_utils import keccak
7-
from safe_eth.eth.eip712 import eip712_encode_hash
7+
from safe_eth.eth.eip712 import eip712_encode, eip712_encode_hash
8+
from safe_eth.eth.utils import fast_keccak
89

910
from safe_transaction_service.history.models import TransferDict
1011
from safe_transaction_service.tokens.models import Token
@@ -81,19 +82,19 @@ def calculate_hash(
8182

8283
class DelegateSignatureHelperV2(TemporarySignatureHelper):
8384
@classmethod
84-
def calculate_hash(
85+
def calculate_hash_and_preimage(
8586
cls,
8687
delegate_address: ChecksumAddress,
8788
chain_id: Optional[int],
8889
previous_totp: bool = False,
89-
) -> Hash32:
90+
) -> tuple[Hash32, bytes]:
9091
"""
9192
Builds a EIP712 object and calculates its hash
9293
9394
:param delegate_address:
9495
:param chain_id:
9596
:param previous_totp:
96-
:return: Hash for the EIP712 generated object from the provided parameters
97+
:return: Hash for the EIP712 generated object from the provided parameters with the preimage
9798
"""
9899
totp = cls.calculate_totp(previous=previous_totp)
99100

@@ -125,7 +126,8 @@ def calculate_hash(
125126
)
126127
payload["domain"]["chainId"] = chain_id
127128

128-
return eip712_encode_hash(payload)
129+
preimage = b"".join(eip712_encode(payload))
130+
return fast_keccak(preimage), preimage
129131

130132

131133
def is_valid_unique_transfer_id(unique_transfer_id: str) -> bool:

safe_transaction_service/history/serializers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,14 @@ def validate_delegator_signature(
456456
for previous_totp, chain_id in list(
457457
itertools.product((True, False), (chain_id, None))
458458
):
459-
message_hash = DelegateSignatureHelperV2.calculate_hash(
460-
delegate, chain_id, previous_totp=previous_totp
459+
message_hash, preimage = (
460+
DelegateSignatureHelperV2.calculate_hash_and_preimage(
461+
delegate, chain_id, previous_totp=previous_totp
462+
)
463+
)
464+
safe_signatures = SafeSignature.parse_signature(
465+
signature, message_hash, safe_hash_preimage=preimage
461466
)
462-
safe_signatures = SafeSignature.parse_signature(signature, message_hash)
463467
if not safe_signatures:
464468
raise ValidationError("Signature is not valid")
465469

0 commit comments

Comments
 (0)