fix(client): stop signing on GetRawData failure; keep RecoverPubkey pure - #298
Conversation
Propagate GetRawData errors instead of calling ledger.SignTx on a bad payload, wrap tx-hash errors with %w, and copy signatures before V normalization so recovery cannot mutate the caller's slice.
📝 WalkthroughWalkthroughTransaction signing now validates raw data and preserves raw-data and transaction-hash errors with context. Nil and empty transaction data return errors. Public-key recovery copies signatures before normalization. Regression tests cover these behaviors. ChangesTransaction integrity
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/client/transaction/controller.go`:
- Around line 115-121: Update GetRawData and the ledger-signing path around
hardwareSignTxForSending to reject transactions whose serialized raw data is nil
or zero-length, including &core.Transaction{}. Preserve the existing error
propagation and prevent ledger.SignTx from receiving an empty payload. Add
regression coverage for GetRawData and Ledger signing with an empty transaction.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 52ec9194-3ba7-4272-abd2-ed6bde912ecf
📒 Files selected for processing (4)
pkg/client/transaction/controller.gopkg/client/transaction/controller_test.gopkg/keystore/crypto_internal_test.gopkg/keystore/recover.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #298 +/- ##
==========================================
+ Coverage 82.77% 82.92% +0.15%
==========================================
Files 77 77
Lines 6333 6348 +15
==========================================
+ Hits 5242 5264 +22
+ Misses 785 779 -6
+ Partials 306 305 -1
🚀 New features to boost your workflow:
|
GetRawData previously marshaled missing RawData to empty bytes with no error, so hardware signing could still target an empty payload. Fail closed and cover empty-transaction cases in tests.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/client/transaction/controller_test.go (1)
425-443: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a table-driven test for invalid raw-data cases.
These tests repeat the setup and assertions. Combine them into one table-driven test with the transaction fixture and expected error as fields. This follows the repository rule to use table-driven tests.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/client/transaction/controller_test.go` around lines 425 - 443, The separate TestGetRawData_NilRawData and TestGetRawData_EmptyRawData tests duplicate setup and assertions; combine them into one table-driven test with cases containing the transaction fixture and expected error substring. Iterate over the cases with subtests, preserving the existing error and nil-raw assertions for both invalid RawData scenarios.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/client/transaction/controller_test.go`:
- Around line 425-443: The separate TestGetRawData_NilRawData and
TestGetRawData_EmptyRawData tests duplicate setup and assertions; combine them
into one table-driven test with cases containing the transaction fixture and
expected error substring. Iterate over the cases with subtests, preserving the
existing error and nil-raw assertions for both invalid RawData scenarios.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 59df1a00-52cc-4581-8b4c-64eeb2af8d06
📒 Files selected for processing (2)
pkg/client/transaction/controller.gopkg/client/transaction/controller_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- pkg/client/transaction/controller.go
Summary
Closes remediation roadmap PR-6 (findings W50, W55): signing-path integrity bugs that produced wrong signatures or mutated caller data without errors.
hardwareSignTxForSendingno longer discardsGetRawDataerrors (which previously allowedledger.SignTxon a nil/empty payload).txConfirmationwraps hash failures with%winstead of replacing the cause.GetRawDatareturns a clear error for a nil transaction.RecoverPubkeycopies the 65-byte signature before Ethereum-style V normalization so callers can re-verify, serialize, or broadcast the original bytes.Test plan
go test ./pkg/client/transaction/ ./pkg/keystore/ -count=1errors.Unwrap; RecoverPubkey non-mutation with high VSummary by CodeRabbit
Bug Fixes
Tests