{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
module EVM.Opcode.Internal where
import Prelude hiding (LT, EQ, GT)
import Control.Monad (void)
import Data.Bits (shift)
import Data.DoubleWord (Word256)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.List as List
import Data.Word (Word8)
data Opcode' j
= STOP
| ADD
| MUL
| SUB
| DIV
| SDIV
| MOD
| SMOD
| ADDMOD
| MULMOD
| EXP
| SIGNEXTEND
| LT
| GT
| SLT
| SGT
| EQ
| ISZERO
| AND
| OR
| XOR
| NOT
| BYTE
| SHL
| SHR
| SAR
| SHA3
| ADDRESS
| BALANCE
| ORIGIN
| CALLER
| CALLVALUE
| CALLDATALOAD
| CALLDATASIZE
| CALLDATACOPY
| CODESIZE
| CODECOPY
| GASPRICE
| EXTCODESIZE
| EXTCODECOPY
| RETURNDATASIZE
| RETURNDATACOPY
| EXTCODEHASH
| BLOCKHASH
| COINBASE
| TIMESTAMP
| NUMBER
| DIFFICULTY
| GASLIMIT
| CHAINID
| SELFBALANCE
| POP
| MLOAD
| MSTORE
| MSTORE8
| SLOAD
| SSTORE
| JUMP j
| JUMPI j
| PC
| MSIZE
| GAS
| JUMPDEST j
| PUSH !Word256
| DUP !Ord16
| SWAP !Ord16
| LOG !Ord5
| CREATE
| CALL
| CALLCODE
| RETURN
| DELEGATECALL
| CREATE2
| STATICCALL
| REVERT
| INVALID
| SELFDESTRUCT
deriving (Opcode' j -> Opcode' j -> Bool
(Opcode' j -> Opcode' j -> Bool)
-> (Opcode' j -> Opcode' j -> Bool) -> Eq (Opcode' j)
forall j. Eq j => Opcode' j -> Opcode' j -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Opcode' j -> Opcode' j -> Bool
$c/= :: forall j. Eq j => Opcode' j -> Opcode' j -> Bool
== :: Opcode' j -> Opcode' j -> Bool
$c== :: forall j. Eq j => Opcode' j -> Opcode' j -> Bool
Eq, Eq (Opcode' j)
Eq (Opcode' j)
-> (Opcode' j -> Opcode' j -> Ordering)
-> (Opcode' j -> Opcode' j -> Bool)
-> (Opcode' j -> Opcode' j -> Bool)
-> (Opcode' j -> Opcode' j -> Bool)
-> (Opcode' j -> Opcode' j -> Bool)
-> (Opcode' j -> Opcode' j -> Opcode' j)
-> (Opcode' j -> Opcode' j -> Opcode' j)
-> Ord (Opcode' j)
Opcode' j -> Opcode' j -> Bool
Opcode' j -> Opcode' j -> Ordering
Opcode' j -> Opcode' j -> Opcode' j
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall j. Ord j => Eq (Opcode' j)
forall j. Ord j => Opcode' j -> Opcode' j -> Bool
forall j. Ord j => Opcode' j -> Opcode' j -> Ordering
forall j. Ord j => Opcode' j -> Opcode' j -> Opcode' j
min :: Opcode' j -> Opcode' j -> Opcode' j
$cmin :: forall j. Ord j => Opcode' j -> Opcode' j -> Opcode' j
max :: Opcode' j -> Opcode' j -> Opcode' j
$cmax :: forall j. Ord j => Opcode' j -> Opcode' j -> Opcode' j
>= :: Opcode' j -> Opcode' j -> Bool
$c>= :: forall j. Ord j => Opcode' j -> Opcode' j -> Bool
> :: Opcode' j -> Opcode' j -> Bool
$c> :: forall j. Ord j => Opcode' j -> Opcode' j -> Bool
<= :: Opcode' j -> Opcode' j -> Bool
$c<= :: forall j. Ord j => Opcode' j -> Opcode' j -> Bool
< :: Opcode' j -> Opcode' j -> Bool
$c< :: forall j. Ord j => Opcode' j -> Opcode' j -> Bool
compare :: Opcode' j -> Opcode' j -> Ordering
$ccompare :: forall j. Ord j => Opcode' j -> Opcode' j -> Ordering
$cp1Ord :: forall j. Ord j => Eq (Opcode' j)
Ord, a -> Opcode' b -> Opcode' a
(a -> b) -> Opcode' a -> Opcode' b
(forall a b. (a -> b) -> Opcode' a -> Opcode' b)
-> (forall a b. a -> Opcode' b -> Opcode' a) -> Functor Opcode'
forall a b. a -> Opcode' b -> Opcode' a
forall a b. (a -> b) -> Opcode' a -> Opcode' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Opcode' b -> Opcode' a
$c<$ :: forall a b. a -> Opcode' b -> Opcode' a
fmap :: (a -> b) -> Opcode' a -> Opcode' b
$cfmap :: forall a b. (a -> b) -> Opcode' a -> Opcode' b
Functor)
concrete :: Opcode' a -> Opcode' ()
concrete :: Opcode' a -> Opcode' ()
concrete = Opcode' a -> Opcode' ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void
jumpAnnot :: Opcode' a -> Maybe a
jumpAnnot :: Opcode' a -> Maybe a
jumpAnnot = \case
JUMP a
a -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
JUMPI a
a -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
Opcode' a
_ -> Maybe a
forall a. Maybe a
Nothing
jumpdestAnnot :: Opcode' a -> Maybe a
jumpdestAnnot :: Opcode' a -> Maybe a
jumpdestAnnot = \case
JUMPDEST a
a -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
Opcode' a
_ -> Maybe a
forall a. Maybe a
Nothing
toWord8 :: Enum e => e -> Word8
toWord8 :: e -> Word8
toWord8 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word8) -> (e -> Int) -> e -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Int
forall a. Enum a => a -> Int
fromEnum
fromWord8 :: Enum e => Word8 -> e
fromWord8 :: Word8 -> e
fromWord8 = Int -> e
forall a. Enum a => Int -> a
toEnum (Int -> e) -> (Word8 -> Int) -> Word8 -> e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
data Ord5
= Ord5_0
| Ord5_1
| Ord5_2
| Ord5_3
| Ord5_4
deriving (Ord5 -> Ord5 -> Bool
(Ord5 -> Ord5 -> Bool) -> (Ord5 -> Ord5 -> Bool) -> Eq Ord5
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ord5 -> Ord5 -> Bool
$c/= :: Ord5 -> Ord5 -> Bool
== :: Ord5 -> Ord5 -> Bool
$c== :: Ord5 -> Ord5 -> Bool
Eq, Eq Ord5
Eq Ord5
-> (Ord5 -> Ord5 -> Ordering)
-> (Ord5 -> Ord5 -> Bool)
-> (Ord5 -> Ord5 -> Bool)
-> (Ord5 -> Ord5 -> Bool)
-> (Ord5 -> Ord5 -> Bool)
-> (Ord5 -> Ord5 -> Ord5)
-> (Ord5 -> Ord5 -> Ord5)
-> Ord Ord5
Ord5 -> Ord5 -> Bool
Ord5 -> Ord5 -> Ordering
Ord5 -> Ord5 -> Ord5
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ord5 -> Ord5 -> Ord5
$cmin :: Ord5 -> Ord5 -> Ord5
max :: Ord5 -> Ord5 -> Ord5
$cmax :: Ord5 -> Ord5 -> Ord5
>= :: Ord5 -> Ord5 -> Bool
$c>= :: Ord5 -> Ord5 -> Bool
> :: Ord5 -> Ord5 -> Bool
$c> :: Ord5 -> Ord5 -> Bool
<= :: Ord5 -> Ord5 -> Bool
$c<= :: Ord5 -> Ord5 -> Bool
< :: Ord5 -> Ord5 -> Bool
$c< :: Ord5 -> Ord5 -> Bool
compare :: Ord5 -> Ord5 -> Ordering
$ccompare :: Ord5 -> Ord5 -> Ordering
$cp1Ord :: Eq Ord5
Ord, Int -> Ord5
Ord5 -> Int
Ord5 -> [Ord5]
Ord5 -> Ord5
Ord5 -> Ord5 -> [Ord5]
Ord5 -> Ord5 -> Ord5 -> [Ord5]
(Ord5 -> Ord5)
-> (Ord5 -> Ord5)
-> (Int -> Ord5)
-> (Ord5 -> Int)
-> (Ord5 -> [Ord5])
-> (Ord5 -> Ord5 -> [Ord5])
-> (Ord5 -> Ord5 -> [Ord5])
-> (Ord5 -> Ord5 -> Ord5 -> [Ord5])
-> Enum Ord5
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Ord5 -> Ord5 -> Ord5 -> [Ord5]
$cenumFromThenTo :: Ord5 -> Ord5 -> Ord5 -> [Ord5]
enumFromTo :: Ord5 -> Ord5 -> [Ord5]
$cenumFromTo :: Ord5 -> Ord5 -> [Ord5]
enumFromThen :: Ord5 -> Ord5 -> [Ord5]
$cenumFromThen :: Ord5 -> Ord5 -> [Ord5]
enumFrom :: Ord5 -> [Ord5]
$cenumFrom :: Ord5 -> [Ord5]
fromEnum :: Ord5 -> Int
$cfromEnum :: Ord5 -> Int
toEnum :: Int -> Ord5
$ctoEnum :: Int -> Ord5
pred :: Ord5 -> Ord5
$cpred :: Ord5 -> Ord5
succ :: Ord5 -> Ord5
$csucc :: Ord5 -> Ord5
Enum, Ord5
Ord5 -> Ord5 -> Bounded Ord5
forall a. a -> a -> Bounded a
maxBound :: Ord5
$cmaxBound :: Ord5
minBound :: Ord5
$cminBound :: Ord5
Bounded)
data Ord16
= Ord16_1
| Ord16_2
| Ord16_3
| Ord16_4
| Ord16_5
| Ord16_6
| Ord16_7
| Ord16_8
| Ord16_9
| Ord16_10
| Ord16_11
| Ord16_12
| Ord16_13
| Ord16_14
| Ord16_15
| Ord16_16
deriving (Ord16 -> Ord16 -> Bool
(Ord16 -> Ord16 -> Bool) -> (Ord16 -> Ord16 -> Bool) -> Eq Ord16
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ord16 -> Ord16 -> Bool
$c/= :: Ord16 -> Ord16 -> Bool
== :: Ord16 -> Ord16 -> Bool
$c== :: Ord16 -> Ord16 -> Bool
Eq, Eq Ord16
Eq Ord16
-> (Ord16 -> Ord16 -> Ordering)
-> (Ord16 -> Ord16 -> Bool)
-> (Ord16 -> Ord16 -> Bool)
-> (Ord16 -> Ord16 -> Bool)
-> (Ord16 -> Ord16 -> Bool)
-> (Ord16 -> Ord16 -> Ord16)
-> (Ord16 -> Ord16 -> Ord16)
-> Ord Ord16
Ord16 -> Ord16 -> Bool
Ord16 -> Ord16 -> Ordering
Ord16 -> Ord16 -> Ord16
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ord16 -> Ord16 -> Ord16
$cmin :: Ord16 -> Ord16 -> Ord16
max :: Ord16 -> Ord16 -> Ord16
$cmax :: Ord16 -> Ord16 -> Ord16
>= :: Ord16 -> Ord16 -> Bool
$c>= :: Ord16 -> Ord16 -> Bool
> :: Ord16 -> Ord16 -> Bool
$c> :: Ord16 -> Ord16 -> Bool
<= :: Ord16 -> Ord16 -> Bool
$c<= :: Ord16 -> Ord16 -> Bool
< :: Ord16 -> Ord16 -> Bool
$c< :: Ord16 -> Ord16 -> Bool
compare :: Ord16 -> Ord16 -> Ordering
$ccompare :: Ord16 -> Ord16 -> Ordering
$cp1Ord :: Eq Ord16
Ord, Int -> Ord16
Ord16 -> Int
Ord16 -> [Ord16]
Ord16 -> Ord16
Ord16 -> Ord16 -> [Ord16]
Ord16 -> Ord16 -> Ord16 -> [Ord16]
(Ord16 -> Ord16)
-> (Ord16 -> Ord16)
-> (Int -> Ord16)
-> (Ord16 -> Int)
-> (Ord16 -> [Ord16])
-> (Ord16 -> Ord16 -> [Ord16])
-> (Ord16 -> Ord16 -> [Ord16])
-> (Ord16 -> Ord16 -> Ord16 -> [Ord16])
-> Enum Ord16
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Ord16 -> Ord16 -> Ord16 -> [Ord16]
$cenumFromThenTo :: Ord16 -> Ord16 -> Ord16 -> [Ord16]
enumFromTo :: Ord16 -> Ord16 -> [Ord16]
$cenumFromTo :: Ord16 -> Ord16 -> [Ord16]
enumFromThen :: Ord16 -> Ord16 -> [Ord16]
$cenumFromThen :: Ord16 -> Ord16 -> [Ord16]
enumFrom :: Ord16 -> [Ord16]
$cenumFrom :: Ord16 -> [Ord16]
fromEnum :: Ord16 -> Int
$cfromEnum :: Ord16 -> Int
toEnum :: Int -> Ord16
$ctoEnum :: Int -> Ord16
pred :: Ord16 -> Ord16
$cpred :: Ord16 -> Ord16
succ :: Ord16 -> Ord16
$csucc :: Ord16 -> Ord16
Enum, Ord16
Ord16 -> Ord16 -> Bounded Ord16
forall a. a -> a -> Bounded a
maxBound :: Ord16
$cmaxBound :: Ord16
minBound :: Ord16
$cminBound :: Ord16
Bounded)
data OpcodeSpec = OpcodeSpec
{ OpcodeSpec -> Word8
opcodeEncoding :: !Word8
, OpcodeSpec -> Word8
opcodeAlpha :: !Word8
, OpcodeSpec -> Word8
opcodeDelta :: !Word8
, OpcodeSpec -> Text
opcodeName :: !Text
} deriving (OpcodeSpec -> OpcodeSpec -> Bool
(OpcodeSpec -> OpcodeSpec -> Bool)
-> (OpcodeSpec -> OpcodeSpec -> Bool) -> Eq OpcodeSpec
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OpcodeSpec -> OpcodeSpec -> Bool
$c/= :: OpcodeSpec -> OpcodeSpec -> Bool
== :: OpcodeSpec -> OpcodeSpec -> Bool
$c== :: OpcodeSpec -> OpcodeSpec -> Bool
Eq, Int -> OpcodeSpec -> ShowS
[OpcodeSpec] -> ShowS
OpcodeSpec -> String
(Int -> OpcodeSpec -> ShowS)
-> (OpcodeSpec -> String)
-> ([OpcodeSpec] -> ShowS)
-> Show OpcodeSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpcodeSpec] -> ShowS
$cshowList :: [OpcodeSpec] -> ShowS
show :: OpcodeSpec -> String
$cshow :: OpcodeSpec -> String
showsPrec :: Int -> OpcodeSpec -> ShowS
$cshowsPrec :: Int -> OpcodeSpec -> ShowS
Show)
opcodeSpec :: Opcode' j -> OpcodeSpec
opcodeSpec :: Opcode' j -> OpcodeSpec
opcodeSpec Opcode' j
opcode = case Opcode' j
opcode of
Opcode' j
STOP -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x00 Word8
0 Word8
0 Text
"stop"
Opcode' j
ADD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x01 Word8
2 Word8
1 Text
"add"
Opcode' j
MUL -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x02 Word8
2 Word8
1 Text
"mul"
Opcode' j
SUB -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x03 Word8
2 Word8
1 Text
"sub"
Opcode' j
DIV -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x04 Word8
2 Word8
1 Text
"div"
Opcode' j
SDIV -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x05 Word8
2 Word8
1 Text
"sdiv"
Opcode' j
MOD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x06 Word8
2 Word8
1 Text
"mod"
Opcode' j
SMOD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x07 Word8
2 Word8
1 Text
"smod"
Opcode' j
ADDMOD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x08 Word8
3 Word8
1 Text
"addmod"
Opcode' j
MULMOD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x09 Word8
3 Word8
1 Text
"mulmod"
Opcode' j
EXP -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x0a Word8
2 Word8
1 Text
"exp"
Opcode' j
SIGNEXTEND -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x0b Word8
2 Word8
1 Text
"signextend"
Opcode' j
LT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x10 Word8
2 Word8
1 Text
"lt"
Opcode' j
GT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x11 Word8
2 Word8
1 Text
"gt"
Opcode' j
SLT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x12 Word8
2 Word8
1 Text
"slt"
Opcode' j
SGT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x13 Word8
2 Word8
1 Text
"sgt"
Opcode' j
EQ -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x14 Word8
2 Word8
1 Text
"eq"
Opcode' j
ISZERO -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x15 Word8
1 Word8
1 Text
"iszero"
Opcode' j
AND -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x16 Word8
2 Word8
1 Text
"and"
Opcode' j
OR -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x17 Word8
2 Word8
1 Text
"or"
Opcode' j
XOR -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x18 Word8
2 Word8
1 Text
"xor"
Opcode' j
NOT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x19 Word8
1 Word8
1 Text
"not"
Opcode' j
BYTE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x1a Word8
2 Word8
1 Text
"byte"
Opcode' j
SHL -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x1b Word8
2 Word8
1 Text
"shl"
Opcode' j
SHR -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x1c Word8
2 Word8
1 Text
"shr"
Opcode' j
SAR -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x1d Word8
2 Word8
1 Text
"sar"
Opcode' j
SHA3 -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x20 Word8
2 Word8
1 Text
"sha3"
Opcode' j
ADDRESS -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x30 Word8
0 Word8
1 Text
"address"
Opcode' j
BALANCE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x31 Word8
1 Word8
1 Text
"balance"
Opcode' j
ORIGIN -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x32 Word8
0 Word8
1 Text
"origin"
Opcode' j
CALLER -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x33 Word8
0 Word8
1 Text
"caller"
Opcode' j
CALLVALUE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x34 Word8
0 Word8
1 Text
"callvalue"
Opcode' j
CALLDATALOAD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x35 Word8
1 Word8
1 Text
"calldataload"
Opcode' j
CALLDATASIZE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x36 Word8
0 Word8
1 Text
"calldatasize"
Opcode' j
CALLDATACOPY -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x37 Word8
3 Word8
0 Text
"calldatacopy"
Opcode' j
CODESIZE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x38 Word8
0 Word8
1 Text
"codesize"
Opcode' j
CODECOPY -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x39 Word8
3 Word8
0 Text
"codecopy"
Opcode' j
GASPRICE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x3a Word8
0 Word8
1 Text
"gasprice"
Opcode' j
EXTCODESIZE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x3b Word8
1 Word8
1 Text
"extcodesize"
Opcode' j
EXTCODECOPY -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x3c Word8
4 Word8
0 Text
"extcodecopy"
Opcode' j
RETURNDATASIZE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x3d Word8
0 Word8
1 Text
"returndatasize"
Opcode' j
RETURNDATACOPY -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x3e Word8
3 Word8
0 Text
"returndatacopy"
Opcode' j
EXTCODEHASH -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x3f Word8
1 Word8
1 Text
"extcodehash"
Opcode' j
BLOCKHASH -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x40 Word8
1 Word8
1 Text
"blockhash"
Opcode' j
COINBASE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x41 Word8
0 Word8
1 Text
"coinbase"
Opcode' j
TIMESTAMP -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x42 Word8
0 Word8
1 Text
"timestamp"
Opcode' j
NUMBER -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x43 Word8
0 Word8
1 Text
"number"
Opcode' j
DIFFICULTY -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x44 Word8
0 Word8
1 Text
"difficulty"
Opcode' j
GASLIMIT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x45 Word8
0 Word8
1 Text
"gaslimit"
Opcode' j
CHAINID -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x46 Word8
0 Word8
1 Text
"chainid"
Opcode' j
SELFBALANCE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x47 Word8
0 Word8
1 Text
"selfbalance"
Opcode' j
POP -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x50 Word8
1 Word8
0 Text
"pop"
Opcode' j
MLOAD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x51 Word8
1 Word8
1 Text
"mload"
Opcode' j
MSTORE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x52 Word8
2 Word8
0 Text
"mstore"
Opcode' j
MSTORE8 -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x53 Word8
2 Word8
0 Text
"mstore8"
Opcode' j
SLOAD -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x54 Word8
1 Word8
1 Text
"sload"
Opcode' j
SSTORE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x55 Word8
2 Word8
0 Text
"sstore"
JUMP{} -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x56 Word8
1 Word8
0 Text
"jump"
JUMPI{} -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x57 Word8
2 Word8
0 Text
"jumpi"
Opcode' j
PC -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x58 Word8
0 Word8
1 Text
"pc"
Opcode' j
MSIZE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x59 Word8
0 Word8
1 Text
"msize"
Opcode' j
GAS -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x5a Word8
0 Word8
1 Text
"gas"
JUMPDEST{} -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0x5b Word8
0 Word8
0 Text
"jumpdest"
PUSH Word256
n ->
let (Word8
pushHex, [Word8]
pushConst) = Word256 -> (Word8, [Word8])
push' Word256
n
in OpcodeSpec :: Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec { opcodeEncoding :: Word8
opcodeEncoding = Word8
pushHex
, opcodeAlpha :: Word8
opcodeAlpha = Word8
0
, opcodeDelta :: Word8
opcodeDelta = Word8
1
, opcodeName :: Text
opcodeName = [Text] -> Text
Text.concat
[ Text
"push"
, String -> Text
Text.pack (Int -> String
forall a. Show a => a -> String
show ([Word8] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
List.length [Word8]
pushConst))
, Text
" "
, String -> Text
Text.pack (Word256 -> String
forall a. Show a => a -> String
show Word256
n) ]
}
DUP Ord16
i ->
let wi :: Word8
wi = Ord16 -> Word8
forall e. Enum e => e -> Word8
toWord8 Ord16
i
in OpcodeSpec :: Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec { opcodeEncoding :: Word8
opcodeEncoding = Word8
0x80 Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
wi
, opcodeAlpha :: Word8
opcodeAlpha = Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1
, opcodeDelta :: Word8
opcodeDelta = Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
2
, opcodeName :: Text
opcodeName = Text
"dup" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (Word8 -> String
forall a. Show a => a -> String
show (Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1))
}
SWAP Ord16
i ->
let wi :: Word8
wi = Ord16 -> Word8
forall e. Enum e => e -> Word8
toWord8 Ord16
i
in OpcodeSpec :: Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec { opcodeEncoding :: Word8
opcodeEncoding = Word8
0x90 Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
wi
, opcodeAlpha :: Word8
opcodeAlpha = Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1
, opcodeDelta :: Word8
opcodeDelta = Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1
, opcodeName :: Text
opcodeName = Text
"swap" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (Word8 -> String
forall a. Show a => a -> String
show (Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1))
}
LOG Ord5
i ->
let wi :: Word8
wi = Ord5 -> Word8
forall e. Enum e => e -> Word8
toWord8 Ord5
i
in OpcodeSpec :: Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec { opcodeEncoding :: Word8
opcodeEncoding = Word8
0xa0 Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
wi
, opcodeAlpha :: Word8
opcodeAlpha = Word8
wi Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
2
, opcodeDelta :: Word8
opcodeDelta = Word8
0
, opcodeName :: Text
opcodeName = Text
"log" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (Word8 -> String
forall a. Show a => a -> String
show Word8
wi)
}
Opcode' j
CREATE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xf0 Word8
3 Word8
1 Text
"create"
Opcode' j
CALL -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xf1 Word8
7 Word8
1 Text
"call"
Opcode' j
CALLCODE -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xf2 Word8
7 Word8
1 Text
"callcode"
Opcode' j
RETURN -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xf3 Word8
2 Word8
0 Text
"return"
Opcode' j
DELEGATECALL -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xf4 Word8
6 Word8
1 Text
"delegatecall"
Opcode' j
CREATE2 -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xf5 Word8
4 Word8
1 Text
"create2"
Opcode' j
STATICCALL -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xfa Word8
6 Word8
1 Text
"staticcall"
Opcode' j
REVERT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xfd Word8
2 Word8
0 Text
"revert"
Opcode' j
INVALID -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xfe Word8
0 Word8
0 Text
"invalid"
Opcode' j
SELFDESTRUCT -> Word8 -> Word8 -> Word8 -> Text -> OpcodeSpec
OpcodeSpec Word8
0xff Word8
1 Word8
0 Text
"selfdestruct"
instance {-# OVERLAPPABLE #-} Show a => Show (Opcode' a) where
show :: Opcode' a -> String
show Opcode' a
opcode = Opcode' () -> String
forall a. Show a => a -> String
show (Opcode' a -> Opcode' ()
forall a. Opcode' a -> Opcode' ()
concrete Opcode' a
opcode) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Opcode' a -> String
forall a. Show a => Opcode' a -> String
showParam Opcode' a
opcode
where
showParam :: Opcode' a -> String
showParam (JUMP a
a) = String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
a
showParam (JUMPI a
a) = String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
a
showParam (JUMPDEST a
a) = String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> a -> String
forall a. Show a => a -> String
show a
a
showParam Opcode' a
_opcode = String
""
push' :: Word256 -> (Word8, [Word8])
push' :: Word256 -> (Word8, [Word8])
push' Word256
i | Word256
i Word256 -> Word256 -> Bool
forall a. Ord a => a -> a -> Bool
< Word256
256 = (Word8
0x60, [Word256 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word256
i])
push' Word256
i = (Word8
opcode Word8 -> Word8 -> Word8
forall a. Num a => a -> a -> a
+ Word8
1, [Word8]
arg [Word8] -> [Word8] -> [Word8]
forall a. Semigroup a => a -> a -> a
<> [Word256 -> Word8
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word256
i])
where (Word8
opcode, [Word8]
arg) = Word256 -> (Word8, [Word8])
push' (Word256
i Word256 -> Int -> Word256
forall a. Bits a => a -> Int -> a
`shift` (-Int
8))
pattern DUP1 :: forall j. Opcode' j
pattern $bDUP1 :: Opcode' j
$mDUP1 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP1 = DUP Ord16_1
pattern DUP2 :: forall j. Opcode' j
pattern $bDUP2 :: Opcode' j
$mDUP2 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP2 = DUP Ord16_2
pattern DUP3 :: forall j. Opcode' j
pattern $bDUP3 :: Opcode' j
$mDUP3 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP3 = DUP Ord16_3
pattern DUP4 :: forall j. Opcode' j
pattern $bDUP4 :: Opcode' j
$mDUP4 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP4 = DUP Ord16_4
pattern DUP5 :: forall j. Opcode' j
pattern $bDUP5 :: Opcode' j
$mDUP5 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP5 = DUP Ord16_5
pattern DUP6 :: forall j. Opcode' j
pattern $bDUP6 :: Opcode' j
$mDUP6 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP6 = DUP Ord16_6
pattern DUP7 :: forall j. Opcode' j
pattern $bDUP7 :: Opcode' j
$mDUP7 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP7 = DUP Ord16_7
pattern DUP8 :: forall j. Opcode' j
pattern $bDUP8 :: Opcode' j
$mDUP8 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP8 = DUP Ord16_8
pattern DUP9 :: forall j. Opcode' j
pattern $bDUP9 :: Opcode' j
$mDUP9 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP9 = DUP Ord16_9
pattern DUP10 :: forall j. Opcode' j
pattern $bDUP10 :: Opcode' j
$mDUP10 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP10 = DUP Ord16_10
pattern DUP11 :: forall j. Opcode' j
pattern $bDUP11 :: Opcode' j
$mDUP11 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP11 = DUP Ord16_11
pattern DUP12 :: forall j. Opcode' j
pattern $bDUP12 :: Opcode' j
$mDUP12 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP12 = DUP Ord16_12
pattern DUP13 :: forall j. Opcode' j
pattern $bDUP13 :: Opcode' j
$mDUP13 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP13 = DUP Ord16_13
pattern DUP14 :: forall j. Opcode' j
pattern $bDUP14 :: Opcode' j
$mDUP14 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP14 = DUP Ord16_14
pattern DUP15 :: forall j. Opcode' j
pattern $bDUP15 :: Opcode' j
$mDUP15 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP15 = DUP Ord16_15
pattern DUP16 :: forall j. Opcode' j
pattern $bDUP16 :: Opcode' j
$mDUP16 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
DUP16 = DUP Ord16_16
pattern SWAP1 :: forall j. Opcode' j
pattern $bSWAP1 :: Opcode' j
$mSWAP1 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP1 = SWAP Ord16_1
pattern SWAP2 :: forall j. Opcode' j
pattern $bSWAP2 :: Opcode' j
$mSWAP2 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP2 = SWAP Ord16_2
pattern SWAP3 :: forall j. Opcode' j
pattern $bSWAP3 :: Opcode' j
$mSWAP3 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP3 = SWAP Ord16_3
pattern SWAP4 :: forall j. Opcode' j
pattern $bSWAP4 :: Opcode' j
$mSWAP4 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP4 = SWAP Ord16_4
pattern SWAP5 :: forall j. Opcode' j
pattern $bSWAP5 :: Opcode' j
$mSWAP5 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP5 = SWAP Ord16_5
pattern SWAP6 :: forall j. Opcode' j
pattern $bSWAP6 :: Opcode' j
$mSWAP6 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP6 = SWAP Ord16_6
pattern SWAP7 :: forall j. Opcode' j
pattern $bSWAP7 :: Opcode' j
$mSWAP7 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP7 = SWAP Ord16_7
pattern SWAP8 :: forall j. Opcode' j
pattern $bSWAP8 :: Opcode' j
$mSWAP8 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP8 = SWAP Ord16_8
pattern SWAP9 :: forall j. Opcode' j
pattern $bSWAP9 :: Opcode' j
$mSWAP9 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP9 = SWAP Ord16_9
pattern SWAP10 :: forall j. Opcode' j
pattern $bSWAP10 :: Opcode' j
$mSWAP10 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP10 = SWAP Ord16_10
pattern SWAP11 :: forall j. Opcode' j
pattern $bSWAP11 :: Opcode' j
$mSWAP11 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP11 = SWAP Ord16_11
pattern SWAP12 :: forall j. Opcode' j
pattern $bSWAP12 :: Opcode' j
$mSWAP12 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP12 = SWAP Ord16_12
pattern SWAP13 :: forall j. Opcode' j
pattern $bSWAP13 :: Opcode' j
$mSWAP13 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP13 = SWAP Ord16_13
pattern SWAP14 :: forall j. Opcode' j
pattern $bSWAP14 :: Opcode' j
$mSWAP14 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP14 = SWAP Ord16_14
pattern SWAP15 :: forall j. Opcode' j
pattern $bSWAP15 :: Opcode' j
$mSWAP15 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP15 = SWAP Ord16_15
pattern SWAP16 :: forall j. Opcode' j
pattern $bSWAP16 :: Opcode' j
$mSWAP16 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
SWAP16 = SWAP Ord16_16
pattern LOG0 :: forall j. Opcode' j
pattern $bLOG0 :: Opcode' j
$mLOG0 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
LOG0 = LOG Ord5_0
pattern LOG1 :: forall j. Opcode' j
pattern $bLOG1 :: Opcode' j
$mLOG1 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
LOG1 = LOG Ord5_1
pattern LOG2 :: forall j. Opcode' j
pattern $bLOG2 :: Opcode' j
$mLOG2 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
LOG2 = LOG Ord5_2
pattern LOG3 :: forall j. Opcode' j
pattern $bLOG3 :: Opcode' j
$mLOG3 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
LOG3 = LOG Ord5_3
pattern LOG4 :: forall j. Opcode' j
pattern $bLOG4 :: Opcode' j
$mLOG4 :: forall r j. Opcode' j -> (Void# -> r) -> (Void# -> r) -> r
LOG4 = LOG Ord5_4