6
6
eigenpodproofs "github.com/Layr-Labs/eigenpod-proofs-generation"
7
7
"github.com/Layr-Labs/eigenpod-proofs-generation/beacon"
8
8
"github.com/Layr-Labs/eigenpod-proofs-generation/common"
9
+ "github.com/attestantio/go-eth2-client/spec"
9
10
"github.com/attestantio/go-eth2-client/spec/deneb"
10
11
"github.com/attestantio/go-eth2-client/spec/phase0"
11
12
"github.com/stretchr/testify/assert"
@@ -27,10 +28,10 @@ func TestProveValidatorContainers(t *testing.T) {
27
28
t .Fatal (err )
28
29
}
29
30
30
- assert .True (t , verifyStateRootAgainstBlockHeader (t , epp , beaconHeader , beaconState . Deneb , verifyValidatorFieldsCallParams .StateRootProof .Proof ))
31
+ assert .True (t , verifyStateRootAgainstBlockHeader (t , epp , beaconHeader , beaconState , verifyValidatorFieldsCallParams .StateRootProof .Proof ))
31
32
32
33
for i := 0 ; i < len (verifyValidatorFieldsCallParams .ValidatorFields ); i ++ {
33
- assert .True (t , verifyValidatorAgainstBeaconState (t , epp , beaconState . Deneb , verifyValidatorFieldsCallParams .ValidatorFieldsProofs [i ], validatorIndices [i ]))
34
+ assert .True (t , verifyValidatorAgainstBeaconState (t , epp , beaconState , verifyValidatorFieldsCallParams .ValidatorFieldsProofs [i ], validatorIndices [i ]))
34
35
}
35
36
}
36
37
@@ -57,7 +58,7 @@ func TestProveValidatorBalances(t *testing.T) {
57
58
}
58
59
}
59
60
60
- func verifyStateRootAgainstBlockHeader (t * testing.T , epp * eigenpodproofs.EigenPodProofs , oracleBlockHeader * phase0.BeaconBlockHeader , oracleState * deneb. BeaconState , proof common.Proof ) bool {
61
+ func verifyStateRootAgainstBlockHeader (t * testing.T , epp * eigenpodproofs.EigenPodProofs , oracleBlockHeader * phase0.BeaconBlockHeader , oracleState * spec. VersionedBeaconState , proof common.Proof ) bool {
61
62
root , err := oracleBlockHeader .HashTreeRoot ()
62
63
if err != nil {
63
64
t .Fatal (err )
@@ -71,8 +72,18 @@ func verifyStateRootAgainstBlockHeader(t *testing.T, epp *eigenpodproofs.EigenPo
71
72
return common .ValidateProof (root , proof , leaf , beacon .STATE_ROOT_INDEX )
72
73
}
73
74
74
- func verifyValidatorAgainstBeaconState (t * testing.T , epp * eigenpodproofs.EigenPodProofs , oracleState * deneb.BeaconState , proof common.Proof , validatorIndex uint64 ) bool {
75
- leaf , err := oracleState .Validators [validatorIndex ].HashTreeRoot ()
75
+ func verifyValidatorAgainstBeaconState (t * testing.T , epp * eigenpodproofs.EigenPodProofs , oracleState * spec.VersionedBeaconState , proof common.Proof , validatorIndex uint64 ) bool {
76
+ var leaf phase0.Root
77
+ var err error
78
+ switch oracleState .Version {
79
+ case spec .DataVersionElectra :
80
+ leaf , err = oracleState .Electra .Validators [validatorIndex ].HashTreeRoot ()
81
+ case spec .DataVersionDeneb :
82
+ leaf , err = oracleState .Deneb .Validators [validatorIndex ].HashTreeRoot ()
83
+ default :
84
+ t .Fatal ("unsupported beacon state version" )
85
+ }
86
+
76
87
if err != nil {
77
88
t .Fatal (err )
78
89
}
@@ -91,8 +102,18 @@ func verifyValidatorBalancesRootAgainstBlockHeader(t *testing.T, epp *eigenpodpr
91
102
if err != nil {
92
103
t .Fatal (err )
93
104
}
94
- /// TODO: update for pectra
95
- return common .ValidateProof (root , proof .Proof , proof .ValidatorBalancesRoot , beacon .STATE_ROOT_INDEX << beacon .BEACON_STATE_TREE_HEIGHT_DENEB | beacon .BALANCES_INDEX )
105
+
106
+ var beaconStateTreeHeight uint64
107
+ switch beaconState .Version {
108
+ case spec .DataVersionElectra :
109
+ beaconStateTreeHeight = beacon .BEACON_STATE_TREE_HEIGHT_ELECTRA
110
+ case spec .DataVersionDeneb :
111
+ beaconStateTreeHeight = beacon .BEACON_STATE_TREE_HEIGHT_DENEB
112
+ default :
113
+ t .Fatal ("unsupported beacon state version" )
114
+ }
115
+
116
+ return common .ValidateProof (root , proof .Proof , proof .ValidatorBalancesRoot , beacon .STATE_ROOT_INDEX << beaconStateTreeHeight | beacon .BALANCES_INDEX )
96
117
}
97
118
98
119
func verifyValidatorBalanceAgainstValidatorBalancesRoot (t * testing.T , epp * eigenpodproofs.EigenPodProofs , oracleState * deneb.BeaconState , validatorBalancesRoot phase0.Root , proof * eigenpodproofs.BalanceProof , validatorIndex uint64 ) bool {
0 commit comments