Skip to content

Commit

Permalink
Calculate SafeOperation preimage
Browse files Browse the repository at this point in the history
- It's needed for validating EIP1271 signatures
  • Loading branch information
Uxio0 committed Mar 8, 2024
1 parent 0b3bbf8 commit a04f96d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions gnosis/safe/account_abstraction/safe_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SafeOperation:
"0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218"
) # bytes32
safe_operation_hash: Optional[bytes] = None
safe_operation_hash_preimage: Optional[bytes] = None

@classmethod
def from_user_operation(cls, user_operation: UserOperation):
Expand Down Expand Up @@ -87,11 +88,11 @@ def get_domain_separator(
)
return _domain_separator_cache[key]

def get_safe_operation_hash(
def get_safe_operation_hash_preimage(
self, chain_id: int, module_address: ChecksumAddress
) -> bytes:
# Cache safe_operation_hash
if not self.safe_operation_hash:
if not self.safe_operation_hash_preimage:
encoded_safe_op_struct = abi_encode(
[
"bytes32",
Expand Down Expand Up @@ -126,7 +127,17 @@ def get_safe_operation_hash(
self.entry_point,
],
)
safe_op_struct_hash = fast_keccak(encoded_safe_op_struct)
self.safe_operation_hash_preimage = fast_keccak(encoded_safe_op_struct)
return self.safe_operation_hash_preimage

def get_safe_operation_hash(
self, chain_id: int, module_address: ChecksumAddress
) -> bytes:
# Cache safe_operation_hash
if not self.safe_operation_hash:
safe_op_struct_hash = self.get_safe_operation_hash_preimage(
chain_id, module_address
)
operation_data = encode_packed(
["bytes1", "bytes1", "bytes32", "bytes32"],
[
Expand Down

0 comments on commit a04f96d

Please sign in to comment.