Safe Haskell | None |
---|---|
Language | Haskell2010 |
- Data types
- Data accessors
- Data constructors
- Opcode dispatch (exec1)
- Opcode helper actions
- How to finalize a transaction
- Substate manipulation
- Cheat codes
- General call implementation ("delegateCall")
- VM error implementation
- Memory helpers
- Tracing
- Stack manipulation
- Bytecode data functions
- Gas cost calculation helpers
- Uninterpreted functions
- Arithmetic
- Emacs setup
Synopsis
- data Error
- = BalanceTooLow Word Word
- | UnrecognizedOpcode Word8
- | SelfDestruction
- | StackUnderrun
- | BadJumpDestination
- | Revert ByteString
- | NoSuchContract Addr
- | OutOfGas Word Word
- | BadCheatCode (Maybe Word32)
- | StackLimitExceeded
- | IllegalOverflow
- | Query Query
- | Choose Choose
- | StateChangeWhileStatic
- | InvalidMemoryAccess
- | CallDepthLimitReached
- | MaxCodeSizeExceeded Word Word
- | PrecompileFailure
- | UnexpectedSymbolicArg
- | DeadPath
- data VMResult
- data VM = VM {}
- data Trace = Trace {}
- data TraceData
- data Query where
- PleaseFetchContract :: Addr -> (Contract -> EVM ()) -> Query
- PleaseFetchSlot :: Addr -> Word -> (Word -> EVM ()) -> Query
- PleaseAskSMT :: SBool -> [SBool] -> (BranchCondition -> EVM ()) -> Query
- data Choose where
- PleaseChoosePath :: (Bool -> EVM ()) -> Choose
- type EVM a = State VM a
- type CodeLocation = (Addr, Int)
- data BranchCondition
- = Case Bool
- | Unknown
- | Inconsistent
- data Cache = Cache {}
- data VMOpts = VMOpts {
- vmoptContract :: Contract
- vmoptCalldata :: (Buffer, SWord 32)
- vmoptValue :: SymWord
- vmoptAddress :: Addr
- vmoptCaller :: SAddr
- vmoptOrigin :: Addr
- vmoptGas :: W256
- vmoptGaslimit :: W256
- vmoptNumber :: W256
- vmoptTimestamp :: SymWord
- vmoptCoinbase :: Addr
- vmoptDifficulty :: W256
- vmoptMaxCodeSize :: W256
- vmoptBlockGaslimit :: W256
- vmoptGasprice :: W256
- vmoptSchedule :: FeeSchedule Word
- vmoptChainId :: W256
- vmoptCreate :: Bool
- vmoptStorageModel :: StorageModel
- data Log = Log Addr Buffer [SymWord]
- data Frame = Frame {}
- data FrameContext
- = CreationContext { }
- | CallContext { }
- data FrameState = FrameState {}
- data TxState = TxState {}
- data SubState = SubState {
- _selfdestructs :: [Addr]
- _touchedAccounts :: [Addr]
- _refunds :: [(Addr, Word)]
- data ContractCode
- data Storage
- data Contract = Contract {}
- data StorageModel
- data Env = Env {
- _contracts :: Map Addr Contract
- _chainId :: Word
- _storageModel :: StorageModel
- _sha3Crack :: Map Word ByteString
- _keccakUsed :: [([SWord 8], SWord 256)]
- data Block = Block {
- _coinbase :: Addr
- _timestamp :: SymWord
- _number :: Word
- _difficulty :: Word
- _gaslimit :: Word
- _maxCodeSize :: Word
- _schedule :: FeeSchedule Word
- blankState :: FrameState
- static :: Lens' FrameState Bool
- stack :: Lens' FrameState [SymWord]
- returndata :: Lens' FrameState Buffer
- pc :: Lens' FrameState Int
- memorySize :: Lens' FrameState Int
- memory :: Lens' FrameState Buffer
- gas :: Lens' FrameState Word
- contract :: Lens' FrameState Addr
- codeContract :: Lens' FrameState Addr
- code :: Lens' FrameState ByteString
- callvalue :: Lens' FrameState SymWord
- caller :: Lens' FrameState SAddr
- calldata :: Lens' FrameState (Buffer, SWord 32)
- frameState :: Lens' Frame FrameState
- frameContext :: Lens' Frame FrameContext
- timestamp :: Lens' Block SymWord
- schedule :: Lens' Block (FeeSchedule Word)
- number :: Lens' Block Word
- maxCodeSize :: Lens' Block Word
- gaslimit :: Lens' Block Word
- difficulty :: Lens' Block Word
- coinbase :: Lens' Block Addr
- value :: Lens' TxState SymWord
- txgaslimit :: Lens' TxState Word
- txReversion :: Lens' TxState (Map Addr Contract)
- toAddr :: Lens' TxState Addr
- substate :: Lens' TxState SubState
- origin :: Lens' TxState Addr
- isCreate :: Lens' TxState Bool
- gasprice :: Lens' TxState Word
- touchedAccounts :: Lens' SubState [Addr]
- selfdestructs :: Lens' SubState [Addr]
- refunds :: Lens' SubState [(Addr, Word)]
- storage :: Lens' Contract Storage
- origStorage :: Lens' Contract (Map Word Word)
- opIxMap :: Lens' Contract (Vector Int)
- nonce :: Lens' Contract Word
- external :: Lens' Contract Bool
- contractcode :: Lens' Contract ContractCode
- codehash :: Lens' Contract W256
- codeOps :: Lens' Contract (Vector (Int, Op))
- balance :: Lens' Contract Word
- storageModel :: Lens' Env StorageModel
- sha3Crack :: Lens' Env (Map Word ByteString)
- keccakUsed :: Lens' Env [([SWord 8], SWord 256)]
- contracts :: Lens' Env (Map Addr Contract)
- chainId :: Lens' Env Word
- path :: Lens' Cache (Map (CodeLocation, Int) Bool)
- fetched :: Lens' Cache (Map Addr Contract)
- traceOpIx :: Lens' Trace Int
- traceData :: Lens' Trace TraceData
- traceCodehash :: Lens' Trace W256
- tx :: Lens' VM TxState
- traces :: Lens' VM (TreePos Empty Trace)
- state :: Lens' VM FrameState
- result :: Lens' VM (Maybe VMResult)
- pathConditions :: Lens' VM [SBool]
- logs :: Lens' VM (Seq Log)
- iterations :: Lens' VM (Map CodeLocation Int)
- frames :: Lens' VM [Frame]
- env :: Lens' VM Env
- cache :: Lens' VM Cache
- burned :: Lens' VM Word
- block :: Lens' VM Block
- bytecode :: Getter Contract ByteString
- unifyCachedContract :: Contract -> Contract -> Contract
- currentContract :: VM -> Maybe Contract
- makeVm :: VMOpts -> VM
- initialContract :: ContractCode -> Contract
- contractWithStore :: ContractCode -> Storage -> Contract
- next :: (?op :: Word8) => EVM ()
- exec1 :: EVM ()
- transfer :: Addr -> Addr -> Word -> EVM ()
- callChecks :: (?op :: Word8) => Contract -> Word -> Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> (Word -> EVM ()) -> EVM ()
- precompiledContract :: (?op :: Word8) => Contract -> Word -> Addr -> Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> EVM ()
- executePrecompile :: (?op :: Word8) => Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> EVM ()
- truncpadlit :: Int -> ByteString -> ByteString
- lazySlice :: Word -> Word -> ByteString -> ByteString
- parseModexpLength :: ByteString -> (Word, Word, Word)
- isZero :: Word -> Word -> ByteString -> Bool
- asInteger :: ByteString -> Integer
- noop :: Monad m => m ()
- pushTo :: MonadState s m => ASetter s s [a] [a] -> a -> m ()
- pushToSequence :: MonadState s m => ASetter s s (Seq a) (Seq a) -> a -> m ()
- getCodeLocation :: VM -> CodeLocation
- askSMT :: CodeLocation -> SBool -> (Bool -> EVM ()) -> EVM ()
- fetchAccount :: Addr -> (Contract -> EVM ()) -> EVM ()
- readStorage :: Storage -> SymWord -> Maybe SymWord
- writeStorage :: SymWord -> SymWord -> Storage -> Storage
- accessStorage :: Addr -> SymWord -> (SymWord -> EVM ()) -> EVM ()
- accountExists :: Addr -> VM -> Bool
- accountEmpty :: Contract -> Bool
- finalize :: EVM ()
- loadContract :: Addr -> EVM ()
- limitStack :: Int -> EVM () -> EVM ()
- notStatic :: EVM () -> EVM ()
- burn :: Word -> EVM () -> EVM ()
- forceConcreteAddr :: SAddr -> (Addr -> EVM ()) -> EVM ()
- forceConcrete :: SymWord -> (Word -> EVM ()) -> EVM ()
- forceConcrete2 :: (SymWord, SymWord) -> ((Word, Word) -> EVM ()) -> EVM ()
- forceConcrete3 :: (SymWord, SymWord, SymWord) -> ((Word, Word, Word) -> EVM ()) -> EVM ()
- forceConcrete4 :: (SymWord, SymWord, SymWord, SymWord) -> ((Word, Word, Word, Word) -> EVM ()) -> EVM ()
- forceConcrete5 :: (SymWord, SymWord, SymWord, SymWord, SymWord) -> ((Word, Word, Word, Word, Word) -> EVM ()) -> EVM ()
- forceConcrete6 :: (SymWord, SymWord, SymWord, SymWord, SymWord, SymWord) -> ((Word, Word, Word, Word, Word, Word) -> EVM ()) -> EVM ()
- forceConcreteBuffer :: Buffer -> (ByteString -> EVM ()) -> EVM ()
- refund :: Word -> EVM ()
- unRefund :: Word -> EVM ()
- touchAccount :: Addr -> EVM ()
- selfdestruct :: Addr -> EVM ()
- cheatCode :: Addr
- cheat :: (?op :: Word8) => (Word, Word) -> (Word, Word) -> EVM ()
- type CheatAction = ([AbiType], Word -> Word -> [AbiValue] -> EVM ())
- cheatActions :: Map Word32 CheatAction
- delegateCall :: (?op :: Word8) => Contract -> Word -> Addr -> Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> EVM () -> EVM ()
- collision :: Maybe Contract -> Bool
- create :: (?op :: Word8) => Addr -> Contract -> Word -> Word -> [SymWord] -> Addr -> ByteString -> EVM ()
- replaceCode :: Addr -> ContractCode -> EVM ()
- replaceCodeOfSelf :: ContractCode -> EVM ()
- resetState :: EVM ()
- vmError :: Error -> EVM ()
- underrun :: EVM ()
- data FrameResult
- finishFrame :: FrameResult -> EVM ()
- accessUnboundedMemoryRange :: FeeSchedule Word -> Word -> Word -> EVM () -> EVM ()
- accessMemoryRange :: FeeSchedule Word -> Word -> Word -> EVM () -> EVM ()
- accessMemoryWord :: FeeSchedule Word -> Word -> EVM () -> EVM ()
- copyBytesToMemory :: Buffer -> Word -> Word -> Word -> EVM ()
- copyCallBytesToMemory :: Buffer -> Word -> Word -> Word -> EVM ()
- readMemory :: Word -> Word -> VM -> Buffer
- word256At :: Functor f => Word -> (SymWord -> f SymWord) -> Buffer -> f Buffer
- withTraceLocation :: MonadState VM m => TraceData -> m Trace
- pushTrace :: TraceData -> EVM ()
- insertTrace :: TraceData -> EVM ()
- popTrace :: EVM ()
- zipperRootForest :: TreePos Empty a -> Forest a
- traceForest :: VM -> Forest Trace
- traceLog :: MonadState VM m => Log -> m ()
- push :: Word -> EVM ()
- pushSym :: SymWord -> EVM ()
- stackOp1 :: (?op :: Word8) => (SymWord -> Word) -> (SymWord -> SymWord) -> EVM ()
- stackOp2 :: (?op :: Word8) => ((SymWord, SymWord) -> Word) -> ((SymWord, SymWord) -> SymWord) -> EVM ()
- stackOp3 :: (?op :: Word8) => ((SymWord, SymWord, SymWord) -> Word) -> ((SymWord, SymWord, SymWord) -> SymWord) -> EVM ()
- checkJump :: Integral n => n -> [SymWord] -> EVM ()
- opSize :: Word8 -> Int
- mkOpIxMap :: ByteString -> Vector Int
- vmOp :: VM -> Maybe Op
- vmOpIx :: VM -> Maybe Int
- opParams :: VM -> Map String SymWord
- readOp :: Word8 -> ByteString -> Op
- mkCodeOps :: ByteString -> Vector (Int, Op)
- costOfCall :: FeeSchedule Word -> Bool -> Word -> Word -> Word -> (Word, Word)
- costOfCreate :: FeeSchedule Word -> Word -> Word -> (Word, Word)
- costOfPrecompile :: FeeSchedule Word -> Addr -> Buffer -> Word
- memoryCost :: FeeSchedule Word -> Word -> Word
- symSHA256N :: SInteger -> SInteger -> SWord 256
- symkeccakN :: SInteger -> SInteger -> SWord 256
- toSInt :: [SWord 8] -> SInteger
- symkeccak' :: [SWord 8] -> SWord 256
- symSHA256 :: [SWord 8] -> [SWord 8]
- ceilDiv :: (Num a, Integral a) => a -> a -> a
- allButOne64th :: (Num a, Integral a) => a -> a
- log2 :: FiniteBits b => b -> Int
Data types
EVM failure modes
The possible result states of a VM
The state of a stepwise EVM execution
Trace | |
|
Queries halt execution until resolved through RPC calls or SMT queries
PleaseFetchContract :: Addr -> (Contract -> EVM ()) -> Query | |
PleaseFetchSlot :: Addr -> Word -> (Word -> EVM ()) -> Query | |
PleaseAskSMT :: SBool -> [SBool] -> (BranchCondition -> EVM ()) -> Query |
PleaseChoosePath :: (Bool -> EVM ()) -> Choose |
type CodeLocation = (Addr, Int) Source #
data BranchCondition Source #
The possible return values of a SMT query
Instances
Show BranchCondition Source # | |
Defined in EVM showsPrec :: Int -> BranchCondition -> ShowS # show :: BranchCondition -> String # showList :: [BranchCondition] -> ShowS # |
The cache is data that can be persisted for efficiency: any expensive query that is constant at least within a block.
A way to specify an initial VM state
VMOpts | |
|
An entry in the VM's "call/create stack"
The state that spans a whole transaction
The "accrued substate" across a transaction
SubState | |
|
data ContractCode Source #
A contract is either in creation (running its "constructor") or
post-creation, and code in these two modes is treated differently
by instructions like EXTCODEHASH
, so we distinguish these two
code types.
InitCode ByteString | Constructor code, during contract creation |
RuntimeCode ByteString | Instance code, after contract creation |
Instances
Eq ContractCode Source # | |
Defined in EVM (==) :: ContractCode -> ContractCode -> Bool # (/=) :: ContractCode -> ContractCode -> Bool # | |
Show ContractCode Source # | |
Defined in EVM showsPrec :: Int -> ContractCode -> ShowS # show :: ContractCode -> String # showList :: [ContractCode] -> ShowS # |
A contract can either have concrete or symbolic storage depending on what type of execution we are doing
The state of a contract
data StorageModel Source #
When doing symbolic execution, we have three different ways to model the storage of contracts. This determines not only the initial contract storage model but also how RPC or state fetched contracts will be modeled.
ConcreteS | Uses |
SymbolicS | Uses |
InitialS | Uses |
Instances
Read StorageModel Source # | |
Defined in EVM readsPrec :: Int -> ReadS StorageModel # readList :: ReadS [StorageModel] # | |
Show StorageModel Source # | |
Defined in EVM showsPrec :: Int -> StorageModel -> ShowS # show :: StorageModel -> String # showList :: [StorageModel] -> ShowS # | |
ParseField StorageModel Source # | |
Defined in EVM parseField :: Maybe Text -> Maybe Text -> Maybe Char -> Parser StorageModel # parseListOfField :: Maybe Text -> Maybe Text -> Maybe Char -> Parser [StorageModel] # readField :: ReadM StorageModel # metavar :: proxy StorageModel -> String # |
Various environmental data
Env | |
|
Data about the block
Block | |
|
iterations :: Lens' VM (Map CodeLocation Int) Source #
bytecode :: Getter Contract ByteString Source #
An "external" view of a contract's bytecode, appropriate for
e.g. EXTCODEHASH
.
Data accessors
Data constructors
initialContract :: ContractCode -> Contract Source #
Initialize empty contract with given code
contractWithStore :: ContractCode -> Storage -> Contract Source #
Opcode dispatch (exec1)
callChecks :: (?op :: Word8) => Contract -> Word -> Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> (Word -> EVM ()) -> EVM () Source #
Checks a *CALL for failure; OOG, too many callframes, memory access etc.
precompiledContract :: (?op :: Word8) => Contract -> Word -> Addr -> Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> EVM () Source #
executePrecompile :: (?op :: Word8) => Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> EVM () Source #
truncpadlit :: Int -> ByteString -> ByteString Source #
lazySlice :: Word -> Word -> ByteString -> ByteString Source #
parseModexpLength :: ByteString -> (Word, Word, Word) Source #
asInteger :: ByteString -> Integer Source #
Opcode helper actions
pushTo :: MonadState s m => ASetter s s [a] [a] -> a -> m () Source #
pushToSequence :: MonadState s m => ASetter s s (Seq a) (Seq a) -> a -> m () Source #
getCodeLocation :: VM -> CodeLocation Source #
askSMT :: CodeLocation -> SBool -> (Bool -> EVM ()) -> EVM () Source #
Construct SMT Query and halt execution until resolved
fetchAccount :: Addr -> (Contract -> EVM ()) -> EVM () Source #
Construct RPC Query and halt execution until resolved
accountEmpty :: Contract -> Bool Source #
How to finalize a transaction
loadContract :: Addr -> EVM () Source #
Loads the selected contract as the current contract to execute
forceConcrete4 :: (SymWord, SymWord, SymWord, SymWord) -> ((Word, Word, Word, Word) -> EVM ()) -> EVM () Source #
forceConcrete5 :: (SymWord, SymWord, SymWord, SymWord, SymWord) -> ((Word, Word, Word, Word, Word) -> EVM ()) -> EVM () Source #
forceConcrete6 :: (SymWord, SymWord, SymWord, SymWord, SymWord, SymWord) -> ((Word, Word, Word, Word, Word, Word) -> EVM ()) -> EVM () Source #
forceConcreteBuffer :: Buffer -> (ByteString -> EVM ()) -> EVM () Source #
Substate manipulation
touchAccount :: Addr -> EVM () Source #
selfdestruct :: Addr -> EVM () Source #
Cheat codes
General call implementation ("delegateCall")
delegateCall :: (?op :: Word8) => Contract -> Word -> Addr -> Addr -> Word -> Word -> Word -> Word -> Word -> [SymWord] -> EVM () -> EVM () Source #
create :: (?op :: Word8) => Addr -> Contract -> Word -> Word -> [SymWord] -> Addr -> ByteString -> EVM () Source #
replaceCode :: Addr -> ContractCode -> EVM () Source #
Replace a contract's code, like when CREATE returns from the constructor code.
replaceCodeOfSelf :: ContractCode -> EVM () Source #
resetState :: EVM () Source #
VM error implementation
data FrameResult Source #
A stack frame can be popped in three ways.
FrameReturned Buffer | STOP, RETURN, or no more code |
FrameReverted Buffer | REVERT |
FrameErrored Error | Any other error |
Instances
Show FrameResult Source # | |
Defined in EVM showsPrec :: Int -> FrameResult -> ShowS # show :: FrameResult -> String # showList :: [FrameResult] -> ShowS # |
finishFrame :: FrameResult -> EVM () Source #
This function defines how to pop the current stack frame in either of
the ways specified by FrameResult
.
It also handles the case when the current stack frame is the only one;
in this case, we set the final _result
of the VM execution.
Memory helpers
accessUnboundedMemoryRange :: FeeSchedule Word -> Word -> Word -> EVM () -> EVM () Source #
accessMemoryRange :: FeeSchedule Word -> Word -> Word -> EVM () -> EVM () Source #
accessMemoryWord :: FeeSchedule Word -> Word -> EVM () -> EVM () Source #
Tracing
withTraceLocation :: MonadState VM m => TraceData -> m Trace Source #
insertTrace :: TraceData -> EVM () Source #
Stack manipulation
stackOp2 :: (?op :: Word8) => ((SymWord, SymWord) -> Word) -> ((SymWord, SymWord) -> SymWord) -> EVM () Source #
stackOp3 :: (?op :: Word8) => ((SymWord, SymWord, SymWord) -> Word) -> ((SymWord, SymWord, SymWord) -> SymWord) -> EVM () Source #
Bytecode data functions
Gas cost calculation helpers
costOfCreate :: FeeSchedule Word -> Word -> Word -> (Word, Word) Source #
costOfPrecompile :: FeeSchedule Word -> Addr -> Buffer -> Word Source #
memoryCost :: FeeSchedule Word -> Word -> Word Source #
Uninterpreted functions
symkeccak' :: [SWord 8] -> SWord 256 Source #
Although we'd like to define this directly as an uninterpreted function, we cannot because [a] is not a symbolic type. We must convert the list into a suitable symbolic type first. The only important property of this conversion is that it is injective. We embedd the bytestring as a pair of symbolic integers, this is a fairly easy solution.
Arithmetic
allButOne64th :: (Num a, Integral a) => a -> a Source #
log2 :: FiniteBits b => b -> Int Source #