plutus-core-1.31.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusCore.Bitwise

Description

Implementations for CIP-121, CIP-122 and CIP-123. Grouped because they all operate on ByteStrings, and require similar functionality.

Synopsis

Wrappers

integerToByteStringWrapperBoolIntegerIntegerBuiltinResult ByteString Source #

Wrapper for integerToByteString to make it more convenient to define as a builtin.

byteStringToIntegerWrapperBoolByteStringInteger Source #

Wrapper for byteStringToInteger to make it more convenient to define as a builtin.

shiftByteStringWrapperByteStringIntegerByteString Source #

Wrapper for calling shiftByteString safely. Specifically, we avoid various edge cases:

  • Empty ByteStrings and zero moves don't do anything
  • Bit moves whose absolute value is larger than the bit length produce all-zeroes

This also ensures we don't accidentally hit integer overflow issues.

rotateByteStringWrapperByteStringIntegerByteString Source #

Wrapper for calling rotateByteString safely. Specifically, we avoid various edge cases:

  • Empty ByteStrings and zero moves don't do anything
  • Bit moves whose absolute value is larger than the bit length gets modulo reduced

Furthermore, we can convert all rotations into positive rotations, by noting that a rotation by b is the same as a rotation by b mod bitLen, where bitLen is the length of the ByteString argument in bits. This value is always non-negative, and if we get 0, we have nothing to do. This reduction also helps us avoid integer overflow issues.

writeBitsWrapperByteString → [Integer] → [Bool] → BuiltinResult ByteString Source #

Needed due to the complexities of passing lists of pairs as arguments. Effectively, we pass the second argument as required by CIP-122 in its 'unzipped' form, truncating mismatches.

Implementation details

integerToByteStringByteOrderIntIntegerEither IntegerToByteStringError ByteString Source #

Conversion from Integer to ByteString, as per CIP-121.

For performance and clarity, the endianness argument uses ByteOrder, and the length argument is an Int.

byteStringToIntegerByteOrderByteStringInteger Source #

Conversion from ByteString to Integer, as per CIP-121.

For clarity, the stated endianness argument uses ByteOrder.

andByteStringBoolByteStringByteStringByteString Source #

Bitwise logical AND, as per CIP-122.

orByteStringBoolByteStringByteStringByteString Source #

Bitwise logical OR, as per CIP-122.

xorByteStringBoolByteStringByteStringByteString Source #

Bitwise logical XOR, as per CIP-122.

complementByteStringByteStringByteString Source #

Bitwise logical complement, as per CIP-122.

readBitByteStringIntBuiltinResult Bool Source #

Bit read at index, as per CIP-122

writeBitsByteString → [(Integer, Bool)] → BuiltinResult ByteString Source #

Bulk bit write, as per CIP-122

replicateByteIntWord8BuiltinResult ByteString Source #

Byte replication, as per CIP-122

rotateByteStringByteStringIntByteString Source #

Rotations, as per CIP-123.

countSetBitsByteStringInt Source #

Counting the number of set bits, as per CIP-123.

findFirstSetBitByteStringInt Source #

Finding the first set bit's index, as per CIP-123.