Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plugin] Warn about missing builtins #5702

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plutus-core/plutus-core/src/PlutusCore/Builtin/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ integerToByteStringWrapper ::
integerToByteStringWrapper endiannessArg lengthArg input
-- Check that we are within the Int range on the non-negative side.
| lengthArg < 0 || lengthArg >= 536870912 = do
emit "builtinIntegerToByteString: inappropriate length argument"
emit "integerToByteString: inappropriate length argument"
emit $ "Length requested: " <> (pack . show $ input)
pure EvaluationFailure
-- As this builtin hasn't been costed yet, we have to impose a temporary limit of 10KiB on requested
Expand All @@ -40,7 +40,7 @@ integerToByteStringWrapper endiannessArg lengthArg input
--
-- TODO: Cost this builtin.
| lengthArg > 10240 = do
emit "builtinIntegerToByteString: padding argument too large"
emit "integerToByteString: padding argument too large"
emit "If you are seeing this, it is a bug: please report this!"
pure EvaluationFailure
| otherwise = let endianness = endiannessArgToByteOrder endiannessArg in
Expand All @@ -50,13 +50,13 @@ integerToByteStringWrapper endiannessArg lengthArg input
case integerToByteString endianness (fromIntegral lengthArg) input of
Left err -> case err of
NegativeInput -> do
emit "builtinIntegerToByteString: cannot convert negative Integer"
emit "integerToByteString: cannot convert negative Integer"
-- This does work proportional to the size of input. However, we're in a failing case
-- anyway, and the user's paid for work proportional to this size in any case.
emit $ "Input: " <> (pack . show $ input)
pure EvaluationFailure
NotEnoughDigits -> do
emit "builtinIntegerToByteString: cannot represent Integer in given number of bytes"
emit "integerToByteString: cannot represent Integer in given number of bytes"
-- This does work proportional to the size of input. However, we're in a failing case
-- anyway, and the user's paid for work proportional to this size in any case.
emit $ "Input: " <> (pack . show $ input)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -820,33 +820,33 @@ test_Conversion =
adjustOption (\x -> max x . HedgehogTestLimit . Just $ 8000) .
testGroup "Integer <-> ByteString conversions" $ [
testGroup "Integer -> ByteString" [
--- lengthOfByteString (builtinIntegerToByteString e d 0) = d
--- lengthOfByteString (integerToByteString e d 0) = d
testPropertyNamed "property 1" "i2b_prop1" . property $ Conversion.i2bProperty1,
-- indexByteString (builtinIntegerToByteString e k 0) j = 0
-- indexByteString (integerToByteString e k 0) j = 0
testPropertyNamed "property 2" "i2b_prop2" . property $ Conversion.i2bProperty2,
-- lengthOfByteString (builtinIntegerToByteString e 0 p) > 0
-- lengthOfByteString (integerToByteString e 0 p) > 0
testPropertyNamed "property 3" "i2b_prop3" . property $ Conversion.i2bProperty3,
-- builtinIntegerToByteString False 0 (multiplyInteger p 256) = consByteString
-- 0 (builtinIntegerToByteString False 0 p)
-- integerToByteString False 0 (multiplyInteger p 256) = consByteString
-- 0 (integerToByteString False 0 p)
testPropertyNamed "property 4" "i2b_prop4" . property $ Conversion.i2bProperty4,
-- builtinIntegerToByteString True 0 (multiplyInteger p 256) = appendByteString
-- (builtinIntegerToByteString True 0 p) (singleton 0)
-- integerToByteString True 0 (multiplyInteger p 256) = appendByteString
-- (integerToByteString True 0 p) (singleton 0)
testPropertyNamed "property 5" "i2b_prop5" . property $ Conversion.i2bProperty5,
-- builtinIntegerToByteString False 0 (plusInteger (multiplyInteger q 256) r) =
-- appendByteString (builtinIntegerToByteString False 0 r) (builtinIntegerToByteString False 0 q)
-- integerToByteString False 0 (plusInteger (multiplyInteger q 256) r) =
-- appendByteString (integerToByteString False 0 r) (integerToByteString False 0 q)
testPropertyNamed "property 6" "i2b_prop6" . property $ Conversion.i2bProperty6,
-- builtinIntegerToByteString True 0 (plusInteger (multiplyInteger q 256) r) =
-- appendByteString (builtinIntegerToByteString False 0 q)
-- (builtinIntegerToByteString False 0 r)
-- integerToByteString True 0 (plusInteger (multiplyInteger q 256) r) =
-- appendByteString (integerToByteString False 0 q)
-- (integerToByteString False 0 r)
testPropertyNamed "property 7" "i2b_prop7" . property $ Conversion.i2bProperty7,
testGroup "CIP-0087 examples" Conversion.i2bCipExamples
],
testGroup "ByteString -> Integer" [
-- builtinByteStringToInteger b (builtinIntegerToByteString b d q) = q
-- byteStringToInteger b (integerToByteString b d q) = q
testPropertyNamed "property 1" "b2i_prop1" . property $ Conversion.b2iProperty1,
-- builtinByteStringToInteger b (consByteString w8 emptyByteString) = w8
-- byteStringToInteger b (consByteString w8 emptyByteString) = w8
testPropertyNamed "property 2" "b2i_prop2" . property $ Conversion.b2iProperty2,
-- builtinIntegerToByteString b (lengthOfByteString bs) (builtinByteStringToInteger b bs) = bs
-- integerToByteString b (lengthOfByteString bs) (byteStringToInteger b bs) = bs
testPropertyNamed "property 3" "b2i_prop3" . property $ Conversion.b2iProperty3,
testGroup "CIP-0087 examples" Conversion.b2iCipExamples
]
Expand Down
12 changes: 6 additions & 6 deletions plutus-ledger-api/test-plugin/Spec/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ patternOptions =
, [(1,9), (2,2), (6,10), (2,3), (1,0), (4,10), (3,5), (5,0), (3,6), (2,4), (1,1), (2,7), (4,8)]
]

{-# INLINEABLE integerToByteString #-}
integerToByteString :: Integer -> BuiltinByteString
integerToByteString n =
{-# INLINEABLE i2Bs #-}
i2Bs :: Integer -> BuiltinByteString
i2Bs n =
if n < 0
then "-" `appendByteString` integerToByteString (negate n)
then "-" `appendByteString` i2Bs (negate n)
-- @48@ is the ASCII code of @0@.
else ListTx.foldr (consByteString . (48 +)) emptyByteString $ toDigits n

{-# INLINEABLE replicateToByteString #-}
-- | Like 'integerToByteString' but generates longer bytestrings, so that repeated recalculations of
-- | Like 'i2Bs but generates longer bytestrings, so that repeated recalculations of
-- currency/token name comparisons get reflected in the budget tests in a visible manner.
replicateToByteString :: Integer -> BuiltinByteString
replicateToByteString i =
ListTx.foldr id emptyByteString $
ListTx.replicate iTo6 (appendByteString $ integerToByteString i)
ListTx.replicate iTo6 (appendByteString $ i2Bs i)
where
iTo2 = i * i
iTo4 = iTo2 * iTo2
Expand Down
Loading
Loading