File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package fuzz
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
6
7
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
7
8
stateutil "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
@@ -34,6 +35,7 @@ func BeaconStateFuzz(input []byte) {
34
35
if err != nil {
35
36
panic (err )
36
37
}
38
+ validateStateHTR (s )
37
39
nextEpoch := helpers .SlotToEpoch (s .Slot ()) + 1
38
40
slot , err := helpers .StartSlot (nextEpoch )
39
41
if err != nil {
@@ -43,4 +45,27 @@ func BeaconStateFuzz(input []byte) {
43
45
_ = err
44
46
return
45
47
}
48
+ validateStateHTR (s )
49
+ }
50
+
51
+ func validateStateHTR (s * stateV0.BeaconState ) {
52
+ rawState , ok := s .InnerStateUnsafe ().(* pb.BeaconState )
53
+ if ! ok {
54
+ panic ("non valid type assertion" )
55
+ }
56
+ rt , err := s .HashTreeRoot (context .Background ())
57
+ nxtRt , err2 := rawState .HashTreeRoot ()
58
+
59
+ if err == nil && err2 != nil {
60
+ panic ("HTR from state had only and error from cached state HTR method" )
61
+ }
62
+ if err != nil && err2 == nil {
63
+ panic ("HTR from state had only and error from fast-ssz HTR method" )
64
+ }
65
+ if err != nil && err2 != nil {
66
+ return
67
+ }
68
+ if rt != nxtRt {
69
+ panic (fmt .Sprintf ("cached HTR gave a root of %#x while fast-ssz gave a root of %#x" , rt , nxtRt ))
70
+ }
46
71
}
You can’t perform that action at this time.
0 commit comments