feat: add separate Bytes API in std/math/uints package for handling bytes (U8) directly#1541
Merged
feat: add separate Bytes API in std/math/uints package for handling bytes (U8) directly#1541
std/math/uints package for handling bytes (U8) directly#1541Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a dedicated Bytes API within the std/math/uints package for direct byte (U8) operations, refactors the existing BinaryField implementation to use the new Bytes helper, and makes the uints constructors cacheable. It also enhances the range checker to handle zero- and one-bit variables directly.
- Add
Bytestype andNewBytesconstructor for byte-level operations with caching instd/math/uints/bytes.go - Refactor
std/math/uints/uint8.goto use the newBytesAPI, updateBinaryField, and deprecate direct rangechecker usage - Update range checker (
std/rangecheck/rangecheck_commit.go) to store theAPIand handle 0- and 1-bit cases - Register uints hints and update hash tests to use
NewBytesandAssertIsEqual
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| std/rangecheck/rangecheck_commit.go | Cache frontend.API in commitChecker and add direct handling for 0/1-bit checks |
| std/math/uints/bytes.go | New Bytes type, NewBytes constructor with caching, bitwise ops, and assertion methods |
| std/math/uints/uint8.go | Refactor U8/U32/U64 and BinaryField to use Bytes, remove inline precomputes |
| std/hints.go | Register hints for the new uints package and additional curve modules |
| std/hash/sha3/sha3_test.go | Switch from uints.New[...] to uints.NewBytes and use AssertIsEqual |
| std/hash/sha2/sha2_test.go | Update constructors and assertions to use the Bytes API |
| std/hash/ripemd160/ripemd160_test.go | Migrate to NewBytes and unified equality assertion |
| internal/kvstore/kvstore_test.go | Adds tests for generic key/value store behavior |
Comments suppressed due to low confidence (2)
std/math/uints/uint8.go:334
- You cannot iterate over an int with
range bf.lenBts(). Either use a traditional for-loop (for j := 0; j < bf.lenBts(); j++) or iterate overretwithfor j := range ret.
for j := range bf.lenBts() {
std/hints.go:50
- The
std/math/uintspackage does not define aGetHintsfunction. You should either implementGetHints()in that package or remove this registration.
solver.RegisterHint(uints.GetHints()...)
ThomasPiellard
previously approved these changes
Jul 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Previously the operations were define over U32 and U64 (as needed or hash functions). But for working directly with bytes didn't allow using boolean operations directly on bytes etc.
Additionally, made the uints API cacheable.
It also resolved #911.
Needed for #1489 refactoring what I'm working on.
Type of change
How has this been tested?
Checklist:
golangci-lintdoes not output errors locally