Skip to content

Commit db8e7b6

Browse files
authored
Merge pull request #912 from argotorg/simplify-gas-computation
EVM: Simplify gas refund computation
2 parents 71c8753 + 9e4559b commit db8e7b6

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/EVM.hs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -771,20 +771,14 @@ exec1 conf = do
771771
let cold_storage_cost = if acc then 0 else g_cold_sload
772772
burn (storage_cost + cold_storage_cost) $ do
773773
updateVMState
774-
775-
unless (currentVal == newVal) $
776-
if currentVal == originalVal then
777-
when (originalVal /= 0 && newVal == 0) $
778-
refund (g_sreset + g_access_list_storage_key)
779-
else do
780-
when (originalVal /= 0) $
781-
if currentVal == 0
782-
then unRefund (g_sreset + g_access_list_storage_key)
783-
else when (newVal == 0) $ refund (g_sreset + g_access_list_storage_key)
784-
when (originalVal == newVal) $
785-
if originalVal == 0
786-
then refund (g_sset - g_sload)
787-
else refund (g_sreset - g_sload)
774+
case (originalVal, currentVal, newVal) of
775+
(o, c, n)
776+
| c == n -> pure ()
777+
| o /= 0 && n == 0 -> refund (g_sreset + g_access_list_storage_key)
778+
| o /= 0 && c == 0 -> do unRefund (g_sreset + g_access_list_storage_key); when (o == n) $ refund (g_sreset - g_sload)
779+
| o /= 0 && o == n -> refund (g_sreset - g_sload)
780+
| o == 0 && o == n -> refund (g_sset - g_sload)
781+
| otherwise -> pure ()
788782
in
789783
whenSymbolicElse updateVMState concreteSstore
790784
_ -> underrun

0 commit comments

Comments
 (0)