-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
105 lines (93 loc) · 2.71 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
package main
import (
"flag"
"fmt"
"github.com/ethereum/go-ethereum/common"
solsha3 "github.com/miguelmota/go-solidity-sha3"
"math/big"
"time"
)
type ConfigPtr struct {
userNonce *int
userAddress *string
chainId *int
gemDifficulty *int
gemAddress *string
gemEntropy *string
gemKind *int
saltStart *string
debug *bool
n *int
}
func main() {
// flag
var defaultN = 25000 * 60 * 60 * 2 // !2 hrs
var cPtr = ConfigPtr{
flag.Int("user-nonce", 0, "User nonce"),
flag.String("user-address", "0xxxx", "User Fantom wallet address"),
flag.Int("chain-id", 250, "Chain ID"),
flag.Int("gem-difficulty", 0, "Gem difficult"),
flag.String("gem-address", "0xxxx", "Gem contract address"),
flag.String("gem-entropy", "0xxxx", "Gem entropy"),
flag.Int("gem-kind", 0, "Gem kind"),
flag.String("salt", "2300000", "Starter salt"),
flag.Bool("debug", false, "Is debug version"),
flag.Int("n", defaultN, "max number of iterations"), // default ~2 hrs
}
flag.Parse()
userNonce := big.NewInt(int64(*cPtr.userNonce))
userAddress := common.HexToAddress(*cPtr.userAddress)
chainId := big.NewInt(int64(*cPtr.chainId))
gemDifficulty := big.NewInt(int64(*cPtr.gemDifficulty))
gemAddress := common.HexToAddress(*cPtr.gemAddress)
gemEntropy := *cPtr.gemEntropy
gemKind := big.NewInt(int64(*cPtr.gemKind))
salt, _ := new(big.Int).SetString(*cPtr.saltStart, 10)
debug := *cPtr.debug
n := int64(*cPtr.n)
// const
total := int64(0)
plus := big.NewInt(1)
max, _ := new(big.Int).SetString("115792089237316195423570985008687907853269984665640564039457584007913129639935", 10)
target := new(big.Int).Div(max, gemDifficulty)
start := time.Now().UnixNano()
// debug
if debug {
fmt.Printf("userNonce: %d\n", userNonce)
fmt.Printf("userAddress: %s\n", userAddress)
fmt.Printf("chainId: %d\n", chainId)
fmt.Printf("gemDifficulty: %d\n", gemDifficulty)
fmt.Printf("gemAddress: %s\n", gemAddress)
fmt.Printf("gemEntropy: %s\n", gemEntropy)
fmt.Printf("gemKind: %d\n", gemKind)
fmt.Printf("salt: %v\n", salt)
fmt.Printf("n: %d\n", n)
}
for true {
// init
total += 1
// process
hash := solsha3.SoliditySHA3(
[]string{"uint256", "bytes32", "address", "address", "uint256", "uint256", "uint256"},
[]interface{}{chainId, gemEntropy, gemAddress, userAddress, gemKind, userNonce, salt},
)
var luck = new(big.Int).SetBytes(hash)
if luck.Cmp(target) != 1 {
fmt.Print(salt)
break
}
// restart
if total >= n {
fmt.Print(-1)
break
}
// debug
if debug {
now := time.Now().UnixNano()
secs := (now-start)/1e9 + 1
fmt.Printf("\rtotal hashes %d in %d secs, hashes per second : %d", total, secs, total/secs)
}
// next
salt.Add(salt, plus)
}
}