@@ -2171,20 +2171,15 @@ accessUnboundedMemoryRange
21712171 -> SymWord
21722172 -> EVM ()
21732173 -> EVM ()
2174- accessUnboundedMemoryRange fees f l continue = do
2175- m0 <- use (state . memorySize)
2176- case (maybeLitWord f, maybeLitWord l, unliteral m0) of
2177- (Just f', Just l', Just (num -> m0')) -> do
2178- let m1 = 32 * ceilDiv (max m0' (f' + l')) 32
2179- burn (memoryCost fees m1 - memoryCost fees m0') $ do
2180- assign (state . memorySize) (num m1)
2181- continue
2182- _ -> do
2183- -- let m1 = 32 * ceilDiv (max m0 (num f + num l)) 32
2184- -- todo: consult smt here
2185- -- assign (state . memorySize) (num m1)
2186- continue
2187-
2174+ accessUnboundedMemoryRange fees f l continue =
2175+ if maybe False ((==) 0 ) (maybeLitWord l) then continue
2176+ -- TODO: check for l .== 0 in the symbolic case as well
2177+ else do
2178+ m0 <- sw256 <$> sFromIntegral <$> use (state . memorySize)
2179+ let m1@ (S _ m1') = 32 * ceilSDiv (smax m0 (f + l)) 32
2180+ burnSym (memoryCost fees m1 - memoryCost fees m0) $ do
2181+ assign (state . memorySize) (sFromIntegral m1')
2182+ continue
21882183
21892184accessMemoryRange
21902185 :: FeeSchedule Word
@@ -2611,12 +2606,12 @@ costOfPrecompile (FeeSchedule {..}) precompileAddr input =
26112606 _ -> error (" unimplemented precompiled contract " ++ show precompileAddr)
26122607
26132608-- Gas cost of memory expansion
2614- memoryCost :: FeeSchedule Word -> Word -> Word
2609+ memoryCost :: FeeSchedule Word -> SymWord -> SymWord
26152610memoryCost FeeSchedule {.. } byteCount =
26162611 let
2617- wordCount = ceilDiv byteCount 32
2618- linearCost = g_memory * wordCount
2619- quadraticCost = div (wordCount * wordCount) 512
2612+ wordCount = ceilSDiv byteCount 32
2613+ linearCost = litWord g_memory * wordCount
2614+ quadraticCost = (wordCount * wordCount) `sDiv` 512
26202615 in
26212616 linearCost + quadraticCost
26222617
0 commit comments