Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv · QuarkChain/revm@3a6aa08 · GitHub
Skip to content

Commit 3a6aa08

Browse files
refactor(op-revm): move SGT config from L1BlockInfo to CfgEnv
Move sgt_enabled and sgt_is_native_backed from L1BlockInfo to CfgEnv, accessed via Cfg trait methods (is_sgt_enabled, is_sgt_native_backed). This eliminates the need to: - Mutate the EVM after creation (no configure_sgt on Evm trait) - Preserve/restore SGT flags around L1BlockInfo::try_fetch - Fork alloy-evm SGT config now flows through CfgEnv at EVM creation time, matching how OpSpecId and other hardfork config is passed. Runtime deduction tracking (sgt_native_deducted, sgt_amount_deducted) remains on L1BlockInfo as it is per-transaction mutable state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79e76f2 commit 3a6aa08

4 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎crates/context/interface/src/cfg.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ pub trait Cfg {
7575

7676
/// Returns the gas params for the EVM.
7777
fngas_params(&self) -> &GasParams;
78+
79+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
80+
/// Default: false. Only used by OP Stack chains with SGT.
81+
fnis_sgt_enabled(&self) -> bool{
82+
false
83+
}
84+
85+
/// Whether SGT is backed 1:1 by native token.
86+
/// Default: true.
87+
fnis_sgt_native_backed(&self) -> bool{
88+
true
89+
}
7890
}
7991

8092
/// What bytecode analysis to perform

‎crates/context/src/cfg.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub struct CfgEnv<SPEC = SpecId> {
4848
publimit_contract_initcode_size:Option<usize>,
4949
/// Skips the nonce validation against the account's nonce
5050
pubdisable_nonce_check:bool,
51+
/// Whether Soul Gas Token (SGT) is enabled for gas payment.
52+
/// Only used by OP Stack chains with SGT deployed. Default: false.
53+
pubsgt_enabled:bool,
54+
/// Whether SGT is backed 1:1 by native token. Default: true.
55+
pubsgt_is_native_backed:bool,
5156
/// Blob max count. EIP-7840 Add blob schedule to EL config files.
5257
///
5358
/// If this config is not set, the check for max blobs will be skipped.
@@ -149,6 +154,8 @@ impl<SPEC> CfgEnv<SPEC> {
149154
limit_contract_initcode_size:None,
150155
spec,
151156
disable_nonce_check:false,
157+
sgt_enabled:false,
158+
sgt_is_native_backed:true,
152159
max_blobs_per_tx:None,
153160
tx_gas_limit_cap:None,
154161
blob_base_fee_update_fraction:None,
@@ -251,6 +258,8 @@ impl<SPEC> CfgEnv<SPEC> {
251258
limit_contract_initcode_size:self.limit_contract_initcode_size,
252259
spec,
253260
disable_nonce_check:self.disable_nonce_check,
261+
sgt_enabled:self.sgt_enabled,
262+
sgt_is_native_backed:self.sgt_is_native_backed,
254263
tx_gas_limit_cap:self.tx_gas_limit_cap,
255264
max_blobs_per_tx:self.max_blobs_per_tx,
256265
blob_base_fee_update_fraction:self.blob_base_fee_update_fraction,
@@ -502,6 +511,14 @@ impl<SPEC: Into<SpecId> + Clone> Cfg for CfgEnv<SPEC> {
502511
fngas_params(&self) -> &GasParams{
503512
&self.gas_params
504513
}
514+
515+
fnis_sgt_enabled(&self) -> bool{
516+
self.sgt_enabled
517+
}
518+
519+
fnis_sgt_native_backed(&self) -> bool{
520+
self.sgt_is_native_backed
521+
}
505522
}
506523

507524
impl<SPEC:Default + Into<SpecId>>DefaultforCfgEnv<SPEC>{

‎crates/op-revm/src/handler.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,7 @@ where
193193
// L1 block info is stored in the context for later use.
194194
// and it will be reloaded from the database if it is not for the current block.
195195
if chain.l2_block != Some(block.number()){
196-
// Preserve SGT configuration from the current chain context
197-
let sgt_enabled = chain.sgt_enabled;
198-
let sgt_is_native_backed = chain.sgt_is_native_backed;
199-
200196
*chain = L1BlockInfo::try_fetch(journal.db_mut(), block.number(), spec)?;
201-
202-
// Restore SGT configuration after fetching L1 block info
203-
chain.sgt_enabled = sgt_enabled;
204-
chain.sgt_is_native_backed = sgt_is_native_backed;
205197
}
206198

207199
letmut caller_account = journal.load_account_with_code_mut(tx.caller())?.data;
@@ -220,7 +212,7 @@ where
220212
};
221213

222214
// NEW: SGT-aware gas deduction path (early return to preserve original code below)
223-
ifchain.sgt_enabled{
215+
ifcfg.is_sgt_enabled(){
224216
// Calculate L2 gas cost (gas_limit × gas_price + blob fees)
225217
let basefee = block.basefee()asu128;
226218
let blob_price = block.blob_gasprice().unwrap_or_default();
@@ -396,8 +388,7 @@ where
396388
}
397389

398390
// NEW: SGT-aware refund logic (early return to preserve original code)
399-
let sgt_enabled = evm.ctx().chain().sgt_enabled;
400-
if sgt_enabled && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
391+
if evm.ctx().cfg().is_sgt_enabled() && evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE{
401392
returnself.reimburse_caller_sgt(evm, frame_result, additional_refund);
402393
}
403394

‎crates/op-revm/src/l1block.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ pub struct L1BlockInfo {
5353
pubempty_ecotone_scalars:bool,
5454
/// Last calculated l1 fee cost. Uses as a cache between validation and pre execution stages.
5555
pubtx_l1_cost:Option<U256>,
56-
/// Whether Soul Gas Token (SGT) is enabled for gas payment
57-
pubsgt_enabled:bool,
58-
/// Whether SGT is native-backed (1:1 with native token)
59-
pubsgt_is_native_backed:bool,
60-
/// Amount of native balance deducted for gas (for refund calculation)
56+
/// Amount of native balance deducted for SGT gas payment (for refund calculation)
6157
pubsgt_native_deducted:U256,
62-
/// Amount of SGT balance deducted for gas (for refund calculation)
58+
/// Amount of SGT balance deducted for gas payment (for refund calculation)
6359
pubsgt_amount_deducted:U256,
6460
}
6561

0 commit comments

Comments
 (0)