@@ -87,6 +87,7 @@ import Test.QuickCheck hiding ((.&.), label)
8787import Text.Megaparsec qualified as P
8888import Text.Megaparsec.Char qualified as P
8989import Text.ParserCombinators.ReadP
90+ import Witch (unsafeInto , into )
9091
9192data AbiValue
9293 = AbiUInt Int Word256
@@ -216,7 +217,7 @@ getAbi t = label (Text.unpack (abiTypeSolidity t)) $
216217 AbiArrayDynamicType t' -> do
217218 AbiUInt _ n <- label " array length" (getAbi (AbiUIntType 256 ))
218219 AbiArrayDynamic t' <$>
219- label " array body" (getAbiSeq (fromIntegral n) (repeat t'))
220+ label " array body" (getAbiSeq (unsafeInto n) (repeat t'))
220221
221222 AbiTupleType ts ->
222223 AbiTuple <$> getAbiSeq (Vector. length ts) (Vector. toList ts)
@@ -228,7 +229,7 @@ putAbi :: AbiValue -> Put
228229putAbi = \ case
229230 AbiUInt _ x ->
230231 forM_ (reverse [0 .. 7 ]) $ \ i ->
231- putWord32be (fromIntegral (shiftR x (i * 32 ) .&. 0xffffffff ))
232+ putWord32be (unsafeInto (shiftR x (i * 32 ) .&. 0xffffffff ))
232233
233234 AbiInt n x -> putAbi (AbiUInt n (fromIntegral x))
234235 AbiAddress x -> putAbi (AbiUInt 160 (fromIntegral x))
@@ -240,7 +241,7 @@ putAbi = \case
240241
241242 AbiBytesDynamic xs -> do
242243 let n = BS. length xs
243- putAbi (AbiUInt 256 (fromIntegral n))
244+ putAbi (AbiUInt 256 (unsafeInto n))
244245 putAbi (AbiBytes n xs)
245246
246247 AbiString s ->
@@ -325,7 +326,7 @@ putAbiSeq xs =
325326 case abiKind (abiValueType x) of
326327 Static -> do putAbi x
327328 putHeads offset xs'
328- Dynamic -> do putAbi (AbiUInt 256 (fromIntegral offset))
329+ Dynamic -> do putAbi (AbiUInt 256 (unsafeInto offset))
329330 putHeads (offset + abiTailSize x) xs'
330331
331332encodeAbiValue :: AbiValue -> BS. ByteString
@@ -387,7 +388,7 @@ basicType v =
387388pack32 :: Int -> [Word32 ] -> Word256
388389pack32 n xs =
389390 sum [ shiftL x ((n - i) * 32 )
390- | (x, i) <- zip (map fromIntegral xs) [1 .. ] ]
391+ | (x, i) <- zip (map into xs) [1 .. ] ]
391392
392393asUInt :: Integral i => Int -> (i -> a ) -> Get a
393394asUInt n f = y <$> getAbi (AbiUIntType n)
@@ -508,7 +509,7 @@ parseAbiValue :: AbiType -> ReadP AbiValue
508509parseAbiValue (AbiUIntType n) = do W256 w <- readS_to_P reads
509510 pure $ AbiUInt n w
510511parseAbiValue (AbiIntType n) = do W256 w <- readS_to_P reads
511- pure $ AbiInt n (num w)
512+ pure $ AbiInt n (unsafeInto w)
512513parseAbiValue AbiAddressType = AbiAddress <$> readS_to_P reads
513514parseAbiValue AbiBoolType = (do W256 w <- readS_to_P reads
514515 pure $ AbiBool (w /= 0 ))
@@ -570,7 +571,7 @@ decodeBuf tps buf
570571
571572decodeStaticArgs :: Int -> Int -> Expr Buf -> [Expr EWord ]
572573decodeStaticArgs offset numArgs b =
573- [readWord (Lit . num $ i) b | i <- [offset,(offset+ 32 ) .. (offset + (numArgs- 1 )* 32 )]]
574+ [readWord (Lit . unsafeInto $ i) b | i <- [offset,(offset+ 32 ) .. (offset + (numArgs- 1 )* 32 )]]
574575
575576
576577-- A modification of 'arbitrarySizedBoundedIntegral' quickcheck library
0 commit comments