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 elements in TypeScript that 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.

Questions:

  • are all gadgets in ZkProgram? I see only rot, xor, and
  • some PRs mention "handle the constant case by using the added functionality in the bindings" For the prover case, how to describe? or go into detail for each gadget?
  • do we want to list gadgets in the gadgets namespace separately from gadgets not in the gadgets namespace? (where are these gadgets?)
  • include code snippets?
  • can we need to describe use cases? or just talk about performance gains? or?
  • primitive constraint system, we replaced Poiseidon with gadget? https://github.com/o1-labs/o1js/pull/1177/files#diff-de4ea0a8fb59a20403ab4c9ab9615587c179a8649e1b1b07297f6c829c94aa88L1
  • resources, what do we want to provide?
  • why are gadgets listed under variables in the reference docs? is it because a gadget variable is already computed when it is used (so performance is faster?) side note: oh weird, we have a -1 here on the reference URL

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 (and other places?)

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

Gadgets in o1js

and, xor, rot, not, range checks, left shift and right shift https://github.com/o1-labs/o1js/blob/main/src/lib/gadgets/gadgets.ts

and()

The AND gadget in the gadgets namespace, which behaves similarly to the & operator in JavaScript. https://github.com/o1-labs/o1js/pull/1193


compactMultiRangeCheck()

Building block for non-native arithmetic with BigInt of size up to 264 bits. https://github.com/o1-labs/o1js/pull/1216


multiRangeCheck()

A building block for non-native arithmetic with BigInt of size up to 264 bits. A provable method for efficient 64-bit range checks using lookup tables. https://github.com/o1-labs/o1js/pull/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.


rotate()

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

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. In contrast to 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.

The ROT implementation handles the constant case by using the added functionality in the bindings. For the prover case, how to implement?


left shift and right shift

Provable methods that support bitwise shifting, an operation that moves the bits of a binary number to the left or right. Unlike rotation, the bits that fall off at the end are discarded and the vacant positions are filled with zeros.

handles the constant case by using the added functionality in the bindings. For the prover case,


https://github.com/o1-labs/o1js/pull/1194

xor()

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


Examples

are all gadgets in ZkProgram? I see only rot, xor, and

https://github.com/o1-labs/o1js/blob/main/src/examples/zkprogram/gadgets.ts