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

feat(lib/babe): Submit BABE equivocation report #2947

Merged
merged 50 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c4522b8
temp
kishansagathiya Nov 11, 2022
5b3dc4b
temp
kishansagathiya Nov 11, 2022
1a5ab3a
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Nov 14, 2022
cbd819c
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Nov 21, 2022
362c62f
completed submitAndReportEquivocation
kishansagathiya Nov 21, 2022
5659776
cleaning up a few things
kishansagathiya Nov 24, 2022
8dfb3fc
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Nov 24, 2022
7ea0f2f
more cleanup
kishansagathiya Nov 24, 2022
752b038
error wrapping and some linting fixes
kishansagathiya Nov 25, 2022
c0c64c6
generate mocks and fix lint
kishansagathiya Nov 25, 2022
2ed3293
added tests
kishansagathiya Nov 25, 2022
d4e71a2
fixed TestEquivocationProof test
kishansagathiya Dec 8, 2022
1ff1cf0
addressed some comments
kishansagathiya Dec 8, 2022
69d8993
addressed some more comments
kishansagathiya Dec 8, 2022
6d245a3
using actual babe authority value in tests
kishansagathiya Dec 8, 2022
945d115
temp
kishansagathiya Dec 12, 2022
fd94c0d
remove testing residual code
kishansagathiya Dec 13, 2022
22d9192
doing some clean up and addressing some comments
kishansagathiya Dec 14, 2022
567b9fb
fix lint
kishansagathiya Dec 14, 2022
7ab911b
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Dec 14, 2022
585a50b
fixing a remaining test
kishansagathiya Dec 15, 2022
ae98e51
fix more tests and lint
kishansagathiya Dec 15, 2022
7e15401
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Dec 15, 2022
bebffa2
addressed some more comments
kishansagathiya Dec 15, 2022
c203e18
fixing things again
kishansagathiya Dec 15, 2022
7f68dd8
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 4, 2023
8368b5a
fixing some mocks
kishansagathiya Jan 5, 2023
0d3a3ef
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 5, 2023
5cc672d
Update lib/babe/verify_test.go
kishansagathiya Jan 17, 2023
fc26f2b
Update dot/types/equivocation.go
kishansagathiya Jan 17, 2023
cb6ed4d
addressing some of the comments
kishansagathiya Jan 17, 2023
fc04f75
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 17, 2023
a456b10
Merge branch 'kishan/feat/equivocation-report' of github.com:ChainSaf…
kishansagathiya Jan 17, 2023
aea22f1
addressed some more comments
kishansagathiya Jan 18, 2023
a9497e4
addressing review comments
kishansagathiya Jan 18, 2023
a032e8c
addressed more reviews
kishansagathiya Jan 19, 2023
118850b
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 19, 2023
44d4d6e
small test fix
kishansagathiya Jan 19, 2023
221bce1
removed mocks fixed tests
kishansagathiya Jan 19, 2023
6aac073
fixing some mocks
kishansagathiya Jan 19, 2023
cdc4624
extra test and some review comments
kishansagathiya Jan 20, 2023
4ffb952
Update lib/babe/verify.go
kishansagathiya Jan 24, 2023
d720001
ErrAuthIndexOutOfBound
kishansagathiya Jan 24, 2023
5bf5b47
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 24, 2023
1600940
Merge branch 'kishan/feat/equivocation-report' of github.com:ChainSaf…
kishansagathiya Jan 24, 2023
b269e4e
fixing auth index out of bound error
kishansagathiya Jan 25, 2023
a381399
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 25, 2023
b1380f6
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 25, 2023
9ec3058
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 26, 2023
49b415b
Merge branch 'development' into kishan/feat/equivocation-report
kishansagathiya Jan 26, 2023
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
6 changes: 6 additions & 0 deletions dot/core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type RuntimeInstance interface {
DecodeSessionKeys(enc []byte) ([]byte, error)
PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)
CheckInherents()
BabeGenerateKeyOwnershipProof(slot uint64, authorityID [32]byte) (
types.OpaqueKeyOwnershipProof, error)
BabeSubmitReportEquivocationUnsignedExtrinsic(
equivocationProof types.BabeEquivocationProof,
keyOwnershipProof types.OpaqueKeyOwnershipProof,
) error
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
Expand Down
29 changes: 29 additions & 0 deletions dot/core/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dot/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type runtimeInterface interface {
DecodeSessionKeys(enc []byte) ([]byte, error)
PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)
CheckInherents()
BabeGenerateKeyOwnershipProof(slot uint64, offenderPublicKey [32]byte) (types.OpaqueKeyOwnershipProof, error)
BabeSubmitReportEquivocationUnsignedExtrinsic(types.BabeEquivocationProof, types.OpaqueKeyOwnershipProof) error
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
Expand Down
2 changes: 2 additions & 0 deletions dot/rpc/modules/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Runtime interface {
ExecuteBlock(block *types.Block) ([]byte, error)
DecodeSessionKeys(enc []byte) ([]byte, error)
PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)
BabeGenerateKeyOwnershipProof(slot uint64, offenderPublicKey [32]byte) (types.OpaqueKeyOwnershipProof, error)
BabeSubmitReportEquivocationUnsignedExtrinsic(types.BabeEquivocationProof, types.OpaqueKeyOwnershipProof) error
CheckInherents()
RandomSeed()
OffchainWorker()
Expand Down
2 changes: 2 additions & 0 deletions dot/state/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ type Runtime interface {
DecodeSessionKeys(enc []byte) ([]byte, error)
PaymentQueryInfo(ext []byte) (*types.RuntimeDispatchInfo, error)
CheckInherents()
BabeGenerateKeyOwnershipProof(slot uint64, offenderPublicKey [32]byte) (types.OpaqueKeyOwnershipProof, error)
BabeSubmitReportEquivocationUnsignedExtrinsic(types.BabeEquivocationProof, types.OpaqueKeyOwnershipProof) error
RandomSeed()
OffchainWorker()
GenerateSessionKeys()
Expand Down
29 changes: 29 additions & 0 deletions dot/sync/mock_runtime_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions dot/types/equivocation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2023 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package types

import "github.com/ChainSafe/gossamer/lib/crypto/sr25519"

// BabeEquivocationProof represents a babe equivocation proof.
// An equivocation happens when a validator produces more than one block on the same slot.
// The proof of equivocation are the given distinct headers that were signed by the validator
// and which include the slot number.
type BabeEquivocationProof struct {
// Offender is the public key of the equivocator.
Offender AuthorityID
// Slot at which the equivocation happened.
Slot uint64
// FirstHeader is the first header involved in the equivocation.
FirstHeader Header
// SecondHeader is the second header involved in the equivocation.
SecondHeader Header
}

// AuthorityID represents a babe authority identifier.
type AuthorityID [sr25519.PublicKeyLength]byte

// OpaqueKeyOwnershipProof is an opaque type used to represent the key ownership proof at the
// runtime API boundary. The inner value is an encoded representation of the actual key
// ownership proof which will be parameterized when defining the runtime. At
// the runtime API boundary this type is unknown and as such we keep this
// opaque representation, implementers of the runtime API will have to make
// sure that all usages of `OpaqueKeyOwnershipProof` refer to the same type.
type OpaqueKeyOwnershipProof []byte
30 changes: 30 additions & 0 deletions dot/types/equivocation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package types

import (
"testing"

"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/pkg/scale"
"github.com/stretchr/testify/require"
)

func TestEquivocationProof(t *testing.T) {
// To get these bytes run
// https://github.com/paritytech/substrate/blob/17c07af0b953b84dbe89341294e98e586f9b4591/frame/babe/src/tests.rs#L932
expectedEncoding := common.MustHexToBytes("0xdef12e42f3e487e9b14095aa8d5cc16a33491f1b50dadcf8811d1480f3fa86270b0000000000000043fd935464ab466417a2d3b51b750b3047acc94708aa8e69bb01d19e7ba841f428cee631e4d752a4de8130431b63246d695dcc87af881316251bc6d35651f9508a03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c1113140c06424142453402000000000a0000000000000004424142456902010cdef12e42f3e487e9b14095aa8d5cc16a33491f1b50dadcf8811d1480f3fa862701000000000000003a3d45dc55b57bf542f4c6ff41af080ec675317f4ed50ae1d2713bf9f892692d010000000000000054c71c235773b82115f0744252369c13414fd0e8bad3e8feff462c6a4bb58a0f0100000000000000c6e9d02ce38de7b255382f804a64f9bc74aad5597f51fde6bb53c0b8a76c22ba054241424501015881750a61f36303470033d7a9c4d5654ee4d11983ba73008cbe4af8e0361e62b1e67b58236a4258f17ceed53d11e204528238a412eab6ce3476e9d3eb42c18143fd935464ab466417a2d3b51b750b3047acc94708aa8e69bb01d19e7ba841f428cee631e4d752a4de8130431b63246d695dcc87af881316251bc6d35651f9508a03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c1113140c06424142453402000000000a0000000000000004424142456902010cdef12e42f3e487e9b14095aa8d5cc16a33491f1b50dadcf8811d1480f3fa862701000000000000003a3d45dc55b57bf542f4c6ff41af080ec675317f4ed50ae1d2713bf9f892692d010000000000000054c71c235773b82115f0744252369c13414fd0e8bad3e8feff462c6a4bb58a0f0100000000000000c6e9d02ce38de7b255382f804a64f9bc74aad5597f51fde6bb53c0b8a76c22ba05424142450101e4df6a034d5057b1eace2dd4918f2357c5ab0413615596ebee5129fb0fcf146a087c8b3b65d55f76ebf91a77504e334be9b6a36cb836adf58cfd1756b149b689") //nolint:lll

decodedProof := BabeEquivocationProof{
FirstHeader: *NewEmptyHeader(),
SecondHeader: *NewEmptyHeader(),
}

err := scale.Unmarshal(expectedEncoding, &decodedProof)
require.NoError(t, err)

actualEncoding, err := scale.Marshal(decodedProof)
require.NoError(t, err)
require.Equal(t, expectedEncoding, actualEncoding)
}
3 changes: 3 additions & 0 deletions lib/babe/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
)

var (
// ErrAuthIndexOutOfBound is returned when a authority index doesn't exist
ErrAuthIndexOutOfBound = errors.New("authority index doesn't exist")

// ErrBadSlotClaim is returned when a slot claim is invalid
ErrBadSlotClaim = errors.New("could not verify slot claim VRF proof")

Expand Down
Loading