Feature/2491 refund ctx - #2492
Open
PropzSaladaz wants to merge 10 commits into
Open
Conversation
|
SUGGESTIONS BEFORE MERGE:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new BITE-gated chain patch (RefundCTXPatch) that changes CTX post-processing to sweep remaining ephemeral CTX sender balance back to the originating contract and reset the ephemeral sender nonce, plus tests and safety guards around CTX classification.
Changes:
- Introduce
RefundCTXPatch(enum + name mapping) and apply it inExecutive/AlethExecutivefinalization for CTX transactions. - Add a
SkaleHostsafeguard to reject any “regular” transaction that would be interpreted as CTX when the refund patch is active. - Expand/adjust unit tests to validate refund behavior (patch on/off), plus add a test-only block-import barrier helper to reduce snapshot/estimateGas race conditions.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unittests/libweb3jsonrpc/jsonrpc.cpp | Adds config overrides + new CTX crafting/refund behavior tests and updates BITE config JSON to include RefundCTXPatchTimestamp. |
| test/unittests/libskale/HashSnapshot.cpp | Serializes snapshot creation with block import via a new test helper barrier. |
| test/unittests/libethereum/PrecompiledTest.cpp | Adds RAII guard for global BITE host wiring/teardown in submitCTX ciphertext validation tests. |
| test/unittests/libethereum/ClientTest.cpp | Wraps estimateGas() calls with the new block-import barrier to avoid races. |
| libhistoric/AlethExecutive.h | Declares CTX refund+ephemeral nonce reset helper under #ifdef BITE. |
| libhistoric/AlethExecutive.cpp | Implements refund logic for historic execution path and gates it behind RefundCTXPatch. |
| libethereum/SkaleHost.cpp | Adds runtime check to prevent CTX-marked txs from appearing in the regular tx list when refund patch is enabled. |
| libethereum/SchainPatchEnum.h | Adds RefundCTXPatch to the patch enum (BITE builds). |
| libethereum/SchainPatch.h | Defines the RefundCTXPatch patch type and documents its purpose. |
| libethereum/SchainPatch.cpp | Adds string↔enum mapping for RefundCTXPatch. |
| libethereum/Executive.h | Declares CTX refund+ephemeral nonce reset helper under #ifdef BITE. |
| libethereum/Executive.cpp | Applies refund behavior in normal execution path finalization when patch is enabled. |
| libethereum/ClientTest.h | Declares ClientTest::withBlockImportBarrier() test-only helper. |
| libethereum/ClientTest.cpp | Implements withBlockImportBarrier() using m_blockImportMutex. |
badrogger
previously approved these changes
Jun 24, 2026
badrogger
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces timestamp-gated refund handling for CTX transactions.
After a CTX finishes execution, its remaining ephemeral-account balance is transferred back to the target contract that originated the CTX. The ephemeral sender nonce is then reset to zero, allowing the empty account to be pruned during state commit.
CTX Behavior
CTX is always refunded. Even if it is reverted, the remainder is sent to where CTX is aimed at - the contract's balance.
Changes
A. New patch timestamp
RefundCTXPatch.RefundCTXPatchTimestampchain configuration field.B. CTX refund and ephemeral-account cleanup
Implemented equivalent behavior in both execution paths:
Executive.AlethExecutive.When the patch is active and the transaction is a CTX:
The regular consensus transaction path also rejects CTX-shaped transactions once the patch is active, preventing user-submitted transactions from triggering destructive ephemeral-account cleanup.
There were already checks at RPC level, but this PR adds additional checks during protocol parsing layer.
C. CTX test refactoring
submitCTXinput, and executing the complete CTX lifecycle.RefundCTXPatchis enabled.Compatibility
Before activation, CTX gas refunds retain their previous behavior. Regular transactions are unaffected.