Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solc 0.6.0 #316

Merged
merged 3 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nix/solc-versions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ rec {
# these versions have not been upstreamed on NixOS/nixpkgs yet, and come from our fork at dapptools/nixpkgs
unreleased = {
solc_0_5_16 = { rev = "725f92e016497dc351f84ff3d2c0c0538676f287"; sha256 = "1qwh0246piiwxxd80dzhya6x1fd2w2kj2rf80y83qa2v03zczqd1"; };
solc_0_6_0 = { rev = "2342685388c0bad7163483c0b96c64f2dae817a3"; sha256 = "0ahqhw47y9xd3gwcxiazxj5ijiahgb4b69bvxja227rfpi9yvx60"; };
};
}
1 change: 1 addition & 0 deletions src/dapp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Integration with `hevm`s new property based testing functionality. Any test with nonzero arguments will be interpreted as a property test whose arguments are randomly generated and run `--fuzz-runs` number of times.
- Support for solc 0.5.16
- Support for solc 0.6.0

## [0.26.0]
### Added
Expand Down
76 changes: 41 additions & 35 deletions src/hevm/src/EVM/Solidity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Data.Aeson.Lens
import Data.Binary.Get (runGet, getWord16be)
import Data.ByteString (ByteString)
import Data.ByteString.Lazy (fromStrict)
import Data.Char (isDigit, digitToInt)
import Data.Char (isDigit)
import Data.Either (isRight)
import Data.Foldable
import Data.Map.Strict (Map)
Expand Down Expand Up @@ -117,15 +117,16 @@ data SrcMap = SM {
srcMapOffset :: {-# UNPACK #-} Int,
srcMapLength :: {-# UNPACK #-} Int,
srcMapFile :: {-# UNPACK #-} Int,
srcMapJump :: JumpType
srcMapJump :: JumpType,
srcMapModifierDepth :: {-# UNPACK #-} Int
} deriving (Show, Eq, Ord, Generic)

data SrcMapParseState
= F1 [Int] Int
| F2 Int [Int] Int
| F3 Int Int [Int] Int
| F4 Int Int Int
| F5 SrcMap
= F1 [Char] Int
| F2 Int [Char] Int
| F3 Int Int [Char] Int
| F4 Int Int Int (Maybe JumpType)
| F5 Int Int Int JumpType [Char]
| Fe
deriving Show

Expand All @@ -139,44 +140,49 @@ makeLenses ''Method
-- Obscure but efficient parser for the Solidity sourcemap format.
makeSrcMaps :: Text -> Maybe (Seq SrcMap)
makeSrcMaps = (\case (_, Fe, _) -> Nothing; x -> Just (done x))
. Text.foldl' (\x y -> go y x) (mempty, F1 [] 1, SM 0 0 0 JumpRegular)
. Text.foldl' (\x y -> go y x) (mempty, F1 [] 1, SM 0 0 0 JumpRegular 0)
where
digits ds = digits' (0 :: Int) (0 :: Int) ds
digits' !x _ [] = x
digits' !x !n (d:ds) = digits' (x + d * 10 ^ n) (n + 1) ds

done (xs, s, p) = let (xs', _, _) = go ';' (xs, s, p) in xs'

go ':' (xs, F1 [] _, p@(SM a _ _ _)) = (xs, F2 a [] 1, p)
go ':' (xs, F1 ds k, p) = (xs, F2 (k * digits ds) [] 1, p)
go :: Char -> (Seq SrcMap, SrcMapParseState, SrcMap) -> (Seq SrcMap, SrcMapParseState, SrcMap)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good luck reviewing this!

go ':' (xs, F1 [] _, p@(SM a _ _ _ _)) = (xs, F2 a [] 1, p)
go ':' (xs, F1 ds k, p) = (xs, F2 (k * (read ds)) [] 1, p)
go '-' (xs, F1 [] _, p) = (xs, F1 [] (-1), p)
go d (xs, F1 ds k, p) | isDigit d = (xs, F1 (digitToInt d : ds) k, p)
go d (xs, F1 ds k, p) | isDigit d = (xs, F1 (d : ds) k, p)
go ';' (xs, F1 [] k, p) = (xs |> p, F1 [] k, p)
go ';' (xs, F1 ds k, SM _ b c d) = let p' = SM (k * digits ds) b c d in
(xs |> p', F1 [] 1, p')
go ';' (xs, F1 ds k, SM _ b c d e) = let p' = SM (k * (read ds)) b c d e in (xs |> p', F1 [] 1, p')

go '-' (xs, F2 a [] _, p) = (xs, F2 a [] (-1), p)
go d (xs, F2 a ds k, p) | isDigit d = (xs, F2 a (digitToInt d : ds) k, p)
go ':' (xs, F2 a [] _, p@(SM _ b _ _)) = (xs, F3 a b [] 1, p)
go ':' (xs, F2 a ds k, p) = (xs, F3 a (k * digits ds) [] 1, p)
go ';' (xs, F2 a [] _, SM _ b c d) = let p' = SM a b c d in (xs |> p', F1 [] 1, p')
go ';' (xs, F2 a ds k, SM _ _ c d) = let p' = SM a (k * digits ds) c d in
go d (xs, F2 a ds k, p) | isDigit d = (xs, F2 a (d : ds) k, p)
go ':' (xs, F2 a [] _, p@(SM _ b _ _ _)) = (xs, F3 a b [] 1, p)
go ':' (xs, F2 a ds k, p) = (xs, F3 a (k * (read ds)) [] 1, p)
go ';' (xs, F2 a [] _, SM _ b c d e) = let p' = SM a b c d e in (xs |> p', F1 [] 1, p')
go ';' (xs, F2 a ds k, SM _ _ c d e) = let p' = SM a (k * (read ds)) c d e in
(xs |> p', F1 [] 1, p')

go d (xs, F3 a b ds k, p) | isDigit d = (xs, F3 a b (digitToInt d : ds) k, p)
go '-' (xs, F3 a b [] _, p) = (xs, F3 a b [] (-1), p)
go ':' (xs, F3 a b [] _, p@(SM _ _ c _)) = (xs, F4 a b c, p)
go ':' (xs, F3 a b ds k, p) = (xs, F4 a b (k * digits ds), p)
go ';' (xs, F3 a b [] _, SM _ _ c d) = let p' = SM a b c d in (xs |> p', F1 [] 1, p')
go ';' (xs, F3 a b ds k, SM _ _ _ d) = let p' = SM a b (k * digits ds) d in
(xs |> p', F1 [] 1, p')
go d (xs, F3 a b ds k, p) | isDigit d = (xs, F3 a b (d : ds) k, p)
go '-' (xs, F3 a b [] _, p) = (xs, F3 a b [] (-1), p)
go ':' (xs, F3 a b [] _, p@(SM _ _ c _ _)) = (xs, F4 a b c Nothing, p)
go ':' (xs, F3 a b ds k, p) = (xs, F4 a b (k * (read ds)) Nothing, p)
go ';' (xs, F3 a b [] _, SM _ _ c d e) = let p' = SM a b c d e in (xs |> p', F1 [] 1, p')
go ';' (xs, F3 a b ds k, SM _ _ _ d e) = let p' = SM a b (k * (read ds)) d e in
(xs |> p', F1 [] 1, p')

go 'i' (xs, F4 a b c, p) = (xs, F5 (SM a b c JumpInto), p)
go 'o' (xs, F4 a b c, p) = (xs, F5 (SM a b c JumpFrom), p)
go '-' (xs, F4 a b c, p) = (xs, F5 (SM a b c JumpRegular), p)
go ';' (xs, F5 s, _) = (xs |> s, F1 [] 1, s)
go 'i' (xs, F4 a b c Nothing, p) = (xs, F4 a b c (Just JumpInto), p)
go 'o' (xs, F4 a b c Nothing, p) = (xs, F4 a b c (Just JumpFrom), p)
go '-' (xs, F4 a b c Nothing, p) = (xs, F4 a b c (Just JumpRegular), p)
go ':' (xs, F4 a b c (Just d), p) = (xs, F5 a b c d [], p)
go ':' (xs, F4 a b c _, p@(SM _ _ _ d _)) = (xs, F5 a b c d [], p)
go ';' (xs, F4 a b c _, SM _ _ _ d e) = let p' = SM a b c d e in
(xs |> p', F1 [] 1, p')

go d (xs, F5 a b c j ds, p) | isDigit d = (xs, F5 a b c j (d : ds), p)
go ';' (xs, F5 a b c j [], _) = let p' = SM a b c j (-1) in -- solc <0.6
(xs |> p', F1 [] 1, p')
go ';' (xs, F5 a b c j ds, _) = let p' = SM a b c j (read ds) in -- solc >=0.6
(xs |> p', F1 [] 1, p')

go c (xs, _, p) = (xs, error ("srcmap: y u " ++ show c ++ "?!?"), p)
go c (xs, state, p) = (xs, error ("srcmap: y u " ++ show c ++ " in state" ++ show state ++ "?!?"), p)

makeSourceCache :: [Text] -> Map Text Value -> IO SourceCache
makeSourceCache paths asts = do
Expand Down Expand Up @@ -380,7 +386,7 @@ astIdMap = foldMap f

astSrcMap :: Map Int Value -> (SrcMap -> Maybe Value)
astSrcMap astIds =
\(SM i n f _) -> Map.lookup (i, n, f) tmp
\(SM i n f _ _) -> Map.lookup (i, n, f) tmp
where
tmp :: Map (Int, Int, Int) Value
tmp =
Expand Down