diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/types/bloom9.go | 17 | ||||
-rw-r--r-- | core/types/common.go | 11 |
2 files changed, 17 insertions, 11 deletions
diff --git a/core/types/bloom9.go b/core/types/bloom9.go index 59b6c69c3..64a8ff49a 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -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 } diff --git a/core/types/common.go b/core/types/common.go index 6c5ac06b1..cb57ef053 100644 --- a/core/types/common.go +++ b/core/types/common.go @@ -1,6 +1,7 @@ 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] } } |