Skip to content

BURN: Skip zero-amount changes and clear empty asset slots - #1008

Merged
Dentosal merged 2 commits into
masterfrom
dento/burn-storage-cleanup
Apr 29, 2026
Merged

Dentosal merged 2 commits into
masterfrom
dento/burn-storage-cleanup

Conversation

@Dentosal

@Dentosal Dentosal commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Previously, burning zero units of a nonexisting asset would write that to the storage. This PR ignores zero-amount burns, although it still produces a receipt for them. In addition, when all assets with some specific have been burned, clears the slot instead of writing a zero there.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • If performance characteristic of an instruction change, update gas costs as well or make a follow-up PR for that
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

@Dentosal Dentosal self-assigned this Apr 27, 2026
@cursor

cursor Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes BURN state transition semantics for contract asset balances (skips storage writes for zero-amount burns and deletes entries when balance hits zero), which can affect persisted state and consensus/state roots. Risk is concentrated in opcode execution and storage mutation paths.

Overview
Minimizes contract asset storage writes during the BURN opcode by skipping balance updates when amount == 0 while still emitting a burn receipt.

When a burn brings an asset balance to exactly zero, it now removes the (contract, asset_id) entry instead of persisting a 0 value, via a new ContractsAssetsStorage::contract_asset_id_balance_remove helper. Tests were updated to treat missing balances as 0 (unwrap_or(0)).

Reviewed by Cursor Bugbot for commit bfc2246. Bugbot is set up for automated code reviews on this repo. Configure here.

@Dentosal Dentosal changed the title Minimize storage usage of burn opcode BURN: Skip zero-amount changes and clear empty asset slots Apr 27, 2026
@Dentosal
Dentosal marked this pull request as ready for review April 27, 2026 15:35
@Dentosal
Dentosal added this pull request to the merge queue Apr 29, 2026
Merged via the queue into master with commit 57aa727 Apr 29, 2026
45 checks passed
@Dentosal
Dentosal deleted the dento/burn-storage-cleanup branch April 29, 2026 12:19
@github-actions github-actions Bot mentioned this pull request Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants