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
86661de0
Commit
86661de0
authored
Mar 17, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed tests and bloom
parent
c21293cd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
19 deletions
+35
-19
bloom9.go
core/types/bloom9.go
+10
-7
common.go
core/types/common.go
+7
-4
gh_test.go
tests/vm/gh_test.go
+18
-8
No files found.
core/types/bloom9.go
View file @
86661de0
...
...
@@ -20,15 +20,15 @@ func CreateBloom(receipts Receipts) Bloom {
func
LogsBloom
(
logs
state
.
Logs
)
*
big
.
Int
{
bin
:=
new
(
big
.
Int
)
for
_
,
log
:=
range
logs
{
data
:=
make
([]
common
.
Hash
,
len
(
log
.
Topics
())
+
1
)
data
[
0
]
=
log
.
Address
()
.
Hash
(
)
data
:=
make
([]
common
.
Hash
,
len
(
log
.
Topics
()))
bin
.
Or
(
bin
,
bloom9
(
log
.
Address
()
.
Bytes
())
)
for
i
,
topic
:=
range
log
.
Topics
()
{
data
[
i
+
1
]
=
topic
data
[
i
]
=
topic
}
for
_
,
b
:=
range
data
{
bin
.
Or
(
bin
,
bloom9
(
crypto
.
Sha3
(
b
[
:
])
))
bin
.
Or
(
bin
,
bloom9
(
b
[
:
]
))
}
}
...
...
@@ -36,21 +36,24 @@ func LogsBloom(logs state.Logs) *big.Int {
}
func
bloom9
(
b
[]
byte
)
*
big
.
Int
{
b
=
crypto
.
Sha3
(
b
[
:
])
r
:=
new
(
big
.
Int
)
for
i
:=
0
;
i
<
6
;
i
+=
2
{
t
:=
big
.
NewInt
(
1
)
//b := uint(b[i+1]) + 512*(uint(b[i])&1)
b
:=
(
uint
(
b
[
i
+
1
])
+
(
uint
(
b
[
i
])
<<
8
))
&
511
b
:=
(
uint
(
b
[
i
+
1
])
+
(
uint
(
b
[
i
])
<<
8
))
&
2047
r
.
Or
(
r
,
t
.
Lsh
(
t
,
b
))
}
return
r
}
var
Bloom9
=
bloom9
func
BloomLookup
(
bin
Bloom
,
topic
common
.
Hash
)
bool
{
bloom
:=
bin
.
Big
()
cmp
:=
bloom9
(
crypto
.
Sha3
(
topic
[
:
])
)
cmp
:=
bloom9
(
topic
[
:
]
)
return
bloom
.
And
(
bloom
,
cmp
)
.
Cmp
(
cmp
)
==
0
}
core/types/common.go
View file @
86661de0
package
types
import
(
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -10,7 +11,9 @@ type BlockProcessor interface {
Process
(
*
Block
)
(
*
big
.
Int
,
error
)
}
type
Bloom
[
256
]
byte
const
bloomLength
=
256
type
Bloom
[
bloomLength
]
byte
func
BytesToBloom
(
b
[]
byte
)
Bloom
{
var
bloom
Bloom
...
...
@@ -19,13 +22,13 @@ func BytesToBloom(b []byte) Bloom {
}
func
(
b
*
Bloom
)
SetBytes
(
d
[]
byte
)
{
if
len
(
b
)
>
len
(
d
)
{
panic
(
"bloom bytes too big"
)
if
len
(
b
)
<
len
(
d
)
{
panic
(
fmt
.
Sprintf
(
"bloom bytes too big %d %d"
,
len
(
b
),
len
(
d
))
)
}
// reverse loop
for
i
:=
len
(
d
)
-
1
;
i
>=
0
;
i
--
{
b
[
i
]
=
b
[
i
]
b
[
bloomLength
-
len
(
d
)
+
i
]
=
b
[
i
]
}
}
...
...
tests/vm/gh_test.go
View file @
86661de0
...
...
@@ -2,7 +2,6 @@ package vm
import
(
"bytes"
"fmt"
"math/big"
"strconv"
"testing"
...
...
@@ -82,9 +81,6 @@ func RunVmTest(p string, t *testing.T) {
helper
.
CreateFileTests
(
t
,
p
,
&
tests
)
for
name
,
test
:=
range
tests
{
if
name
!=
"log2_nonEmptyMem"
{
continue
}
db
,
_
:=
ethdb
.
NewMemDatabase
()
statedb
:=
state
.
New
(
common
.
Hash
{},
db
)
for
addr
,
account
:=
range
test
.
Pre
{
...
...
@@ -172,12 +168,26 @@ func RunVmTest(p string, t *testing.T) {
if
len
(
test
.
Logs
)
!=
len
(
logs
)
{
t
.
Errorf
(
"log length mismatch. Expected %d, got %d"
,
len
(
test
.
Logs
),
len
(
logs
))
}
else
{
fmt
.
Println
(
"A"
,
test
.
Logs
)
fmt
.
Println
(
"B"
,
logs
)
for
i
,
log
:=
range
test
.
Logs
{
if
common
.
HexToAddress
(
log
.
AddressF
)
!=
logs
[
i
]
.
Address
()
{
t
.
Errorf
(
"'%s' log address expected %v got %x"
,
name
,
log
.
AddressF
,
logs
[
i
]
.
Address
())
}
if
!
bytes
.
Equal
(
logs
[
i
]
.
Data
(),
helper
.
FromHex
(
log
.
DataF
))
{
t
.
Errorf
(
"'%s' log data expected %v got %x"
,
name
,
log
.
DataF
,
logs
[
i
]
.
Data
())
}
if
len
(
log
.
TopicsF
)
!=
len
(
logs
[
i
]
.
Topics
())
{
t
.
Errorf
(
"'%s' log topics length expected %d got %d"
,
name
,
len
(
log
.
TopicsF
),
logs
[
i
]
.
Topics
())
}
else
{
for
j
,
topic
:=
range
log
.
TopicsF
{
if
common
.
HexToHash
(
topic
)
!=
logs
[
i
]
.
Topics
()[
j
]
{
t
.
Errorf
(
"'%s' log topic[%d] expected %v got %x"
,
name
,
j
,
topic
,
logs
[
i
]
.
Topics
()[
j
])
}
}
}
genBloom
:=
common
.
LeftPadBytes
(
types
.
LogsBloom
(
state
.
Logs
{
logs
[
i
]})
.
Bytes
(),
256
)
fmt
.
Println
(
"A BLOOM"
,
log
.
BloomF
)
fmt
.
Printf
(
"B BLOOM %x
\n
"
,
genBloom
)
if
!
bytes
.
Equal
(
genBloom
,
common
.
Hex2Bytes
(
log
.
BloomF
))
{
t
.
Errorf
(
"'%s' bloom mismatch"
,
name
)
}
...
...
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