Skip to content
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

feat!: prevent implicit asset burn #3540

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

petertonysmith94
Copy link
Contributor

@petertonysmith94 petertonysmith94 commented Jan 3, 2025

Release notes

In this release, we:

  • Added a guard to sendTransaction to ensure that we prevent implicit asset burns

Summary

Users can add inputs to a transaction in two ways:

  1. transactionRequest.addCoinInput() or transactionRequest.addMessageInput()
    • These methods automatically adds change outputs if there are none, preventing involuntary asset burn.
  2. transactionRequest.inputs.push({ ... })
    • This, however, is less safe and can result in assets being burned by mistake if users don't also explicitly add output changes via transactionRequest.outputs.push({ ... }).

This PR focuses on the second, less safe method and adds a new check to prevent implicit asset burn unless the enableAssetBurn flag is set to true in the <wallet|provider>.sendTransaction() method.

Breaking Changes

// before
const transactionRequest = new ScriptTransactionRequest();
transactionRequest.inputs.push({ ... });

// since outputs weren't added, assets would be burned
await sender.sendTransaction(transactionRequest);
// after
const transactionRequest = new ScriptTransactionRequest();
transactionRequest.inputs.push({ ... });

// now, an error will be thrown unless `enableAssetBurn`is true,
// in which case, assets can still be burned
await sender.sendTransaction(transactionRequest, {
  enableAssetBurn: true,
});

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@petertonysmith94 petertonysmith94 added the feat Issue is a feature label Jan 3, 2025
@petertonysmith94 petertonysmith94 self-assigned this Jan 3, 2025
Copy link

vercel bot commented Jan 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 8:44pm
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 8:44pm
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 9, 2025 8:44pm

@petertonysmith94 petertonysmith94 changed the title feat: prevent illicit burn feat: prevent illicit asset burn Jan 3, 2025
@petertonysmith94 petertonysmith94 changed the title feat: prevent illicit asset burn feat: prevent implicit asset burn Jan 3, 2025
packages/fuel-gauge/src/transaction.test.ts Outdated Show resolved Hide resolved
danielbate
danielbate previously approved these changes Jan 9, 2025
arboleya
arboleya previously approved these changes Jan 9, 2025
Copy link
Contributor

@Torres-ssf Torres-ssf left a comment

Choose a reason for hiding this comment

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

Nice job @petertonysmith94 👍

Co-authored-by: Sérgio Torres <[email protected]>
Copy link
Contributor

github-actions bot commented Jan 9, 2025

Coverage Report:

Lines Branches Functions Statements
76.99%(+0.09%) 70.54%(+0.19%) 75.04%(+0.15%) 77%(+0.1%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/account/src/account.ts 80%
(+1.77%)
68.05%
(+2.78%)
82.5%
(+2.5%)
79.76%
(+1.73%)
🔴 packages/account/src/providers/provider.ts 68.76%
(+0.07%)
58.58%
(+0.5%)
70.21%
(+0%)
68.49%
(+0.07%)
🔴 packages/account/src/providers/transaction-request/helpers.ts 100%
(+0%)
97.14%
(+0.99%)
100%
(+0%)
100%
(+0%)
🔴 packages/account/src/wallet/base-wallet-unlocked.ts 96.29%
(+0.14%)
75%
(+0%)
100%
(+0%)
96.42%
(+0.13%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent implicit burn
5 participants