-
Notifications
You must be signed in to change notification settings - Fork 278
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
test: fuzz share commitments #1749
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3aebb0c
test: fuzz share commitments
cmwaters d9875fc
remove fuzzing files
cmwaters ba41200
repurpose numTxs
cmwaters 6b16eb3
Merge branch 'main' into cal/fuzz-share-commitments
cmwaters 0575021
fix benchmarks
cmwaters 94788cc
Merge branch 'main' into cal/fuzz-share-commitments
cmwaters 8e23fa4
fix build
cmwaters 9118f19
Merge branch 'main' into cal/fuzz-share-commitments
cmwaters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ tools-stamp | |
__debug_bin | ||
profile.out | ||
testing/e2e/networks/*/ | ||
square/testdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package square_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/app" | ||
"github.com/celestiaorg/celestia-app/app/encoding" | ||
"github.com/celestiaorg/celestia-app/pkg/appconsts" | ||
"github.com/celestiaorg/celestia-app/pkg/da" | ||
"github.com/celestiaorg/celestia-app/pkg/inclusion" | ||
"github.com/celestiaorg/celestia-app/pkg/shares" | ||
"github.com/celestiaorg/celestia-app/pkg/square" | ||
blob "github.com/celestiaorg/celestia-app/x/blob/types" | ||
"github.com/celestiaorg/rsmt2d" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// FuzzSquare uses fuzzing to test the following: | ||
// - That neither `Construct` or `Reconstruct` panics | ||
// - That `Construct` never errors | ||
// - That `Reconstruct` never errors from the input of `Construct`'s output | ||
// - That both `Construct` and `Reconstruct` return the same square | ||
// - That the square can be extended and a data availability header can be generated | ||
// - That each share commitment in each PFB can be used to verify the inclusion of the blob it corresponds to. | ||
func FuzzSquare(f *testing.F) { | ||
var ( | ||
normalTxCount uint = 12 | ||
pfbCount uint = 91 | ||
blobsPerPfb uint = 2 | ||
blobSize uint = 812 | ||
) | ||
f.Add(normalTxCount, pfbCount, blobsPerPfb, blobSize) | ||
f.Fuzz(func(t *testing.T, normalTxCount, pfbCount, blobsPerPfb, blobSize uint) { | ||
// ignore invalid values | ||
if pfbCount > 0 && (blobSize == 0 || blobsPerPfb == 0) { | ||
t.Skip() | ||
} | ||
txs := generateMixedTxs(int(normalTxCount), int(pfbCount), int(blobsPerPfb), int(blobSize)) | ||
s, orderedTxs, err := square.Build(txs, appconsts.DefaultMaxSquareSize) | ||
require.NoError(t, err) | ||
s2, err := square.Construct(orderedTxs, appconsts.DefaultMaxSquareSize) | ||
require.NoError(t, err) | ||
require.True(t, s.Equals(s2)) | ||
|
||
cacher := inclusion.NewSubtreeCacher(uint64(s.Size())) | ||
eds, err := rsmt2d.ComputeExtendedDataSquare(shares.ToBytes(s), appconsts.DefaultCodec(), cacher.Constructor) | ||
require.NoError(t, err) | ||
dah := da.NewDataAvailabilityHeader(eds) | ||
|
||
decoder := encoding.MakeConfig(app.ModuleEncodingRegisters...).TxConfig.TxDecoder() | ||
|
||
builder, err := square.NewBuilder(appconsts.DefaultMaxSquareSize, orderedTxs...) | ||
require.NoError(t, err) | ||
totalPfbs := builder.NumPFBs() | ||
totalNormalTxs := builder.NumTxs() - totalPfbs | ||
for pfbIndex := 0; pfbIndex < totalPfbs; pfbIndex++ { | ||
wpfb, err := builder.GetWrappedPFB(pfbIndex + totalNormalTxs) | ||
require.NoError(t, err) | ||
tx, err := decoder(wpfb.Tx) | ||
require.NoError(t, err) | ||
|
||
pfb, ok := tx.GetMsgs()[0].(*blob.MsgPayForBlobs) | ||
require.True(t, ok) | ||
|
||
for blobIndex, shareIndex := range wpfb.ShareIndexes { | ||
commitment, err := inclusion.GetCommitment(cacher, dah, int(shareIndex), shares.SparseSharesNeeded(pfb.BlobSizes[blobIndex])) | ||
require.NoError(t, err) | ||
require.Equal(t, pfb.ShareCommitments[blobIndex], commitment) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] an exported function on the builder for normal txs:
builder.NumNormalTxs()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll wait for the need to arise first