Skip to content

Instantly share code, notes, and snippets.

@itzmeanjan
Created July 27, 2021 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itzmeanjan/3ab624a4bb1dd77bd3eede66175b75ca to your computer and use it in GitHub Desktop.
Save itzmeanjan/3ab624a4bb1dd77bd3eede66175b75ca to your computer and use it in GitHub Desktop.
Missing Plasma Deposit Transactions Finder - An attempt to find reportedly missing Plasma State Syncs on Polygon
#!/usr/bin/python3
from requests import post
def find_missing_depositBlockIds():
url = 'https://mainnet.infura.io/v3/<project-id>'
from_ = 10_167_767
to_ = from_ + 1_000
stop_ = 12_908_120
with open('missing.csv', 'w') as fd:
while to_ < stop_:
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getLogs",
"params": [{
"address": "0x401F6c983eA34274ec46f84D70b31C151321188b",
"topics": ["0x1dadc8d0683c6f9824e885935c1bec6f76816730dcec148dda8cf25a7b9f797b"],
"fromBlock": hex(from_),
"toBlock": hex(to_)
}]}
print(f'querying in {from_} - {to_}')
from_ = to_
to_ = from_ + 1_000
resp = post(url, json=data)
if resp.status_code != 200:
print('non-200 received !')
continue
body = resp.json()
if 'result' not in body:
print('unexpected response !')
continue
missed = list(map(lambda e: (*e[:2], get_stateSyncId(*e[:2])),
filter(lambda e: not e[-1],
map(lambda e: (e[0], e[1], is_deposited(e[1])),
map(lambda e: (e['transactionHash'],
int(f'0x{e["data"][-64:]}', base=16)),
body['result'])))))
if missed:
print(f'{len(missed)} missed state sync(s) found !')
for (tx_hash, depositBlockId, stateSyncId) in missed:
fd.write(f'{tx_hash}; {depositBlockId}; {stateSyncId}\n')
def get_stateSyncId(tx_hash: str, depositBlockId: int) -> int:
url = 'https://mainnet.infura.io/v3/<project-id>'
state_sync_event = '0x103fed9db65eac19c4d870f49ab7520fe03b99f1838e5996caf47e9e43308392'
receiver_address = '0x000000000000000000000000d9c7c4ed4b66858301d0cb28cc88bf655fe34861'
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getTransactionReceipt",
"params": [tx_hash]
}
resp = post(url, json=data)
if resp.status_code != 200:
print('non-200 received !')
return None
body = resp.json()
if 'result' not in body:
print('unexpected response !')
return None
state_sync_id = list(map(lambda e: int(e['topics'][1], base=16),
filter(lambda e: e['topics'][0] == state_sync_event and e['topics'][-1] == receiver_address and e['data'].endswith(hex(depositBlockId)[2:]),
body['result']['logs'])))[0]
return state_sync_id
def is_deposited(deposit_id: int) -> bool:
url = 'https://polygon-mainnet.infura.io/v3/<project-id>'
method_id = '0xb02c43d0'
data = {
"jsonrpc": "2.0",
"id": 1,
"method": "eth_call",
"params": [{
"from": "0x63ec5767F54F6943750A70eB6117EA2D9Ca77313",
"to": "0xD9c7C4ED4B66858301D0cb28Cc88bf655Fe34861",
"data": f'{method_id}{hex(deposit_id)[2:].rjust(64, "0")}',
},
"latest"
]}
resp = post(url, json=data)
if resp.status_code != 200:
print('non-200 received !')
return False
body = resp.json()
if 'result' not in body:
print('unexpected response !')
return False
return body['result'] == '0x0000000000000000000000000000000000000000000000000000000000000001'
if __name__ == '__main__':
try:
find_missing_depositBlockIds()
except KeyboardInterrupt:
print('exiting !')
@itzmeanjan
Copy link
Author

What's it ?

This script attempts to find all Plasma State Syncs happened on Ethereum, from block 10_167_767 to block 12_908_120, which are reportedly missing on Polygon i.e. not played properly in Bor/ playing didn't result into expected state change.

This will produce one CSV file with all those transactions, along with respective Plasma depositBlockId & stateSyncId, which can be later explored for replaying missing Plasma state syncs.

How to use ?

  • Make sure you've python(>=3.7) installed
  • Replace placeholder RPC url(s) with appropriate URLs --- this is only where Polygon RPC is required
  • Run with
python3 missing_plasma_deposit_finder.py
  • After execution is completed, you should see missing.csv in PWD, which will have entries of missed Plasma state syncs --- if any
less missing.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment