Skip to content

Commit

Permalink
Merge branch 'main' into merge/o1js-main-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed May 17, 2024
2 parents 46082e3 + 8cf3b08 commit 9e76d3c
Show file tree
Hide file tree
Showing 46 changed files with 2,274 additions and 436 deletions.
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,33 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
_Security_ in case of vulnerabilities.
-->

## [Unreleased](https://github.com/o1-labs/o1js/compare/4a17de857...HEAD)
## [Unreleased](https://github.com/o1-labs/o1js/compare/6a1012162...HEAD)

### Fixes

- Fix type inference for `method.returns(Type)`, to require a matching return signature https://github.com/o1-labs/o1js/pull/1653
- Fix `Struct.empty()` returning a garbage object when one of the base types doesn't support `empty()` https://github.com/o1-labs/o1js/pull/1657

## [1.2.0](https://github.com/o1-labs/o1js/compare/4a17de857...6a1012162) - 2024-05-14

### Added

- **Offchain state MVP** exported under `Experimental.OffchainState` https://github.com/o1-labs/o1js/pull/1630 https://github.com/o1-labs/o1js/pull/1652
- allows you to store any number of fields and key-value maps on your zkApp
- implemented using actions which define an offchain Merkle tree
- `Option` for defining an optional version of any provable type https://github.com/o1-labs/o1js/pull/1630
- `MerkleTree.clone()` and `MerkleTree.getLeaf()`, new convenience methods for merkle trees https://github.com/o1-labs/o1js/pull/1630
- `MerkleList.forEach()`, a simple and safe way for iterating over a `MerkleList`
- `Unconstrained.provableWithEmpty()` to create an unconstrained provable type with a known `empty()` value https://github.com/o1-labs/o1js/pull/1630
- `Permissions.VerificationKey`, a namespace for verification key permissions https://github.com/o1-labs/o1js/pull/1639
- Includes more accurate names for the `impossible` and `proof` permissions for verification keys, which are now called `impossibleDuringCurrentVersion` and `proofDuringCurrentVersion` respectively.

### Changed

- `State()` now optionally accepts an initial value as input parameter https://github.com/o1-labs/o1js/pull/1630
- Example: `@state(Field) x = State(Field(1));`
- Initial values will be set in the default `init()` method
- You no longer need a custom `init()` method to set initial values

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To ensure consistency within the o1js ecosystem and ease review and use by our t
- `npm install <your-package>` works and is all that is needed to use the package.
- o1js must be listed as a [peer dependency](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#peerdependencies).
- If applicable, the package must work both on the web and in NodeJS.
- The package is created using the [zkApp CLI](https://github.com/o1-labs/zkapp-cli) (recommended).
- The package is created using the [zkApp CLI](https://www.npmjs.com/package/zkapp-cli) (recommended).
If you did not create the package using the zkApp CLI, follow these guidelines for code consistency:
- Use TypeScript, and export types from `d.ts` files. We suggest that you base your tsconfig on the [tsconfig.json](./tsconfig.json) that o1js uses.
- Code must be auto-formatted with [prettier](https://prettier.io/). We encourage you to use [.prettierrc.cjs](./.prettierrc.cjs), the same prettier config as o1js.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The easiest way to write zk programs is using o1js.

o1js is a TypeScript library for [zk-SNARKs](https://minaprotocol.com/blog/what-are-zk-snarks) and zkApps. You can use o1js to write zk smart contracts based on zero-knowledge proofs for the Mina Protocol.

o1js is automatically included when you create a project using the [Mina zkApp CLI](https://github.com/o1-labs/zkapp-cli).
o1js is automatically included when you create a project using the [zkApp CLI](https://www.npmjs.com/package/zkapp-cli).

## Learn More

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "o1js",
"description": "TypeScript framework for zk-SNARKs and zkApps",
"version": "1.1.0",
"version": "1.2.0",
"license": "Apache-2.0",
"homepage": "https://github.com/o1-labs/o1js/",
"keywords": [
Expand Down
3 changes: 1 addition & 2 deletions src/examples/simple-zkapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ const doProofs = true;
const beforeGenesis = UInt64.from(Date.now());

class SimpleZkapp extends SmartContract {
@state(Field) x = State<Field>();
@state(Field) x = State(initialState);

events = { update: Field, payout: UInt64, payoutReceiver: PublicKey };

@method
async init() {
super.init();
this.x.set(initialState);
}

@method.returns(Field)
Expand Down
7 changes: 2 additions & 5 deletions src/examples/zkapps/dex/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
TokenContract,
AccountUpdateForest,
Struct,
TransactionVersion,
} from 'o1js';

export { Erc20Like, TrivialCoin };
Expand Down Expand Up @@ -79,10 +78,8 @@ class TrivialCoin extends TokenContract implements Erc20Like {
// make account non-upgradable forever
this.account.permissions.set({
...Permissions.default(),
setVerificationKey: {
auth: Permissions.impossible(),
txnVersion: TransactionVersion.current(),
},
setVerificationKey:
Permissions.VerificationKey.impossibleDuringCurrentVersion(),
setPermissions: Permissions.impossible(),
access: Permissions.proofOrSignature(),
});
Expand Down
15 changes: 3 additions & 12 deletions src/examples/zkapps/dex/upgradability.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { expect } from 'expect';
import {
AccountUpdate,
Mina,
Permissions,
PrivateKey,
UInt64,
TransactionVersion,
} from 'o1js';
import { AccountUpdate, Mina, Permissions, PrivateKey, UInt64 } from 'o1js';
import { getProfiler } from '../../utils/profiler.js';
import { TokenContract, addresses, createDex, keys, tokenIds } from './dex.js';

Expand Down Expand Up @@ -446,10 +439,8 @@ async function upgradeabilityTests({ withVesting }: { withVesting: boolean }) {
let update = AccountUpdate.createSigned(addresses.dex);
update.account.permissions.set({
...Permissions.initial(),
setVerificationKey: {
auth: Permissions.impossible(),
txnVersion: TransactionVersion.current(),
},
setVerificationKey:
Permissions.VerificationKey.impossibleDuringCurrentVersion(),
});
});
await tx.prove();
Expand Down
5 changes: 0 additions & 5 deletions src/examples/zkapps/voting/dummy-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
method,
DeployArgs,
Permissions,
TransactionVersion,
} from 'o1js';

export class DummyContract extends SmartContract {
Expand All @@ -19,10 +18,6 @@ export class DummyContract extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
setPermissions: Permissions.proofOrSignature(),
setVerificationKey: {
auth: Permissions.signature(),
txnVersion: TransactionVersion.current(),
},
incrementNonce: Permissions.proofOrSignature(),
});
this.sum.set(Field(0));
Expand Down
6 changes: 1 addition & 5 deletions src/examples/zkapps/voting/membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
provablePure,
AccountUpdate,
Provable,
TransactionVersion,
} from 'o1js';
import { Member } from './member.js';
import { ParticipantPreconditions } from './preconditions.js';
Expand Down Expand Up @@ -76,10 +75,7 @@ export class Membership_ extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
setPermissions: Permissions.proofOrSignature(),
setVerificationKey: {
auth: Permissions.proofOrSignature(),
txnVersion: TransactionVersion.current(),
},
setVerificationKey: Permissions.VerificationKey.proofOrSignature(),
incrementNonce: Permissions.proofOrSignature(),
});
}
Expand Down
6 changes: 1 addition & 5 deletions src/examples/zkapps/voting/voting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
provablePure,
AccountUpdate,
Provable,
TransactionVersion,
} from 'o1js';

import { Member } from './member.js';
Expand Down Expand Up @@ -103,10 +102,7 @@ export class Voting_ extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
incrementNonce: Permissions.proofOrSignature(),
setVerificationKey: {
auth: Permissions.none(),
txnVersion: TransactionVersion.current(),
},
setVerificationKey: Permissions.VerificationKey.none(),
setPermissions: Permissions.proofOrSignature(),
});
this.accumulatedVotes.set(Reducer.initialActionState);
Expand Down
7 changes: 2 additions & 5 deletions src/examples/zkapps/zkapp-self-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ import {
Mina,
AccountUpdate,
Provable,
TransactionVersion,
} from 'o1js';

class SelfUpdater extends SmartContract {
init() {
super.init();
this.account.permissions.set({
...Permissions.default(),
setVerificationKey: {
auth: Permissions.proof(),
txnVersion: TransactionVersion.current(),
},
setVerificationKey:
Permissions.VerificationKey.proofDuringCurrentVersion(),
});
}

Expand Down
30 changes: 23 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ export type {
FlexibleProvablePure,
InferProvable,
} from './lib/provable/types/struct.js';
export { provable, provablePure, Struct } from './lib/provable/types/struct.js';
export {
provable,
provablePure,
} from './lib/provable/types/provable-derivers.js';
export { Struct } from './lib/provable/types/struct.js';
export { Unconstrained } from './lib/provable/types/unconstrained.js';
export { Provable } from './lib/provable/provable.js';
export {
Expand All @@ -48,6 +52,7 @@ export { Gadgets } from './lib/provable/gadgets/gadgets.js';
export { Types } from './bindings/mina-transaction/types.js';

export { MerkleList, MerkleListIterator } from './lib/provable/merkle-list.js';
export { Option } from './lib/provable/option.js';

export * as Mina from './lib/mina/mina.js';
export {
Expand All @@ -59,16 +64,13 @@ export {
type PendingTransactionPromise,
} from './lib/mina/transaction.js';
export type { DeployArgs } from './lib/mina/zkapp.js';
export {
SmartContract,
method,
declareMethods,
Reducer,
} from './lib/mina/zkapp.js';
export { SmartContract, method, declareMethods } from './lib/mina/zkapp.js';
export { Reducer } from './lib/mina/actions/reducer.js';
export { state, State, declareState } from './lib/mina/state.js';

export type { JsonProof } from './lib/proof-system/zkprogram.js';
export {
type ProofBase,
Proof,
DynamicProof,
SelfProof,
Expand Down Expand Up @@ -126,6 +128,7 @@ export { setNumberOfWorkers } from './lib/proof-system/workers.js';

// experimental APIs
import { memoizeWitness } from './lib/provable/provable.js';
import * as OffchainState_ from './lib/mina/actions/offchain-state.js';
export { Experimental };

const Experimental_ = {
Expand All @@ -138,6 +141,19 @@ const Experimental_ = {
*/
namespace Experimental {
export let memoizeWitness = Experimental_.memoizeWitness;

// offchain state
export let OffchainState = OffchainState_.OffchainState;

/**
* Commitments that keep track of the current state of an offchain Merkle tree constructed from actions.
* Intended to be stored on-chain.
*
* Fields:
* - `root`: The root of the current Merkle tree
* - `actionState`: The hash pointing to the list of actions that have been applied to form the current Merkle tree
*/
export class OffchainStateCommitments extends OffchainState_.OffchainStateCommitments {}
}

Error.stackTraceLimit = 100000;
Loading

0 comments on commit 9e76d3c

Please sign in to comment.