plutus-core-1.34.1.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

Documentation

integerToByteStringBoolIntegerIntegerBuiltinResult ByteString Source #

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

byteStringToIntegerBoolByteStringInteger Source #

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

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

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.

shiftByteStringByteStringIntegerByteString Source #

Wrapper for calling unsafesShiftByteString 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.

rotateByteStringByteStringIntegerByteString Source #

Wrapper for calling unsafeRotateByteString 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 are reduced modulo the length

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.

readBitByteStringIntBuiltinResult Bool Source #

Bit read at index, as per CIP-122

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

Bulk bit write, as per CIP-122

replicateByteIntegerWord8BuiltinResult ByteString Source #

Byte replication, as per CIP-122 We want to cautious about the allocation of huge amounts of memory so we impose the same length limit that's used in integerToByteString.

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.