Skip to content

Commit

Permalink
chore: remove the threshold argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Dec 4, 2024
1 parent 7da31af commit a508263
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
3 changes: 2 additions & 1 deletion blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ type Commitment []byte

// Verify takes a data root and verifies if the
// provided proof's subtree roots were committed to the given data root.
func (p *Proof) Verify(dataRoot []byte, subtreeRootThreshold int) (bool, error) {
func (p *Proof) Verify(dataRoot []byte) (bool, error) {
if len(dataRoot) == 0 {
return false, errors.New("root must be non-empty")
}

subtreeRootThreshold := appconsts.SubtreeRootThreshold(appVersion)
if subtreeRootThreshold <= 0 {
return false, errors.New("subtreeRootThreshold must be > 0")
}
Expand Down
2 changes: 1 addition & 1 deletion blob/blob_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ func FuzzCommitmentProofVerify(f *testing.F) {
if commitProof == nil {
return
}
_, _ = commitProof.Verify(val.Root, val.SThreshold)
_, _ = commitProof.Verify(val.Root)
})
}
14 changes: 3 additions & 11 deletions blob/repro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestProofRowProofVerifyWithEmptyRoot(t *testing.T) {
},
}
root := []byte{0xd3, 0x4d, 0x34}
if _, err := cp.Verify(root, 1); err == nil {
if _, err := cp.Verify(root); err == nil {
t.Fatal("expected a non-nil error")
}
}
Expand All @@ -30,7 +30,7 @@ func TestProofRowProofVerify(t *testing.T) {
Proofs: []*merkle.Proof{{}},
},
}
if _, err := cp.Verify(nil, 1); err == nil {
if _, err := cp.Verify(nil); err == nil {
t.Fatal("expected a non-nil error")
}
}
Expand All @@ -43,15 +43,7 @@ func TestCommitmentProofVerifySliceBound(t *testing.T) {
&proof,
},
}
if _, err := cp.Verify(nil, 1); err == nil {
t.Fatal("expected a non-nil error")
}
}

// Reported at https://github.com/celestiaorg/celestia-node/issues/3728.
func TestProofVerifyZeroSubThreshold(t *testing.T) {
cp := new(Proof)
if _, err := cp.Verify(nil, 0); err == nil {
if _, err := cp.Verify(nil); err == nil {
t.Fatal("expected a non-nil error")
}
}
Expand Down
2 changes: 1 addition & 1 deletion blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (s *Service) Included(
if err != nil {
return false, err
}
return proof.Verify(header.DataHash, appconsts.SubtreeRootThreshold(appVersion))
return proof.Verify(header.DataHash)
}

// retrieve retrieves blobs and their proofs by requesting the whole namespace and
Expand Down
16 changes: 5 additions & 11 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestBlobService_Get(t *testing.T) {
assert.True(t, ok)

verifyFn := func(t *testing.T, blob *Blob, proof *Proof) {
valid, err := proof.Verify(header.DataHash, appconsts.SubtreeRootThreshold(appVersion))
valid, err := proof.Verify(header.DataHash)
require.NoError(t, err)
require.True(t, valid)
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestBlobService_Get(t *testing.T) {

header, err := service.headerGetter(ctx, 1)
require.NoError(t, err)
valid, err := proof.Verify(header.DataHash, appconsts.SubtreeRootThreshold(appVersion))
valid, err := proof.Verify(header.DataHash)
require.NoError(t, err)
require.True(t, valid)
},
Expand Down Expand Up @@ -1010,19 +1010,13 @@ func proveAndVerifyShareCommitments(t *testing.T, blobSize int) {
require.NoError(t, err)

// make sure the actual commitment attests to the data
valid, err := actualCommitmentProof.Verify(
dataRoot,
appconsts.DefaultSubtreeRootThreshold,
)
valid, err := actualCommitmentProof.Verify(dataRoot)
require.NoError(t, err)
require.True(t, valid)

// generate an expected proof and verify it's valid
expectedCommitmentProof := generateProofFromBlock(t, eds, nss[msgIndex].Bytes(), blobs[msgIndex], dataRoot)
valid, err = expectedCommitmentProof.Verify(
dataRoot,
appconsts.DefaultSubtreeRootThreshold,
)
valid, err = expectedCommitmentProof.Verify(dataRoot)
require.NoError(t, err)
require.True(t, valid)

Expand Down Expand Up @@ -1219,7 +1213,7 @@ func TestBlobVerify(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
valid, err := test.proof.Verify(test.dataRoot, appconsts.SubtreeRootThreshold(appVersion))
valid, err := test.proof.Verify(test.dataRoot)
if test.expectErr {
assert.Error(t, err)
} else {
Expand Down

0 comments on commit a508263

Please sign in to comment.