Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-mina-submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Dec 19, 2023
2 parents 8e9fd7c + d68441b commit 6ba1d9d
Show file tree
Hide file tree
Showing 32 changed files with 1,350 additions and 307 deletions.
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,39 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
_Removed_ for now removed features.
_Fixed_ for any bug fixes.
_Security_ in case of vulnerabilities.
-->

## [Unreleased](https://github.com/o1-labs/o1js/compare/7acf19d0d...HEAD)

### Breaking changes

- Rename `Gadgets.rotate()` to `Gadgets.rotate64()` to better reflect the amount of bits the gadget operates on. https://github.com/o1-labs/o1js/pull/1259
- Rename `Gadgets.{leftShift(), rightShift()}` to `Gadgets.{leftShift64(), rightShift64()}` to better reflect the amount of bits the gadget operates on. https://github.com/o1-labs/o1js/pull/1259

### Added

- Non-native elliptic curve operations exposed through `createForeignCurve()` class factory https://github.com/o1-labs/o1js/pull/1007
- **ECDSA signature verification** exposed through `createEcdsa()` class factory https://github.com/o1-labs/o1js/pull/1240 https://github.com/o1-labs/o1js/pull/1007

- For an example, see `./src/examples/crypto/ecdsa`

- `Gadgets.rotate32()` for rotation over 32 bit values https://github.com/o1-labs/o1js/pull/1259
- `Gadgets.leftShift32()` for left shift over 32 bit values https://github.com/o1-labs/o1js/pull/1259
- `Gadgets.divMod32()` division modulo 2^32 that returns the remainder and quotient of the operation https://github.com/o1-labs/o1js/pull/1259
- `Gadgets.rangeCheck32()` range check for 32 bit values https://github.com/o1-labs/o1js/pull/1259
- `Gadgets.addMod32()` addition modulo 2^32 https://github.com/o1-labs/o1js/pull/1259
- Expose new bitwise gadgets on `UInt32` and `UInt64` https://github.com/o1-labs/o1js/pull/1259
- bitwise XOR via `{UInt32, UInt64}.xor()`
- bitwise NOT via `{UInt32, UInt64}.not()`
- bitwise ROTATE via `{UInt32, UInt64}.rotate()`
- bitwise LEFTSHIFT via `{UInt32, UInt64}.leftShift()`
- bitwise RIGHTSHIFT via `{UInt32, UInt64}.rightShift()`
- bitwise AND via `{UInt32, UInt64}.and()`

### Fixed

- Fix stack overflows when calling provable methods with large inputs https://github.com/o1-labs/o1js/pull/1334

## [0.15.0](https://github.com/o1-labs/o1js/compare/1ad7333e9e...7acf19d0d)

### Breaking changes
Expand Down
38 changes: 38 additions & 0 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,41 @@ act -j Build-And-Test-Server --matrix test_type:"Simple integration tests" -s $G
### Releasing

To release a new version of o1js, you must first update the version number in `package.json`. Then, you can create a new pull request to merge your changes into the main branch. Once the pull request is merged, a CI job will automatically publish the new version to npm.

## Test zkApps against the local blockchain network

In order to be able to test zkApps against the local blockchain network, you need to spin up such a network first.
You can do so in several ways.

1. Using [zkapp-cli](https://www.npmjs.com/package/zkapp-cli)'s 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
```

Please refer to `zk lightnet --help` for more information.

2. Using 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
```

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

Next up, you will need the Mina blockchain accounts information in order to be used in your zkApp.
Once 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.
The corresponding example can be found here: [src/examples/zkapps/hello_world/run_live.ts](https://github.com/o1-labs/o1js/blob/ec789794b2067addef6b6f9c9a91c6511e07e37c/src/examples/zkapps/hello_world/run_live.ts)
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node --enable-source-maps src/build/run.js $@
node --enable-source-maps --stack-trace-limit=1000 src/build/run.js $@
2 changes: 1 addition & 1 deletion src/bindings
8 changes: 4 additions & 4 deletions src/examples/zkprogram/gadgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Field, Provable, Gadgets, ZkProgram } from 'o1js';
let cs = Provable.constraintSystem(() => {
let f = Provable.witness(Field, () => Field(12));

let res1 = Gadgets.rotate(f, 2, 'left');
let res2 = Gadgets.rotate(f, 2, 'right');
let res1 = Gadgets.rotate64(f, 2, 'left');
let res2 = Gadgets.rotate64(f, 2, 'right');

res1.assertEquals(Field(48));
res2.assertEquals(Field(3));
Expand All @@ -21,8 +21,8 @@ const BitwiseProver = ZkProgram({
privateInputs: [],
method: () => {
let a = Provable.witness(Field, () => Field(48));
let actualLeft = Gadgets.rotate(a, 2, 'left');
let actualRight = Gadgets.rotate(a, 2, 'right');
let actualLeft = Gadgets.rotate64(a, 2, 'left');
let actualRight = Gadgets.rotate64(a, 2, 'right');

let expectedLeft = Field(192);
actualLeft.assertEquals(expectedLeft);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace Experimental {
export type Callback<Result> = Callback_<Result>;
}

Error.stackTraceLimit = 1000;
Error.stackTraceLimit = 100000;

// deprecated stuff
export { isReady, shutdown };
Expand Down
10 changes: 10 additions & 0 deletions src/lib/account_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1505,13 +1505,23 @@ class AccountUpdate implements Types.AccountUpdate {
body[key] = JSON.stringify(body[key]) as any;
}
}
if (body.authorizationKind?.isProved === false) {
delete (body as any).authorizationKind?.verificationKeyHash;
}
if (
body.authorizationKind?.isProved === false &&
body.authorizationKind?.isSigned === false
) {
delete (body as any).authorizationKind;
}
if (
jsonUpdate.authorization !== undefined ||
body.authorizationKind?.isProved === true ||
body.authorizationKind?.isSigned === true
) {
(body as any).authorization = jsonUpdate.authorization;
}

body.mayUseToken = {
parentsOwnToken: this.body.mayUseToken.parentsOwnToken.toBoolean(),
inheritFromParent: this.body.mayUseToken.inheritFromParent.toBoolean(),
Expand Down
44 changes: 19 additions & 25 deletions src/lib/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { defineBinable } from '../bindings/lib/binable.js';
import { NonNegativeInteger } from '../bindings/crypto/non-negative.js';
import { asProver } from './provable-context.js';

export { BoolVar, Bool, isBool };
export { BoolVar, Bool };

// same representation, but use a different name to communicate intent / constraints
type BoolVar = FieldVar;
Expand All @@ -34,7 +34,7 @@ class Bool {
value: BoolVar;

constructor(x: boolean | Bool | BoolVar) {
if (Bool.#isBool(x)) {
if (x instanceof Bool) {
this.value = x.value;
return;
}
Expand Down Expand Up @@ -75,7 +75,7 @@ class Bool {
if (this.isConstant() && isConstant(y)) {
return new Bool(this.toBoolean() && toBoolean(y));
}
return new Bool(Snarky.bool.and(this.value, Bool.#toVar(y)));
return new Bool(Snarky.bool.and(this.value, toFieldVar(y)));
}

/**
Expand All @@ -87,7 +87,7 @@ class Bool {
if (this.isConstant() && isConstant(y)) {
return new Bool(this.toBoolean() || toBoolean(y));
}
return new Bool(Snarky.bool.or(this.value, Bool.#toVar(y)));
return new Bool(Snarky.bool.or(this.value, toFieldVar(y)));
}

/**
Expand All @@ -102,7 +102,7 @@ class Bool {
}
return;
}
Snarky.bool.assertEqual(this.value, Bool.#toVar(y));
Snarky.bool.assertEqual(this.value, toFieldVar(y));
} catch (err) {
throw withMessage(err, message);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ class Bool {
if (this.isConstant() && isConstant(y)) {
return new Bool(this.toBoolean() === toBoolean(y));
}
return new Bool(Snarky.bool.equals(this.value, Bool.#toVar(y)));
return new Bool(Snarky.bool.equals(this.value, toFieldVar(y)));
}

/**
Expand Down Expand Up @@ -194,14 +194,14 @@ class Bool {
}

static toField(x: Bool | boolean): Field {
return new Field(Bool.#toVar(x));
return new Field(toFieldVar(x));
}

/**
* Boolean negation.
*/
static not(x: Bool | boolean): Bool {
if (Bool.#isBool(x)) {
if (x instanceof Bool) {
return x.not();
}
return new Bool(!x);
Expand All @@ -211,7 +211,7 @@ class Bool {
* Boolean AND operation.
*/
static and(x: Bool | boolean, y: Bool | boolean): Bool {
if (Bool.#isBool(x)) {
if (x instanceof Bool) {
return x.and(y);
}
return new Bool(x).and(y);
Expand All @@ -221,7 +221,7 @@ class Bool {
* Boolean OR operation.
*/
static or(x: Bool | boolean, y: Bool | boolean): Bool {
if (Bool.#isBool(x)) {
if (x instanceof Bool) {
return x.or(y);
}
return new Bool(x).or(y);
Expand All @@ -231,7 +231,7 @@ class Bool {
* Asserts if both {@link Bool} are equal.
*/
static assertEqual(x: Bool, y: Bool | boolean): void {
if (Bool.#isBool(x)) {
if (x instanceof Bool) {
x.assertEquals(y);
return;
}
Expand All @@ -242,7 +242,7 @@ class Bool {
* Checks two {@link Bool} for equality.
*/
static equal(x: Bool | boolean, y: Bool | boolean): Bool {
if (Bool.#isBool(x)) {
if (x instanceof Bool) {
return x.equals(y);
}
return new Bool(x).equals(y);
Expand Down Expand Up @@ -342,15 +342,6 @@ class Bool {
return new Bool(x.value);
},
};

static #isBool(x: boolean | Bool | BoolVar): x is Bool {
return x instanceof Bool;
}

static #toVar(x: boolean | Bool): BoolVar {
if (Bool.#isBool(x)) return x.value;
return FieldVar.constant(B(x));
}
}

const BoolBinable = defineBinable({
Expand All @@ -362,6 +353,8 @@ const BoolBinable = defineBinable({
},
});

// internal helper functions

function isConstant(x: boolean | Bool): x is boolean | ConstantBool {
if (typeof x === 'boolean') {
return true;
Expand All @@ -370,17 +363,18 @@ function isConstant(x: boolean | Bool): x is boolean | ConstantBool {
return x.isConstant();
}

function isBool(x: unknown) {
return x instanceof Bool;
}

function toBoolean(x: boolean | Bool): boolean {
if (typeof x === 'boolean') {
return x;
}
return x.toBoolean();
}

function toFieldVar(x: boolean | Bool): BoolVar {
if (x instanceof Bool) return x.value;
return FieldVar.constant(B(x));
}

// TODO: This is duplicated
function withMessage(error: unknown, message?: string) {
if (message === undefined || !(error instanceof Error)) return error;
Expand Down
Loading

0 comments on commit 6ba1d9d

Please sign in to comment.