-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CERT 8125 Support Multisig Address Check (#83)
* CERT 8125 Support Multisig Address Check * Fix hashable multisig data * Add multisig check test for regression * Address Yoav CR * Update lock to mitigate the https://github.com/Certora/Quorum/security/dependabot/1 Vulnerable
- Loading branch information
1 parent
7ddc23d
commit eb535a3
Showing
6 changed files
with
878 additions
and
654 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
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,49 @@ | ||
import requests | ||
from pydantic import BaseModel | ||
|
||
from quorum.utils.singleton import singleton | ||
|
||
|
||
class MultisigData(BaseModel): | ||
""" | ||
MultisigData is a Pydantic model for Safe Multisig data. | ||
""" | ||
|
||
class Config: | ||
frozen = True | ||
|
||
address: str | ||
owners: list[str] | ||
threshold: int | ||
|
||
def __hash__(self) -> int: | ||
return hash((self.address, tuple(self.owners), self.threshold)) | ||
|
||
|
||
@singleton | ||
class SafeAPI: | ||
""" | ||
SafeAPI is a class designed to interact with the Safe Multisig API. | ||
It fetches and stores data for various Safe Multisig contracts. | ||
""" | ||
|
||
SAFE_API_URL = "https://safe-transaction-mainnet.safe.global/api/v1/safes" | ||
|
||
def __init__(self): | ||
self.session = requests.Session() | ||
|
||
def get_multisig_info(self, address: str) -> MultisigData | None: | ||
""" | ||
Get Safe Multisig data for a given address. | ||
Args: | ||
address (str): The contract address of the Safe Multisig. | ||
Returns: | ||
MultisigData: The Safe Multisig data for the specified address, or None if not found. | ||
""" | ||
response = self.session.get(f"{self.SAFE_API_URL}/{address}") | ||
if not response.ok: | ||
return None | ||
data = response.json() | ||
return MultisigData(**data) |
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,21 @@ | ||
from quorum.apis.multisig.safe_api import SafeAPI | ||
|
||
|
||
def test_safe_api(): | ||
api = SafeAPI() | ||
multisig = api.get_multisig_info("0xA1c93D2687f7014Aaf588c764E3Ce80aF016229b") | ||
assert multisig.owners == [ | ||
"0x320A4e54e3641A7a9dAF47016a93CDe6F848A340", | ||
"0xb647055A9915bF9c8021a684E175A353525b9890", | ||
"0x6efa225841090Fb54d7bCE4593c700C0f24C4be8", | ||
"0x329c54289Ff5D6B7b7daE13592C6B1EDA1543eD4", | ||
"0x009d13E9bEC94Bf16791098CE4E5C168D27A9f07", | ||
] | ||
assert multisig.threshold == 3 | ||
assert multisig.address == "0xA1c93D2687f7014Aaf588c764E3Ce80aF016229b" | ||
|
||
|
||
def test_non_multisig(): | ||
api = SafeAPI() | ||
non_multisig = api.get_multisig_info("0x0000000000000000000000000000000000000000") | ||
assert non_multisig is None |