fix: restore gas padding for delegated Privy transactions#598
Conversation
estimateAndBuildTxBody (used by PrivyWalletProvider.sendTransaction) estimates gas without any buffer since commit 6b98685 removed the gasPadding option. This causes delegated Privy/social-login transactions to revert with ~96% gas usage — the raw estimate is too tight for the actual execution cost of executeBatchWithAuthorization calls. This is not overridable from consumer projects: - PrivyWalletProvider.sendTransaction() does not accept a gasPadding param - useSendTransaction silently drops gasPadding for the Privy code path - Gas estimation is entirely internal to estimateAndBuildTxBody Observed on-chain (VeChain mainnet): - Without padding: gas limit ~890K, used ~854K (96%), reverted - With padding restored: gas limit ~1.8M, used ~823K (46%), success - VTHO cost is identical since VeChain charges on gas used, not limit Restores the original { gasPadding: 1 } that was present before 6b98685.
👋 Thanks for your contribution!Since this PR comes from a forked repository, the lint and build will only run for internal PRs for security reasons. Thank you for your patience! 🙏 |
📝 WalkthroughWalkthroughA single parameter ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
🧹 Nitpick comments (1)
packages/vechain-kit/src/hooks/generic-delegator/useGenericDelegator.ts (1)
86-90: LGTM! Consider adding an explanatory comment.The restoration of
gasPadding: 1is correct and necessary for delegated Privy transactions to avoid gas-related reverts. Since this hardcoded value differs from the conditional pattern inuseSendTransaction(which only applies padding when explicitly requested), a brief comment would help future maintainers understand why it's always applied here.📝 Suggested comment for clarity
const gasResult = await thor.gas.estimateGas( clauses, randomTransactionUser?.address ?? '', + // gasPadding: 1 doubles the gas estimate, required for delegated transactions + // (e.g., executeBatchWithAuthorization) that need extra headroom beyond base estimation { gasPadding: 1 }, );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vechain-kit/src/hooks/generic-delegator/useGenericDelegator.ts` around lines 86 - 90, Add a brief explanatory comment above the thor.gas.estimateGas call in useGenericDelegator.ts (the block that computes gasResult) clarifying that gasPadding: 1 is intentionally hardcoded for delegated Privy transactions to prevent gas-related reverts, and note why this differs from the conditional padding behavior in useSendTransaction; reference the gasResult variable and the thor.gas.estimateGas(...) invocation so future maintainers understand the rationale.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/vechain-kit/src/hooks/generic-delegator/useGenericDelegator.ts`:
- Around line 86-90: Add a brief explanatory comment above the
thor.gas.estimateGas call in useGenericDelegator.ts (the block that computes
gasResult) clarifying that gasPadding: 1 is intentionally hardcoded for
delegated Privy transactions to prevent gas-related reverts, and note why this
differs from the conditional padding behavior in useSendTransaction; reference
the gasResult variable and the thor.gas.estimateGas(...) invocation so future
maintainers understand the rationale.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d2a9f2cd-35a9-4f0b-a4aa-8e9dba0d3090
📒 Files selected for processing (1)
packages/vechain-kit/src/hooks/generic-delegator/useGenericDelegator.ts
Summary
Restores
{ gasPadding: 1 }inestimateAndBuildTxBody, removed in 6b98685 as a side effect of refactoring. Without it, delegated Privy/social-login transactions revert due to insufficient gas.Problem
estimateAndBuildTxBody(used byPrivyWalletProvider.sendTransaction) callsthor.gas.estimateGas()without any buffer. The raw estimate is too tight forexecuteBatchWithAuthorizationcalls.gasPadding: 1was present from the initial introduction of batch smart account transactions (252b1a2, Mar 2 2025) through the extraction intoestimateAndBuildTxBody(ab58b8e, Sep 16 2025). It was removed 2 days later in 6b98685 ("Update building and signing tx") alongside theuseGenericDelegatorflag, with no mention in the commit message.Not overridable from consumer projects
PrivyWalletProvider.sendTransaction()does not accept agasPaddingparameteruseSendTransactiondropsgasPaddingfor the Privy code path (line 142-148), while the DappKit path (line 156-163) does forward itestimateAndBuildTxBodyFix
Restores the original behavior.
gasPadding: 1is the max supported by the SDK ((0, 1]range) and doubles the estimate, consistent with the 6-month history of this code path.Summary by CodeRabbit