Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
9571a512
Commit
9571a512
authored
Jan 11, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt no coding standards
parent
8bbf879c
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
973 additions
and
938 deletions
+973
-938
README.md
README.md
+5
-0
block_manager.go
block_manager.go
+60
-60
dagger.go
dagger.go
+101
-98
dagger_test.go
dagger_test.go
+9
-9
dev_console.go
dev_console.go
+94
-92
ethereum.go
ethereum.go
+66
-66
peer.go
peer.go
+59
-59
rlp.go
rlp.go
+198
-190
rlp_test.go
rlp_test.go
+37
-37
server.go
server.go
+80
-81
test_runner.go
test_runner.go
+15
-15
test_runner_test.go
test_runner_test.go
+14
-14
testing.go
testing.go
+1
-0
vm.go
vm.go
+234
-217
No files found.
README.md
View file @
9571a512
...
...
@@ -21,3 +21,8 @@ Command line options
-c launch the developer console
-m start mining fake blocks and broadcast fake messages to the net
Contribution
============
See CONTRIB.md
block_manager.go
View file @
9571a512
...
...
@@ -13,7 +13,7 @@ type BlockChain struct {
func
NewBlockChain
()
*
BlockChain
{
bc
:=
&
BlockChain
{}
bc
.
genesisBlock
=
ethutil
.
NewBlock
(
ethutil
.
Encode
(
ethutil
.
Genesis
)
)
bc
.
genesisBlock
=
ethutil
.
NewBlock
(
ethutil
.
Encode
(
ethutil
.
Genesis
)
)
return
bc
}
...
...
@@ -55,7 +55,7 @@ func (bm *BlockManager) ProcessBlock(block *ethutil.Block) error {
// Wait for all Tx to finish processing
for
i
:=
0
;
i
<
txCount
;
i
++
{
<-
lockChan
<-
lockChan
}
return
nil
...
...
dagger.go
View file @
9571a512
package
main
import
(
"github.com/ethereum/ethutil-go"
"github.com/obscuren/sha3"
"hash"
"math/big"
"math/rand"
"time"
"github.com/obscuren/sha3"
"hash"
"github.com/ethereum/ethutil-go"
)
type
Dagger
struct
{
...
...
@@ -15,6 +15,7 @@ type Dagger struct {
}
var
Found
bool
func
(
dag
*
Dagger
)
Find
(
obj
*
big
.
Int
,
resChan
chan
int64
)
{
r
:=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
...
...
@@ -29,7 +30,9 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
}
// Break out if found
if
Found
{
break
}
if
Found
{
break
}
}
resChan
<-
0
...
...
@@ -55,7 +58,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
// Wait for each go routine to finish
for
k
:=
0
;
k
<
amountOfRoutines
;
k
++
{
// Get the result from the channel. 0 = quit
if
r
:=
<-
resChan
;
r
!=
0
{
if
r
:=
<-
resChan
;
r
!=
0
{
res
=
r
}
}
...
...
@@ -101,7 +104,7 @@ func (dag *Dagger) Node(L uint64, i uint64) *big.Int {
b
.
SetBytes
(
Sum
(
d
))
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
(
Sum
(
sha
))
...
...
dagger_test.go
View file @
9571a512
package
main
import
(
"testing"
"math/big"
"testing"
)
func
BenchmarkDaggerSearch
(
b
*
testing
.
B
)
{
...
...
dev_console.go
View file @
9571a512
package
main
import
(
"fmt"
"bufio"
"strings"
"os"
"errors"
"encoding/hex"
"errors"
"fmt"
"github.com/ethereum/ethdb-go"
"github.com/ethereum/ethutil-go"
"os"
"strings"
)
type
Console
struct
{
...
...
@@ -60,7 +60,9 @@ func (i *Console) ParseInput(input string) bool {
fmt
.
Fprintln
(
os
.
Stderr
,
"reading input:"
,
err
)
}
if
len
(
tokens
)
==
0
{
return
true
}
if
len
(
tokens
)
==
0
{
return
true
}
err
:=
i
.
ValidateInput
(
tokens
[
0
],
count
-
1
)
if
err
!=
nil
{
...
...
@@ -80,19 +82,19 @@ func (i *Console) ParseInput(input string) bool {
case
"print"
:
i
.
db
.
Print
()
case
"dag"
:
fmt
.
Println
(
DaggerVerify
(
ethutil
.
Big
(
tokens
[
1
]),
// hash
fmt
.
Println
(
DaggerVerify
(
ethutil
.
Big
(
tokens
[
1
]),
// hash
ethutil
.
BigPow
(
2
,
36
),
// diff
ethutil
.
Big
(
tokens
[
2
])))
// nonce
ethutil
.
Big
(
tokens
[
2
])))
// nonce
case
"exit"
,
"quit"
,
"q"
:
return
false
case
"help"
:
fmt
.
Printf
(
"COMMANDS:
\n
"
+
"
\0
33[1m= DB =
\0
33[0m
\n
"
+
"update KEY VALUE - Updates/Creates a new value for the given key
\n
"
+
"get KEY - Retrieves the given key
\n
"
+
"root - Prints the hex encoded merkle root
\n
"
+
"rawroot - Prints the raw merkle root
\n
"
+
"
\0
33[1m= Dagger =
\0
33[0m
\n
"
+
fmt
.
Printf
(
"COMMANDS:
\n
"
+
"
\0
33[1m= DB =
\0
33[0m
\n
"
+
"update KEY VALUE - Updates/Creates a new value for the given key
\n
"
+
"get KEY - Retrieves the given key
\n
"
+
"root - Prints the hex encoded merkle root
\n
"
+
"rawroot - Prints the raw merkle root
\n
"
+
"
\0
33[1m= Dagger =
\0
33[0m
\n
"
+
"dag HASH NONCE - Verifies a nonce with the given hash with dagger
\n
"
)
default
:
fmt
.
Println
(
"Unknown command:"
,
tokens
[
0
])
...
...
ethereum.go
View file @
9571a512
package
main
import
(
"flag"
"fmt"
"github.com/ethereum/ethutil-go"
"log"
"os"
"os/signal"
"flag"
"runtime"
"log"
"github.com/ethereum/ethutil-go"
)
const
Debug
=
true
var
StartConsole
bool
var
StartMining
bool
func
Init
()
{
flag
.
BoolVar
(
&
StartConsole
,
"c"
,
false
,
"debug and testing console"
)
flag
.
BoolVar
(
&
StartMining
,
"m"
,
false
,
"start dagger mining"
)
...
...
@@ -46,7 +47,7 @@ func main() {
if
StartConsole
{
console
:=
NewConsole
()
console
.
Start
()
}
else
{
}
else
{
log
.
Println
(
"Starting Ethereum"
)
server
,
err
:=
NewServer
()
...
...
@@ -78,7 +79,6 @@ func main() {
return
}
// Wait for shutdown
server
.
WaitForShutdown
()
}
...
...
peer.go
View file @
9571a512
package
main
import
(
"net"
"log"
"github.com/ethereum/ethwire-go"
"log"
"net"
)
type
Peer
struct
{
...
...
@@ -49,7 +49,7 @@ out:
}
// Break out of the for loop if a quit message is posted
case
<-
p
.
quit
:
case
<-
p
.
quit
:
break
out
}
}
...
...
rlp.go
View file @
9571a512
package
main
import
(
"fmt"
"bytes"
"fmt"
"github.com/ethereum/ethutil-go"
"math"
"math/big"
"github.com/ethereum/ethutil-go"
)
type
RlpEncoder
struct
{
rlpData
[]
byte
}
func
NewRlpEncoder
()
*
RlpEncoder
{
encoder
:=
&
RlpEncoder
{}
...
...
@@ -95,10 +96,11 @@ func (attr *RlpDataAttribute) Get(idx int) *RlpDataAttribute {
type
RlpDecoder
struct
{
rlpData
interface
{}
}
func
NewRlpDecoder
(
rlpData
[]
byte
)
*
RlpDecoder
{
decoder
:=
&
RlpDecoder
{}
// Decode the data
data
,
_
:=
Decode
(
rlpData
,
0
)
data
,
_
:=
Decode
(
rlpData
,
0
)
decoder
.
rlpData
=
data
return
decoder
...
...
@@ -110,9 +112,11 @@ func (dec *RlpDecoder) Get(idx int) *RlpDataAttribute {
/// Raw methods
func
BinaryLength
(
n
uint64
)
uint64
{
if
n
==
0
{
return
0
}
if
n
==
0
{
return
0
}
return
1
+
BinaryLength
(
n
/
256
)
return
1
+
BinaryLength
(
n
/
256
)
}
func
ToBinarySlice
(
n
uint64
,
length
uint64
)
[]
uint64
{
...
...
@@ -120,10 +124,12 @@ func ToBinarySlice(n uint64, length uint64) []uint64 {
length
=
BinaryLength
(
n
)
}
if
n
==
0
{
return
make
([]
uint64
,
1
)
}
if
n
==
0
{
return
make
([]
uint64
,
1
)
}
slice
:=
ToBinarySlice
(
n
/
256
,
0
)
slice
=
append
(
slice
,
n
%
256
)
slice
:=
ToBinarySlice
(
n
/
256
,
0
)
slice
=
append
(
slice
,
n
%
256
)
return
slice
}
...
...
@@ -138,9 +144,11 @@ func ToBin(n uint64, length uint64) string {
}
func
FromBin
(
data
[]
byte
)
uint64
{
if
len
(
data
)
==
0
{
return
0
}
if
len
(
data
)
==
0
{
return
0
}
return
FromBin
(
data
[
:
len
(
data
)
-
1
])
*
256
+
uint64
(
data
[
len
(
data
)
-
1
])
return
FromBin
(
data
[
:
len
(
data
)
-
1
])
*
256
+
uint64
(
data
[
len
(
data
)
-
1
])
}
func
Decode
(
data
[]
byte
,
pos
int
)
(
interface
{},
int
)
{
...
...
@@ -161,16 +169,16 @@ func Decode(data []byte, pos int) (interface{}, int) {
case
char
<
64
:
b
:=
int
(
data
[
pos
])
-
55
b2
:=
int
(
FromBin
(
data
[
pos
+
1
:
pos
+
1
+
b
]))
return
FromBin
(
data
[
pos
+
1
+
b
:
pos
+
1
+
b
+
b2
]),
pos
+
1
+
b
+
b2
return
FromBin
(
data
[
pos
+
1
+
b
:
pos
+
1
+
b
+
b2
]),
pos
+
1
+
b
+
b2
case
char
<
120
:
b
:=
int
(
data
[
pos
])
-
64
return
data
[
pos
+
1
:
pos
+
1
+
b
],
pos
+
1
+
b
return
data
[
pos
+
1
:
pos
+
1
+
b
],
pos
+
1
+
b
case
char
<
128
:
b
:=
int
(
data
[
pos
])
-
119
b2
:=
int
(
FromBin
(
data
[
pos
+
1
:
pos
+
1
+
b
]))
return
data
[
pos
+
1
+
b
:
pos
+
1
+
b
+
b2
],
pos
+
1
+
b
+
b2
return
data
[
pos
+
1
+
b
:
pos
+
1
+
b
+
b2
],
pos
+
1
+
b
+
b2
case
char
<
184
:
b
:=
int
(
data
[
pos
])
-
128
...
...
@@ -186,7 +194,7 @@ func Decode(data []byte, pos int) (interface{}, int) {
case
char
<
192
:
b
:=
int
(
data
[
pos
])
-
183
//b2 := int(FromBin(data[pos+1 : pos+1+b])) (ref implementation has an unused variable)
pos
=
pos
+
1
+
b
pos
=
pos
+
1
+
b
for
i
:=
0
;
i
<
b
;
i
++
{
var
obj
interface
{}
...
...
@@ -218,11 +226,11 @@ func Encode(object interface{}) []byte {
buff
.
WriteString
(
string
(
num
))
}
else
if
num
<=
uint64
(
math
.
Pow
(
2
,
256
))
{
b
:=
ToBin
(
num
,
0
)
buff
.
WriteString
(
string
(
len
(
b
)
+
23
)
+
b
)
buff
.
WriteString
(
string
(
len
(
b
)
+
23
)
+
b
)
}
else
{
b
:=
ToBin
(
num
,
0
)
b2
:=
ToBin
(
uint64
(
len
(
b
)),
0
)
buff
.
WriteString
(
string
(
len
(
b2
)
+
55
)
+
b2
+
b
)
buff
.
WriteString
(
string
(
len
(
b2
)
+
55
)
+
b2
+
b
)
}
case
*
big
.
Int
:
...
...
@@ -230,10 +238,10 @@ func Encode(object interface{}) []byte {
case
string
:
if
len
(
t
)
<
56
{
buff
.
WriteString
(
string
(
len
(
t
)
+
64
)
+
t
)
buff
.
WriteString
(
string
(
len
(
t
)
+
64
)
+
t
)
}
else
{
b2
:=
ToBin
(
uint64
(
len
(
t
)),
0
)
buff
.
WriteString
(
string
(
len
(
b2
)
+
119
)
+
b2
+
t
)
buff
.
WriteString
(
string
(
len
(
b2
)
+
119
)
+
b2
+
t
)
}
case
[]
byte
:
...
...
rlp_test.go
View file @
9571a512
package
main
import
(
"testing"
"fmt"
"testing"
)
func
TestEncode
(
t
*
testing
.
T
)
{
...
...
@@ -30,7 +30,7 @@ func TestEncode(t *testing.T) {
func
TestMultiEncode
(
t
*
testing
.
T
)
{
inter
:=
[]
interface
{}{
[]
interface
{}{
"1"
,
"2"
,
"3"
,
"1"
,
"2"
,
"3"
,
},
[]
string
{
"string"
,
...
...
server.go
View file @
9571a512
...
...
@@ -2,11 +2,11 @@ package main
import
(
"container/list"
"net"
"log"
_
"time"
"github.com/ethereum/ethdb-go"
"github.com/ethereum/ethutil-go"
"log"
"net"
_
"time"
)
type
Server
struct
{
...
...
@@ -57,7 +57,6 @@ func (s *Server) ConnectToPeer(addr string) error {
s
.
peers
.
PushBack
(
peer
)
peer
.
Start
()
log
.
Println
(
"Connected to peer ::"
,
conn
.
RemoteAddr
())
return
nil
...
...
@@ -95,10 +94,10 @@ func (s *Server) Start() {
//go func() {
// for {
// s.Broadcast("block", Encode("blockdata"))
//
// time.Sleep(100 * time.Millisecond)
// }
// }()
//
// time.Sleep(100 * time.Millisecond)
// }
// }()
}
func
(
s
*
Server
)
Stop
()
{
...
...
@@ -117,5 +116,5 @@ func (s *Server) Stop() {
// This function will wait for a shutdown and resumes main thread execution
func
(
s
*
Server
)
WaitForShutdown
()
{
<-
s
.
shutdownChan
<-
s
.
shutdownChan
}
test_runner.go
View file @
9571a512
package
main
import
(
"encoding/json"
"fmt"
"testing"
"encoding/json"
)
type
TestSource
struct
{
...
...
test_runner_test.go
View file @
9571a512
package
main
import
(
_
"fmt"
"testing"
"encoding/hex"
_
"fmt"
"testing"
)
var
testsource
=
`{"Inputs":{
...
...
testing.go
View file @
9571a512
package
main
/*
import (
...
...
vm.go
View file @
9571a512
package
main
import
(
"math/big"
"fmt"
"strconv"
"github.com/ethereum/ethutil-go"
"math/big"
"strconv"
)
// Op codes
...
...
@@ -61,18 +61,21 @@ const (
)
type
OpType
int
const
(
tNorm
=
iota
tData
tExtro
tCrypto
)
type
TxCallback
func
(
opType
OpType
)
bool
// Simple push/pop stack mechanism
type
Stack
struct
{
data
[]
string
}
func
NewStack
()
*
Stack
{
return
&
Stack
{}
}
...
...
@@ -112,7 +115,7 @@ func NewVm() *Vm {
}
}
func
(
vm
*
Vm
)
ProcContract
(
tx
*
ethutil
.
Transaction
,
func
(
vm
*
Vm
)
ProcContract
(
tx
*
ethutil
.
Transaction
,
block
*
ethutil
.
Block
,
cb
TxCallback
)
{
// Instruction pointer
pc
:=
0
...
...
@@ -136,7 +139,9 @@ out:
nb
:=
ethutil
.
NumberToBytes
(
uint64
(
pc
),
32
)
op
,
_
,
_
:=
ethutil
.
Instr
(
contract
.
State
()
.
Get
(
string
(
nb
)))
if
!
cb
(
0
)
{
break
}
if
!
cb
(
0
)
{
break
}
if
Debug
{
//fmt.Printf("%-3d %-4d\n", pc, op)
...
...
@@ -173,11 +178,17 @@ out:
case
oSDIV
:
x
,
y
:=
vm
.
stack
.
Popn
()
// n > 2**255
if
x
.
Cmp
(
Pow256
)
>
0
{
x
.
Sub
(
Pow256
,
x
)
}
if
y
.
Cmp
(
Pow256
)
>
0
{
y
.
Sub
(
Pow256
,
y
)
}
if
x
.
Cmp
(
Pow256
)
>
0
{
x
.
Sub
(
Pow256
,
x
)
}
if
y
.
Cmp
(
Pow256
)
>
0
{
y
.
Sub
(
Pow256
,
y
)
}
z
:=
new
(
big
.
Int
)
z
.
Div
(
x
,
y
)
if
z
.
Cmp
(
Pow256
)
>
0
{
z
.
Sub
(
Pow256
,
z
)
}
if
z
.
Cmp
(
Pow256
)
>
0
{
z
.
Sub
(
Pow256
,
z
)
}
// Push result on to the stack
vm
.
stack
.
Push
(
z
.
String
())
case
oMOD
:
...
...
@@ -187,11 +198,17 @@ out:
case
oSMOD
:
x
,
y
:=
vm
.
stack
.
Popn
()
// n > 2**255
if
x
.
Cmp
(
Pow256
)
>
0
{
x
.
Sub
(
Pow256
,
x
)
}
if
y
.
Cmp
(
Pow256
)
>
0
{
y
.
Sub
(
Pow256
,
y
)
}
if
x
.
Cmp
(
Pow256
)
>
0
{
x
.
Sub
(
Pow256
,
x
)
}
if
y
.
Cmp
(
Pow256
)
>
0
{
y
.
Sub
(
Pow256
,
y
)
}
z
:=
new
(
big
.
Int
)
z
.
Mod
(
x
,
y
)
if
z
.
Cmp
(
Pow256
)
>
0
{
z
.
Sub
(
Pow256
,
z
)
}
if
z
.
Cmp
(
Pow256
)
>
0
{
z
.
Sub
(
Pow256
,
z
)
}
// Push result on to the stack
vm
.
stack
.
Push
(
z
.
String
())
case
oEXP
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment