Last active
June 17, 2022 14:59
-
-
Save astrovm/8daa65261426dab9879a180c3d1bf29b to your computer and use it in GitHub Desktop.
calculate wintermute's multisig nonce
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 eth_utils import to_canonical_address, to_checksum_address | |
from eth._utils.address import generate_contract_address | |
factory = '0x76E2cFc1F5Fa8F6a5b3fC4c8F4788F0116861F9B' # gnosis safe factory | |
target = '0x4f3a120E72C76c22ae802D129F599BFDbc31cb81' # wintermute's multisig | |
nonce = 0 | |
while True: | |
safe = generate_contract_address(to_canonical_address(factory), nonce) | |
safe_address = to_checksum_address(safe) | |
print(nonce, safe, safe_address) | |
if safe_address == target: | |
print('found!') | |
break | |
nonce += 1 |
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 sys import exit | |
from eth_utils import to_canonical_address, to_checksum_address | |
from eth._utils.address import generate_contract_address | |
from concurrent.futures import as_completed, ThreadPoolExecutor | |
# gnosis safe factory deployer | |
deployer = '0x1aa7451DD11b8cb16AC089ED7fE05eFa00100A6A' | |
# wintermute's multisig | |
target = '0x4f3a120E72C76c22ae802D129F599BFDbc31cb81' | |
max_workers = 12 | |
factory_start_nonce = 0 | |
factory_max_nonce = 10000 | |
multisig_start_nonce = 0 | |
multisig_max_nonce = 10000 | |
executor = ThreadPoolExecutor(max_workers=max_workers) | |
searches = [] | |
def gen_contract(deployer, nonce): | |
contract = generate_contract_address(to_canonical_address(deployer), nonce) | |
contract_address = to_checksum_address(contract) | |
return contract_address | |
found = False | |
def find_nonce(deployer_nonce, factory, target, start_nonce, max_nonce): | |
for nonce in range(start_nonce, max_nonce): | |
if found == True: | |
return False | |
safe = gen_contract(factory, nonce) | |
if safe == target: | |
print( | |
f"""found in nonce {nonce} at factory {factory} (deployer nonce {deployer_nonce})""") | |
return True | |
nonce += 1 | |
return False | |
for nonce in range(factory_start_nonce, factory_max_nonce): | |
factory = gen_contract(deployer, nonce) | |
searches.append(executor.submit(find_nonce, nonce, factory, target, | |
multisig_start_nonce, multisig_max_nonce)) | |
for search in as_completed(searches): | |
if search.result() == True: | |
found = True | |
executor.shutdown(cancel_futures=True) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment