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

[Malleability] QuorumCertificate, TimeoutCertificate, LightCollection, ExecutionResult and Attestation malleability tests. #7029

Open
wants to merge 13 commits into
base: yurii/malleability-check-test
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions engine/execution/ingestion/block_queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package block_queue

import (
"errors"
"math/rand"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -11,6 +12,16 @@ import (
"github.com/onflow/flow-go/utils/unittest"
)

// TestMissingCollectionID_Malleability confirms that the MissingCollection struct, which implements
// the [flow.IDEntity] interface, is resistant to tampering.
func TestMissingCollectionID_Malleability(t *testing.T) {
unittest.RequireEntityNonMalleable(t, &MissingCollection{
BlockID: unittest.IdentifierFixture(),
Height: rand.Uint64(),
Guarantee: unittest.CollectionGuaranteeFixture(),
})
}

func TestSingleBlockBecomeReady(t *testing.T) {
t.Parallel()
// Given a chain
Expand Down
8 changes: 8 additions & 0 deletions model/flow/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ func TestLightCollectionFingerprint(t *testing.T) {
assert.Equal(t, colID, decodedID)
assert.Equal(t, col.Light(), decoded)
}

// TestLightCollectionID_Malleability confirms that the LightCollection struct, which implements
// the [flow.IDEntity] interface, is resistant to tampering.
func TestLightCollectionID_Malleability(t *testing.T) {
unittest.RequireEntityNonMalleable(t, &flow.LightCollection{
Transactions: unittest.IdentifierListFixture(5),
})
}
6 changes: 6 additions & 0 deletions model/flow/execution_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
"github.com/onflow/flow-go/utils/unittest"
)

// TestExecutionResultID_Malleability confirms that the ExecutionResult struct, which implements
// the [flow.IDEntity] interface, is resistant to tampering.
func TestExecutionResultID_Malleability(t *testing.T) {
unittest.RequireEntityNonMalleable(t, unittest.ExecutionResultFixture(unittest.WithServiceEvents(3)))
}

// TestExecutionResultGroupBy tests the GroupBy method of ExecutionResultList:
// * grouping should preserve order and multiplicity of elements
// * group for unknown identifier should be empty
Expand Down
13 changes: 13 additions & 0 deletions model/flow/quorum_certificate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flow_test

import (
"testing"

"github.com/onflow/flow-go/utils/unittest"
)

// TestQuorumCertificateID_Malleability confirms that the QuorumCertificate struct, which implements
// the [flow.IDEntity] interface, is resistant to tampering.
func TestQuorumCertificateID_Malleability(t *testing.T) {
unittest.RequireEntityNonMalleable(t, unittest.QuorumCertificateFixture())
}
6 changes: 6 additions & 0 deletions model/flow/resultApproval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ func TestResultApprovalEncode(t *testing.T) {
id := ra.ID()
assert.NotEqual(t, flow.ZeroID, id)
}

// TestAttestationID_Malleability confirms that the Attestation struct, which implements
// the [flow.IDEntity] interface, is resistant to tampering.
func TestAttestationID_Malleability(t *testing.T) {
unittest.RequireEntityNonMalleable(t, unittest.AttestationFixture())
}
14 changes: 14 additions & 0 deletions model/flow/timeout_certificate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package flow_test

import (
"testing"

"github.com/onflow/flow-go/consensus/hotstuff/helper"
"github.com/onflow/flow-go/utils/unittest"
)

// TestTimeoutCertificateID_Malleability confirms that the TimeoutCertificate struct, which implements
// the [flow.IDEntity] interface, is resistant to tampering.
func TestTimeoutCertificateID_Malleability(t *testing.T) {
unittest.RequireEntityNonMalleable(t, helper.MakeTC())
}
6 changes: 6 additions & 0 deletions utils/unittest/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ func generateCustomFlowValue(field reflect.Value) any {
return flow.ClusterQCVoteDataFromQC(QuorumCertificateWithSignerIDsFixture())
case reflect.TypeOf(flow.QuorumCertificate{}):
return *QuorumCertificateFixture()
case reflect.TypeOf(flow.CollectionGuarantee{}):
return *CollectionGuaranteeFixture()
case reflect.TypeOf(flow.Chunk{}):
return *ChunkFixture(IdentifierFixture(), uint(rand.Uint32()), StateCommitmentFixture())
case reflect.TypeOf(flow.ServiceEvent{}):
return EpochCommitFixture().ServiceEvent()
case reflect.TypeOf(flow.TimeoutCertificate{}):
return flow.TimeoutCertificate{
View: rand.Uint64(),
Expand Down