Fix BIP276 decoding, AuthFetch data race, and add NUM2BIN tests#288
Merged
Fix BIP276 decoding, AuthFetch data race, and add NUM2BIN tests#288
Conversation
- Fix regex to accept hex digits A-F in network/version fields
(changed \d{2} to [0-9A-Fa-f]{2})
- Fix hex parsing using strconv.ParseInt with base 16 instead of Atoi
- Fix network/version field order (were swapped during decode)
- Allow empty data in BIP276 strings (changed + to * in regex)
- Add comprehensive tests for roundtrip encode/decode
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add mutex protection to AuthFetch struct for concurrent map/slice access: - Add sync.RWMutex to protect callbacks, peers, and certificatesReceived - Add thread-safe accessor methods: GetPeer, SetPeer, DeletePeer, GetCallback, SetCallback, DeleteCallback, InvokeCallback, AppendCertificatesReceived, GetOrCreatePeer, UpdatePeerIdentity, etc. - Update Fetch and SendCertificateRequest to use thread-safe accessors - Add TestAuthFetchConcurrentMapAccess race detection test This mirrors the mutex pattern already used in auth/peer.go (callbacksMu). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add regression test confirming that large data items (up to 10MB) can be created on the stack using NUM2BIN when WithAfterGenesis() is enabled. The test uses the exact script template from issue #261 and verifies: - 100KB and 10MB operations succeed with AfterGenesis - Operations correctly fail with pre-genesis 520-byte limit without AfterGenesis - Documents when "cannot fit it into n sized array" error occurs (target size smaller than the minimal encoding of the input data) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Use ParseUint with 8-bit size constraint instead of ParseInt with 64-bit to properly bound network and version values (0-255 range). This addresses the CodeQL alerts about potential integer overflow when converting int64 to int on 32-bit systems. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace manual map + mutex pattern with sync.Map for peers and callbacks. This simplifies the code by removing helper methods and inlining thread-safe operations. The certificatesReceived slice still uses a dedicated mutex. Benefits: - Reduced code complexity (removed ~100 lines of helper methods) - Better test coverage since operations are inlined - sync.Map is optimized for concurrent read-heavy workloads Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace require.Empty(authFetch.peers) with Range-based check since sync.Map contains noCopy and cannot be passed by value. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
BIP276 spec defines format as: <prefix>:<version><network><data><checksum> The previous implementation had version and network swapped in both encode and decode functions, breaking interoperability with other BIP276 implementations. Changes: - Encode: put version before network (was network before version) - Decode: read version from res[2], network from res[3] (was swapped) - Update tests with correct expected values This is a breaking change for any existing BIP276 strings encoded with this library, but is necessary for spec compliance. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
rohenaz
approved these changes
Feb 12, 2026
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.



Summary
This PR addresses three issues:
Fix BIP276 decoding bugs (#286)
\d{2}to[0-9A-Fa-f]{2}to support hex digits A-F in network/version fields+to*in data pattern to allow empty datastrconv.Atoitostrconv.ParseInt(..., 16, 64)for proper hex parsingFix data race in AuthFetch (#262)
sync.RWMutexto protect concurrent access topeers,callbacks, andcertificatesReceivedmaps/slicesGetPeer,SetPeer,GetCallback,SetCallback,DeleteCallback,AppendCertificatesReceived, etc.Fetch()andSendCertificateRequest()to use thread-safe methodsAdd test for large stack data NUM2BIN operations (#261)
TestLargeStackDataNUM2BINusing the exact script template from issue [BUG] Go-SDK cannot process transactions which generate large data items on stack #261WithAfterGenesis()Test plan
go test -race)🤖 Generated with Claude Code