Skip to content

Commit

Permalink
Fixed VerifyIndexedAttestation (#4382)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored and prestonvanloon committed Jan 1, 2020
1 parent 6039fed commit b3c09b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions beacon-chain/core/blocks/block_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/binary"
"fmt"
"reflect"
"sort"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -702,11 +703,11 @@ func VerifyIndexedAttestation(ctx context.Context, beaconState *pb.BeaconState,
setIndices = append(setIndices, i)
set[i] = true
}
sorted := sort.SliceIsSorted(setIndices, func(i, j int) bool {
sort.SliceStable(setIndices, func(i, j int) bool {
return setIndices[i] < setIndices[j]
})
if !sorted {
return fmt.Errorf("attesting indices are not sorted, got %v", sorted)
if !reflect.DeepEqual(setIndices, indices) {
return errors.New("attesting indices is not uniquely sorted")
}

domain := helpers.Domain(beaconState.Fork, indexedAtt.Data.Target.Epoch, params.BeaconConfig().DomainBeaconAttester)
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/core/blocks/block_operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,23 +1210,23 @@ func TestVerifyIndexedAttestation_OK(t *testing.T) {
Epoch: 1,
},
},
AttestingIndices: []uint64{47, 99, 99},
AttestingIndices: []uint64{47, 99, 101},
}},
{attestation: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{
Epoch: 4,
},
},
AttestingIndices: []uint64{21, 72, 21},
AttestingIndices: []uint64{21, 72},
}},
{attestation: &ethpb.IndexedAttestation{
Data: &ethpb.AttestationData{
Target: &ethpb.Checkpoint{
Epoch: 7,
},
},
AttestingIndices: []uint64{100, 121, 100, 121},
AttestingIndices: []uint64{100, 121, 122},
}},
}

Expand Down

0 comments on commit b3c09b7

Please sign in to comment.