Created
October 25, 2021 06:49
-
-
Save sc0Vu/cb3643dc8dc4584a8f730f028fe76098 to your computer and use it in GitHub Desktop.
calculate_address
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 { ethers } from "hardhat" | |
async function main() { | |
const factoryAddress = '6b6960949B595b22548F4FBf3561Be459cA4F964' | |
const bytecode = '60806040527312c85994c04520f5216ce788414fdde2b591e1a06000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561006457600080fd5b5061018e806100746000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306fdde0314610051578063380c7a6714610084575b600080fd5b34801561005d57600080fd5b5061006661009b565b60405180826000191660001916815260200191505060405180910390f35b34801561009057600080fd5b506100996100c3565b005b60007f736d617278000000000000000000000000000000000000000000000000000000905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663380c7a676040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401600060405180830381600087803b15801561014857600080fd5b505af115801561015c573d6000803e3d6000fd5b505050505600a165627a7a7230582007ba358db1834d181bbf97426752d3d121e49a3ef0bcd2e57ae288e4ed5cd9a20029' | |
const abi = new ethers.utils.AbiCoder() | |
for (let salt = 123457; salt < 1000000000; salt += 1) { | |
const addr = ethers.utils.keccak256( | |
Buffer.from('ff' + | |
factoryAddress + | |
abi.encode(['uint256'],[salt]).slice(2).toString() + | |
ethers.utils.keccak256(Buffer.from(bytecode, 'hex')).slice(2).toString(), 'hex') | |
).slice(-40) | |
if (addr.toLowerCase().indexOf('badc0de') >= 0) { | |
console.log('Bang!!', addr, salt) | |
return | |
} else { | |
console.log('QQ!', addr) | |
} | |
} | |
} | |
main() | |
.then(() => console.log('Calculate address~')) | |
.catch(console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment