-
Notifications
You must be signed in to change notification settings - Fork 120
[DRAFT] Fix refund calculation #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -448,13 +448,13 @@ impl TracingInspector { | |
| memory, | ||
| returndata, | ||
| gas_remaining: interp.control.gas().remaining(), | ||
| gas_refund_counter: interp.control.gas().refunded() as u64, | ||
| gas_used, | ||
| decoded: None, | ||
| immediate_bytes, | ||
|
|
||
| // fields will be populated end of call | ||
| gas_cost: 0, | ||
| gas_refund_counter: 0, | ||
| storage_change: None, | ||
| status: InstructionResult::Continue, | ||
| }); | ||
|
|
@@ -518,6 +518,8 @@ impl TracingInspector { | |
| // TODO: Figure out why this can overflow. https://github.com/paradigmxyz/revm-inspectors/pull/38 | ||
| step.gas_cost = step.gas_remaining.saturating_sub(interp.control.gas().remaining()); | ||
|
|
||
| step.gas_refund_counter = interp.control.gas().refunded(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense |
||
|
|
||
| // set the status | ||
| step.status = interp.control.instruction_result(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,8 @@ pub struct CallTrace { | |
| pub steps: Vec<CallTraceStep>, | ||
| /// Optional complementary decoded call data. | ||
| pub decoded: DecodedCallTrace, | ||
| /// The total gas refunded in the call. | ||
| pub gas_refunded: u64 | ||
|
Comment on lines
+100
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't necessarily need this here because we could derive this from the sum of all refunds in the steps? |
||
| } | ||
|
|
||
| impl CallTrace { | ||
|
|
@@ -675,7 +677,7 @@ pub struct CallTraceStep { | |
| /// Remaining gas before step execution | ||
| pub gas_remaining: u64, | ||
| /// Gas refund counter before step execution | ||
| pub gas_refund_counter: u64, | ||
| pub gas_refund_counter: i64, | ||
| /// Total gas used before step execution | ||
| pub gas_used: u64, | ||
| // Fields filled in `step_end` | ||
|
|
@@ -707,7 +709,7 @@ impl CallTraceStep { | |
| gas_cost: self.gas_cost, | ||
| op: self.op.to_string(), | ||
| pc: self.pc as u64, | ||
| refund_counter: (self.gas_refund_counter > 0).then_some(self.gas_refund_counter), | ||
| refund_counter: (self.gas_refund_counter > 0).then_some(self.gas_refund_counter as u64), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can do it like this but only if we update the refund counters accordingly, because we're now only tracking the refund on a per call level, so what we need to di is one post processing step that updates the counter when a call ended. I believe we could do this when we initialize the first calltrace using the sum of all gas refunds up until this point. |
||
| // Filled, if not disabled manually | ||
| stack: None, | ||
| // Filled in `CallTraceArena::geth_trace` as a result of compounding all slot changes | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense because we always need to init this with 0