Created
December 15, 2022 00:26
-
-
Save akerbabber/7628554d79209074a832d1ccf62544c8 to your computer and use it in GitHub Desktop.
Optimism bridge hack detector
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
#! /usr/local/bin/node | |
// Transfers between L1 and L2 using the Optimism SDK | |
const ethers = require("ethers"); | |
const optimismSDK = require("@eth-optimism/sdk"); | |
const axios = require("axios"); | |
require("dotenv").config(); | |
const l1BridgeAddress = "0x99c9fc46f92e8a1c0dec1b1747d010903e884be1"; | |
const erc20ABI = [ | |
// Read-Only Functions | |
"function balanceOf(address owner) view returns (uint256)", | |
"function decimals() view returns (uint8)", | |
"function symbol() view returns (string)", | |
"function totalSupply() view returns (uint256)", | |
// Authenticated Functions | |
"function transfer(address to, uint amount) returns (bool)", | |
// Events | |
"event Transfer(address indexed from, address indexed to, uint amount)", | |
]; | |
//crossChainMessenger = new optimismSDK.CrossChainMessenger({ | |
// l1ChainId: 1, // Mainnet value, 5 for goerli | |
// l2ChainId: 10, // Optimism mainnet value, 420 for optimism goerli | |
// l1SignerOrProvider: l1Signer, | |
// l2SignerOrProvider: l2Signer, | |
//}); | |
// | |
async function main() { | |
const l2RpcProvider = new ethers.providers.AlchemyWebSocketProvider( | |
"optimism", | |
"<api key here>" | |
); | |
const l1RpcProvider = new ethers.providers.AlchemyWebSocketProvider( | |
"mainnet", | |
"<api key here>" | |
); | |
async function getTokenList() { | |
const response = await axios.get( | |
"https://static.optimism.io/optimism.tokenlist.json" | |
); | |
return response; | |
} | |
let crossChainMessenger = new optimismSDK.CrossChainMessenger({ | |
l1ChainId: 1, | |
l2ChainId: 10, | |
l1SignerOrProvider: l1RpcProvider, | |
l2SignerOrProvider: l2RpcProvider, | |
}); | |
const res = await getTokenList(); | |
const tokenList = res.data.tokens; | |
let filteredList = []; | |
await Promise.all( | |
tokenList.map((token) => { | |
if ( | |
token.extensions.optimismBridgeAddress === | |
"0x4200000000000000000000000000000000000010" | |
) | |
filteredList.push(token); | |
}) | |
); | |
let l2BalanceList = []; | |
await Promise.all( | |
filteredList.map(async (token) => { | |
let l2ERC20 = new ethers.Contract(token.address, erc20ABI, l2RpcProvider); | |
try { | |
const l2Supply = await l2ERC20.totalSupply(); | |
const tokens = await axios.get( | |
`https://raw.githubusercontent.com/ethereum-optimism/ethereum-optimism.github.io/master/data/${token.symbol}/data.json` | |
); | |
console.log(tokens.data.tokens.ethereum); | |
let l1ERC20 = new ethers.Contract( | |
tokens.data.tokens.ethereum.address, | |
erc20ABI, | |
l1RpcProvider | |
); | |
let l1Supply = await l1ERC20.balanceOf(l1BridgeAddress); | |
l2BalanceList.push({ | |
...token, | |
l2TotalSupply: l2Supply.toString(), | |
l1TotalSupply: l1Supply.toString(), | |
...tokens.data.tokens, | |
}); | |
} catch (err) {} | |
}) | |
); | |
console.log(l2BalanceList); | |
//const receipt = await crossChainMessenger.getMessageStatus('0x6c80cae06b599e0a1ad217211609ce9d67d6c74b2c90ccc8d2457749ea6a307b'); | |
// console.log(receipt); | |
//process.exit(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment