8000 `symbolic`: Deduplicate `mkInitialRegVal` across projects · Issue #432 · GaloisInc/macaw · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

symbolic: Deduplicate mkInitialRegVal across projects #432

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

Open
langston-barrett opened this issue Aug 30, 2024 · 3 comments
Open

symbolic: Deduplicate mkInitialRegVal across projects #432

langston-barrett opened this issue Aug 30, 2024 · 3 comments
Labels
symbolic-execution Issues relating to macaw-symbolic and symbolic execution

Comments

@langston-barrett
Copy link
Contributor

Apparently, it's common to make an initial struct of completely symbolic registers:

mkInitialRegVal :: (CB.IsSymInterface sym, MT.HasRepr (MC.ArchReg arch) MT.TypeRepr)

https://github.com/GaloisInc/pate/blob/c43542818be7780264d8a2552bfeba1cffba2902/src/Pate/Verification/InlineCallee.hs#L88

https://github.com/GaloisInc/ambient-verifier/blob/eab04abb9750825a25ec0cbe0379add63f05f6c6/src/Ambient/Verifier/SymbolicExecution.hs#L172

https://github.com/GaloisInc/saw-script/blob/47a7632c973df3fdb2d32268edc92948fc150f2d/src/SAWScript/X86Spec.hs#L453

We should probably export this kind of functionality from macaw-symbolic, to prevent reinventing the wheel. Ideally, this could have some sort of tie-in with the solution to #430, such that the initial register state is reasonably suitable for executing actual machine code.

This does kind of toe the line of what should be included in macaw-symbolic. Certainly, one can imagine clients that would not want to set all registers to fully symbolic values. However, it appears to be relatively common in practice. I think it's not unreasonable to include helpers for setting macaw-symbolic up "in the normal way", and allow clients with more specific needs to use lower-level APIs to achieve what they want. We could also consider collecting this sort of functionality in a separate library, so that not every dependency would have to pay the price of additional compile time.

@langston-barrett langston-barrett added the symbolic-execution Issues relating to macaw-symbolic and symbolic execution label Aug 30, 2024
@langston-barrett
Copy link
Contributor Author

See also freshValue in macaw-x86-symbolic:

@RyanGlScott
Copy link
Contributor

And for even more prior art, see freshCrucibleConstant in macaw-symbolic:

-- | Create a fresh Crucible constant based on the supplied Macaw 'M.TypeRepr'.
freshCrucibleConstant ::
forall sym tp.
IsSymInterface sym =>
sym ->
SolverSymbol ->
M.TypeRepr tp ->
IO (C.RegValue sym (ToCrucibleType tp))

@langston-barrett
Copy link
Contributor Author

Found another one 😆

-- | Generate fresh symbolic variables of supported types
freshSymVar
:: (CB.IsSymInterface sym, MonadIO m)
=> sym
-> String
-> Ctx.Index ctx tp
-> C.TypeRepr tp
-> m (C.RegValue' sym tp)
freshSymVar sym prefix idx tp =
liftIO $ C.RV <$> case W.userSymbol $ prefix ++ show (Ctx.indexVal idx) of
Right symbol -> case tp of
LLVM.LLVMPointerRepr w ->
-- FIXME: This makes a symbolic bitvector - the block ID should also be symbolic
LLVM.llvmPointer_bv sym
=<< W.freshConstant sym symbol (W.BaseBVRepr w)
C.BoolRepr ->
W.freshConstant sym symbol W.BaseBoolRepr
_ -> fail $ "unsupported variable type: " ++ show tp
Left err -> fail $ show err

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
symbolic-execution Issues relating to macaw-symbolic and symbolic execution
Projects
None yet
Development

No branches or pull requests

2 participants
0