celestiaorg / go-square

A library for encoding blobs into a 2D square of evenly sized chunks designed for sampling and reconstruction
Apache License 2.0
13 stars 17 forks source link

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

Open odeke-em opened 2 weeks ago

odeke-em commented 2 weeks ago

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 https://github.com/celestiaorg/go-square/blob/f0bf09056c663a3d6aad93b453bac71665c2dba5/inclusion/blob_share_commitment_rules.go#L84 or simply

SubtreeWidth(2, 0)

Please define what happens when we have a subtreeRootThreshold=0

Version

f0bf09056c663a3d6aad93b453bac71665c2dba5

Steps to Reproduce

Please see above.

Kindly cc-ing @cristaloleg @walldiss @Wondertan

For Admin Use

evan-forbes commented 1 week ago

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 commented 1 week ago

alternatively to panicking, we could pass the app version to https://github.com/celestiaorg/go-square/blob/f0bf09056c663a3d6aad93b453bac71665c2dba5/inclusion/blob_share_commitment_rules.go#L78-L98