Skip to content

Commit

Permalink
fix: call gas refund only if success (#1395)
Browse files Browse the repository at this point in the history
<!--- Please provide a general summary of your changes in the title
above -->

<!-- Give an estimate of the time you spent on this PR in terms of work
days.
Did you spend 0.5 days on this PR or rather 2 days?  -->

Time spent on this PR:

## Pull request type

<!-- Please try to limit your pull request to one type,
submit multiple pull requests if needed. -->

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying,
or link to a relevant issue. -->

Resolves #1389

## What is the new behavior?

<!-- Please describe the behavior or changes that are being added by
this PR. -->

No refunds are applied if the call reverted

<!-- Reviewable:start -->
- - -
This change is [<img src="https://reviewable.io/review_button.svg"
height="34" align="absmiddle"
alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1395)
<!-- Reviewable:end -->
  • Loading branch information
obatirou authored Sep 5, 2024
1 parent 25a58e8 commit e181743
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/kakarot/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1032,14 +1032,20 @@ namespace CallHelper {
) * evm.return_data_len;
Memory.store_n(actual_output_size, evm.return_data, ret_offset.low);

if (evm.reverted != FALSE) {
tempvar gas_refund = evm.message.parent.evm.gas_refund;
} else {
tempvar gas_refund = evm.message.parent.evm.gas_refund + evm.gas_refund;
}

tempvar evm = new model.EVM(
message=message,
return_data_len=evm.return_data_len,
return_data=evm.return_data,
program_counter=evm.message.parent.evm.program_counter + 1,
stopped=evm.message.parent.evm.stopped,
gas_left=evm.message.parent.evm.gas_left + evm.gas_left,
gas_refund=evm.message.parent.evm.gas_refund + evm.gas_refund,
gas_refund=gas_refund,
reverted=evm.message.parent.evm.reverted,
);

Expand Down

0 comments on commit e181743

Please sign in to comment.