Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: add sync committee duties to proto #1375

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/eth2signeddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ import (
"github.com/obolnetwork/charon/eth2util/signing"
)

var (
_ Eth2SignedData = VersionedSignedBeaconBlock{}
_ Eth2SignedData = Attestation{}
_ Eth2SignedData = SignedVoluntaryExit{}
_ Eth2SignedData = VersionedSignedBlindedBeaconBlock{}
_ Eth2SignedData = VersionedSignedValidatorRegistration{}
_ Eth2SignedData = SignedRandao{}
_ Eth2SignedData = BeaconCommitteeSelection{}
_ Eth2SignedData = SignedAggregateAndProof{}
_ Eth2SignedData = SignedSyncMessage{}
_ Eth2SignedData = SignedSyncContributionAndProof{}
_ Eth2SignedData = SyncCommitteeSelection{}
)

// VerifyEth2SignedData verifies signature associated with given Eth2SignedData.
func VerifyEth2SignedData(ctx context.Context, eth2Cl eth2wrap.Client, data Eth2SignedData, pubkey *bls_sig.PublicKey) error {
epoch, err := data.Epoch(ctx, eth2Cl)
Expand Down
12 changes: 12 additions & 0 deletions core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ func ParSignedDataFromProto(typ DutyType, data *pbv1.ParSignedData) (ParSignedDa
return ParSignedData{}, errors.Wrap(err, "unmarshal signed sync message")
}
signedData = s
case DutyPrepareSyncContribution:
var s SyncCommitteeSelection
if err := json.Unmarshal(data.Data, &s); err != nil {
return ParSignedData{}, errors.Wrap(err, "unmarshal sync committee selection")
}
signedData = s
case DutySyncContribution:
var s SignedSyncContributionAndProof
if err := json.Unmarshal(data.Data, &s); err != nil {
return ParSignedData{}, errors.Wrap(err, "unmarshal sync contribution and proof")
}
signedData = s
default:
return ParSignedData{}, errors.New("unsupported duty type")
}
Expand Down
39 changes: 20 additions & 19 deletions core/proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"math/rand"
"testing"

"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -81,6 +79,14 @@ func TestParSignedDataSetProto(t *testing.T) {
Type: core.DutySyncMessage,
Data: core.NewSignedSyncMessage(testutil.RandomSyncCommitteeMessage()),
},
{
Type: core.DutyPrepareSyncContribution,
Data: core.NewSyncCommitteeSelection(testutil.RandomSyncCommitteeSelection()),
},
{
Type: core.DutySyncContribution,
Data: core.NewSignedSyncContributionAndProof(testutil.RandomSignedSyncContributionAndProof()),
},
}
for _, test := range tests {
t.Run(test.Type.String(), func(t *testing.T) {
Expand Down Expand Up @@ -132,6 +138,10 @@ func TestUnsignedDataToProto(t *testing.T) {
Type: core.DutyAggregator,
Data: core.NewAggregatedAttestation(testutil.RandomAttestation()),
},
{
Type: core.DutySyncContribution,
Data: core.NewSyncContribution(testutil.RandomSyncCommitteeContribution()),
},
}

for _, test := range tests {
Expand Down Expand Up @@ -221,22 +231,13 @@ func randomSignedData(t *testing.T) map[core.DutyType]core.SignedData {
t.Helper()

return map[core.DutyType]core.SignedData{
core.DutyAttester: core.Attestation{Attestation: *testutil.RandomAttestation()},
core.DutyExit: core.SignedVoluntaryExit{SignedVoluntaryExit: *testutil.RandomExit()},
core.DutyRandao: core.SignedRandao{eth2util.SignedEpoch{Epoch: testutil.RandomEpoch(), Signature: testutil.RandomEth2Signature()}},
core.DutyProposer: core.VersionedSignedBeaconBlock{
VersionedSignedBeaconBlock: spec.VersionedSignedBeaconBlock{
Version: spec.DataVersionBellatrix,
Bellatrix: &bellatrix.SignedBeaconBlock{
Message: testutil.RandomBellatrixBeaconBlock(t),
Signature: testutil.RandomEth2Signature(),
},
},
},
core.DutyPrepareAggregator: testutil.RandomCoreBeaconCommitteeSelection(),
core.DutyAggregator: core.SignedAggregateAndProof{SignedAggregateAndProof: eth2p0.SignedAggregateAndProof{
Message: testutil.RandomAggregateAndProof(),
Signature: testutil.RandomEth2Signature(),
}},
core.DutyAttester: core.NewAttestation(testutil.RandomAttestation()),
core.DutyExit: core.NewSignedVoluntaryExit(testutil.RandomExit()),
core.DutyRandao: core.SignedRandao{eth2util.SignedEpoch{Epoch: testutil.RandomEpoch(), Signature: testutil.RandomEth2Signature()}},
core.DutyProposer: testutil.RandomCoreVersionSignedBeaconBlock(t),
core.DutyPrepareAggregator: testutil.RandomCoreBeaconCommitteeSelection(),
core.DutyAggregator: core.NewSignedAggregateAndProof(testutil.RandomSignedAggregateAndProof()),
core.DutyPrepareSyncContribution: core.NewSyncCommitteeSelection(testutil.RandomSyncCommitteeSelection()),
core.DutySyncContribution: core.NewSignedSyncContributionAndProof(testutil.RandomSignedSyncContributionAndProof()),
}
}
1 change: 1 addition & 0 deletions core/signeddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
_ SignedData = SignedAggregateAndProof{}
_ SignedData = SignedSyncMessage{}
_ SignedData = SignedSyncContributionAndProof{}
_ SignedData = SyncCommitteeSelection{}
)

// SigFromETH2 returns a new signature from eth2 phase0 BLSSignature.
Expand Down
4 changes: 4 additions & 0 deletions core/signeddata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func TestSignedDataSetSignature(t *testing.T) {
name: "signed sync contribution",
data: core.NewSignedSyncContributionAndProof(testutil.RandomSignedSyncContributionAndProof()),
},
{
name: "signed sync committee selection",
data: core.NewSyncCommitteeSelection(testutil.RandomSyncCommitteeSelection()),
},
}

for _, test := range tests {
Expand Down
7 changes: 7 additions & 0 deletions core/unsigneddata.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ func UnmarshalUnsignedData(typ DutyType, data []byte) (UnsignedData, error) {
return nil, errors.Wrap(err, "unmarshal aggregated attestation")
}

return resp, nil
case DutySyncContribution:
var resp SyncContribution
if err := json.Unmarshal(data, &resp); err != nil {
return nil, errors.Wrap(err, "unmarshal sync contribution")
}

return resp, nil
default:
return nil, errors.New("unsupported unsigned data duty type")
Expand Down