fix(revm): restore original_value after token fee reimbursement#43
fix(revm): restore original_value after token fee reimbursement#43
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds per-transaction runtime state and L1-data fee caching; extends fee handling to support ERC20 token reimbursement (slot-based or internal EVM-call), introduces helpers to perform/restore fee transfers and preserve original storage values, and updates morph sload/sstore behavior and tests. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller/Tx
participant Handler as revm::handler
participant EVM as MorphEvm
participant Runtime as MorphTxRuntime
participant DB as Journal/State
Caller->>Handler: Submit transaction (may include token fee)
Handler->>EVM: validate_and_deduct_fee (compute L1 data fee)
EVM->>Runtime: cache per-tx L1 data fee & TokenFeeInfo
Handler->>Runtime: track_forced_cold_slot(address, slot, original)
alt token reimbursement via slot
Handler->>EVM: transfer_erc20_with_slot(from,to,token,amt)
EVM->>DB: write slot changes (journal)
Runtime->>DB: restore_tracked_original_value for forced-cold slots
else token reimbursement via internal CALL
Handler->>EVM: evm_call(balanceOf/transfer calldata)
EVM-->>Handler: result + logs (pre/post fee logs separated)
Runtime->>DB: restore_tracked_original_value if needed
end
Handler->>Caller: continue execution with restored originals and fee logs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/revm/src/handler.rs`:
- Around line 629-633: The conditionals with the let-chains involving
tx.fee_slot_original_values and state.get_mut(&address) are misformatted and
failing rustfmt; reformat these blocks to match rustfmt style (e.g., split the
chained let/if into rustfmt-friendly lines or use parentheses) and run cargo fmt
--all to ensure CI passes; locate the affected expressions around
tx.fee_slot_original_values.iter().find(|(saved_address, saved_slot, _)|
*saved_address == address && *saved_slot == slot_key) and the subsequent let
Some(account) = state.get_mut(&address) and apply the same reformatting to the
other similar block later (the one with the same pattern at the other
occurrence).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 57274f97-8334-4285-9795-bbc350892473
📒 Files selected for processing (1)
crates/revm/src/handler.rs
Code reviewFound 2 issues:
In Fix: only assign morph-reth/crates/revm/src/handler.rs Lines 443 to 460 in e685baa
morph-reth/crates/revm/src/runtime.rs Lines 36 to 50 in e685baa Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
Summary
main-branch fix with the current runtime-tracker implementation instead of keeping a reimbursement-only patchMorphTxRuntimeto track forced-cold slot originals across token-fee deduction, EVM execution, and reimbursementSSTOREwith regression testsContext
mainalready had a partial fix based onMorphTxEnv::fee_slot_original_values, but that only covered the EVMSLOADpath. The reimbursement path still calledtransfer_erc20_with_slotdirectly and bypassedsload_morph, which let revm overwriteoriginal_valuefor the fee-token balance slots.This PR now matches the current in-progress implementation used on the working branch:
MorphTxEnvand into a dedicatedMorphTxRuntimeMorphContextSSTOREoverride so forced-cold slots are also protected when the first main-execution touch is a write instead of a readThis replaces the earlier minimal reimbursement-only patch on this PR branch.
Test Plan
cargo fmtcargo test -p morph-revmcargo test -p morph-evmSummary by CodeRabbit
New Features
Bug Fixes