Skip to content

fix: restore gas padding for delegated Privy transactions#598

Merged
Agilulfo1820 merged 1 commit into
vechain:mainfrom
Emilvooo:fix/restore-delegated-tx-gas-padding
Mar 9, 2026
Merged

fix: restore gas padding for delegated Privy transactions#598
Agilulfo1820 merged 1 commit into
vechain:mainfrom
Emilvooo:fix/restore-delegated-tx-gas-padding

Conversation

@Emilvooo

@Emilvooo Emilvooo commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Restores { gasPadding: 1 } in estimateAndBuildTxBody, removed in 6b98685 as a side effect of refactoring. Without it, delegated Privy/social-login transactions revert due to insufficient gas.

Problem

estimateAndBuildTxBody (used by PrivyWalletProvider.sendTransaction) calls thor.gas.estimateGas() without any buffer. The raw estimate is too tight for executeBatchWithAuthorization calls.

gasPadding: 1 was present from the initial introduction of batch smart account transactions (252b1a2, Mar 2 2025) through the extraction into estimateAndBuildTxBody (ab58b8e, Sep 16 2025). It was removed 2 days later in 6b98685 ("Update building and signing tx") alongside the useGenericDelegator flag, with no mention in the commit message.

Not overridable from consumer projects

  1. PrivyWalletProvider.sendTransaction() does not accept a gasPadding parameter
  2. useSendTransaction drops gasPadding for the Privy code path (line 142-148), while the DappKit path (line 156-163) does forward it
  3. Gas estimation is entirely internal to estimateAndBuildTxBody

Fix

const gasResult = await thor.gas.estimateGas(
    clauses,
    randomTransactionUser?.address ?? '',
    +{ gasPadding: 1 },
);

Restores the original behavior. gasPadding: 1 is 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

  • Bug Fixes
    • Improved gas estimation accuracy in transaction operations to ensure more reliable gas calculations.

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.
@github-actions

github-actions Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

👋 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.
Please ensure that your PR is coming from a meaningful branch name. Eg. feature/my-feature not main

      **Next steps:**
      1. A maintainer will review your code
      2. If approved, they'll add the `safe-to-build` label to trigger build and test
      3. **After each new commit**, the maintainer will need to remove and re-add the label for security

Thank you for your patience! 🙏

@coderabbitai

coderabbitai Bot commented Mar 9, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

A single parameter (gasPadding: 1) was added to the gas estimation call in the generic delegator hook's transaction building function, affecting gas calculation behavior during gas estimation.

Changes

Cohort / File(s) Summary
Gas Estimation Configuration
packages/vechain-kit/src/hooks/generic-delegator/useGenericDelegator.ts
Added gasPadding: 1 option to thor.gas.estimateGas() call within estimateAndBuildTxBody function.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • victorkl400
  • Agilulfo1820

Poem

🐰 A whisker of padding, so light and so fine,
One line of gas buffer—the networks align!
Where transactions once trembled with worry and doubt,
Now steady they flow, no reverting about! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: restoring gas padding for delegated Privy transactions, which aligns perfectly with the PR objectives and the single-line code change adding gasPadding: 1.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 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: 1 is correct and necessary for delegated Privy transactions to avoid gas-related reverts. Since this hardcoded value differs from the conditional pattern in useSendTransaction (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

📥 Commits

Reviewing files that changed from the base of the PR and between 238a6de and d3e1c89.

📒 Files selected for processing (1)
  • packages/vechain-kit/src/hooks/generic-delegator/useGenericDelegator.ts

@Agilulfo1820 Agilulfo1820 added safe-to-deploy Label to approve external PRs to preview environment safe-to-build labels Mar 9, 2026
@Agilulfo1820 Agilulfo1820 merged commit 2a91c4a into vechain:main Mar 9, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe-to-build safe-to-deploy Label to approve external PRs to preview environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants