fix(token-2022): enforce transfer-hook checks in free pricing#423
fix(token-2022): enforce transfer-hook checks in free pricing#423
Conversation
📊 TypeScript Coverage ReportCoverage: 33.9% View detailed reportCoverage artifacts have been uploaded to this workflow run. |
Greptile SummaryThis PR closes a security gap where the free price model skipped Token-2022 transfer-hook mutability validation by moving the check above the price-model branching in
Confidence Score: 4/5Safe to merge after resolving the estimateTransactionFee / signAndSendTransaction flow mismatch (P1). The core fix is correct and well-tested. One P1 defect exists: estimateTransactionFee hardcodes DelayedSigning, producing false validation errors for clients calling it before signAndSendTransaction on mutable-hook mints under the default policy. The two P2 issues are style-only and do not affect runtime behavior. crates/lib/src/rpc_server/method/estimate_transaction_fee.rs — hardcoded TransferHookValidationFlow::DelayedSigning on line 84.
|
| Filename | Overview |
|---|---|
| crates/lib/src/fee/fee.rs | Core fix: estimate_kora_fee now calls validate_token2022_transfer_hooks_in_transaction before price-model branching, closing the free-mode bypass. Logic and tests are correct. |
| crates/lib/src/rpc_server/method/estimate_transaction_fee.rs | Hardcodes TransferHookValidationFlow::DelayedSigning, causing false validation errors when clients call estimateTransactionFee on mutable-hook transactions they intend to send via signAndSendTransaction (P1). |
| crates/lib/src/token/token.rs | New validate_token2022_transfer_hooks_in_transaction correctly deduplicates mint checks, resolves legacy transfer mints via source account, and respects the configurable TransferHookPolicy. |
| crates/lib/src/config.rs | Adds TransferHookPolicy enum and transfer_hook_policy field to Token2022Config; struct-level #[serde(default)] added, making field-level default on transfer_hook_policy redundant (P2). |
| crates/lib/src/bundle/helper.rs | Correctly infers TransferHookValidationFlow from PluginExecutionContext and threads it into estimate_kora_fee for bundle processing. |
| tests/free_signing/free_signing_tests.rs | Adds regression tests for mutable-hook rejection in free signTransaction and allowing in signAndSendTransaction; helper correctly builds a mutable-authority mint with transfer hook. |
| tests/tokens/token_2022_extensions_test.rs | Existing transfer-hook tests updated to use signAndSendTransaction for the allow-path, correctly reflecting the new policy default. |
| crates/lib/src/transaction/versioned_transaction.rs | Sets TransferHookValidationFlow based on will_send flag before calling estimate_kora_fee, cleanly mapping signTransaction → DelayedSigning and signAndSendTransaction → ImmediateSignAndSend. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Client Request] --> B{RPC Method}
B -->|signTransaction| C[DelayedSigning]
B -->|signAndSendTransaction| D[ImmediateSignAndSend]
B -->|estimateTransactionFee| E[DelayedSigning HARDCODED]
B -->|signBundle| F[DelayedSigning]
B -->|signAndSendBundle| G[ImmediateSignAndSend]
C --> H[estimate_kora_fee]
D --> H
E --> H
F --> H
G --> H
H --> I[validate_token2022_transfer_hooks]
I --> J{TransferHookPolicy}
J -->|DenyAll| K[Always reject mutable hook]
J -->|DenyMutableForDelayedSigning| L{Flow type?}
J -->|AllowAll| M[Always allow]
L -->|DelayedSigning| N[Reject mutable hook]
L -->|ImmediateSignAndSend| O[Allow mutable hook]
H --> P{Price Model}
P -->|Free| Q[Return 0 fee]
P -->|Fixed or Margin| R[Calculate fee]
Reviews (2): Last reviewed commit: "test(token-2022): add transfer-hook poli..." | Re-trigger Greptile
|
Tip: Greploops — Automatically fix all review issues by running Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal. |
Run Token-2022 transfer-hook authority validation before price-model branching so free and paid flows enforce the same guard.\n\nReuse shared mint-level validation logic and add regression tests covering free mode rejection/allow paths.
404d6ca to
c9c664a
Compare
Summary
Test Plan (if applicable)
Breaking Changes (if applicable)
📊 Unit Test Coverage
Unit Test Coverage: 85.2%
View Detailed Coverage Report