-
Notifications
You must be signed in to change notification settings - Fork 42
Safer intent GetOutpoints #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughRegisterIntent now rejects proofs that contain no inputs. Proof.GetOutpoints returns an empty slice when a PSBT has one or zero inputs. Tests added for GetOutpoints covering zero- and one-input PSBTs. Changes
Sequence Diagram(s)sequenceDiagram
participant Service as RegisterIntent
participant Proof as Proof.GetOutpoints
participant DB as IntentStore
Service->>Proof: call GetOutpoints(proof)
alt UnsignedTx inputs ≤ 1
Proof-->>Service: return []
Service->>Service: return INVALID_INTENT_PSBT (proof misses inputs, include TxID)
else UnsignedTx inputs > 1
Proof-->>Service: return outpoints[]
Service->>DB: continue intent registration with outpoints
DB-->>Service: ack
Service-->>Client: success
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
internal/core/application/service.go(1 hunks)pkg/ark-lib/intent/proof.go(1 hunks)pkg/ark-lib/intent/proof_test.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
pkg/ark-lib/intent/proof_test.go (1)
pkg/ark-lib/intent/proof.go (1)
Proof(41-43)
internal/core/application/service.go (2)
pkg/errors/errors.go (2)
INVALID_INTENT_PSBT(290-290)PsbtMetadata(111-113)pkg/ark-lib/intent/proof.go (1)
New(136-160)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: unit tests
- GitHub Check: integration tests
- GitHub Check: Build and Scan
🔇 Additional comments (2)
pkg/ark-lib/intent/proof.go (1)
165-167: LGTM: Proper guard against insufficient inputs.The guard correctly handles edge cases where the PSBT has no inputs or only the toSpend input. Since the first input is always the toSpend transaction (as verified in the
Verifyfunction), returning an empty slice whenlen(p.UnsignedTx.TxIn) <= 1is the appropriate behavior.pkg/ark-lib/intent/proof_test.go (1)
11-33: LGTM: Well-structured tests for edge cases.The tests properly cover the boundary conditions:
- Zero inputs: validates that an empty PSBT returns no outpoints
- One input: validates that a PSBT with only the toSpend input returns no outpoints
These tests ensure the guard clause in
GetOutpoints()works correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
pkg/ark-lib/intent/proof.go (1)
165-167: LGTM! Defensive guard prevents panic and aligns with validation logic.This guard correctly handles edge cases where the PSBT has insufficient inputs. Since input 0 is the toSpend transaction, returning
nilwhenlen <= 1accurately reflects that no real user inputs exist. It also prevents a panic at line 168 whenlen == 0would cause a negative slice capacity.Optional: Enhance method documentation for clarity.
Consider updating the method comment to explicitly document the
nilreturn case:// GetOutpoints returns the list of inputs proving ownership of coins -// the first input is the toSpend tx, we ignore it +// the first input is the toSpend tx, we ignore it. +// Returns nil if there are no real user inputs (0 or 1 total inputs). func (p Proof) GetOutpoints() []wire.OutPoint {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
internal/core/application/service.go(1 hunks)pkg/ark-lib/intent/proof.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/core/application/service.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Build and Scan
- GitHub Check: integration tests
- GitHub Check: unit tests
Make sure
RegisterIntentfails in case of zero-input psbt is passed.@altafan please review
Summary by CodeRabbit
Bug Fixes
Tests