Skip to content

Commit fa1a99a

Browse files
committed
EVM: Simplify accessStorageForGas
This function is needed only in concrete mode and we can simplify it when we know the slot is a concrete value.
1 parent dc776c2 commit fa1a99a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/EVM.hs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ exec1 conf = do
736736
else finalizeLoad $ Expr.readStorage' (Expr.concKeccakOnePass x) this.storage
737737

738738
concreteRead :: EVM t s () = do
739-
acc <- accessStorageForGas self x
739+
acc <- accessStorageForGas self (forceLit x)
740740
let cost = if acc then g_warm_storage_read else g_cold_sload
741741
burn cost $ if this.external
742742
then accessStorage self x finalizeLoad
@@ -767,7 +767,7 @@ exec1 conf = do
767767
| (currentVal == originalVal) = g_sreset
768768
| otherwise = g_sload
769769

770-
acc <- accessStorageForGas self x
770+
acc <- accessStorageForGas self slot
771771
let cold_storage_cost = if acc then 0 else g_cold_sload
772772
burn (storage_cost + cold_storage_cost) $ do
773773
updateVMState
@@ -1754,15 +1754,12 @@ accessAccountForGas addr = do
17541754

17551755
-- | returns a wrapped boolean- if true, this slot has been touched before in the txn (warm gas cost as in EIP 2929)
17561756
-- otherwise cold
1757-
accessStorageForGas :: Expr EAddr -> Expr EWord -> EVM t s Bool
1757+
accessStorageForGas :: Expr EAddr -> W256 -> EVM t s Bool
17581758
accessStorageForGas addr key = do
17591759
accessedStrkeys <- use (#tx % #subState % #accessedStorageKeys)
1760-
case maybeLitWordSimp key of
1761-
Just litword -> do
1762-
let accessed = member (addr, litword) accessedStrkeys
1763-
assign (#tx % #subState % #accessedStorageKeys) (insert (addr, litword) accessedStrkeys)
1764-
pure accessed
1765-
_ -> pure False
1760+
let accessed = member (addr, key) accessedStrkeys
1761+
unless accessed $ assign (#tx % #subState % #accessedStorageKeys) (insert (addr, key) accessedStrkeys)
1762+
pure accessed
17661763

17671764
-- * Cheat codes
17681765

0 commit comments

Comments
 (0)