packages feed

evm-opcodes 0.3.2 → 0.3.3

raw patch · 4 files changed

+36/−4 lines, 4 files

Files

evm-opcodes.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           evm-opcodes-version:        0.3.2+version:        0.3.3 synopsis:       Opcode types for Ethereum Virtual Machine (EVM) description:    This library provides opcode types for the Ethereum Virtual Machine. category:       Ethereum, Finance, Network
src/EVM/Opcode.hs view
@@ -235,6 +235,8 @@     0x46 -> pure CHAINID     0x47 -> pure SELFBALANCE     0x48 -> pure BASEFEE+    0x49 -> pure BLOBHASH+    0x4a -> pure BLOBBASEFEE      -- 50s: Stack, Memory, Storage and Flow Operations     0x50 -> pure POP@@ -249,6 +251,10 @@     0x59 -> pure MSIZE     0x5a -> pure GAS     0x5b -> pure jumpdest+    0x5c -> pure TLOAD+    0x5d -> pure TSTORE+    0x5e -> pure MCOPY+    0x5f -> pure PUSH0      -- f0s: System Operations     0xf0 -> pure CREATE
test/OpcodeGenerators.hs view
@@ -90,9 +90,11 @@   , GASPRICE, EXTCODESIZE, EXTCODECOPY, RETURNDATASIZE, RETURNDATACOPY, EXTCODEHASH    , BLOCKHASH, COINBASE, TIMESTAMP, NUMBER, PREVRANDAO, GASLIMIT, CHAINID, SELFBALANCE, BASEFEE+  , BLOBHASH, BLOBBASEFEE    , POP, MLOAD, MSTORE, MSTORE8, SLOAD, SSTORE {- , JUMP, JUMPI -}, PC, MSIZE, GAS {- , JUMPDEST -}-    {- , PUSH -}+  , TLOAD, TSTORE, MCOPY+  , PUSH0 {- , PUSH -}   , CREATE, CALL, CALLCODE, RETURN, DELEGATECALL, CREATE2, STATICCALL, REVERT, INVALID, SELFDESTRUCT   ] <> map DUP [minBound..maxBound]     <> map SWAP [minBound..maxBound]
test/OpcodeTest.hs view
@@ -8,10 +8,11 @@ import qualified Data.ByteString as BS import           Data.DoubleWord (Word256) import           Data.Foldable (for_)-import           Data.List (permutations)-import           Data.Maybe (mapMaybe)+import           Data.List (permutations, sort)+import           Data.Maybe (isNothing, mapMaybe) import           Data.Text (Text) import qualified Data.Text as Text+import           Data.Word (Word8)  import           Hedgehog import qualified Hedgehog.Gen as Gen@@ -65,6 +66,21 @@   opcode2 <- evalMaybe (readOp c cs)   opcode1 === opcode2 +-- Property: 'opcode1' covers all single-byte non-jump opcodes that 'readOp' handles.+-- Uses 'Bounded' on 'Word8' to enumerate all possible byte values, ensuring that+-- when new opcodes are added to 'readOp', they must also be added to 'opcode1'.+hprop_opcode1_complete :: Property+hprop_opcode1_complete = withTests 1 $ property $ do+  let readOpOpcodes =+        [ op+        | byte <- [minBound..maxBound :: Word8]+        , Just op <- [readOp byte BS.empty]+        , opcodeSize op == 1+        , isNothing (jumpAnnot op)+        , isNothing (jumpdestAnnot op)+        ]+  sort (map Opcode.concrete opcode1) === sort readOpOpcodes+ hprop_translate_LabelledOpcode :: Property hprop_translate_LabelledOpcode = withTests 10000 $ property $ do   labelledOpcodes <- forAll genLabelledOpcodes@@ -208,6 +224,8 @@     it "shows CHAINID" $ show' CHAINID `shouldBe` "CHAINID"     it "shows SELFBALANCE" $ show' SELFBALANCE `shouldBe` "SELFBALANCE"     it "shows BASEFEE" $ show' BASEFEE `shouldBe` "BASEFEE"+    it "shows BLOBHASH" $ show' BLOBHASH `shouldBe` "BLOBHASH"+    it "shows BLOBBASEFEE" $ show' BLOBBASEFEE `shouldBe` "BLOBBASEFEE"      -- 50s: Stack, Memory, Storage and Flow Operations     it "shows POP" $ show' POP `shouldBe` "POP"@@ -222,6 +240,12 @@     it "shows MSIZE" $ show' MSIZE `shouldBe` "MSIZE"     it "shows GAS" $ show' GAS `shouldBe` "GAS"     it "shows JUMPDEST" $ show' (JUMPDEST ()) `shouldBe` "JUMPDEST ()"+    it "shows TLOAD" $ show' TLOAD `shouldBe` "TLOAD"+    it "shows TSTORE" $ show' TSTORE `shouldBe` "TSTORE"+    it "shows MCOPY" $ show' MCOPY `shouldBe` "MCOPY"++    -- 5f: PUSH0+    it "shows PUSH0" $ show' PUSH0 `shouldBe` "PUSH0"      -- 60s & 70s: Push Operations     for_ [0, 255, 256, 65535, 65536] $ \i ->