Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Error
- data VMResult
- data VM = VM {}
- data Trace = Trace {}
- data TraceData
- data ExecMode
- data Query where
- type EVM a = State VM a
- data Cache = Cache {}
- data VMOpts = VMOpts {
- vmoptCode :: ByteString
- vmoptCalldata :: ByteString
- vmoptValue :: W256
- vmoptAddress :: Addr
- vmoptCaller :: Addr
- vmoptOrigin :: Addr
- vmoptGas :: W256
- vmoptNumber :: W256
- vmoptTimestamp :: W256
- vmoptCoinbase :: Addr
- vmoptDifficulty :: W256
- vmoptGaslimit :: W256
- vmoptGasprice :: W256
- vmoptSchedule :: FeeSchedule Word
- data Log = Log Addr ByteString [Word]
- data Frame = Frame {}
- data FrameContext
- data FrameState = FrameState {
- _contract :: Addr
- _codeContract :: Addr
- _code :: ByteString
- _pc :: Int
- _stack :: [Word]
- _memory :: ByteString
- _memorySize :: Int
- _calldata :: ByteString
- _callvalue :: Word
- _caller :: Addr
- _gas :: Word
- _returndata :: ByteString
- _static :: Bool
- data TxState = TxState {
- _selfdestructs :: [Addr]
- _refunds :: [(Addr, Word)]
- data Contract = Contract {}
- data Env = Env {
- _contracts :: Map Addr Contract
- _sha3Crack :: Map Word ByteString
- _origin :: Addr
- data Block = Block {
- _coinbase :: Addr
- _timestamp :: Word
- _number :: Word
- _difficulty :: Word
- _gaslimit :: Word
- _gasprice :: Word
- _schedule :: FeeSchedule Word
- blankState :: FrameState
- static :: Lens' FrameState Bool
- stack :: Lens' FrameState [Word]
- returndata :: Lens' FrameState ByteString
- pc :: Lens' FrameState Int
- memorySize :: Lens' FrameState Int
- memory :: Lens' FrameState ByteString
- gas :: Lens' FrameState Word
- contract :: Lens' FrameState Addr
- codeContract :: Lens' FrameState Addr
- code :: Lens' FrameState ByteString
- callvalue :: Lens' FrameState Word
- caller :: Lens' FrameState Addr
- calldata :: Lens' FrameState ByteString
- frameState :: Lens' Frame FrameState
- frameContext :: Lens' Frame FrameContext
- timestamp :: Lens' Block Word
- schedule :: Lens' Block (FeeSchedule Word)
- number :: Lens' Block Word
- gasprice :: Lens' Block Word
- gaslimit :: Lens' Block Word
- difficulty :: Lens' Block Word
- coinbase :: Lens' Block Addr
- selfdestructs :: Lens' TxState [Addr]
- refunds :: Lens' TxState [(Addr, Word)]
- storage :: Lens' Contract (Map Word Word)
- opIxMap :: Lens' Contract (Vector Int)
- nonce :: Lens' Contract Word
- external :: Lens' Contract Bool
- codesize :: Lens' Contract Int
- codehash :: Lens' Contract W256
- codeOps :: Lens' Contract (Vector (Int, Op))
- bytecode :: Lens' Contract ByteString
- balance :: Lens' Contract Word
- sha3Crack :: Lens' Env (Map Word ByteString)
- origin :: Lens' Env Addr
- contracts :: Lens' Env (Map Addr Contract)
- fetched :: Iso' 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)
- logs :: Lens' VM (Seq Log)
- frames :: Lens' VM [Frame]
- execMode :: Lens' VM ExecMode
- env :: Lens' VM Env
- cache :: Lens' VM Cache
- burned :: Lens' VM Word
- block :: Lens' VM Block
- currentContract :: VM -> Maybe Contract
- makeVm :: VMOpts -> VM
- initialContract :: ByteString -> Contract
- next :: (?op :: Word8) => EVM ()
- exec1 :: EVM ()
- precompiledContract :: (?op :: Word8) => EVM ()
- 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 ()
- touchAccount :: Addr -> (Contract -> EVM ()) -> EVM ()
- accessStorage :: Addr -> Word -> (Word -> EVM ()) -> EVM ()
- replaceCode :: Addr -> ByteString -> EVM ()
- replaceCodeOfSelf :: ByteString -> EVM ()
- resetState :: EVM ()
- finalize :: EVM ()
- loadContract :: Addr -> EVM ()
- limitStack :: Int -> EVM () -> EVM ()
- notStatic :: EVM () -> EVM ()
- burn :: Word -> EVM () -> EVM ()
- refund :: Word -> EVM ()
- cheatCode :: Addr
- cheat :: (?op :: Word8) => (Word, Word) -> (Word, Word) -> EVM ()
- type CheatAction = ([AbiType], [AbiValue] -> EVM (Maybe AbiValue))
- cheatActions :: Map Word32 CheatAction
- delegateCall :: (?op :: Word8) => FeeSchedule Word -> Word -> Addr -> Word -> Word -> Word -> Word -> [Word] -> EVM () -> EVM ()
- underrun :: EVM ()
- data FrameResult
- finishFrame :: FrameResult -> EVM ()
- vmError :: Error -> EVM ()
- accessMemoryRange :: FeeSchedule Word -> Word -> Word -> EVM () -> EVM ()
- accessMemoryWord :: FeeSchedule Word -> Word -> EVM () -> EVM ()
- copyBytesToMemory :: ByteString -> Word -> Word -> Word -> EVM ()
- readMemory :: Word -> Word -> VM -> ByteString
- word256At :: Functor f => Word -> (Word -> f Word) -> ByteString -> f ByteString
- 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 ()
- stackOp1 :: (?op :: Word8) => (Word -> Word) -> (Word -> Word) -> EVM ()
- stackOp2 :: (?op :: Word8) => ((Word, Word) -> Word) -> ((Word, Word) -> Word) -> EVM ()
- stackOp3 :: (?op :: Word8) => ((Word, Word, Word) -> Word) -> ((Word, Word, Word) -> Word) -> EVM ()
- checkJump :: Integral n => n -> [Word] -> EVM ()
- insidePushData :: Int -> EVM Bool
- opSize :: Word8 -> Int
- mkOpIxMap :: ByteString -> Vector Int
- vmOp :: VM -> Maybe Op
- vmOpIx :: VM -> Maybe Int
- opParams :: VM -> Map String Word
- readOp :: Word8 -> ByteString -> Op
- mkCodeOps :: ByteString -> Vector (Int, Op)
- costOfCall :: FeeSchedule Word -> Maybe a -> Word -> Word -> Word -> (Word, Word)
- memoryCost :: FeeSchedule Word -> Word -> Word
- ceilDiv :: (Num a, Integral a) => a -> a -> a
- allButOne64th :: (Num a, Integral a) => a -> a
- log2 :: FiniteBits b => b -> Int
Data types
The possible result states of a VM
VMFailure Error | An operation failed |
VMSuccess ByteString | Reached STOP, RETURN, or end-of-code |
The state of a stepwise EVM execution
Trace | |
|
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"
data FrameState Source #
The "registers" of the VM along with memory and data stack
FrameState | |
|
The state that spans a whole transaction
The state of a contract
Various environmental data
Env | |
|
Data about the block
Data accessors
Data constructors
initialContract :: ByteString -> Contract Source #
Opcode dispatch (exec1)
precompiledContract :: (?op :: Word8) => EVM () 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 #
replaceCode :: Addr -> ByteString -> EVM () Source #
Replace a contract's code, like when CREATE returns from the constructor code.
replaceCodeOfSelf :: ByteString -> EVM () Source #
resetState :: EVM () Source #
loadContract :: Addr -> EVM () Source #
Cheat codes
General call implementation ("delegateCall")
delegateCall :: (?op :: Word8) => FeeSchedule Word -> Word -> Addr -> Word -> Word -> Word -> Word -> [Word] -> EVM () -> EVM () Source #
VM error implementation
data FrameResult Source #
A stack frame can be popped in three ways.
FrameReturned ByteString | STOP, RETURN, or no more code |
FrameReverted ByteString | 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
accessMemoryRange :: FeeSchedule Word -> Word -> Word -> EVM () -> EVM () Source #
accessMemoryWord :: FeeSchedule Word -> Word -> EVM () -> EVM () Source #
copyBytesToMemory :: ByteString -> Word -> Word -> Word -> EVM () Source #
readMemory :: Word -> Word -> VM -> ByteString Source #
word256At :: Functor f => Word -> (Word -> f Word) -> ByteString -> f ByteString Source #
Tracing
withTraceLocation :: MonadState VM m => TraceData -> m Trace Source #
insertTrace :: TraceData -> EVM () Source #
Stack manipulation
stackOp3 :: (?op :: Word8) => ((Word, Word, Word) -> Word) -> ((Word, Word, Word) -> Word) -> EVM () Source #
Bytecode data functions
Gas cost calculation helpers
memoryCost :: FeeSchedule Word -> Word -> Word Source #
Arithmetic
allButOne64th :: (Num a, Integral a) => a -> a Source #
log2 :: FiniteBits b => b -> Int Source #