@@ -113,7 +113,42 @@ func TestProcessBLSToExecutionChange(t *testing.T) {
113
113
require .NoError (t , err )
114
114
require .DeepEqual (t , digest [:], val .WithdrawalCredentials )
115
115
})
116
+ t .Run ("nil validator does not panic" , func (t * testing.T ) {
117
+ priv , err := bls .RandKey ()
118
+ require .NoError (t , err )
119
+ pubkey := priv .PublicKey ().Marshal ()
116
120
121
+ message := & ethpb.BLSToExecutionChange {
122
+ ToExecutionAddress : []byte {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 , 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0x10 , 0x11 , 0x12 , 0x13 },
123
+ ValidatorIndex : 0 ,
124
+ FromBlsPubkey : pubkey ,
125
+ }
126
+
127
+ registry := []* ethpb.Validator {
128
+ nil ,
129
+ }
130
+ st , err := state_native .InitializeFromProtoPhase0 (& ethpb.BeaconState {
131
+ Validators : registry ,
132
+ Fork : & ethpb.Fork {
133
+ CurrentVersion : params .BeaconConfig ().GenesisForkVersion ,
134
+ PreviousVersion : params .BeaconConfig ().GenesisForkVersion ,
135
+ },
136
+ Slot : params .BeaconConfig ().SlotsPerEpoch * 5 ,
137
+ })
138
+ require .NoError (t , err )
139
+
140
+ signature , err := signing .ComputeDomainAndSign (st , time .CurrentEpoch (st ), message , params .BeaconConfig ().DomainBLSToExecutionChange , priv )
141
+ require .NoError (t , err )
142
+
143
+ signed := & ethpb.SignedBLSToExecutionChange {
144
+ Message : message ,
145
+ Signature : signature ,
146
+ }
147
+ _ , err = blocks .ValidateBLSToExecutionChange (st , signed )
148
+ // The state should return an empty validator, even when the validator object in the registry is
149
+ // nil. This error should return when the withdrawal credentials are invalid or too short.
150
+ require .ErrorIs (t , err , blocks .ErrInvalidBLSPrefix )
151
+ })
117
152
t .Run ("non-existent validator" , func (t * testing.T ) {
118
153
priv , err := bls .RandKey ()
119
154
require .NoError (t , err )
0 commit comments