Created
August 26, 2024 10:02
-
-
Save sgc-code/0e461f9638ca3f530e3929af15c2013d to your computer and use it in GitHub Desktop.
Find Undeployed Account
This file contains hidden or 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
import { hash, CallData, RawArgs, CairoOption, CairoOptionVariant, CairoCustomEnum } from "starknet"; | |
import { exit } from "process"; | |
// Fill this two values to find the implementation details. Assumes there's no guardian | |
const addressToFind = BigInt("0x000000000"); | |
const ownerPubKey = "0x0000000"; | |
///////////////////////////////////////////////////////////////////////////// | |
// They delegate to a classhash | |
const CAIRO_0_NEW_PROXIES = [ | |
"0x03530cc4759d78042f1b543bf797f5f3d647cde0388c33734cf91b7f7b9314a9", // v0.2.3.1 and // v0.2.3 | |
"0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918", // v0.2.2 | |
] | |
// They delegate to an implementation contract | |
const CAIRO_0_OLD_PROXIES = [ | |
"0x08f1dae4382de84c1ab18cc73d38578f3ef70b2174ac9a54a1c4ae165ea668c", // v0.2.1 | |
// example account 0x058b8fe506303315adb0bf63ffcaf6f21a6bbf77c6e554ee1d2bc11d9304e14a | |
"0x071c3c99f5cf76fc19945d4b8b7d34c7c5528f22730d56192b50c6bbfd338a64" // v0.2.0 | |
] | |
// Used by Cairo 0 New proxies | |
const CAIRO_0_CLASSHASHES = [ | |
// | |
"0x033434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2",// v0.2.3.1 | |
"0x1a7820094feaf82d53f53f214b81292d717e7bb9a92bb2488092cd306f3993f", // v0.2.3 | |
"0x3e327de1c40540b98d05cbcb13552008e36f0ec8d61d46956d2f9752c294328", // v0.2.2 | |
//-- plugin accounts | |
"0x036360b6dc469deb485cf633371b3e8a0a1497dd7f816337d1bd6decd6411296", // v0.2.3.1 (plugin account) | |
"0x0ebe4b44d154bc07eacad202ee19757cdc73e7d4c672bc20d9031450c6db3ad", // v0.2.3 (plugin account) | |
//-- work with 0.2.0 and 0.2.1 proxies, but keeping here just in case | |
"0x06a1776964b9f991c710bfe910b8b37578b32b26a7dffd1669a1a59ac94bf82f", // v0.2.1 | |
"0x06a1776964b9f991c710bfe910b8b37578b32b26a7dffd1669a1a59ac94bf82f", // v0.2.0 | |
]; | |
// v0.1.0 (no proxy) | |
const CAIRO_0_V0_1_0_CLASSHASH = "0x02c3348ad109f7f3967df6494b3c48741d61675d9a7915b265aa7101a631dc33"; | |
// Used by Cairo 0 Old proxies | |
// TODO could be wrong, we should check what was used by AX | |
const CAIRO_0_IMPL_ADDRESS = [ | |
"0x1bd7ca87f139693e6681be2042194cf631c4e8d77027bf0ea9e6d55fc6018ac", // v0.2.1 | |
"0x5f28c66afd8a6799ddbe1933bce2c144625031aafa881fa38fa830790eff204" // v0.2.0 | |
]; | |
const CAIRO_1_HASHES_WITHOUT_SIGNER_TYPES = [ | |
"0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003", // v0.3.0 | |
"0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b", // v0.3.1 | |
"0x7f8ac221236add990375a03a03cb30f758535a1dcebe78692ee16ef265ebc14", // 0.3.1 with 5 min escape (sepolia) | |
"0x45bb3b296122454fb31d45c48da6143df12bcf58311dcd75193df42d79f8dd2", // 0.3.0-rc2 (goerli-1, goerli-2) | |
"0x5ff858f178257126353d03db2e50410c7cb399d9fc68b67ffe127d9b8b2a33c", // 0.3.0-rc2 tweaked with version 0.3.99 (goerli-1, goerli-2) | |
]; | |
const CAIRO_1_HASHES_AFTER_SIGNER_TYPES = [ | |
"0x036078334509b514626504edc9fb252328d1a240e4e948bef8d0c08dff45927f", // v0.4.0 | |
]; | |
const checkDeployParams = (deployPayload: { addressSalt: string, classHash: string, constructorCalldata: RawArgs, implementationName: string },) => { | |
const calculatedAddress = hash.calculateContractAddressFromHash( | |
deployPayload.addressSalt, | |
deployPayload.classHash, | |
deployPayload.constructorCalldata, | |
0 // deployer address | |
); | |
if (BigInt(calculatedAddress) === addressToFind) { | |
console.log(`Found address: ${calculatedAddress}, implementation: ${deployPayload.implementationName}`); | |
exit(0); | |
} | |
}; | |
console.log(`Trying v0.1.0`); | |
checkDeployParams({ | |
classHash: CAIRO_0_V0_1_0_CLASSHASH, | |
constructorCalldata: CallData.compile({ owner: ownerPubKey, guardian: 0 }), | |
addressSalt: ownerPubKey, // TODO this is wrong, salt was not the owner pubkey back then, for instance tx 0x0427df38a863d7de1223095b91546bb3bbb593a579dc311ee6378249e08b128b | |
implementationName: "v0.1.0" | |
}); | |
console.log(`Trying cairo0 old proxies`); | |
for (const implementationAddress of CAIRO_0_IMPL_ADDRESS) { | |
for (const proxyClassHash of CAIRO_0_OLD_PROXIES) { | |
checkDeployParams({ | |
classHash: proxyClassHash, | |
constructorCalldata: CallData.compile({ implementationAddress }), | |
addressSalt: ownerPubKey, | |
implementationName: implementationAddress | |
}); | |
} | |
} | |
console.log(`Trying cairo0 new proxies`); | |
for (const implementation of CAIRO_0_CLASSHASHES) { | |
for (const proxyClassHash of CAIRO_0_NEW_PROXIES) { | |
checkDeployParams({ | |
classHash: proxyClassHash, | |
constructorCalldata: CallData.compile({ | |
implementation, | |
selector: hash.getSelectorFromName("initialize"), | |
calldata: CallData.compile({ owner: ownerPubKey, guardian: 0 }) | |
}), | |
addressSalt: ownerPubKey, | |
implementationName: implementation | |
}); | |
} | |
} | |
console.log(`Trying cairo1 contracts before signer types`); | |
for (const classHash of CAIRO_1_HASHES_WITHOUT_SIGNER_TYPES) { | |
checkDeployParams({ | |
classHash, | |
constructorCalldata: CallData.compile({ owner: ownerPubKey, guardian: 0n }), | |
addressSalt: ownerPubKey, | |
implementationName: classHash | |
}); | |
} | |
console.log(`Trying cairo1 contracts before using types`); | |
for (const classHash of CAIRO_1_HASHES_AFTER_SIGNER_TYPES) { | |
const ownerSigner = new CairoCustomEnum({ | |
Starknet: { signer: ownerPubKey }, | |
Secp256k1: undefined, | |
Secp256r1: undefined, | |
Eip191: undefined, | |
Webauthn: undefined, | |
}); | |
const guardian = new CairoOption(CairoOptionVariant.None); | |
checkDeployParams({ | |
classHash, | |
constructorCalldata: CallData.compile({ owner: ownerSigner, guardian }), | |
addressSalt: ownerPubKey, | |
implementationName: classHash | |
}); | |
} | |
console.log("Address not found"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment