Skip to content

Commit

Permalink
Merge pull request #1405 from o1-labs/merge/berkeley-develop-main
Browse files Browse the repository at this point in the history
Merge berkeley into main
  • Loading branch information
mitschabaude authored Feb 2, 2024
2 parents 600e2ff + 6dea1fa commit 2c55ad7
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 98 deletions.
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ src/bindings/compiled/web_bindings/**/plonk_wasm*
src/bindings/compiled/web_bindings/**/*.bc.js
src/bindings/compiled/node_bindings/*
dist/**/*
src/mina/**/*
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@ 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/e5d1e0f...HEAD)
## [Unreleased](https://github.com/o1-labs/o1js/compare/834a44002...HEAD)

## [0.16.0](https://github.com/o1-labs/o1js/compare/e5d1e0f...834a44002)

### Breaking changes

- Reduce number of constraints of ECDSA verification by 5%, which breaks deployed contracts using ECDSA https://github.com/o1-labs/o1js/pull/1376
- Protocol change that adds a "transaction version" to the permission to set verification keys https://github.com/MinaProtocol/mina/pull/14407
- See [the relevant RFC](https://github.com/MinaProtocol/mina/blob/9577ad689a8e4d4f97e1d0fc3d26e20219f4abd1/rfcs/0051-verification-key-permissions.md) for the motivation behind this change
- Breaks all deployed contracts, as it changes the account update layout

### Added

- Provable type `Packed<T>` to pack small field elements into fewer field elements https://github.com/o1-labs/o1js/pull/1376
- Provable type `Hashed<T>` to represent provable types by their hash https://github.com/o1-labs/o1js/pull/1377
- This also exposes `Poseidon.hashPacked()` to efficiently hash an arbitrary type

### Changed

- Reduce number of constraints of ECDSA verification by 5% https://github.com/o1-labs/o1js/pull/1376

## [0.15.4](https://github.com/o1-labs/o1js/compare/be748e42e...e5d1e0f)

### Changed
Expand Down
72 changes: 50 additions & 22 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ git submodule update --init --recursive

For most users, building o1js is as simple as running:

# o1js README-dev

o1js is a TypeScript framework designed for zk-SNARKs and zkApps on the Mina blockchain.

- [zkApps Overview](https://docs.minaprotocol.com/zkapps)
- [Mina README](/src/mina/README.md)

For more information on our development process and how to contribute, see [CONTRIBUTING.md](https://github.com/o1-labs/o1js/blob/main/CONTRIBUTING.md). This document is meant to guide you through building o1js from source and understanding the development workflow.

## Prerequisites

Before starting, ensure you have the following tools installed:

- [Git](https://git-scm.com/)
- [Node.js and npm](https://nodejs.org/)
- [Dune](https://github.com/ocaml/dune) (only needed when compiling o1js from source)
- [Cargo](https://www.rust-lang.org/learn/get-started) (only needed when compiling o1js from source)

After cloning the repository, you need to fetch the submodules:

```sh
git submodule update --init --recursive
```

## Building o1js

For most users, building o1js is as simple as running:

```sh
npm install
npm run build
Expand Down Expand Up @@ -155,32 +183,32 @@ Use the lightweight Mina blockchain network (Lightnet) to test on a local blockc

The easiest way is to use [zkApp CLI](https://www.npmjs.com/package/zkapp-cli) sub-commands:

```shell
zk lightnet start # start the local network
# Do your tests and other interactions with the network
zk lightnet logs # manage the logs of the local network
zk lightnet explorer # visualize the local network state
zk lightnet stop # stop the local network
```
```shell
zk lightnet start # start the local network
# Do your tests and other interactions with the network
zk lightnet logs # manage the logs of the local network
zk lightnet explorer # visualize the local network state
zk lightnet stop # stop the local network
```

Use `zk lightnet --help` for more information.
Use `zk lightnet --help` for more information.

You can also use the corresponding [Docker image](https://hub.docker.com/r/o1labs/mina-local-network) manually:

```shell
docker run --rm --pull=missing -it \
--env NETWORK_TYPE="single-node" \
--env PROOF_LEVEL="none" \
--env LOG_LEVEL="Trace" \
-p 3085:3085 \
-p 5432:5432 \
-p 8080:8080 \
-p 8181:8181 \
-p 8282:8282 \
o1labs/mina-local-network:o1js-main-latest-lightnet
```

See the [Docker Hub repository](https://hub.docker.com/r/o1labs/mina-local-network) for more information.
```shell
docker run --rm --pull=missing -it \
--env NETWORK_TYPE="single-node" \
--env PROOF_LEVEL="none" \
--env LOG_LEVEL="Trace" \
-p 3085:3085 \
-p 5432:5432 \
-p 8080:8080 \
-p 8181:8181 \
-p 8282:8282 \
o1labs/mina-local-network:o1js-main-latest-lightnet
```

See the [Docker Hub repository](https://hub.docker.com/r/o1labs/mina-local-network) for more information.

Next up, get the Mina blockchain accounts information to be used in your zkApp.
After the local network is up and running, you can use the [Lightnet](https://github.com/o1-labs/o1js/blob/ec789794b2067addef6b6f9c9a91c6511e07e37c/src/lib/fetch.ts#L1012) `o1js API namespace` to get the accounts information.
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": "0.15.4",
"version": "0.16.0",
"license": "Apache-2.0",
"homepage": "https://github.com/o1-labs/o1js/",
"keywords": [
Expand Down
6 changes: 5 additions & 1 deletion src/examples/zkapps/dex/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Mina,
Int64,
VerificationKey,
TransactionVersion,
} from 'o1js';

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

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

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

import { Member } from './member.js';
Expand Down Expand Up @@ -103,7 +104,10 @@ export class Voting_ extends SmartContract {
editState: Permissions.proofOrSignature(),
editActionState: Permissions.proofOrSignature(),
incrementNonce: Permissions.proofOrSignature(),
setVerificationKey: Permissions.none(),
setVerificationKey: {
auth: Permissions.none(),
txnVersion: TransactionVersion.current(),
},
setPermissions: Permissions.proofOrSignature(),
});
this.accumulatedVotes.set(Reducer.initialActionState);
Expand Down
7 changes: 6 additions & 1 deletion src/examples/zkapps/zkapp-self-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ import {
AccountUpdate,
Circuit,
Provable,
TransactionVersion,
UInt32,
} from 'o1js';

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

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export {
AccountUpdate,
Permissions,
ZkappPublicInput,
TransactionVersion,
} from './lib/account_update.js';

export type { TransactionStatus } from './lib/fetch.js';
Expand Down
39 changes: 31 additions & 8 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ import {
} from '../bindings/mina-transaction/transaction-leaves.js';
import { TokenId as Base58TokenId } from './base58-encodings.js';
import { hashWithPrefix, packToFields } from './hash.js';
import { mocks, prefixes } from '../bindings/crypto/constants.js';
import {
mocks,
prefixes,
protocolVersions,
} from '../bindings/crypto/constants.js';
import { Context } from './global-context.js';
import { MlArray } from './ml/base.js';
import { Signature, signFieldElement } from '../mina-signer/src/signature.js';
Expand All @@ -45,7 +49,7 @@ import { isSmartContract } from './mina/smart-contract-base.js';
import { activeInstance } from './mina/mina-instance.js';

// external API
export { AccountUpdate, Permissions, ZkappPublicInput };
export { AccountUpdate, Permissions, ZkappPublicInput, TransactionVersion };
// internal API
export {
smartContractContext,
Expand Down Expand Up @@ -74,6 +78,10 @@ export {

const ZkappStateLength = 8;

const TransactionVersion = {
current: () => UInt32.from(protocolVersions.txnVersion),
};

type SmartContractContext = {
this: SmartContract;
methodCallDepth: number;
Expand Down Expand Up @@ -205,7 +213,10 @@ interface Permissions extends Permissions_ {
* key associated with the circuit tied to this account. Effectively
* "upgradeability" of the smart contract.
*/
setVerificationKey: Permission;
setVerificationKey: {
auth: Permission;
txnVersion: UInt32;
};

/**
* The {@link Permission} corresponding to the ability to set the zkapp uri
Expand Down Expand Up @@ -271,7 +282,10 @@ let Permissions = {
receive: Permission.none(),
setDelegate: Permission.signature(),
setPermissions: Permission.signature(),
setVerificationKey: Permission.signature(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.signature(),
editActionState: Permission.proof(),
setTokenSymbol: Permission.signature(),
Expand All @@ -287,7 +301,10 @@ let Permissions = {
receive: Permission.none(),
setDelegate: Permission.signature(),
setPermissions: Permission.signature(),
setVerificationKey: Permission.signature(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.signature(),
editActionState: Permission.signature(),
setTokenSymbol: Permission.signature(),
Expand All @@ -304,7 +321,10 @@ let Permissions = {
access: Permission.none(),
setDelegate: Permission.none(),
setPermissions: Permission.none(),
setVerificationKey: Permission.none(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.none(),
editActionState: Permission.none(),
setTokenSymbol: Permission.none(),
Expand All @@ -320,7 +340,10 @@ let Permissions = {
access: Permission.impossible(),
setDelegate: Permission.impossible(),
setPermissions: Permission.impossible(),
setVerificationKey: Permission.impossible(),
setVerificationKey: {
auth: Permission.signature(),
txnVersion: TransactionVersion.current(),
},
setZkappUri: Permission.impossible(),
editActionState: Permission.impossible(),
setTokenSymbol: Permission.impossible(),
Expand Down Expand Up @@ -356,7 +379,7 @@ let Permissions = {
return Object.fromEntries(
Object.entries(permissions).map(([k, v]) => [
k,
Permissions.fromString(v),
Permissions.fromString(typeof v === 'string' ? v : v.auth),
])
) as unknown as Permissions;
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ async function verifyAccountUpdate(
case 'delegate':
return perm.setDelegate;
case 'verificationKey':
return perm.setVerificationKey;
return perm.setVerificationKey.auth;
case 'permissions':
return perm.setPermissions;
case 'zkappUri':
Expand Down
Loading

0 comments on commit 2c55ad7

Please sign in to comment.