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

inclusion: SubtreeWidth should define what happens when subtreeRootThreshold<=0 else a divide by zero panic on #120

Open
4 tasks
odeke-em opened this issue Oct 25, 2024 · 2 comments
Labels
bug Something isn't working external

Comments

@odeke-em
Copy link
Contributor

Summary of Bug

Found by fuzzing in less than 2 minutes and even on CI/CD per https://github.com/celestiaorg/go-square/actions/runs/11515786009/job/32057128298?pr=119, we have a divide by zero at

s := (shareCount / subtreeRootThreshold)

or simply

SubtreeWidth(2, 0)

Please define what happens when we have a subtreeRootThreshold=0

Version

f0bf090

Steps to Reproduce

Please see above.

Kindly cc-ing @cristaloleg @walldiss @Wondertan

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@evan-forbes
Copy link
Member

evan-forbes commented Oct 28, 2024

the constant is consensus critical, so any tx or node that has a different value will have different blob share commitments and different data roots

therefore its safe to panic if a negative value is used, although I don't think we need to add if statements that check for this everywhere given its consensus critical

@evan-forbes
Copy link
Member

alternatively to panicking, we could pass the app version to

// SubTreeWidth returns the maximum number of leaves per subtree in the share
// commitment over a given blob. The input should be the total number of shares
// used by that blob. See ADR-013.
func SubTreeWidth(shareCount, subtreeRootThreshold int) int {
// Per ADR-013, we use a predetermined threshold to determine width of sub
// trees used to create share commitments
s := (shareCount / subtreeRootThreshold)
// round up if the width is not an exact multiple of the threshold
if shareCount%subtreeRootThreshold != 0 {
s++
}
// use a power of two equal to or larger than the multiple of the subtree
// root threshold
s = RoundUpPowerOfTwo(s)
// use the minimum of the subtree width and the min square size, this
// gurarantees that a valid value is returned
return min(s, BlobMinSquareSize(shareCount))
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external
Projects
None yet
Development

No branches or pull requests

2 participants