forked from wangbar0133/create2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
132 lines (117 loc) · 3.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"crypto/ecdsa"
"flag"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
"github.com/panjf2000/ants/v2"
"math/rand"
"os"
"strings"
"sync"
)
const ResultFile = "result.txt"
func getAddress(devContractAddress common.Address, initCodeHash []byte, p string, s string) {
for {
i := rand.Uint64()
salt := uint256.NewInt(i).Bytes32()
address := crypto.CreateAddress2(devContractAddress, salt, initCodeHash).String()
if strings.HasPrefix(address, p) && strings.HasSuffix(address, s) {
fmt.Println(i)
fmt.Println(address)
fmt.Println()
f, err := os.OpenFile(ResultFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
_, err = fmt.Fprintf(f, "i: %d ; address: %s\n", i, address)
if err != nil {
fmt.Println(err)
return
}
}
}
}
func getAddressEoa(p string, s string) {
for {
privateKey, _ := crypto.GenerateKey()
publicKey := privateKey.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
address := crypto.PubkeyToAddress(*publicKeyECDSA).String()
if strings.HasPrefix(address, p) && strings.HasSuffix(address, s) {
fmt.Println(address)
privateKeyBytes := crypto.FromECDSA(privateKey)
fmt.Println(hexutil.Encode(privateKeyBytes))
fmt.Println()
f, err := os.OpenFile(ResultFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println(err)
return
}
defer f.Close()
_, err = fmt.Fprintf(f, "address: %s ; privateKey: %s\n", address, hexutil.Encode(privateKeyBytes))
if err != nil {
fmt.Println(err)
return
}
}
}
}
var (
address = flag.String("a", "", "dev contract address")
byteCode = flag.String("i", "", "init byte code")
prefix = flag.String("p", "", "prefix of address")
suffix = flag.String("s", "", "suffix of address")
goNum = flag.Int("n", 1000, "goroutine number")
)
func main() {
flag.Parse()
p := "0x" + *prefix
s := *suffix
fmt.Println("[+] Start!")
if *address == "" {
fmt.Printf("[+] Generate EOA address with prefix %s and suffix %s\n", p, s)
fmt.Printf("[+] Generate goroutine Num: %d \n", *goNum)
defer ants.Release()
runTimes := *goNum
// Use the common pool.
var wg sync.WaitGroup
syncCalculateSum := func() {
getAddressEoa(p, s)
wg.Done()
}
for i := 0; i < runTimes; i++ {
wg.Add(1)
_ = ants.Submit(syncCalculateSum)
}
wg.Wait()
fmt.Printf("running goroutines: %d\n", ants.Running())
fmt.Printf("finish all tasks.\n")
} else {
fmt.Printf("[+] Generate contract address with prefix %s and suffix %s\n", p, s)
fmt.Printf("[+] Generate goroutine Num: %d \n", *goNum)
devContractAddress := common.BytesToAddress(common.FromHex(*address))
initByteCode := common.FromHex(*byteCode)
initCodeHash := crypto.Keccak256(initByteCode)
defer ants.Release()
runTimes := *goNum
// Use the common pool.
var wg sync.WaitGroup
syncCalculateSum := func() {
getAddress(devContractAddress, initCodeHash, p, s)
wg.Done()
}
for i := 0; i < runTimes; i++ {
wg.Add(1)
_ = ants.Submit(syncCalculateSum)
}
wg.Wait()
fmt.Printf("running goroutines: %d\n", ants.Running())
fmt.Printf("finish all tasks.\n")
}
}