Skip to content

Commit 075f674

Browse files
committed
Amend documentation in Builtins.Internal about budgeting and invariants on Bytestring builtins
1 parent 517fc37 commit 075f674

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

plutus-tx/src/PlutusTx/Builtins/Internal.hs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818
Most users should not use this module directly, but rather use 'PlutusTx.Builtins'.
1919
2020
Please note that the documentation for each function will only include operational invariants
21-
if there are any. This documentation assumes type system correctly enforces and prevents any structural
22-
errors on the generated UPLC. See Note [Structural vs operational errors within builtins].
21+
if there are any. This documentation assumes that the type system correctly enforces and
22+
prevents any structural errors on the generated UPLC. See Note [Structural vs operational errors
23+
within builtins].
24+
25+
Also note that all builtin functions will fail if the CEK machine exceeds its evaluation budget.
26+
Builtin functions with dynamic costing are particularly prone to budget overruns: for example,
27+
addInteger and appendByteString differ cost based on input size, so supplying very large integers or
28+
byte strings will cause these functions to abort when the budget limit is reached and fail.
29+
See Note [Budgeting].
2330
-}
2431
module PlutusTx.Builtins.Internal where
2532

@@ -893,9 +900,11 @@ bls12_381_finalVerify (BuiltinBLS12_381_MlResult a) (BuiltinBLS12_381_MlResult b
893900
CONVERSION
894901
-}
895902

896-
{-| Converts the given integer to a bytestring. The first argument specifies
897-
endianness (True for big-endian), followed by the target length of the resulting bytestring
898-
and the integer itself. See 'PlutusCore.Bitwise.integerToByteString' for its invariances.
903+
{- | Converts the given integer to a bytestring. The first argument specifies
904+
endianness (True for big-endian), followed by the target length of the resulting bytestring
905+
and the integer itself. Fails if the target length is greater than 8192 or if the length
906+
argument is 0 and the result won't fit into 8192 bytes.
907+
See 'PlutusCore.Bitwise.integerToByteString' for its invariants in detail.
899908
-}
900909
integerToByteString
901910
:: BuiltinBool
@@ -1045,13 +1054,14 @@ writeBits (BuiltinByteString bs) (BuiltinList ixes) (BuiltinBool bit) =
10451054
BuiltinSuccessWithLogs logs bs' -> traceAll logs $ BuiltinByteString bs'
10461055
{-# OPAQUE writeBits #-}
10471056

1048-
{-| Creates a bytestring of a given length by repeating the given byte.
1049-
Fails if the byte, second argument, is not in range @[0,255]@ or the length is negative.
1057+
{- | Creates a bytestring of a given length by repeating the given byte.
1058+
Fails if the byte, second argument, is not in range @[0,255]@, the length is negative,
1059+
or when the length is greater than 8192.
10501060
-}
1051-
replicateByte
1052-
:: BuiltinInteger
1053-
-> BuiltinInteger
1054-
-> BuiltinByteString
1061+
replicateByte ::
1062+
BuiltinInteger ->
1063+
BuiltinInteger ->
1064+
BuiltinByteString
10551065
replicateByte n w8 =
10561066
case Bitwise.replicateByte n (fromIntegral w8) of
10571067
BuiltinFailure logs err ->

0 commit comments

Comments
 (0)