Skip to content

Conversation

@0xRVE
Copy link
Contributor

@0xRVE 0xRVE commented Jan 28, 2026

fixes paritytech/contract-issues#213 where storage deposit refunds failed in nested/reentrant calls.

Problem
Storage refunds were calculated incorrectly when a contract allocated storage, then performed a nested call that cleared it. Pending storage changes lived only in the parent FrameMeter, so child frames could not see them and refunds were skipped.

Solution
Apply pending storage deposit changes to a cloned ContractInfo before creating nested frames. This makes the parent’s storage state visible to child frames during refund calculation.

Implementation

  • Added apply_pending_changes_to_contract() to apply pending diffs to ContractInfo
  • Added apply_pending_storage_changes() wrapper on FrameMeter
  • Applied pending storage changes before nested frame creation in exec.rs (3 locations)

@0xRVE 0xRVE added the T7-smart_contracts This PR/Issue is related to smart contracts. label Jan 28, 2026
@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 28, 2026

/cmd prdoc --audience runtime_dev --bump patch

@0xRVE 0xRVE changed the title [WIP][pallet-revive] attempted fix [pallet-revive] Fix storage deposit refunds in nested contract calls Jan 28, 2026
@0xRVE 0xRVE requested a review from TorstenStueber January 28, 2026 10:12
@pgherveou
Copy link
Contributor

can you capture the example from the issue in the tests?

@0xRVE
Copy link
Contributor Author

0xRVE commented Jan 29, 2026

can you capture the example from the issue in the tests?

nested_call_refund_matches_direct_refund asserts that a nested clear refunds the same as a direct clear. If you have a different reproducer in mind, please point me to the exact steps and I will mirror it in the tests.

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/21477444021
Failed job name: fmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T7-smart_contracts This PR/Issue is related to smart contracts.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage deposit refunds not working happening in sub frame

3 participants