|
| 1 | +-- |
| 2 | +-- Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +-- you may not use this file except in compliance with the License. |
| 4 | +-- You may obtain a copy of the License at |
| 5 | +-- |
| 6 | +-- http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +-- |
| 8 | +-- Unless required by applicable law or agreed to in writing, software |
| 9 | +-- distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +-- See the License for the specific language governing permissions and |
| 12 | +-- limitations under the License. |
| 13 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 14 | + |
| 15 | +module Main where |
| 16 | + |
| 17 | +import System.Environment |
| 18 | +import System.Exit |
| 19 | +import Control.Exception.Base |
| 20 | +import System.IO |
| 21 | +import System.IO.Error |
| 22 | + |
| 23 | +import Text.Parsec hiding (try) |
| 24 | +import Text.Parsec.String |
| 25 | +import Text.Parsec.Token |
| 26 | +import Solidity |
| 27 | +import CFG |
| 28 | +import StaticAnalysis |
| 29 | +import StaticAnalysis.Util |
| 30 | +import StaticAnalysis.ComplianceChecking as ComplianceChecking |
| 31 | +import StaticAnalysis.ICFG as ICFG |
| 32 | +import StaticAnalysis.CallGraph as CallGraph |
| 33 | +import Parseable |
| 34 | +import DEA |
| 35 | +import Numeric |
| 36 | +import Numeric.Natural |
| 37 | + |
| 38 | +type Filename = String |
| 39 | + |
| 40 | +failWith :: IO a -> String -> IO a |
| 41 | +io `failWith` e = io `catch` (const $ (fail e) :: IOError -> IO a) |
| 42 | + |
| 43 | +ifNot :: Bool -> String -> IO () |
| 44 | +ifNot c e = if c then return () else fail e |
| 45 | + |
| 46 | +parseIO :: Parseable a => Filename -> String -> IO a |
| 47 | +parseIO filename = either (fail . (parseError ++) . show) return . parse parser "" |
| 48 | + where |
| 49 | + parseError = "Error during parsing of <"++filename++">\n" |
| 50 | + |
| 51 | + |
| 52 | +main = |
| 53 | + do arguments <- getArgs |
| 54 | + ifNot (length arguments == 2) |
| 55 | + ("Usage: <number bigger than 0> <input solidity file> <input dea file>") |
| 56 | + let [inSCFile, inDEAFile] = arguments |
| 57 | + inputText <- readFile inSCFile |
| 58 | + `failWith` ("Cannot read Solidity file <"++inSCFile++">") |
| 59 | + solidityCode <- parseIO inSCFile inputText |
| 60 | + inputDEA <- readFile inDEAFile |
| 61 | + `failWith` ("Cannot read DEA file <"++inDEAFile++">") |
| 62 | + dea <- parseIO inDEAFile inputDEA |
| 63 | + let cg = icallgraph (ICFG.instrument (CFG.contractCFG solidityCode) dea) |
| 64 | + let compliant = ComplianceChecking.compliantWith (0) (ICFG.instrument (CFG.contractCFG solidityCode) dea) dea cg |
| 65 | + if compliant then putStrLn ("Smart contract is compliant with DEA!") else putStrLn ("Smart contract is not compliant with DEA!") |
| 66 | + `catch` (putStrLn . ioeGetErrorString) |
0 commit comments