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
8363aba7
Commit
8363aba7
authored
Jun 24, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Ethash Godeps
parent
22c7ce01
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
19 deletions
+54
-19
Godeps.json
Godeps/Godeps.json
+2
-2
ethash.go
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
+19
-9
ethash_test.go
.../_workspace/src/github.com/ethereum/ethash/ethash_test.go
+16
-0
internal.c
...e/src/github.com/ethereum/ethash/src/libethash/internal.c
+2
-2
internal.h
...e/src/github.com/ethereum/ethash/src/libethash/internal.h
+15
-6
No files found.
Godeps/Godeps.json
View file @
8363aba7
...
@@ -21,8 +21,8 @@
...
@@ -21,8 +21,8 @@
},
},
{
{
"ImportPath"
:
"github.com/ethereum/ethash"
,
"ImportPath"
:
"github.com/ethereum/ethash"
,
"Comment"
:
"v23.1-22
2-g173b8ff
"
,
"Comment"
:
"v23.1-22
7-g8f6ccaa
"
,
"Rev"
:
"
173b8ff953610c13710061e83b95b50c73d7ea50
"
"Rev"
:
"
8f6ccaaef9b418553807a73a95cb5f49cd3ea39f
"
},
},
{
{
"ImportPath"
:
"github.com/howeyc/fsnotify"
,
"ImportPath"
:
"github.com/howeyc/fsnotify"
,
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
View file @
8363aba7
...
@@ -100,19 +100,29 @@ type Light struct {
...
@@ -100,19 +100,29 @@ type Light struct {
func
(
l
*
Light
)
Verify
(
block
pow
.
Block
)
bool
{
func
(
l
*
Light
)
Verify
(
block
pow
.
Block
)
bool
{
// TODO: do ethash_quick_verify before getCache in order
// TODO: do ethash_quick_verify before getCache in order
// to prevent DOS attacks.
// to prevent DOS attacks.
var
(
blockNum
:=
block
.
NumberU64
()
blockNum
=
block
.
NumberU64
()
difficulty
=
block
.
Difficulty
()
cache
=
l
.
getCache
(
blockNum
)
dagSize
=
C
.
ethash_get_datasize
(
C
.
uint64_t
(
blockNum
))
)
if
l
.
test
{
dagSize
=
dagSizeForTesting
}
if
blockNum
>=
epochLength
*
2048
{
if
blockNum
>=
epochLength
*
2048
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"block number %d too high, limit is %d"
,
epochLength
*
2048
)
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"block number %d too high, limit is %d"
,
epochLength
*
2048
)
return
false
return
false
}
}
difficulty
:=
block
.
Difficulty
()
/* Cannot happen if block header diff is validated prior to PoW, but can
happen if PoW is checked first due to parallel PoW checking.
We could check the minimum valid difficulty but for SoC we avoid (duplicating)
Ethereum protocol consensus rules here which are not in scope of Ethash
*/
if
difficulty
.
Cmp
(
common
.
Big0
)
==
0
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"invalid block difficulty"
)
return
false
}
cache
:=
l
.
getCache
(
blockNum
)
dagSize
:=
C
.
ethash_get_datasize
(
C
.
uint64_t
(
blockNum
))
if
l
.
test
{
dagSize
=
dagSizeForTesting
}
// Recompute the hash using the cache.
// Recompute the hash using the cache.
hash
:=
hashToH256
(
block
.
HashNoNonce
())
hash
:=
hashToH256
(
block
.
HashNoNonce
())
ret
:=
C
.
ethash_light_compute_internal
(
cache
.
ptr
,
dagSize
,
hash
,
C
.
uint64_t
(
block
.
Nonce
()))
ret
:=
C
.
ethash_light_compute_internal
(
cache
.
ptr
,
dagSize
,
hash
,
C
.
uint64_t
(
block
.
Nonce
()))
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/ethash_test.go
View file @
8363aba7
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
"testing"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
)
func
init
()
{
func
init
()
{
...
@@ -59,6 +60,14 @@ var validBlocks = []*testBlock{
...
@@ -59,6 +60,14 @@ var validBlocks = []*testBlock{
},
},
}
}
var
invalidZeroDiffBlock
=
testBlock
{
number
:
61440000
,
hashNoNonce
:
crypto
.
Sha3Hash
([]
byte
(
"foo"
)),
difficulty
:
big
.
NewInt
(
0
),
nonce
:
0xcafebabec00000fe
,
mixDigest
:
crypto
.
Sha3Hash
([]
byte
(
"bar"
)),
}
func
TestEthashVerifyValid
(
t
*
testing
.
T
)
{
func
TestEthashVerifyValid
(
t
*
testing
.
T
)
{
eth
:=
New
()
eth
:=
New
()
for
i
,
block
:=
range
validBlocks
{
for
i
,
block
:=
range
validBlocks
{
...
@@ -68,6 +77,13 @@ func TestEthashVerifyValid(t *testing.T) {
...
@@ -68,6 +77,13 @@ func TestEthashVerifyValid(t *testing.T) {
}
}
}
}
func
TestEthashVerifyInvalid
(
t
*
testing
.
T
)
{
eth
:=
New
()
if
eth
.
Verify
(
&
invalidZeroDiffBlock
)
{
t
.
Errorf
(
"should not validate - we just ensure it does not panic on this block"
)
}
}
func
TestEthashConcurrentVerify
(
t
*
testing
.
T
)
{
func
TestEthashConcurrentVerify
(
t
*
testing
.
T
)
{
eth
,
err
:=
NewForTesting
()
eth
,
err
:=
NewForTesting
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/src/libethash/internal.c
View file @
8363aba7
...
@@ -284,13 +284,13 @@ bool ethash_quick_check_difficulty(
...
@@ -284,13 +284,13 @@ bool ethash_quick_check_difficulty(
ethash_h256_t
const
*
header_hash
,
ethash_h256_t
const
*
header_hash
,
uint64_t
const
nonce
,
uint64_t
const
nonce
,
ethash_h256_t
const
*
mix_hash
,
ethash_h256_t
const
*
mix_hash
,
ethash_h256_t
const
*
difficult
y
ethash_h256_t
const
*
boundar
y
)
)
{
{
ethash_h256_t
return_hash
;
ethash_h256_t
return_hash
;
ethash_quick_hash
(
&
return_hash
,
header_hash
,
nonce
,
mix_hash
);
ethash_quick_hash
(
&
return_hash
,
header_hash
,
nonce
,
mix_hash
);
return
ethash_check_difficulty
(
&
return_hash
,
difficult
y
);
return
ethash_check_difficulty
(
&
return_hash
,
boundar
y
);
}
}
ethash_light_t
ethash_light_new_internal
(
uint64_t
cache_size
,
ethash_h256_t
const
*
seed
)
ethash_light_t
ethash_light_new_internal
(
uint64_t
cache_size
,
ethash_h256_t
const
*
seed
)
...
...
Godeps/_workspace/src/github.com/ethereum/ethash/src/libethash/internal.h
View file @
8363aba7
...
@@ -46,27 +46,36 @@ static inline void ethash_h256_reset(ethash_h256_t* hash)
...
@@ -46,27 +46,36 @@ static inline void ethash_h256_reset(ethash_h256_t* hash)
memset
(
hash
,
0
,
32
);
memset
(
hash
,
0
,
32
);
}
}
// Returns if hash is less than or equal to
difficulty
// Returns if hash is less than or equal to
boundary (2^256/difficulty)
static
inline
bool
ethash_check_difficulty
(
static
inline
bool
ethash_check_difficulty
(
ethash_h256_t
const
*
hash
,
ethash_h256_t
const
*
hash
,
ethash_h256_t
const
*
difficult
y
ethash_h256_t
const
*
boundar
y
)
)
{
{
//
Difficult
y is big endian
//
Boundar
y is big endian
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
for
(
int
i
=
0
;
i
<
32
;
i
++
)
{
if
(
ethash_h256_get
(
hash
,
i
)
==
ethash_h256_get
(
difficult
y
,
i
))
{
if
(
ethash_h256_get
(
hash
,
i
)
==
ethash_h256_get
(
boundar
y
,
i
))
{
continue
;
continue
;
}
}
return
ethash_h256_get
(
hash
,
i
)
<
ethash_h256_get
(
difficult
y
,
i
);
return
ethash_h256_get
(
hash
,
i
)
<
ethash_h256_get
(
boundar
y
,
i
);
}
}
return
true
;
return
true
;
}
}
/**
* Difficulty quick check for POW preverification
*
* @param header_hash The hash of the header
* @param nonce The block's nonce
* @param mix_hash The mix digest hash
* @param boundary The boundary is defined as (2^256 / difficulty)
* @return true for succesful pre-verification and false otherwise
*/
bool
ethash_quick_check_difficulty
(
bool
ethash_quick_check_difficulty
(
ethash_h256_t
const
*
header_hash
,
ethash_h256_t
const
*
header_hash
,
uint64_t
const
nonce
,
uint64_t
const
nonce
,
ethash_h256_t
const
*
mix_hash
,
ethash_h256_t
const
*
mix_hash
,
ethash_h256_t
const
*
difficult
y
ethash_h256_t
const
*
boundar
y
);
);
struct
ethash_light
{
struct
ethash_light
{
...
...
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