mirror of https://github.com/status-im/op-geth.git
db console is now a general console.
This commit is contained in:
parent
92b6667bd1
commit
d2b3071b4d
45
dagger.go
45
dagger.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
"github.com/obscuren/sha3"
|
"github.com/obscuren/sha3"
|
||||||
|
"hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dagger struct {
|
type Dagger struct {
|
||||||
|
@ -27,8 +28,11 @@ func (dag *Dagger) Search(diff *big.Int) *big.Int {
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
if dag.Eval(rnd).Cmp(obj) < 0 {
|
if dag.Eval(rnd).Cmp(obj) < 0 {
|
||||||
fmt.Println("Found result! i = ", i)
|
fmt.Println("Found result! nonce = ", rnd)
|
||||||
|
|
||||||
return rnd
|
return rnd
|
||||||
|
} else {
|
||||||
|
fmt.Println("Not found :( nonce = ", rnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
rnd = rnd.Add(rnd, big.NewInt(1))
|
rnd = rnd.Add(rnd, big.NewInt(1))
|
||||||
|
@ -37,6 +41,16 @@ func (dag *Dagger) Search(diff *big.Int) *big.Int {
|
||||||
return big.NewInt(0)
|
return big.NewInt(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DaggerVerify(hash, diff, nonce *big.Int) bool {
|
||||||
|
dagger := &Dagger{}
|
||||||
|
dagger.hash = hash
|
||||||
|
|
||||||
|
obj := BigPow(2, 256)
|
||||||
|
obj = obj.Div(obj, diff)
|
||||||
|
|
||||||
|
return dagger.Eval(nonce).Cmp(obj) < 0
|
||||||
|
}
|
||||||
|
|
||||||
func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
|
func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
|
||||||
if L == i {
|
if L == i {
|
||||||
return dag.hash
|
return dag.hash
|
||||||
|
@ -63,16 +77,21 @@ func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
|
||||||
d.Write(big.NewInt(int64(i)).Bytes())
|
d.Write(big.NewInt(int64(i)).Bytes())
|
||||||
d.Write(big.NewInt(int64(k)).Bytes())
|
d.Write(big.NewInt(int64(k)).Bytes())
|
||||||
|
|
||||||
b.SetBytes(d.Sum(nil))
|
b.SetBytes(Sum(d))
|
||||||
pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
|
pk := b.Uint64() & ((1 << ((L - 1) * 3)) - 1)
|
||||||
sha.Write(dag.Node(L - 1, pk).Bytes())
|
sha.Write(dag.Node(L - 1, pk).Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.SetBytes(sha.Sum(nil))
|
ret.SetBytes(Sum(sha))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Sum(sha hash.Hash) []byte {
|
||||||
|
in := make([]byte, 32)
|
||||||
|
return sha.Sum(in)
|
||||||
|
}
|
||||||
|
|
||||||
func (dag *Dagger) Eval(N *big.Int) *big.Int {
|
func (dag *Dagger) Eval(N *big.Int) *big.Int {
|
||||||
pow := BigPow(2, 26)
|
pow := BigPow(2, 26)
|
||||||
dag.xn = N.Div(N, pow)
|
dag.xn = N.Div(N, pow)
|
||||||
|
@ -81,10 +100,11 @@ func (dag *Dagger) Eval(N *big.Int) *big.Int {
|
||||||
sha.Reset()
|
sha.Reset()
|
||||||
ret := new(big.Int)
|
ret := new(big.Int)
|
||||||
|
|
||||||
doneChan := make(chan bool, 3)
|
//doneChan := make(chan bool, 3)
|
||||||
|
|
||||||
for k := 0; k < 4; k++ {
|
for k := 0; k < 4; k++ {
|
||||||
go func(_k int) {
|
//go func(_k int) {
|
||||||
|
_k := k
|
||||||
d := sha3.NewKeccak224()
|
d := sha3.NewKeccak224()
|
||||||
b := new(big.Int)
|
b := new(big.Int)
|
||||||
|
|
||||||
|
@ -94,17 +114,18 @@ func (dag *Dagger) Eval(N *big.Int) *big.Int {
|
||||||
d.Write(N.Bytes())
|
d.Write(N.Bytes())
|
||||||
d.Write(big.NewInt(int64(_k)).Bytes())
|
d.Write(big.NewInt(int64(_k)).Bytes())
|
||||||
|
|
||||||
b.SetBytes(d.Sum(nil))
|
b.SetBytes(Sum(d))
|
||||||
pk := (b.Uint64() & 0x1ffffff)
|
pk := (b.Uint64() & 0x1ffffff)
|
||||||
|
|
||||||
sha.Write(dag.Node(9, pk).Bytes())
|
sha.Write(dag.Node(9, pk).Bytes())
|
||||||
doneChan <- true
|
//doneChan <- true
|
||||||
}(k)
|
//}(k)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k := 0; k < 4; k++ {
|
//for k := 0; k < 4; k++ {
|
||||||
<- doneChan
|
// <- doneChan
|
||||||
}
|
//}
|
||||||
|
|
||||||
return ret.SetBytes(sha.Sum(nil))
|
|
||||||
|
return ret.SetBytes(Sum(sha))
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ func (i *DbInterface) ValidateInput(action string, argumentLength int) error {
|
||||||
case action == "get" && argumentLength != 1:
|
case action == "get" && argumentLength != 1:
|
||||||
err = true
|
err = true
|
||||||
expArgCount = 1
|
expArgCount = 1
|
||||||
|
case action == "dag" && argumentLength != 2:
|
||||||
|
err = true
|
||||||
|
expArgCount = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
if err {
|
if err {
|
||||||
|
@ -74,6 +77,8 @@ func (i *DbInterface) ParseInput(input string) bool {
|
||||||
fmt.Println(i.trie.root)
|
fmt.Println(i.trie.root)
|
||||||
case "print":
|
case "print":
|
||||||
i.db.Print()
|
i.db.Print()
|
||||||
|
case "dag":
|
||||||
|
fmt.Println(DaggerVerify(Big(tokens[1]), BigPow(2, 36), Big(tokens[2])))
|
||||||
case "exit", "quit", "q":
|
case "exit", "quit", "q":
|
||||||
return false
|
return false
|
||||||
case "help":
|
case "help":
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"flag"
|
"flag"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
_"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Debug = true
|
const Debug = true
|
||||||
|
@ -13,7 +14,7 @@ const Debug = true
|
||||||
var StartDBQueryInterface bool
|
var StartDBQueryInterface bool
|
||||||
var StartMining bool
|
var StartMining bool
|
||||||
func Init() {
|
func Init() {
|
||||||
flag.BoolVar(&StartDBQueryInterface, "db", false, "start db query interface")
|
flag.BoolVar(&StartDBQueryInterface, "c", false, "console interface")
|
||||||
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -46,9 +47,7 @@ func main() {
|
||||||
dbInterface.Start()
|
dbInterface.Start()
|
||||||
} else if StartMining {
|
} else if StartMining {
|
||||||
dagger := &Dagger{}
|
dagger := &Dagger{}
|
||||||
seed := dagger.Search(BigPow(2, 36))
|
dagger.Search(BigPow(2, 36))
|
||||||
|
|
||||||
fmt.Println("dagger res = ", seed)
|
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("[DBUG]: Starting Ethereum")
|
fmt.Println("[DBUG]: Starting Ethereum")
|
||||||
server, err := NewServer()
|
server, err := NewServer()
|
||||||
|
|
Loading…
Reference in New Issue