@@ -103,43 +103,54 @@ func ProcessAttestationsNoVerifySignature(
103
103
// used before processing attestation with the beacon state.
104
104
func VerifyAttestationNoVerifySignature (
105
105
ctx context.Context ,
106
- beaconState iface.BeaconState ,
106
+ beaconState iface.ReadOnlyBeaconState ,
107
107
att * ethpb.Attestation ,
108
- ) (iface. BeaconState , error ) {
108
+ ) error {
109
109
ctx , span := trace .StartSpan (ctx , "core.VerifyAttestationNoVerifySignature" )
110
110
defer span .End ()
111
111
112
112
if err := helpers .ValidateNilAttestation (att ); err != nil {
113
- return nil , err
113
+ return err
114
114
}
115
115
currEpoch := helpers .CurrentEpoch (beaconState )
116
116
prevEpoch := helpers .PrevEpoch (beaconState )
117
117
data := att .Data
118
118
if data .Target .Epoch != prevEpoch && data .Target .Epoch != currEpoch {
119
- return nil , fmt .Errorf (
119
+ return fmt .Errorf (
120
120
"expected target epoch (%d) to be the previous epoch (%d) or the current epoch (%d)" ,
121
121
data .Target .Epoch ,
122
122
prevEpoch ,
123
123
currEpoch ,
124
124
)
125
125
}
126
+
127
+ if data .Target .Epoch == currEpoch {
128
+ if ! beaconState .MatchCurrentJustifiedCheckpoint (data .Source ) {
129
+ return errors .New ("source check point not equal to current justified checkpoint" )
130
+ }
131
+ } else {
132
+ if ! beaconState .MatchPreviousJustifiedCheckpoint (data .Source ) {
133
+ return errors .New ("source check point not equal to previous justified checkpoint" )
134
+ }
135
+ }
136
+
126
137
if err := helpers .ValidateSlotTargetEpoch (att .Data ); err != nil {
127
- return nil , err
138
+ return err
128
139
}
129
140
130
141
s := att .Data .Slot
131
142
minInclusionCheck := s + params .BeaconConfig ().MinAttestationInclusionDelay <= beaconState .Slot ()
132
143
epochInclusionCheck := beaconState .Slot () <= s + params .BeaconConfig ().SlotsPerEpoch
133
144
if ! minInclusionCheck {
134
- return nil , fmt .Errorf (
145
+ return fmt .Errorf (
135
146
"attestation slot %d + inclusion delay %d > state slot %d" ,
136
147
s ,
137
148
params .BeaconConfig ().MinAttestationInclusionDelay ,
138
149
beaconState .Slot (),
139
150
)
140
151
}
141
152
if ! epochInclusionCheck {
142
- return nil , fmt .Errorf (
153
+ return fmt .Errorf (
143
154
"state slot %d > attestation slot %d + SLOTS_PER_EPOCH %d" ,
144
155
beaconState .Slot (),
145
156
s ,
@@ -148,28 +159,28 @@ func VerifyAttestationNoVerifySignature(
148
159
}
149
160
activeValidatorCount , err := helpers .ActiveValidatorCount (beaconState , att .Data .Target .Epoch )
150
161
if err != nil {
151
- return nil , err
162
+ return err
152
163
}
153
164
c := helpers .SlotCommitteeCount (activeValidatorCount )
154
165
if uint64 (att .Data .CommitteeIndex ) >= c {
155
- return nil , fmt .Errorf ("committee index %d >= committee count %d" , att .Data .CommitteeIndex , c )
166
+ return fmt .Errorf ("committee index %d >= committee count %d" , att .Data .CommitteeIndex , c )
156
167
}
157
168
158
169
if err := helpers .VerifyAttestationBitfieldLengths (beaconState , att ); err != nil {
159
- return nil , errors .Wrap (err , "could not verify attestation bitfields" )
170
+ return errors .Wrap (err , "could not verify attestation bitfields" )
160
171
}
161
172
162
173
// Verify attesting indices are correct.
163
174
committee , err := helpers .BeaconCommitteeFromState (beaconState , att .Data .Slot , att .Data .CommitteeIndex )
164
175
if err != nil {
165
- return nil , err
176
+ return err
166
177
}
167
178
indexedAtt , err := attestationutil .ConvertToIndexed (ctx , att , committee )
168
179
if err != nil {
169
- return nil , err
180
+ return err
170
181
}
171
182
172
- return nil , attestationutil .IsValidAttestationIndices (ctx , indexedAtt )
183
+ return attestationutil .IsValidAttestationIndices (ctx , indexedAtt )
173
184
}
174
185
175
186
// ProcessAttestationNoVerifySignature processes the attestation without verifying the attestation signature. This
@@ -182,7 +193,7 @@ func ProcessAttestationNoVerifySignature(
182
193
ctx , span := trace .StartSpan (ctx , "core.ProcessAttestationNoVerifySignature" )
183
194
defer span .End ()
184
195
185
- if _ , err := VerifyAttestationNoVerifySignature (ctx , beaconState , att ); err != nil {
196
+ if err := VerifyAttestationNoVerifySignature (ctx , beaconState , att ); err != nil {
186
197
return nil , err
187
198
}
188
199
@@ -201,16 +212,10 @@ func ProcessAttestationNoVerifySignature(
201
212
}
202
213
203
214
if data .Target .Epoch == currEpoch {
204
- if ! beaconState .MatchCurrentJustifiedCheckpoint (data .Source ) {
205
- return nil , errors .New ("source check point not equal to current justified checkpoint" )
206
- }
207
215
if err := beaconState .AppendCurrentEpochAttestations (pendingAtt ); err != nil {
208
216
return nil , err
209
217
}
210
218
} else {
211
- if ! beaconState .MatchPreviousJustifiedCheckpoint (data .Source ) {
212
- return nil , errors .New ("source check point not equal to previous justified checkpoint" )
213
- }
214
219
if err := beaconState .AppendPreviousEpochAttestations (pendingAtt ); err != nil {
215
220
return nil , err
216
221
}
0 commit comments