Skip to content

Commit

Permalink
fix: SSTORE gas refund (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Sep 3, 2024
1 parent 2902d76 commit b7b673c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/evm/src/gas.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CODEDEPOSIT: u128 = 200;

const SSTORE_SET: u128 = 20000;
const SSTORE_RESET: u128 = 5000;
const REFUND_SSTORE_CLEARS: u128 = 15000;
const REFUND_SSTORE_CLEARS: u128 = 4800;

const TRANSACTION_ZERO_DATA: u128 = 4;
const TRANSACTION_NON_ZERO_DATA_INIT: u128 = 16;
Expand Down
43 changes: 43 additions & 0 deletions scripts/gas_debug_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import re


def process_logs(logs):
current_address = None
previous_gas = None
accumulated_gas = 0

pattern = re.compile(r"Address (\d+), gas left in call (\d+)")

for line in logs.split("\n"):
match = pattern.search(line)
if match:
address, gas_left = match.groups()
gas_left = int(gas_left)

if address != current_address:
if current_address is not None:
print(
f"Total gas used for {hex(int(current_address))}: {accumulated_gas}"
)
current_address = address
previous_gas = gas_left
accumulated_gas = 0
else:
gas_used = previous_gas - gas_left
accumulated_gas += gas_used
print(
f"Gas used in step for {hex(int(current_address))}: {gas_used} (Total: {accumulated_gas})"
)
previous_gas = gas_left

if current_address is not None:
print(f"Total gas used for {hex(int(current_address))}: {accumulated_gas}")


# Example usage
logs = """
Address 1169201309864722334562947866173026415724746034380, gas left in call 79978528
Address 1169201309864722334562947866173026415724746034380, gas left in call 79978525
"""

process_logs(logs)

0 comments on commit b7b673c

Please sign in to comment.