refactor: replace is_power_of_ten lookup tables with log10_floor + pow macro#323
Conversation
…w macro Closes #295. Public API unchanged. The new public(package) macro `is_power_of_ten!` in internal/macros.move computes the predicate via the existing log10_floor and std::u256::pow primitives, eliminating the duplicated power-of-ten constants that previously caused the missing 10^77 entry (fixed in #291). Only u128 and u256 wrappers are retargeted per the team's gas-report decision; u8 through u64 keep their inline disjunctions.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis PR replaces hardcoded lookup tables in ChangesPower-of-Ten Computation Refactor
🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CHANGELOG.md`:
- Line 28: Update the CHANGELOG entry for u128::is_power_of_ten and
u256::is_power_of_ten to append the PR reference " (`#323`)" at the end of the
sentence, and apply the proposed wording tweaks: change "lookup table" to
"lookup tables" and "caused" to "led to" so the sentence reads with the PR
reference included and the clearer phrasing. Ensure the public API unchanged
clause remains intact and that the final line ends with the PR reference.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9e5a7b92-6476-4ad8-b33a-0167dc2da0f0
📒 Files selected for processing (7)
CHANGELOG.mdmath/core/sources/internal/macros.movemath/core/sources/u128.movemath/core/sources/u256.movemath/core/tests/macros/is_power_of_ten.movemath/core/tests/u128_tests.movemath/core/tests/u256_tests.move
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #323 +/- ##
==========================================
- Coverage 95.91% 95.88% -0.03%
==========================================
Files 22 22
Lines 2202 2186 -16
Branches 599 591 -8
==========================================
- Hits 2112 2096 -16
Misses 65 65
Partials 25 25
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Nenad <nenad.misic@openzeppelin.com>
immrsd
left a comment
There was a problem hiding this comment.
LGTM!
Pushed couple commits to remove no longer used binary_search helper and add more tests
Summary
public(package) macro fun is_power_of_ten<$Int>ininternal/macros.move. The macro widens the input tou256, short-circuits on zero, and verifiesn == 10^log10_floor(n)using the existinglog10_floorandstd::u256::powprimitives.u128::is_power_of_tenandu256::is_power_of_tennow delegate to the macro. The hardcoded lookup tables (39 entries for u128, 78 entries for u256) are deleted.u8/u16/u32/u64is_power_of_teninline disjunctions are unchanged per the team's gas-report decision.Closes #295.