-
-
Save banteg/68ad51b133d447aa4a165bea0c7b91a1 to your computer and use it in GitHub Desktop.
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
from eip712 import EIP712Message | |
from ape import Contract, accounts | |
from eth_account.messages import _hash_eip191_message | |
from ape.contracts.base import ContractCall | |
class SafeMessage(EIP712Message): | |
_chainId_ = 5 | |
_verifyingContract_ = "0xD079CE05Ea47d3438eEC7e8D20d48961AC3D20EC" | |
message: "bytes" | |
message = b"test" | |
msg = SafeMessage(message=message) | |
msg_hash = _hash_eip191_message(msg.signable_message) | |
safe = Contract("0xD079CE05Ea47d3438eEC7e8D20d48961AC3D20EC") | |
fallback = Contract("0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4") | |
assert msg.signable_message.header == safe.domainSeparator() | |
assert _hash_eip191_message(msg.signable_message) == bytes(fallback.getMessageHashForSafe(safe, message)) | |
signers = [accounts.load(dev) for dev in ["yfi", "goerli"]] | |
sorted_signers = sorted(signers, key=lambda x: int(x.address, 16)) | |
signatures = [dev.sign_message(msg.signable_message) for dev in sorted_signers] | |
encoded = b"".join(sig.encode_rsv() for sig in signatures) | |
# this should not revert | |
safe.checkSignatures(msg_hash, message, encoded) | |
# this should return the magic value | |
EIP1271_MAGIC_VALUE = bytes.fromhex('20c13b0b') | |
is_valid_signature = ContractCall(fallback.contract_type.view_methods["isValidSignature(bytes,bytes)"], str(safe)) | |
assert is_valid_signature(message, encoded) == EIP1271_MAGIC_VALUE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment