Skip to main content
info

Please note that zkApp programmability is not yet available on Mina Mainnet, but zkApps can now be deployed to Berkeley Testnet.

Gadgets

Gadgets are amalgamations of the lowest level gates in the proof system (addition, multiplication) into more sophisticated boolean operations (XOR, NOT). Gadgets in o1js simplify the process of creating new cryptographic primitives and make it possible to implement other crypto algorithms, such as SHA.

Think of gadgets as atomic logic gates that mask large circuits.

Gadgets are small, reusable building blocks you can use to create more complex cryptographic constructions. Understanding the properties and behavior of these smaller components aids in building secure and efficient systems.

Gadgets and test See https://docs.minaprotocol.com/zkapps/o1js-reference/modules#gadgets

The https://github.com/o1-labs/o1js/blob/main/src/lib/gadgets/gadgets.ts namespace (let's explain).

Available gadgets are https://github.com/o1-labs/o1js/tree/main/src/lib/gadgets:

Gadgets assume that input is at most 64 bits in size. The input value must be in the range [0, 2^64).

and()

AND gadget to the existing Gadgets namespace, which behaves similarly to the & operator in JavaScript. o1-labs/o1js#1193

multiRangeCheck()

A provable method for efficient 64-bit range checks using lookup tables. (0.14.0, #1181)

not()

A provable method to support bitwise shifting for native field elements. https://github.com/o1-labs/o1js/pull/1198

NOT adds the implementation for a NOT gate to the existing Gadgets namespace. A bitwise NOT is an operation that returns 1 in each bit position if the corresponding bit of the operand is 0, and returns 0 if the corresponding bit of the operand is 1. o1-labs/o1js#1198

compactMultiRangeCheck()

Building block for non-native arithmetic with BigInt of size up to 264 bits.

rotate()

A provable method to support bitwise rotation for native field elements. (0.14.0, #1182)

a bitwise rotation is, a rotation (often referred to as a "bitwise rotation") is an operation that shifts the bits of a binary number either to the left or to the right, but unlike a standard shift operation, the bits that "fall off" the end are not discarded. Instead, they "wrap around" to the other end.

Rotate Left (ROL): In this operation, bits are shifted to the left. The bits that fall off the leftmost side "wrap around" and reappear on the rightmost side. Rotate Right (ROR): In this operation, bits are shifted to the right. The bits that fall off the rightmost side "wrap around" and reappear on the leftmost side.

xor()

A provable method to support bitwise XOR operations for native field elements. (0.14.0, #1177)