fix(btcindexer): validate Sui recipient address in OP_RETURN#350
Merged
fix(btcindexer): validate Sui recipient address in OP_RETURN#350
Conversation
Signed-off-by: sczembor <stanislaw.czembor@gmail.com>
Contributor
Reviewer's GuideAdds validation logic for Sui recipient addresses parsed from OP_RETURN outputs and expands unit test coverage to verify correct behavior for valid and invalid scripts, including fixture updates to match the new validation rules. Class diagram for btcindexer Sui OP_RETURN parsing utilitiesclassDiagram
class BtcIndexerModule {
+parseSuiRecipientFromOpReturn(script Buffer) string_or_null
+isValidSuiAddress(address string) bool
}
class parseSuiRecipientFromOpReturn {
+script Buffer
+return string_or_null
}
class isValidSuiAddress {
+address string
+return bool
}
BtcIndexerModule --> parseSuiRecipientFromOpReturn
BtcIndexerModule --> isValidSuiAddress
parseSuiRecipientFromOpReturn ..> isValidSuiAddress
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
sczembor
commented
Feb 9, 2026
Signed-off-by: sczembor <43810037+sczembor@users.noreply.github.com>
Contributor
Author
|
@sourcery-ai title |
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `packages/btcindexer/src/btcindexer.ts:1312-1317` </location>
<code_context>
// Check simple transfer format: 1-byte flag (0x00)
- // TODO: add validation for the sui address
if (payload[0] === 0x00) {
const addressBytes = payload.subarray(1);
- return `0x${addressBytes.toString("hex")}`;
+ if (addressBytes.length !== 32) {
+ return null;
+ }
+ const address = `0x${addressBytes.toString("hex")}`;
+ if (!isValidSuiAddress(address)) {
+ return null;
+ }
</code_context>
<issue_to_address>
**suggestion:** Avoid hardcoding the 32-byte address length; use a named constant for maintainability and consistency.
This `32` is a protocol-level constant and already assumed elsewhere (e.g., `Buffer.alloc(32, …)` in tests). Please introduce a named constant like `const SUI_ADDRESS_NUM_BYTES = 32;` and reuse it here and anywhere else this assumption appears to keep things consistent and easier to update if the address size changes.
Suggested implementation:
```typescript
import { logError, logger } from "@gonative-cc/lib/logger";
import { isValidSuiAddress } from "@mysten/sui/utils";
import { OP_RETURN } from "./opcodes";
import { BitcoinMerkleTree } from "./bitcoin-merkle-tree";
import { SuiClient, type SuiClientI } from "./sui_client";
const SUI_ADDRESS_NUM_BYTES = 32;
const payload = script.subarray(2);
// Check simple transfer format: 1-byte flag (0x00)
if (payload[0] === 0x00) {
const addressBytes = payload.subarray(1);
if (addressBytes.length !== SUI_ADDRESS_NUM_BYTES) {
return null;
}
```
```typescript
const address = `0x${addressBytes.toString("hex")}`;
if (!isValidSuiAddress(address)) {
return null;
}
return address;
}
//TODO: in the future we need to update the relayer to correctly handle the flag 0x01
// for now we cannot determine the recipient
```
You should also:
1. Search this file (and possibly related modules) for other occurrences where the Sui address length is assumed as `32` (e.g., `Buffer.alloc(32, ...)`, `new Uint8Array(32)`, or length checks) and replace those with `SUI_ADDRESS_NUM_BYTES` for consistency.
2. In tests that construct or assert on 32-byte Sui addresses (e.g., `Buffer.alloc(32, ...)`), introduce and reuse the same constant (or import it from a shared module) to keep test expectations aligned with the production constant.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
robert-zaremba
approved these changes
Feb 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses #340 by validating Sui recipient addresses extracted from Bitcoin OP_RETURN outputs in the BTC indexer, preventing malformed/invalid Sui addresses from being accepted during deposit parsing.
Changes:
- Add Sui address validation (
isValidSuiAddress) when parsing recipient data fromOP_RETURN. - Update regtest fixture block/tx data to use the strictly validated Sui address encoding.
- Add unit tests for
parseSuiRecipientFromOpReturncovering invalid scripts/flags/lengths and valid extraction.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/btcindexer/src/btcindexer.ts |
Validates parsed Sui recipient with isValidSuiAddress before accepting OP_RETURN payloads. |
packages/btcindexer/src/btcindexer.test.ts |
Updates regtest fixture data and adds unit tests for parseSuiRecipientFromOpReturn. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: sczembor <43810037+sczembor@users.noreply.github.com>
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
Closes: #340
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!to the type prefix if API or client breaking changeCHANGELOG.mdSummary by Sourcery
Validate Sui recipient addresses extracted from Bitcoin OP_RETURN outputs and expand test coverage for parseSuiRecipientFromOpReturn.
Bug Fixes:
Enhancements:
Tests: