From e1817435882a8514d37bb71193c5d9097326467c Mon Sep 17 00:00:00 2001 From: Oba Date: Thu, 5 Sep 2024 19:06:51 +0200 Subject: [PATCH] fix: call gas refund only if success (#1395) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Time spent on this PR: ## Pull request type 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? Resolves #1389 ## What is the new behavior? No refunds are applied if the call reverted - - - This change is [Reviewable](https://reviewable.io/reviews/kkrt-labs/kakarot/1395) --- src/kakarot/instructions/system_operations.cairo | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/kakarot/instructions/system_operations.cairo b/src/kakarot/instructions/system_operations.cairo index 0bbe8e7ad..73dd31373 100644 --- a/src/kakarot/instructions/system_operations.cairo +++ b/src/kakarot/instructions/system_operations.cairo @@ -1032,6 +1032,12 @@ 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, @@ -1039,7 +1045,7 @@ namespace CallHelper { 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, );