-
Notifications
You must be signed in to change notification settings - Fork 7
/
fuzz.go
55 lines (47 loc) · 1.33 KB
/
fuzz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package fuzz
import (
"helper"
"github.com/protolambda/zrnt/eth2/beacon/transition"
"github.com/cespare/xxhash"
//"github.com/protolambda/zrnt/eth2/util/hashing"
//"github.com/protolambda/zrnt/eth2/util/ssz"
)
func xxhash256(input []byte) [32]byte {
var ret [32]byte
hash := xxhash.Sum64(input)
ret[0] = byte(hash & 0xFF)
ret[1] = byte(hash >> 8) & 0xFF
ret[2] = byte(hash >> 16) & 0xFF
ret[3] = byte(hash >> 24) & 0xFF
ret[4] = byte(hash >> 32) & 0xFF
ret[5] = byte(hash >> 40) & 0xFF
ret[6] = byte(hash >> 48) & 0xFF
ret[7] = byte(hash >> 56) & 0xFF
return ret
}
func init() {
helper.SetInputType(helper.INPUT_TYPE_BLOCK_WRAPPER)
/* Uncomment once PySpec can use xxhash */
/*
ssz.InitZeroHashes(xxhash256)
hashing.Hash = xxhash256
hashing.GetHashFn = func() hashing.HashFn {
return xxhash256
}
*/
}
func Fuzz(data []byte) []byte {
blockWrapper, err := helper.DecodeBlockWrapper(data, false)
if err != nil {
panic("Decoding failed")
}
state, err := helper.GetStateByID(blockWrapper.StateID)
if err != nil {
panic("Retrieving state failed")
}
err = transition.StateTransition(&state, &blockWrapper.Block, false)
if err != nil {
return []byte{}
}
return helper.EncodeState(state)
}