Skip to content

Commit

Permalink
chore!: delete FitsInSquare (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze authored Jan 5, 2024
1 parent 1c0eefa commit 0b49c5a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 129 deletions.
23 changes: 0 additions & 23 deletions pkg/inclusion/blob_share_commitment_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,6 @@ import (
"golang.org/x/exp/constraints"
)

// FitsInSquare uses the non interactive default rules to see if blobs of some
// lengths will fit in a square of squareSize starting at share index cursor.
// Returns whether the blobs fit in the square and the number of shares used by
// blobs. See ADR-013 and the blob share commitment rules.
//
// ../../specs/src/specs/data_square_layout.md#blob-share-commitment-rules
func FitsInSquare(cursor, squareSize, subtreeRootThreshold int, blobShareLens ...int) (bool, int) {
if len(blobShareLens) == 0 {
if cursor <= squareSize*squareSize {
return true, 0
}
return false, 0
}
firstBlobLen := 1
if len(blobShareLens) > 0 {
firstBlobLen = blobShareLens[0]
}
// here we account for padding between the compact and sparse shares
cursor = NextShareIndex(cursor, firstBlobLen, subtreeRootThreshold)
sharesUsed, _ := BlobSharesUsedNonInteractiveDefaults(cursor, subtreeRootThreshold, blobShareLens...)
return cursor+sharesUsed <= squareSize*squareSize, sharesUsed
}

// BlobSharesUsedNonInteractiveDefaults returns the number of shares used by a given set
// of blobs share lengths. It follows the blob share commitment rules and
// returns the share indexes for each blob.
Expand Down
106 changes: 0 additions & 106 deletions pkg/inclusion/blob_share_commitment_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,112 +45,6 @@ func TestBlobSharesUsedNonInteractiveDefaults(t *testing.T) {
}
}

func TestFitsInSquare(t *testing.T) {
type test struct {
name string
blobs []int
start int
size int
fits bool
}
tests := []test{
{
name: "1 blobs size 2 shares (2 blob shares, 2 compact, size 4)",
blobs: []int{2},
start: 2,
size: 4,
fits: true,
},
{
name: "10 blobs size 10 shares (100 blob shares, 0 compact, size 4)",
blobs: []int{10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
start: 0,
size: 4,
fits: false,
},
{
name: "15 blobs size 1 share (15 blob shares, 0 compact, size 4)",
blobs: []int{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
start: 0,
size: 4,
fits: true,
},
{
name: "15 blobs size 1 share starting at share 2 (15 blob shares, 2 compact, size 4)",
blobs: []int{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
start: 2,
size: 4,
fits: false,
},
{
name: "8 blobs of various sizes (48 blob shares, 1 compact share, size 8)",
blobs: []int{3, 9, 3, 7, 8, 3, 7, 8},
start: 1,
size: 8,
fits: true,
},
{
// C = compact share
// P = padding share
//
// |C|C|C|C|C|C|P|P|
// |3|3|3|P|9|9|9|9|
// |9|9|9|9|9|P|P|P|
// |3|3|3|P|7|7|7|7|
// |7|7|7|P|8|8|8|8|
// |8|8|8|8|3|3|3|P|
// |7|7|7|7|7|7|7|P|
// |8|8|8|8|8|8|8|8|
name: "8 blobs of various sizes (48 blob shares, 6 compact, size 8)",
blobs: []int{3, 9, 3, 7, 8, 3, 7, 8},
start: 6,
size: 8,
fits: true,
},
{
name: "0 blobs (0 blob shares, 5 compact, size 2)",
blobs: []int{},
start: 5,
size: 2,
fits: false,
},
{
name: "0 blobs (0 blob shares, 4 compact, size 2)",
blobs: []int{},
start: 4,
size: 2,
fits: true,
},
{
name: "0 blobs. Cursor at the the max share index",
blobs: []int{},
start: 16,
size: 4,
fits: true,
},
{
name: "0 blobs. Cursor higher than max share index",
blobs: []int{},
start: 17,
size: 4,
fits: false,
},
{
name: "0 blobs. Cursor higher than max share index (again)",
blobs: []int{},
start: 18,
size: 4,
fits: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
res, _ := inclusion.FitsInSquare(tt.start, tt.size, defaultSubtreeRootThreshold, tt.blobs...)
assert.Equal(t, tt.fits, res)
})
}
}

func TestNextShareIndex(t *testing.T) {
type test struct {
name string
Expand Down

0 comments on commit 0b49c5a

Please sign in to comment.