This package has been deprecated

Author message:

This package was renamed to o1js-pack - Please install that package instead

snarkyjs-pack
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

SnarkyPack

Make the most of your ZKApp state!

What is it

SnarkyPack is a library for snarkyJS that allows a zkapp developer to pack extra data into a single Field.

Usage in a ZKApp

import {
  PackedBoolFactory,
  PackedStringFactory,
  PackedUInt32Factory,
} from 'snarkyjs-pack';

const MyPackedBools = PackedBoolFactory(254); // Max of 254 Bools
const MyPackedString = PackedCharacterFactory(120); // Max of 120 Characters
const MyPackedUInts = PackedUInt32Factory(7); // Max of 7 UInt32s

const sevenUints = [1, 2, 3, 4, 5, 6, 7].map(x => UInt32.from(x));
const myPackedUInts = new MyPackedUInts(MyPackedUInts.pack(sevenUints), sevenUints);

What's the catch?

If a zkapp has two or more independent Fields of state, then preconditions can be set on just one, or on any combination of the Fields. With SnarkyPack, one precondition will be set on the packed Field, which means that independent updates cannot happen asynchronously.

For example, let's say there is a voting app with two independent Fields of state: yesCount and noCount. If one user issues an update to yesCount and another user issues an update to noCount at the same time, both proofs may be valid at the same time. Both transactions may succeed during the same block, since they don't interfere with each others' preconditions. With SnarkyPack, a devolper can save state by putting both yesCount and noCount into the same Field of state, making room for other state to exist on chain. The tradeoff is that two votes will no longer be able to be cast independently. yesCount and noCount depend on the same precontition, meaning that to update one or the other, you must lock both.

How to build

npm run build

How to run tests

npm run test
npm run testw # watch mode

How to run coverage

npm run coverage

Credits

Thanks to @mario_zito for seeding the idea for this library on discord (Thread 1, Thread 2), and to @gregor for sounding out the early implementation.

License

Apache-2.0

Package Sidebar

Install

npm i snarkyjs-pack

Weekly Downloads

1

Version

0.3.0

License

Apache-2.0

Unpacked Size

279 kB

Total Files

90

Last publish

Collaborators

  • fourfiveninethreezero