66 eigenpodproofs "github.com/Layr-Labs/eigenpod-proofs-generation"
77 "github.com/Layr-Labs/eigenpod-proofs-generation/beacon"
88 "github.com/Layr-Labs/eigenpod-proofs-generation/common"
9+ "github.com/attestantio/go-eth2-client/spec"
910 "github.com/attestantio/go-eth2-client/spec/deneb"
1011 "github.com/attestantio/go-eth2-client/spec/phase0"
1112 "github.com/stretchr/testify/assert"
@@ -27,10 +28,10 @@ func TestProveValidatorContainers(t *testing.T) {
2728 t .Fatal (err )
2829 }
2930
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 ))
3132
3233 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 ]))
3435 }
3536}
3637
@@ -57,7 +58,7 @@ func TestProveValidatorBalances(t *testing.T) {
5758 }
5859}
5960
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 {
6162 root , err := oracleBlockHeader .HashTreeRoot ()
6263 if err != nil {
6364 t .Fatal (err )
@@ -71,8 +72,18 @@ func verifyStateRootAgainstBlockHeader(t *testing.T, epp *eigenpodproofs.EigenPo
7172 return common .ValidateProof (root , proof , leaf , beacon .STATE_ROOT_INDEX )
7273}
7374
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+
7687 if err != nil {
7788 t .Fatal (err )
7889 }
@@ -91,8 +102,18 @@ func verifyValidatorBalancesRootAgainstBlockHeader(t *testing.T, epp *eigenpodpr
91102 if err != nil {
92103 t .Fatal (err )
93104 }
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 )
96117}
97118
98119func verifyValidatorBalanceAgainstValidatorBalancesRoot (t * testing.T , epp * eigenpodproofs.EigenPodProofs , oracleState * deneb.BeaconState , validatorBalancesRoot phase0.Root , proof * eigenpodproofs.BalanceProof , validatorIndex uint64 ) bool {
0 commit comments