Skip to content

Commit 51e565f

Browse files
authored
Merge pull request #163 from arcz/fix-regressions
Fix SAR arithmetic overflow and copySlice regressions
2 parents 7f98fa8 + df40f9b commit 51e565f

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Arithmetic overflow in concrete `SAR` edge case
13+
- Unnecessary application of `CopySlice` in concrete edge case
14+
815
## [0.50.1] - 2022-12-29
916

10-
## Fixed
17+
### Fixed
1118

1219
- `hevm exec` no longer fails with `hevm: No match in record selector smttimeout`
1320
- the `gas`, `gaslimit`, `priorityfee`, and `gasprice` cli options are now respected

src/EVM/Expr.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ shr = op2
181181

182182
sar :: Expr EWord -> Expr EWord -> Expr EWord
183183
sar = op2 SAR (\x y ->
184-
let asSigned = (fromIntegral y) :: Int256
185-
in fromIntegral $ shiftR asSigned (fromIntegral x))
184+
let msb = testBit y 255
185+
asSigned = fromIntegral y :: Int256
186+
in if x > 256 then
187+
if msb then maxBound else 0
188+
else
189+
fromIntegral $ shiftR asSigned (fromIntegral x))
186190

187191
-- ** Bufs ** --------------------------------------------------------------------------------------
188192

@@ -319,7 +323,6 @@ copySlice a@(Lit srcOffset) b@(Lit dstOffset) c@(Lit size) d@(ConcreteBuf src) e
319323

320324
copySlice a@(Lit srcOffset) b@(Lit dstOffset) c@(Lit size) d@(ConcreteBuf src) e@(ConcreteBuf dst)
321325
| dstOffset < maxBytes
322-
, srcOffset < maxBytes
323326
, size < maxBytes =
324327
let hd = padRight (num dstOffset) $ BS.take (num dstOffset) dst
325328
sl = if srcOffset > num (BS.length src)

test/BlockchainTests.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,7 @@ ciIgnoredFiles =
112112

113113
commonProblematicTests :: Map String (TestTree -> TestTree)
114114
commonProblematicTests = Map.fromList
115-
[ ("twoOps_d0g0v0_London", expectFailBecause "TODO: regression")
116-
, ("sar_2^256-1_0_d0g0v0_London", expectFailBecause "TODO: regression")
117-
, ("shiftCombinations_d0g0v0_London", expectFailBecause "TODO: regression")
118-
, ("shiftSignedCombinations_d0g0v0_London", expectFailBecause "TODO: regression")
119-
, ("bufferSrcOffset_d14g0v0_London", expectFailBecause "TODO: regression")
120-
, ("bufferSrcOffset_d38g0v0_London", expectFailBecause "TODO: regression")
121-
, ("loopMul_d0g0v0_London", ignoreTestBecause "hevm is too slow")
115+
[ ("loopMul_d0g0v0_London", ignoreTestBecause "hevm is too slow")
122116
, ("loopMul_d1g0v0_London", ignoreTestBecause "hevm is too slow")
123117
, ("loopMul_d2g0v0_London", ignoreTestBecause "hevm is too slow")
124118
, ("CALLBlake2f_MaxRounds_d0g0v0_London", ignoreTestBecause "very slow, bypasses timeout due time spent in FFI")

0 commit comments

Comments
 (0)