Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add v2 carbon arb contract and relevant scripts #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions contracts/tokens/CarbonTokenArbiV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./CarbonWrappedERC20.sol";

/**
* @title CarbonTokenArbiV2 - Carbon Token for Arbitrum
*
* @dev Carbon Token (SWTH)
*/
contract CarbonTokenArbiV2 is CarbonWrappedERC20 {
constructor(
address lockProxyAddress,
address[] memory tokenOwners,
uint256[] memory balances
) CarbonWrappedERC20(lockProxyAddress, "Carbon Token", "SWTH") {
uint length = balances.length;
uint index = 0;

for (index; index < length; index++) {
_mint(tokenOwners[index], balances[index]);
}
}

/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 8;
}
}
121 changes: 121 additions & 0 deletions scripts/carbonarb/current-arbi-carbon-balances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"0x05d324055ba8c84d4812a27cc4fd895f573c542b": "113.43282151",
"0x07314f7ae386a4596bfcdbff0b95241d40e9fd37": "429.63007561",
"0x08a3c2a819e3de7aca384c798269b3ce1cd0e437": "4.16732068",
"0x0ad913e81cf3b84240c8151605fde036c52b415f": "0.07721755",
"0x0ba511b382ce9e88bdd60020f23314cd7360fd0d": "22.43881925",
"0x1111111254eeb25477b68fb85ed929f73a960582": "1E-08",
"0x11ddd59c33c73c44733b4123a86ea5ce57f6e854": "1E-08",
"0x1325c8791c61d05a1b1f86ef7ad7925cbde26b2a": "4.92323251",
"0x15640cc23697cfb99ee993ef295188d0ea22969f": "3.82090736",
"0x19e7a74e33bf64012ed3049bcf60365b72df6bdb": "100.92667356",
"0x1d3141bea7991a16461508061470edfd413def59": "6.27889982",
"0x1d8cfffca2b539a7ee4fa7201d70388e793cc938": "18.39220416",
"0x1dbbab2af76b53b8fe48fb5498c64f95d1c8740a": "24.43334761",
"0x1fd3595c20c68eacfba4c3623621eda0603f85b8": "814.76731548",
"0x1ff64f22d924c414de06163fd0183321ca6d4df3": "0.00339771",
"0x2271378dc66958b85adc24f9f488508e7c77c0b5": "22.75093628",
"0x282e622db0d55a66c4b707e64209c301d41d9a6e": "2770335.69962935",
"0x29a9a105d32ea1174d2c126899c091153a5db051": "12.4448261",
"0x2a06913d5b8748b222e1236768c24ca19198b374": "1",
"0x3021a59f56cae360183c40965d7059a4a73a7ba7": "226.75242826",
"0x392ff8adb20a658b86f29fb85bfa6d1d30ac74c3": "50000",
"0x3a16a04d75f24343ee97d8c9c4683e99209944e3": "6.77202056",
"0x3f928932d029f19b98beecc14aafcfe50b611b79": "4.37193628",
"0x41dca13a03276466d44556dcb474b44537c2b15e": "916.51836603",
"0x41fa13b82375b72f14cb8732399e560e4c1dcfca": "2.93698974",
"0x43ab31f8b1de4be98a81362d4ed91e1648daa4d9": "136.09282475",
"0x45122988df4e1e373e88103d1a39fec2ec5b529a": "4504.2549321",
"0x45463020eeb67dbc101fa65a7f9f4b219a0137f2": "466.37159892",
"0x4b9afd6e59dc95a37ab07aae49886052940acdc6": "0.55354395",
"0x4bf94e649b7b3d2226978072b8d10bcf7c71f53e": "4.04710492",
"0x4e264ee6080bfc6ec89bca450938b42f89e2ff98": "190.89432086",
"0x4f82e73edb06d29ff62c91ec8f5ff06571bdeb29": "25.26422744",
"0x4fdc543894b153baac3b3f5c00ddfa1f68a32d56": "3.17069531",
"0x53e7d7dda0ed4c7a6e225013592e41738c31c782": "7.7129665",
"0x57a2b9da9dabd12d2f12a2aa955a107ba3574513": "8.66961828",
"0x584e43c9206d24f1ebf2f7dea865449e1810a33d": "5.32346221",
"0x598a6e00c5a025e5224cf498ff58e531035c9600": "11.09619452",
"0x5d77ee528f0d7a0eac7c17f24d6893da7d0e78e9": "1.98324851",
"0x5d92b493fc65079db100f273c19fedd819a9b178": "9.14812649",
"0x60ddd915a32554f1d0ad4e91242b7831dc36a08d": "97.16161737",
"0x6252c0e32cab14351220ed50904fdbe0e29be77a": "440.47559653",
"0x64768a3a2453f1e8de9e43e92d65fc36e4c9872d": "1E-08",
"0x65535f6bddedbdb6c366f94a908b6f7387243439": "9.83742509",
"0x68a92de41fda62341a799a1b5e33ac57d82c4870": "0.51758161",
"0x6a8247bc77084acf32901f6a29369bc702d25769": "127.72862226",
"0x6b5a9291df9830ed381f6a630900be99201a3073": "25.11981004",
"0x6c7bac3060624ea5db06f022d9cbfe2cf83bc81b": "13.42371107",
"0x6fc27a66251811194dfd6c841592ae40cd50d9ae": "304.92707703",
"0x6fc5b92e99450a80e4e5232b0d8ccfd7da91791a": "530.25987981",
"0x720c9244473dfc596547c1f7b6261c7112a3dad4": "27.26993319",
"0x78b08d9674b3bd0e632159864ac0b98dac60416a": "20.14264736",
"0x7bb999cdebf647049df70ee346b64bafb097c614": "104.2319",
"0x7ca11e5e06f850fd6f80099b1768b680d7e3dad4": "210",
"0x7d831dd3a6f1553b9b995f499f4d31d4935b34f8": "653.77207431",
"0x80a3f7833d7ff96c093a013c8497d65c2ccbfdb1": "11306.12486291",
"0x83ad1590eda907d75e016a7b6830943d83013d8e": "17.46972609",
"0x84c58db5296e4c1ffbcf384099e75fcbd20d67f1": "1906.63103185",
"0x8942d85e2c87b9ff7476736e6ce2b50fa871f9e1": "7.14720255",
"0x89a5671105a4213d0ffae41e609076abdf724917": "10053.57091287",
"0x8ac6a283f4edc9ef4fb954c1b89224780184d7ec": "79.42456884",
"0x8af3daff710d8b1be4da4e899f1b9d11994ad98d": "735.14898404",
"0x8b071f8de7c9d331ca7146fad766779f024a0213": "5.80112035",
"0x8b0bf63fec4d2bf7602c9f05f0821d638b8945e1": "15.12060016",
"0x8b21e121af08e41b122ce3b5e4c6e8fe836e6db8": "4.36850968",
"0x8cbb1f6676b5c943e96a2e881af6681d719b9590": "33.70040371",
"0x8f95083565afebb7125d53f46c0dbea1e276e284": "213.59309775",
"0x94a17d35197c22e687c511e370e3618667e3c0d1": "12.36669668",
"0x94e9e6d04b58af02ff3a1c98991c79cd68a409d7": "13.65158767",
"0x966fcdae6da2f5ae8c1778b92575695523e04449": "10994.79095472",
"0x99513ad97b00075c30e367bf5d897fa23b6c9c4f": "0.14405503",
"0xa0446d8804611944f1b527ecd37d7dcbe442caba": "215.2858978",
"0xa1dadaaeb0b71bd66ded96be1af3f97d76b3fdd3": "16.10507193",
"0xa665a94de06acabbc4306e97a51df03c86ca37ce": "1E-08",
"0xa671018f5204f2a9c93c8d64b9046e295cf8dc8f": "3.89121523",
"0xa6bd3bf2a26a317bf572dacce198202bd02b0fbf": "10009.74099224",
"0xa960e92b8545fb621f97b19827fa4e31d02c7e08": "4.84592534",
"0xa9fac309ea02c09f5eb7137bbaaca80032dcea5b": "21870.62388378",
"0xaa318a86ebac3ad803568bf472e1fb67ce400563": "1.02999122",
"0xab930e565cad29ece7d143fc81ab876c68088fdd": "195.76074743",
"0xac30f95a72ddfe1e8957c4356b78b0732334da80": "1.5065594",
"0xaf80df4e690a8424bb5cce27f3b5fef2f5811d81": "5451.45843598",
"0xb01f8f528702d411d24c9bb8cc0e2fff779ec013": "0.29985203",
"0xb076558b404e95d4899f296a18e3fdad943e0046": "10987.50342433",
"0xb1e6f8820826491fcc5519f84ff4e2bdbb6e3cad": "8706269.57935636",
"0xb5f894047536c93d166e0a7fce05656b04718e66": "7.23482285",
"0xb60d3c620d67becc722bfe985323e3b95d0ab7cf": "21670.91300359",
"0xb7c1763bda0051f39373382274fa824abe7328ae": "271337.67919819",
"0xb9c6fe5cf462cb50b7372b2fee7e235107b1ebb7": "8.19123163",
"0xba4ed1be76587e000588fc3499707caf581e626b": "7127.53776717",
"0xba9646f96169260c56345512cec6e59ae207a8e7": "1.06769856",
"0xbad4262477565d4c3670370c2e077918918f5ee9": "502.66153677",
"0xbada249c8fc001501522f3a25fcec57a04d32a0a": "2.46005861",
"0xc120fee4140a9e82943d87d81b2dbafa728d8317": "4.9999998",
"0xc4fe4873ba6d4de21f51fbd844265348cf67f575": "8.42149202",
"0xc6a53d96f92be41b9a7ccd9daa5d52cb7a8fdb92": "373.07400212",
"0xc6de57bcf015c51ac0e0fe8a4e3ab09f481bec34": "253.90500386",
"0xc8d9b774f920382e9b69900c9506e7126d3ee899": "1.63403617",
"0xc9b826bad20872eb29f9b1d8af4befe8460b50c6": "12548658.6543851",
"0xcb129ac14f74e9bb2226bbcf1e339587558f469a": "404.87692203",
"0xcb5cb130b7c4e943fbacefb6ef5987107e261132": "1.61808236",
"0xcd3c26ecae98b7b28d1e0f8ceb166a8bf01e1f7e": "8.904E-05",
"0xce330f4c5862a6d32b621b3f7390bcaf2c5d55e8": "5.85910394",
"0xce3f30a20f3fca6873112537a8983f02e3985ae8": "3.47502541",
"0xd0faeb934d7e42d2a629a956feb48cc0d929d3ee": "220154.27307481",
"0xd1839a8b890ef288754d5e4cae15ea328e84ec0b": "7.3E-07",
"0xd1b47490209ccb7a806e8a45d9479490c040abf4": "1E-08",
"0xd75a7e2116415e7dce1dad9be8129fc0cdc7a718": "2.16850306",
"0xe222fbe074a436145b255442d919e4e3a6c6a480": "65.55790568",
"0xe605a93ff80545453fcff8c7b97a955c27778a4e": "2.71919078",
"0xeda2c4cc6ee963388539001b64d23db7fb814e83": "0.00289489",
"0xee7300cb9ac02c50ffaebbc7be85d38e9dd63a08": "30.16020604",
"0xeeaca69f8119e338f77877d37c712230f123617c": "3.41404193",
"0xf081470f5c6fbccf48cc4e5b82dd926409dcdd67": "1E-08",
"0xf2efc7b78168abc6a5be99e5624c64f2499d91fc": "15605.96508674",
"0xf556f51b242fe21e0420414e6dcbaa48c4a2ed66": "0.20153057",
"0xf990660ae5e23099778a84f9fc77c00801cad2e3": "6.75680064",
"0xfc5ba534f035de9edf6e35a185f5b6b4607008f0": "940.83307536",
"0xfca569f77e96696dc919a763bedef6bad9bd2cd7": "56486.83503223",
"0xfd24b7e4ae91720290bafbc6df75d89ce1032c3b": "3.26991549"
}
113 changes: 113 additions & 0 deletions scripts/carbonarb/kyber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { BigNumber } from 'bignumber.js';
import { ethers } from 'ethers'
import fs from 'fs'

// exploit block 153082115

const startBlock = 50507900;
const exploitBlock = 153082115;
const endBlock = exploitBlock - 1;
const range = 1000000;

const bytes32Prefix = /^0x[0]{24}/;

(async () => {
const filepath = "./scripts/carbonarb/transfers.txt";
if (fs.existsSync(filepath)) fs.rmSync(filepath);
const stream = fs.createWriteStream(filepath);

const balances: { [hash: string]: BigNumber } = {}
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"

console.log("https://arb1.arbitrum.io/rpc")
const provider = new ethers.providers.JsonRpcBatchProvider("https://arb1.arbitrum.io/rpc");
const contractAbi = [{"inputs":[{"internalType":"address","name":"lockProxyAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnLocked","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"circulatingSupply","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lockProxyAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]; // Insert your contract ABI here
const contract = new ethers.Contract("0xF763fa322Dc58dEe588252fAFee5f448e863b633", contractAbi, provider);
const transferEventFilter = contract.filters.Transfer();

let exit = false;
let block = startBlock;
while (true) {
const toBlock = Math.min(block + range, endBlock)
console.log("block", block + 1, toBlock);
const transfers = await contract.queryFilter(transferEventFilter, block + 1, toBlock);

transfers.forEach(t => {
const b: number = t.blockNumber;
const from = t.topics[1].replace(bytes32Prefix, "0x")
const to = t.topics[2].replace(bytes32Prefix, "0x")
const amount = new BigNumber(ethers.BigNumber.from(t.data).toString()).toString(10);
stream.write(`${b.toString().padStart(9)} ${t.transactionHash} ${from} ${to} ${amount}\n`)

if (from != ZERO_ADDRESS) {
const currentBalance = balances[from] ?? new BigNumber(0)
const newBalance = currentBalance.minus(amount)
balances[from] = newBalance
}

if (to != ZERO_ADDRESS) {
const currentBalance = balances[to] ?? new BigNumber(0)
const newBalance = currentBalance.plus(amount)
balances[to] = newBalance
}

// console.log(t.blockNumber, t.transactionHash, from, to, amount)
});

block += range;

if (block + range >= endBlock) {
if (exit) break;
exit = true;
}
}

const balancesArray = Object.entries(balances)
const filteredBalances : { [hash: string]: BigNumber } = {}
let count = 0
for (const entry of balancesArray) {
const address = entry[0]
const balance = entry[1]
if (balance.isGreaterThan(new BigNumber(0))) {
count++
filteredBalances[address] = balance
}
}

// const currentBalancesArray = Object.entries(currentBalances)

// for (const entry of currentBalancesArray) {
// const address = entry[0]
// const balance = new BigNumber(entry[1])

// if (!filteredBalances[address]) {
// console.log(`MISSING ADDRESS: ${address} of BALANCES: ${balance}\n`)
// continue
// }

// if (!balance.isEqualTo(filteredBalances[address])) {
// console.log(`CURRENT BALANCE AND PRE EXPLOIT BALANCE DIFFERS FOR ADDRESS ${address}:
// PRE EXPLOIT: ${filteredBalances[address]}
// CURRENT: ${balance}
// \n`)
// }
// }

const filteredBalancesArray = Object.entries(filteredBalances)
const tokenOwnersArray: string[] = []
const finalBalancesArray: Number[] = []

for (const entry of filteredBalancesArray) {
const address = entry[0]
const balance = entry[1].toNumber()

tokenOwnersArray.push(address)
finalBalancesArray.push(balance)
}

fs.writeFileSync("./scripts/carbonarb/pre-kyber-exploit-carbon-arb-owners.json", JSON.stringify(tokenOwnersArray), 'utf8')

fs.writeFileSync("./scripts/carbonarb/pre-kyber-exploit-carbon-arb-balances.json", JSON.stringify(finalBalancesArray), 'utf8')

stream.close();
})().catch(console.error).finally(() => process.exit(0));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[870626957935636,499999980,7942456884,3016020604,21000000000,65377207431,25390500386,27133767919819,2443334761,1,37307400212,19576074743,1,19089432086,190663103185,94083307536,1098750342433,42963007561,44047559653,21528589780,2726993319,416732068,3370040371,1130612486291,450425493210,5000000000000,100000000,163403617,22675242826,277033569962935,11343282151,9716161737,50266153677,712753776717,492323251,437193628,382090736,326991549,271919078,216850306,161808236,106769856,51758161,30492707703,2526422744,20153057,289489,1099479095472,13609282475,2275093628,1610507193,1109619452,585910394,14405503,1839220416,1342371107,842149202,317069531,677202056,2511981004,2014264736,1512060016,983742509,404710492,2243881925,1746972609,1244482610,714720255,1365158767,2167091300359,914812649,866961828,819123163,771296650,723482285,675680064,627889982,580112035,532346221,484592534,436850968,389121523,341404193,293698974,246005861,198324851,150655940,102999122,55354395,7721755,21359309775,1000974099224,10092667356,46637159892,12772862226,73,1254925447217063,10423198904,29985203,1005357091287,73514898404,1,81476731548,2187062388378,1,40487692203,91651836603,5648683503223,1236669668,1,1560596508674,347502541,1,22015427307481,545145843598,339771]
Loading