Skip to content

Conversation

oooLowNeoNooo
Copy link

Fix inconsistent behavior between bold/math and util/arbmath log2 implementations

  • bold/math.Log2Floor and Log2Ceil were panicking on input 0
  • util/arbmath.Log2ceil was returning 0 for input 0

This inconsistency was causing potential issues in critical code paths like
bold/state-commitments/history/history_commitment.go where Log2Floor is used
for Merkle tree depth calculations.

Changes:

  • Log2Floor and Log2Ceil now return 0 for input 0 (consistent with arbmath.Log2ceil)
  • Updated all tests to reflect new behavior
  • Added documentation explaining the consistency requirement

This change is mathematically sound for tree depth calculations where log2(0) = 0
represents zero depth needed for zero elements.

@eljobe eljobe self-assigned this Sep 22, 2025
Copy link
Member

@eljobe eljobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oooLowNeoNooo, we really only have separate bold.math and arbmath packages because bold used to be in a separate github repository.

Would you consider moving this bold.math package over into arbmath so that we only have one implementation of Log2Ceil across the codebase?

@eljobe eljobe assigned oooLowNeoNooo and unassigned eljobe Sep 22, 2025
@oooLowNeoNooo oooLowNeoNooo requested a review from eljobe October 1, 2025 10:02
@eljobe eljobe assigned eljobe and unassigned oooLowNeoNooo Oct 1, 2025
})
}

func FuzzUnsingedIntegerLog2Floor(f *testing.F) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also bring over the fuzzing and benchmarking tests.

@eljobe eljobe assigned oooLowNeoNooo and unassigned eljobe Oct 1, 2025
@oooLowNeoNooo oooLowNeoNooo requested a review from eljobe October 1, 2025 11:53
@eljobe eljobe assigned eljobe and unassigned oooLowNeoNooo Oct 1, 2025
@eljobe eljobe added this pull request to the merge queue Oct 1, 2025
@eljobe eljobe removed this pull request from the merge queue due to a manual request Oct 1, 2025
@eljobe
Copy link
Member

eljobe commented Oct 1, 2025

Please fix up the lint errors as well.

@eljobe eljobe assigned oooLowNeoNooo and unassigned eljobe Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants