Skip to content

Commit

Permalink
Merge pull request #1109 from GaloisInc/server-tweaks-bump
Browse files Browse the repository at this point in the history
Server tweaks bump
  • Loading branch information
mergify[bot] committed Mar 9, 2021
2 parents a818032 + 96eb69f commit 9da72c5
Show file tree
Hide file tree
Showing 21 changed files with 326 additions and 337 deletions.
1 change: 0 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ packages:
deps/dwarf
deps/argo/argo
deps/argo/tasty-script-exitcode
deps/argo/python
deps/cryptol/cryptol-remote-api
2 changes: 1 addition & 1 deletion deps/argo
Submodule argo updated 62 files
+4 −5 .github/workflows/ci.yml
+1 −1 README.rst
+10 −4 argo/argo.cabal
+428 −336 argo/src/Argo.hs
+28 −8 argo/src/Argo/DefaultMain.hs
+69 −412 argo/src/Argo/ServerState.hs
+0 −1 cabal.project
+0 −21 docs/CryptolPython.rst
+0 −3 docs/SAWPython.rst
+0 −43 dreams/salsa20.py
+0 −99 dreams/salsa20_comp.py
+0 −46 dreams/swap.py
+0 −182 examples/Salsa20.cry
+ examples/salsa20.bc
+0 −191 examples/salsa20.c
+0 −72 examples/salsa20.h
+0 −187 examples/salsa20.py
+ examples/swap.bc
+0 −13 examples/swap.c
+0 −39 examples/swap.py
+7 −14 file-echo-api/file-echo-api.cabal
+15 −12 file-echo-api/file-echo-api/Main.hs
+59 −0 file-echo-api/mutable-file-echo-api/Main.hs
+28 −91 file-echo-api/src/FileEchoServer.hs
+155 −0 file-echo-api/src/MutableFileEchoServer.hs
+0 −426 file-echo-api/test-scripts/file-echo-tests.py
+5 −0 python/CHANGELOG.md
+11 −0 python/LICENSE
+3 −0 python/README.md
+0 −34 python/argo-python.cabal
+0 −0 python/argo_client/__init__.py
+0 −0 python/argo_client/connection.py
+31 −6 python/argo_client/interaction.py
+0 −0 python/argo_client/netstring.py
+0 −0 python/argo_client/py.typed
+0 −457 python/cryptol/__init__.py
+0 −478 python/cryptol/bitvector.py
+0 −505 python/cryptol/cryptoltypes.py
+0 −29 python/cryptol/solver.py
+0 −2 python/cryptol/test/__init__.py
+0 −447 python/cryptol/test/test_bitvector.py
+0 −42 python/hs-test/Main.hs
+0 −6 python/hs/Argo/PythonBindings.hs
+1 −12 python/mypy.ini
+6 −0 python/pyproject.toml
+0 −2 python/requirements.txt
+0 −365 python/saw/__init__.py
+0 −84 python/saw/commands.py
+0 −82 python/saw/connection.py
+0 −243 python/saw/dashboard.py
+0 −99 python/saw/exceptions.py
+0 −384 python/saw/llvm.py
+0 −60 python/saw/llvm_types.py
+0 −93 python/saw/proofscript.py
+0 −0 python/saw/py.typed
+42 −7 python/setup.py
+0 −0 python/tests/__init__.py
+1 −0 python/tests/test-data/base.txt
+0 −0 python/tests/test-data/hello.txt
+455 −0 python/tests/test_file_echo_api.py
+207 −0 python/tests/test_file_echo_interaction.py
+133 −0 python/tests/test_mutable_file_echo_api.py
2 changes: 1 addition & 1 deletion deps/cryptol
Submodule cryptol updated 46 files
+1 −1 .github/ci.sh
+0 −2 cabal.project
+8 −0 cry
+34 −20 cryptol-remote-api/cryptol-eval-server/Main.hs
+2 −21 cryptol-remote-api/cryptol-remote-api.cabal
+31 −26 cryptol-remote-api/cryptol-remote-api/Main.hs
+83 −0 cryptol-remote-api/python/README.md
+524 −0 cryptol-remote-api/python/cryptol/__init__.py
+478 −0 cryptol-remote-api/python/cryptol/bitvector.py
+505 −0 cryptol-remote-api/python/cryptol/cryptoltypes.py
+0 −0 cryptol-remote-api/python/cryptol/py.typed
+29 −0 cryptol-remote-api/python/cryptol/solver.py
+13 −0 cryptol-remote-api/python/mypy.ini
+30 −0 cryptol-remote-api/python/requirements.txt
+44 −0 cryptol-remote-api/python/setup.py
+0 −0 cryptol-remote-api/python/tests/__init__.py
+0 −0 cryptol-remote-api/python/tests/cryptol/__init__.py
+0 −0 cryptol-remote-api/python/tests/cryptol/test-files/Foo.cry
+0 −0 cryptol-remote-api/python/tests/cryptol/test-files/Id.cry
+0 −0 cryptol-remote-api/python/tests/cryptol/test-files/Inst.cry
+0 −0 cryptol-remote-api/python/tests/cryptol/test-files/M.cry
+0 −0 cryptol-remote-api/python/tests/cryptol/test-files/Param.cry
+447 −0 cryptol-remote-api/python/tests/cryptol/test_bitvector.py
+139 −0 cryptol-remote-api/python/tests/cryptol/test_cryptol_api.py
+279 −0 cryptol-remote-api/python/tests/cryptol/test_low_level_ops.py
+28 −0 cryptol-remote-api/python/tests/cryptol_eval/M.cry
+36 −0 cryptol-remote-api/python/tests/cryptol_eval/test_basics.py
+48 −0 cryptol-remote-api/run_rpc_tests.sh
+47 −28 cryptol-remote-api/src/CryptolServer.hs
+1 −1 cryptol-remote-api/src/CryptolServer/Call.hs
+1 −1 cryptol-remote-api/src/CryptolServer/ChangeDir.hs
+32 −0 cryptol-remote-api/src/CryptolServer/ClearState.hs
+33 −29 cryptol-remote-api/src/CryptolServer/Data/Expression.hs
+2 −2 cryptol-remote-api/src/CryptolServer/EvalExpr.hs
+1 −1 cryptol-remote-api/src/CryptolServer/FocusedModule.hs
+2 −2 cryptol-remote-api/src/CryptolServer/LoadModule.hs
+1 −1 cryptol-remote-api/src/CryptolServer/Names.hs
+2 −2 cryptol-remote-api/src/CryptolServer/Sat.hs
+1 −1 cryptol-remote-api/src/CryptolServer/TypeCheck.hs
+0 −70 cryptol-remote-api/test-scripts/cryptol-api_test.py
+0 −245 cryptol-remote-api/test-scripts/cryptol-tests.py
+0 −47 cryptol-remote-api/test-scripts/eval-server-test.py
+0 −8 cryptol-remote-api/test/Dockerfile
+0 −87 cryptol-remote-api/test/Test.hs
+0 −17 cryptol-remote-api/test/test-cryptol-remote-api.py
+1 −1 deps/argo
72 changes: 40 additions & 32 deletions saw-remote-api/saw-remote-api/Main.hs
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where

import Argo
import Argo.DefaultMain
import qualified Argo
import qualified Argo.DefaultMain as Argo (defaultMain)
import qualified Argo.Doc as Doc

import SAWServer
import SAWServer ( SAWState, initialState )
import SAWServer.CryptolSetup
( cryptolLoadModuleDescr,
cryptolLoadModule,
cryptolLoadFileDescr,
cryptolLoadFile )
--import SAWServer.JVMCrucibleSetup
--import SAWServer.JVMVerify
import SAWServer.LLVMCrucibleSetup
( llvmLoadModuleDescr, llvmLoadModule )
import SAWServer.LLVMVerify
( llvmVerifyDescr,
llvmVerify,
llvmAssumeDescr,
llvmAssume,
llvmVerifyX86Descr,
llvmVerifyX86 )
import SAWServer.ProofScript
import SAWServer.SaveTerm
import SAWServer.SetOption
( makeSimpsetDescr, makeSimpset, proveDescr, prove )
import SAWServer.SaveTerm ( saveTermDescr, saveTerm )
import SAWServer.SetOption ( setOptionDescr, setOption )


main :: IO ()
main =
do theApp <- mkDefaultApp "SAW RPC Server" serverDocs initialState sawMethods
defaultMain description theApp
main = do
theApp <- Argo.mkApp
"SAW RPC Server"
serverDocs
(Argo.defaultAppOpts
Argo.MutableState)
initialState
sawMethods
Argo.defaultMain description theApp

serverDocs :: [Doc.Block]
serverDocs =
Expand All @@ -32,65 +50,55 @@ description :: String
description =
"An RPC server for SAW."

sawMethods :: [AppMethod SAWState]
sawMethods :: [Argo.AppMethod SAWState]
sawMethods =
-- Cryptol
[ method
[ Argo.command
"SAW/Cryptol/load module"
Command
cryptolLoadModuleDescr
cryptolLoadModule
, method
, Argo.command
"SAW/Cryptol/load file"
Command
cryptolLoadFileDescr
cryptolLoadFile
, method
, Argo.command
"SAW/Cryptol/save term"
Command
saveTermDescr
saveTerm
-- JVM
{-
, method "SAW/JVM/load class" Command (Doc.Paragraph [Doc.Text "TODO"]) jvmLoadClass
, method "SAW/JVM/verify" Command (Doc.Paragraph [Doc.Text "TODO"]) jvmVerify
, method "SAW/JVM/assume" Command (Doc.Paragraph [Doc.Text "TODO"]) jvmAssume
, Argo.command "SAW/JVM/load class" (Doc.Paragraph [Doc.Text "TODO"]) jvmLoadClass
, Argo.command "SAW/JVM/verify" (Doc.Paragraph [Doc.Text "TODO"]) jvmVerify
, Argo.command "SAW/JVM/assume" (Doc.Paragraph [Doc.Text "TODO"]) jvmAssume
-}
-- LLVM
, method
, Argo.command
"SAW/LLVM/load module"
Command
llvmLoadModuleDescr
llvmLoadModule
, method
, Argo.command
"SAW/LLVM/verify"
Command
llvmVerifyDescr
llvmVerify
, method
, Argo.command
"SAW/LLVM/verify x86"
Command
llvmVerifyX86Descr
llvmVerifyX86
, method
, Argo.command
"SAW/LLVM/assume"
Command
llvmAssumeDescr
llvmAssume
-- General
, method
, Argo.command
"SAW/make simpset"
Command
makeSimpsetDescr
makeSimpset
, method
, Argo.command
"SAW/prove"
Command
proveDescr
prove
, method
, Argo.command
"SAW/set option"
Command
setOptionDescr
setOption
]
83 changes: 46 additions & 37 deletions saw-remote-api/src/SAWServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module SAWServer
( module SAWServer
) where

import Prelude hiding (mod)
import Control.Lens
import Control.Lens ( Lens', view, lens, over )
import Data.Aeson (FromJSON(..), ToJSON(..), withText)
import Data.ByteString (ByteString)
import Data.Kind (Type)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Parameterized.Pair
import Data.Parameterized.Some
import Data.Parameterized.Pair ( Pair(..) )
import Data.Parameterized.Some ( Some(..) )
import Data.Text (Text)
import qualified Data.Text as T
import qualified Crypto.Hash as Hash
Expand Down Expand Up @@ -58,9 +59,17 @@ import Verifier.SAW.CryptolEnv (initCryptolEnv, bindTypedTerm)
import Verifier.SAW.Rewriter (Simpset)
import qualified Cryptol.Utils.Ident as Cryptol

import Argo
import qualified Argo
import qualified CryptolServer (validateServerState, ServerState(..))
import SAWServer.Exceptions
( serverValNotFound,
notAnLLVMModule,
notAnLLVMSetup,
notAnLLVMMethodSpecIR,
notASimpset,
notATerm,
notAJVMClass,
notAJVMMethodSpecIR )

type SAWCont = (SAWEnv, SAWTask)

Expand Down Expand Up @@ -144,19 +153,19 @@ trackedFiles :: Lens' SAWState (Map FilePath (Hash.Digest Hash.SHA256))
trackedFiles = lens _trackedFiles (\v tf -> v { _trackedFiles = tf })


pushTask :: SAWTask -> Method SAWState ()
pushTask t = modifyState mod
pushTask :: SAWTask -> Argo.Command SAWState ()
pushTask t = Argo.modifyState mod
where mod (SAWState env bic stack ro rw tf) =
SAWState env bic ((t, env) : stack) ro rw tf

dropTask :: Method SAWState ()
dropTask = modifyState mod
dropTask :: Argo.Command SAWState ()
dropTask = Argo.modifyState mod
where mod (SAWState _ _ [] _ _ _) = error "Internal error - stack underflow"
mod (SAWState _ sc ((_t, env):stack) ro rw tf) =
SAWState env sc stack ro rw tf

getHandleAlloc :: Method SAWState Crucible.HandleAllocator
getHandleAlloc = roHandleAlloc . view sawTopLevelRO <$> getState
getHandleAlloc :: Argo.Command SAWState Crucible.HandleAllocator
getHandleAlloc = roHandleAlloc . view sawTopLevelRO <$> Argo.getState

initialState :: (FilePath -> IO ByteString) -> IO SAWState
initialState readFileFn =
Expand Down Expand Up @@ -326,77 +335,77 @@ instance KnownCrucibleSetupType a => IsServerVal (LLVMCrucibleSetupM a) where
instance IsServerVal (Some CMS.LLVMModule) where
toServerVal = VLLVMModule

setServerVal :: IsServerVal val => ServerName -> val -> Method SAWState ()
setServerVal :: IsServerVal val => ServerName -> val -> Argo.Command SAWState ()
setServerVal name val =
do debugLog $ "Saving " <> (T.pack (show name))
modifyState $
do Argo.debugLog $ "Saving " <> (T.pack (show name))
Argo.modifyState $
over sawEnv $
\(SAWEnv env) ->
SAWEnv (M.insert name (toServerVal val) env)
debugLog $ "Saved " <> (T.pack (show name))
st <- getState
debugLog $ "State is " <> T.pack (show st)
Argo.debugLog $ "Saved " <> (T.pack (show name))
st <- Argo.getState @SAWState
Argo.debugLog $ "State is " <> T.pack (show st)


getServerVal :: ServerName -> Method SAWState ServerVal
getServerVal :: ServerName -> Argo.Command SAWState ServerVal
getServerVal n =
do SAWEnv serverEnv <- view sawEnv <$> getState
st <- getState
debugLog $ "Looking up " <> T.pack (show n) <> " in " <> T.pack (show st)
do SAWEnv serverEnv <- view sawEnv <$> Argo.getState
st <- Argo.getState @SAWState
Argo.debugLog $ "Looking up " <> T.pack (show n) <> " in " <> T.pack (show st)
case M.lookup n serverEnv of
Nothing -> raise (serverValNotFound n)
Nothing -> Argo.raise (serverValNotFound n)
Just val -> return val

bindCryptolVar :: Text -> TypedTerm -> Method SAWState ()
bindCryptolVar :: Text -> TypedTerm -> Argo.Command SAWState ()
bindCryptolVar x t =
do modifyState $ over sawTopLevelRW $ \rw ->
do Argo.modifyState $ over sawTopLevelRW $ \rw ->
rw { rwCryptol = bindTypedTerm (Cryptol.mkIdent x, t) (rwCryptol rw) }

getJVMClass :: ServerName -> Method SAWState JSS.Class
getJVMClass :: ServerName -> Argo.Command SAWState JSS.Class
getJVMClass n =
do v <- getServerVal n
case v of
VJVMClass c -> return c
_other -> raise (notAJVMClass n)
_other -> Argo.raise (notAJVMClass n)

getJVMMethodSpecIR :: ServerName -> Method SAWState (CMS.CrucibleMethodSpecIR CJ.JVM)
getJVMMethodSpecIR :: ServerName -> Argo.Command SAWState (CMS.CrucibleMethodSpecIR CJ.JVM)
getJVMMethodSpecIR n =
do v <- getServerVal n
case v of
VJVMMethodSpecIR ir -> return ir
_other -> raise (notAJVMMethodSpecIR n)
_other -> Argo.raise (notAJVMMethodSpecIR n)

getLLVMModule :: ServerName -> Method SAWState (Some CMS.LLVMModule)
getLLVMModule :: ServerName -> Argo.Command SAWState (Some CMS.LLVMModule)
getLLVMModule n =
do v <- getServerVal n
case v of
VLLVMModule m -> return m
_other -> raise (notAnLLVMModule n)
_other -> Argo.raise (notAnLLVMModule n)

getLLVMSetup :: ServerName -> Method SAWState (Pair CrucibleSetupTypeRepr LLVMCrucibleSetupM)
getLLVMSetup :: ServerName -> Argo.Command SAWState (Pair CrucibleSetupTypeRepr LLVMCrucibleSetupM)
getLLVMSetup n =
do v <- getServerVal n
case v of
VLLVMCrucibleSetup setup -> return setup
_other -> raise (notAnLLVMSetup n)
_other -> Argo.raise (notAnLLVMSetup n)

getLLVMMethodSpecIR :: ServerName -> Method SAWState (CMS.SomeLLVM CMS.CrucibleMethodSpecIR)
getLLVMMethodSpecIR :: ServerName -> Argo.Command SAWState (CMS.SomeLLVM CMS.CrucibleMethodSpecIR)
getLLVMMethodSpecIR n =
do v <- getServerVal n
case v of
VLLVMMethodSpecIR ir -> return ir
_other -> raise (notAnLLVMMethodSpecIR n)
_other -> Argo.raise (notAnLLVMMethodSpecIR n)

getSimpset :: ServerName -> Method SAWState Simpset
getSimpset :: ServerName -> Argo.Command SAWState Simpset
getSimpset n =
do v <- getServerVal n
case v of
VSimpset ss -> return ss
_other -> raise (notASimpset n)
_other -> Argo.raise (notASimpset n)

getTerm :: ServerName -> Method SAWState TypedTerm
getTerm :: ServerName -> Argo.Command SAWState TypedTerm
getTerm n =
do v <- getServerVal n
case v of
VTerm t -> return t
_other -> raise (notATerm n)
_other -> Argo.raise (notATerm n)
Loading

0 comments on commit 9da72c5

Please sign in to comment.