Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
- 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
- Arithmetic
- Orphan instances
Synopsis
- blankState :: VMOps t => ST s (FrameState t s)
- bytecode :: Getter Contract (Maybe (Expr Buf))
- currentContract :: VM t s -> Maybe Contract
- makeVm :: VMOps t => VMOpts t -> ST s (VM t s)
- unknownContract :: Expr EAddr -> Contract
- abstractContract :: ContractCode -> Expr EAddr -> Contract
- emptyContract :: Contract
- initialContract :: ContractCode -> Contract
- isCreation :: ContractCode -> Bool
- next :: (?op :: Word8) => EVM t s ()
- exec1 :: forall (t :: VMType) s. VMOps t => EVM t s ()
- transfer :: VMOps t => Expr EAddr -> Expr EAddr -> Expr EWord -> EVM t s ()
- callChecks :: forall (t :: VMType) s. (?op :: Word8, VMOps t) => Contract -> Gas t -> Expr EAddr -> Expr EAddr -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> (Gas t -> EVM t s ()) -> EVM t s ()
- precompiledContract :: (?op :: Word8, VMOps t) => Contract -> Gas t -> Addr -> Addr -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> EVM t s ()
- executePrecompile :: (?op :: Word8, VMOps t) => Addr -> Gas t -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> EVM t s ()
- truncpadlit :: Int -> ByteString -> ByteString
- lazySlice :: W256 -> W256 -> ByteString -> ByteString
- parseModexpLength :: ByteString -> (W256, W256, W256)
- isZero :: W256 -> W256 -> ByteString -> Bool
- asInteger :: ByteString -> Integer
- noop :: Monad m => m ()
- pushTo :: MonadState s m => Lens s s [a] [a] -> a -> m ()
- pushToSequence :: MonadState s m => Setter s s (Seq a) (Seq a) -> a -> m ()
- getCodeLocation :: VM t s -> CodeLocation
- query :: Query t s -> EVM t s ()
- choose :: Choose s -> EVM Symbolic s ()
- fetchAccount :: VMOps t => Expr EAddr -> (Contract -> EVM t s ()) -> EVM t s ()
- accessStorage :: VMOps t => Expr EAddr -> Expr EWord -> (Expr EWord -> EVM t s ()) -> EVM t s ()
- accountExists :: Expr EAddr -> VM t s -> Bool
- accountEmpty :: Contract -> Bool
- finalize :: VMOps t => EVM t s ()
- loadContract :: Expr EAddr -> State (VM t s) ()
- limitStack :: VMOps t => Int -> EVM (t :: VMType) s () -> EVM t s ()
- notStatic :: VMOps t => EVM t s () -> EVM t s ()
- forceAddr :: VMOps t => Expr EWord -> String -> (Expr EAddr -> EVM t s ()) -> EVM t s ()
- forceConcrete :: VMOps t => Expr EWord -> String -> (W256 -> EVM t s ()) -> EVM t s ()
- forceConcreteAddr :: VMOps t => Expr EAddr -> String -> (Addr -> EVM t s ()) -> EVM t s ()
- forceConcreteAddr2 :: VMOps t => (Expr EAddr, Expr EAddr) -> String -> ((Addr, Addr) -> EVM t s ()) -> EVM t s ()
- forceConcrete2 :: VMOps t => (Expr EWord, Expr EWord) -> String -> ((W256, W256) -> EVM t s ()) -> EVM t s ()
- forceConcreteBuf :: VMOps t => Expr Buf -> String -> (ByteString -> EVM t s ()) -> EVM t s ()
- refund :: Word64 -> EVM t s ()
- unRefund :: Word64 -> EVM t s ()
- touchAccount :: Expr EAddr -> EVM t s ()
- selfdestruct :: Expr EAddr -> EVM t s ()
- accessAndBurn :: VMOps t => Expr EAddr -> EVM t s () -> EVM t s ()
- accessAccountForGas :: Expr EAddr -> EVM t s Bool
- accessStorageForGas :: Expr EAddr -> Expr EWord -> EVM t s Bool
- cheatCode :: Expr EAddr
- cheat :: (?op :: Word8, VMOps t) => (Expr EWord, Expr EWord) -> (Expr EWord, Expr EWord) -> EVM t s ()
- type CheatAction t s = Expr EWord -> Expr EWord -> Expr Buf -> EVM t s ()
- cheatActions :: VMOps t => Map FunctionSelector (CheatAction t s)
- delegateCall :: (VMOps t, ?op :: Word8) => Contract -> Gas t -> Expr EAddr -> Expr EAddr -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> (Expr EAddr -> EVM t s ()) -> EVM t s ()
- collision :: Maybe Contract -> Bool
- create :: forall t s. (?op :: Word8, VMOps t) => Expr EAddr -> Contract -> Expr EWord -> Gas t -> Expr EWord -> [Expr EWord] -> Expr EAddr -> Expr Buf -> EVM t s ()
- parseInitCode :: Expr Buf -> Maybe ContractCode
- replaceCode :: Expr EAddr -> ContractCode -> EVM t s ()
- replaceCodeOfSelf :: ContractCode -> EVM t s ()
- resetState :: VMOps t => EVM t s ()
- vmError :: VMOps t => EvmError -> EVM t s ()
- wrap :: Typeable a => [Expr a] -> [SomeExpr]
- underrun :: VMOps t => EVM t s ()
- data FrameResult
- = FrameReturned (Expr Buf)
- | FrameReverted (Expr Buf)
- | FrameErrored EvmError
- finishFrame :: VMOps t => FrameResult -> EVM t s ()
- accessUnboundedMemoryRange :: VMOps t => Word64 -> Word64 -> EVM t s () -> EVM t s ()
- accessMemoryRange :: VMOps t => Expr EWord -> Expr EWord -> EVM t s () -> EVM t s ()
- accessMemoryWord :: VMOps t => Expr EWord -> EVM t s () -> EVM t s ()
- copyBytesToMemory :: Expr Buf -> Expr EWord -> Expr EWord -> Expr EWord -> EVM t s ()
- copyCallBytesToMemory :: Expr Buf -> Expr EWord -> Expr EWord -> EVM t s ()
- readMemory :: Expr EWord -> Expr EWord -> EVM t s (Expr Buf)
- withTraceLocation :: TraceData -> EVM t s Trace
- pushTrace :: TraceData -> EVM t s ()
- insertTrace :: TraceData -> EVM t s ()
- popTrace :: EVM t s ()
- zipperRootForest :: TreePos Empty a -> Forest a
- traceForest :: VM t s -> Forest Trace
- traceForest' :: Expr End -> Forest Trace
- traceContext :: Expr End -> Map (Expr EAddr) Contract
- traceTopLog :: [Expr Log] -> EVM t s ()
- push :: W256 -> EVM t s ()
- pushSym :: Expr EWord -> EVM t s ()
- pushAddr :: Expr EAddr -> EVM t s ()
- stackOp1 :: (?op :: Word8, VMOps t) => Word64 -> (Expr EWord -> Expr EWord) -> EVM t s ()
- stackOp2 :: (?op :: Word8, VMOps t) => Word64 -> (Expr EWord -> Expr EWord -> Expr EWord) -> EVM t s ()
- stackOp3 :: (?op :: Word8, VMOps t) => Word64 -> (Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord) -> EVM t s ()
- checkJump :: VMOps t => Int -> [Expr EWord] -> EVM t s ()
- noJumpIntoInitData :: VMOps t => Int -> EVM t s () -> EVM t s ()
- isValidJumpDest :: VM t s -> Int -> Bool
- opSize :: Word8 -> Int
- mkOpIxMap :: ContractCode -> Vector Int
- vmOp :: VM t s -> Maybe Op
- vmOpIx :: VM t s -> Maybe Int
- mkCodeOps :: ContractCode -> Vector (Int, Op)
- concreteModexpGasFee :: ByteString -> Word64
- costOfPrecompile :: FeeSchedule Word64 -> Addr -> Expr Buf -> Word64
- memoryCost :: FeeSchedule Word64 -> Word64 -> Word64
- hashcode :: ContractCode -> Expr EWord
- opslen :: ContractCode -> Int
- codelen :: ContractCode -> Expr EWord
- toBuf :: ContractCode -> Maybe (Expr Buf)
- codeloc :: EVM t s CodeLocation
- createAddress :: Expr EAddr -> Maybe W64 -> EVM t s (Expr EAddr)
- create2Address :: Expr EAddr -> W256 -> ByteString -> EVM t s (Expr EAddr)
- freshSymAddr :: EVM t s (Expr EAddr)
- isPrecompileAddr :: Expr EAddr -> Bool
- ceilDiv :: (Num a, Integral a) => a -> a -> a
- allButOne64th :: (Num a, Integral a) => a -> a
- log2 :: FiniteBits b => b -> Int
- writeMemory :: MutableMemory s -> Int -> ByteString -> EVM t s ()
- freezeMemory :: MutableMemory s -> EVM t s (Expr Buf)
- symbolify :: VM Concrete s -> VM Symbolic s
- symbolifyFrameState :: FrameState Concrete s -> FrameState Symbolic s
- symbolifyFrame :: Frame Concrete s -> Frame Symbolic s
- symbolifyResult :: VMResult Concrete s -> VMResult Symbolic s
- forceLit :: Expr EWord -> W256
- burn :: VMOps t => Word64 -> EVM t s () -> EVM t s ()
Documentation
blankState :: VMOps t => ST s (FrameState t s) Source #
bytecode :: Getter Contract (Maybe (Expr Buf)) Source #
An "external" view of a contract's bytecode, appropriate for
e.g. EXTCODEHASH
.
Data accessors
Data constructors
abstractContract :: ContractCode -> Expr EAddr -> Contract Source #
Initialize an abstract contract with known code
emptyContract :: Contract Source #
Initialize an empty contract without code
initialContract :: ContractCode -> Contract Source #
Initialize empty contract with given code
isCreation :: ContractCode -> Bool Source #
Opcode dispatch (exec1)
callChecks :: forall (t :: VMType) s. (?op :: Word8, VMOps t) => Contract -> Gas t -> Expr EAddr -> Expr EAddr -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> (Gas t -> EVM t s ()) -> EVM t s () Source #
Checks a *CALL for failure; OOG, too many callframes, memory access etc.
precompiledContract :: (?op :: Word8, VMOps t) => Contract -> Gas t -> Addr -> Addr -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> EVM t s () Source #
executePrecompile :: (?op :: Word8, VMOps t) => Addr -> Gas t -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> EVM t s () Source #
truncpadlit :: Int -> ByteString -> ByteString Source #
lazySlice :: W256 -> W256 -> ByteString -> ByteString Source #
parseModexpLength :: ByteString -> (W256, W256, W256) Source #
asInteger :: ByteString -> Integer Source #
Opcode helper actions
pushTo :: MonadState s m => Lens s s [a] [a] -> a -> m () Source #
pushToSequence :: MonadState s m => Setter s s (Seq a) (Seq a) -> a -> m () Source #
getCodeLocation :: VM t s -> CodeLocation Source #
fetchAccount :: VMOps t => Expr EAddr -> (Contract -> EVM t s ()) -> EVM t s () Source #
Construct RPC Query and halt execution until resolved
accessStorage :: VMOps t => Expr EAddr -> Expr EWord -> (Expr EWord -> EVM t s ()) -> EVM t s () Source #
accountEmpty :: Contract -> Bool Source #
How to finalize a transaction
loadContract :: Expr EAddr -> State (VM t s) () Source #
Loads the selected contract as the current contract to execute
forceConcreteAddr2 :: VMOps t => (Expr EAddr, Expr EAddr) -> String -> ((Addr, Addr) -> EVM t s ()) -> EVM t s () Source #
forceConcrete2 :: VMOps t => (Expr EWord, Expr EWord) -> String -> ((W256, W256) -> EVM t s ()) -> EVM t s () Source #
forceConcreteBuf :: VMOps t => Expr Buf -> String -> (ByteString -> EVM t s ()) -> EVM t s () Source #
Substate manipulation
accessAccountForGas :: Expr EAddr -> EVM t s Bool Source #
returns a wrapped boolean- if true, this address has been touched before in the txn (warm gas cost as in EIP 2929) otherwise cold
accessStorageForGas :: Expr EAddr -> Expr EWord -> EVM t s Bool Source #
returns a wrapped boolean- if true, this slot has been touched before in the txn (warm gas cost as in EIP 2929) otherwise cold
Cheat codes
cheat :: (?op :: Word8, VMOps t) => (Expr EWord, Expr EWord) -> (Expr EWord, Expr EWord) -> EVM t s () Source #
cheatActions :: VMOps t => Map FunctionSelector (CheatAction t s) Source #
General call implementation ("delegateCall")
delegateCall :: (VMOps t, ?op :: Word8) => Contract -> Gas t -> Expr EAddr -> Expr EAddr -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord -> [Expr EWord] -> (Expr EAddr -> EVM t s ()) -> EVM t s () Source #
create :: forall t s. (?op :: Word8, VMOps t) => Expr EAddr -> Contract -> Expr EWord -> Gas t -> Expr EWord -> [Expr EWord] -> Expr EAddr -> Expr Buf -> EVM t s () Source #
parseInitCode :: Expr Buf -> Maybe ContractCode Source #
Parses a raw Buf into an InitCode
solidity implements constructor args by appending them to the end of the initcode. we support this internally by treating initCode as a concrete region (initCode) followed by a potentially symbolic region (arguments).
when constructing a contract that has symbolic constructor args, we need to apply some heuristics to convert the (unstructured) initcode in memory into this structured representation. The (unsound, bad, hacky) way that we do this, is by: looking for the first potentially symbolic byte in the input buffer and then splitting it there into code / data.
replaceCode :: Expr EAddr -> ContractCode -> EVM t s () Source #
Replace a contract's code, like when CREATE returns from the constructor code.
replaceCodeOfSelf :: ContractCode -> EVM t s () Source #
resetState :: VMOps t => EVM t s () Source #
VM error implementation
data FrameResult Source #
A stack frame can be popped in three ways.
FrameReturned (Expr Buf) | STOP, RETURN, or no more code |
FrameReverted (Expr Buf) | REVERT |
FrameErrored EvmError | Any other error |
Instances
Show FrameResult Source # | |
Defined in EVM showsPrec :: Int -> FrameResult -> ShowS # show :: FrameResult -> String # showList :: [FrameResult] -> ShowS # |
finishFrame :: VMOps t => FrameResult -> EVM t s () 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
Tracing
insertTrace :: TraceData -> EVM t s () Source #
Stack manipulation
stackOp2 :: (?op :: Word8, VMOps t) => Word64 -> (Expr EWord -> Expr EWord -> Expr EWord) -> EVM t s () Source #
stackOp3 :: (?op :: Word8, VMOps t) => Word64 -> (Expr EWord -> Expr EWord -> Expr EWord -> Expr EWord) -> EVM t s () Source #
Bytecode data functions
Gas cost calculation helpers
costOfPrecompile :: FeeSchedule Word64 -> Addr -> Expr Buf -> Word64 Source #
memoryCost :: FeeSchedule Word64 -> Word64 -> Word64 Source #
opslen :: ContractCode -> Int Source #
The length of the code ignoring any constructor args. This represents the region that can contain executable opcodes
codelen :: ContractCode -> Expr EWord Source #
The length of the code including any constructor args. This can return an abstract value
codeloc :: EVM t s CodeLocation Source #
create2Address :: Expr EAddr -> W256 -> ByteString -> EVM t s (Expr EAddr) Source #
Arithmetic
allButOne64th :: (Num a, Integral a) => a -> a Source #
log2 :: FiniteBits b => b -> Int Source #
writeMemory :: MutableMemory s -> Int -> ByteString -> EVM t s () Source #
freezeMemory :: MutableMemory s -> EVM t s (Expr Buf) Source #
symbolifyFrameState :: FrameState Concrete s -> FrameState Symbolic s Source #