Skip to content

MF2-I03: reject reused home channel ID explicitly#766

Merged
philanton merged 3 commits into
fix/audit-findings-finalx2from
fix/nitronode-mf2-i03
May 19, 2026
Merged

MF2-I03: reject reused home channel ID explicitly#766
philanton merged 3 commits into
fix/audit-findings-finalx2from
fix/nitronode-mf2-i03

Conversation

@philanton
Copy link
Copy Markdown
Contributor

Summary

  • After a challenged channel close, issueChallengeRescue() emits a fresh-epoch state with HomeChannelID == nil. The same-home-channel-id check in request_creation() was gated on currentState.HomeChannelID != nil, so when the ledger head was a post-rescue state the explicit reject was skipped and the invariant fell back to the channels.channel_id primary key on CreateChannel.
  • No direct funds risk — duplicate creation still aborts on the PK collision inside the transaction — but the user-facing error is opaque (failed to create channel: duplicate key) and the business rule lives in the storage layer instead of the handler.
  • Patch looks up the channel by computed homeChannelID before CreateChannel and rejects with cannot use same home channel id regardless of prior-state shape. The channel is already initialized guard for non-final prior states with a non-nil HomeChannelID is preserved.

Test plan

  • go test ./nitronode/api/channel_v1/...
  • go vet ./nitronode/api/channel_v1/...
  • New regression TestRequestCreation_RejectReusedHomeChannelID covers post-rescue head (HomeChannelID == nil) with a prior channel record still in channels — must return cannot use same home channel id before reaching CreateChannel/StoreUserState.

🤖 Generated with Claude Code

After a challenged channel close, issueChallengeRescue() emits a fresh-epoch
state with HomeChannelID == nil. The same-home-channel-id check in
request_creation() was gated on currentState.HomeChannelID != nil, so the
invariant was enforced indirectly by the channels.channel_id primary key on
CreateChannel rather than by handler validation. That produced opaque storage
errors instead of a deterministic rejection.

Look up the channel by ID before CreateChannel and reject explicitly,
regardless of prior-state shape.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9b9edf6-e09f-4052-825b-21d42d7ef48c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/nitronode-mf2-i03

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@philanton philanton changed the base branch from main to fix/audit-findings-finalx2 May 18, 2026 12:44
… fix/nitronode-mf2-i03

# Conflicts:
#	nitronode/api/channel_v1/request_creation_test.go
Copy link
Copy Markdown
Contributor

@nksazonov nksazonov left a comment

Choose a reason for hiding this comment

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

Good job! The audit finding is fully addressed with a clean, well-tested fix.

Comment thread nitronode/api/channel_v1/request_creation.go Outdated
Comment thread nitronode/api/channel_v1/request_creation.go
…hannel-lookup error

- Rename the error wrapping GetChannelByID to "failed to look up channel by computed id" so it does not collide in logs with the GetLastUserState wrap.
- Add TestRequestCreation_ChannelAlreadyInitialized covering the prior-state-non-final guard when the computed home channel ID is not yet stored.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@ihsraham ihsraham left a comment

Choose a reason for hiding this comment

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

Thanks for tightening this up. The latest head closes I-03 for me: reused computed home channel IDs are rejected before CreateChannel, including the detached-state case, and the added regression coverage covers the closure path. Approving.

@philanton philanton merged commit 3c63626 into fix/audit-findings-finalx2 May 19, 2026
3 checks passed
@philanton philanton deleted the fix/nitronode-mf2-i03 branch May 19, 2026 08:29
nksazonov added a commit that referenced this pull request May 19, 2026
- MF2-I02: fix: add SESSION_KEY_AUTH_TYPEHASH to session key authorization payload (#767)
- MF2-M02: accept pre-finalize escrow version in ongoing check (#765)                                                                                  
- MF2-L03: docs: document home chain migration as not yet active off-chain (#769)                                                                     
- MF2-I03: reject reused home channel ID explicitly (#766)                                                                                             
- MF2-H03: guard challenge_rescue against post-Finalize close (#768)                                                                                 
- MF2-C02: bound ledger values to Solidity uint256/int256 ranges (#764)                                                                                
- MF2-C01: preserve post-Finalize closing marker across challenge cycle (#762)                                                                         
- MF2-M01: fix(sdk): use keccak256(utf8) for session key application ID hashing (#761)
- MF2-H01: harden receiver-state issuance and dispute resolution (#759)                                                                               
- MF2-L01: gate transfer_send during channel creation (#763)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants