Skip to content

Commit 6ba1d9d

Browse files
committed
Merge branch 'main' into feat/add-mina-submodule
2 parents 8e9fd7c + d68441b commit 6ba1d9d

32 files changed

+1350
-307
lines changed

CHANGELOG.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,39 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1313
_Removed_ for now removed features.
1414
_Fixed_ for any bug fixes.
1515
_Security_ in case of vulnerabilities.
16-
17-
1816
-->
1917

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

20+
### Breaking changes
21+
22+
- 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
23+
- 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
24+
2225
### Added
2326

2427
- Non-native elliptic curve operations exposed through `createForeignCurve()` class factory https://github.com/o1-labs/o1js/pull/1007
2528
- **ECDSA signature verification** exposed through `createEcdsa()` class factory https://github.com/o1-labs/o1js/pull/1240 https://github.com/o1-labs/o1js/pull/1007
29+
2630
- For an example, see `./src/examples/crypto/ecdsa`
2731

32+
- `Gadgets.rotate32()` for rotation over 32 bit values https://github.com/o1-labs/o1js/pull/1259
33+
- `Gadgets.leftShift32()` for left shift over 32 bit values https://github.com/o1-labs/o1js/pull/1259
34+
- `Gadgets.divMod32()` division modulo 2^32 that returns the remainder and quotient of the operation https://github.com/o1-labs/o1js/pull/1259
35+
- `Gadgets.rangeCheck32()` range check for 32 bit values https://github.com/o1-labs/o1js/pull/1259
36+
- `Gadgets.addMod32()` addition modulo 2^32 https://github.com/o1-labs/o1js/pull/1259
37+
- Expose new bitwise gadgets on `UInt32` and `UInt64` https://github.com/o1-labs/o1js/pull/1259
38+
- bitwise XOR via `{UInt32, UInt64}.xor()`
39+
- bitwise NOT via `{UInt32, UInt64}.not()`
40+
- bitwise ROTATE via `{UInt32, UInt64}.rotate()`
41+
- bitwise LEFTSHIFT via `{UInt32, UInt64}.leftShift()`
42+
- bitwise RIGHTSHIFT via `{UInt32, UInt64}.rightShift()`
43+
- bitwise AND via `{UInt32, UInt64}.and()`
44+
45+
### Fixed
46+
47+
- Fix stack overflows when calling provable methods with large inputs https://github.com/o1-labs/o1js/pull/1334
48+
2849
## [0.15.0](https://github.com/o1-labs/o1js/compare/1ad7333e9e...7acf19d0d)
2950

3051
### Breaking changes

README-dev.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,41 @@ act -j Build-And-Test-Server --matrix test_type:"Simple integration tests" -s $G
144144
### Releasing
145145

146146
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.
147+
148+
## Test zkApps against the local blockchain network
149+
150+
In order to be able to test zkApps against the local blockchain network, you need to spin up such a network first.
151+
You can do so in several ways.
152+
153+
1. Using [zkapp-cli](https://www.npmjs.com/package/zkapp-cli)'s sub commands:
154+
155+
```shell
156+
zk lightnet start # start the local network
157+
# Do your tests and other interactions with the network
158+
zk lightnet logs # manage the logs of the local network
159+
zk lightnet explorer # visualize the local network state
160+
zk lightnet stop # stop the local network
161+
```
162+
163+
Please refer to `zk lightnet --help` for more information.
164+
165+
2. Using the corresponding [Docker image](https://hub.docker.com/r/o1labs/mina-local-network) manually:
166+
167+
```shell
168+
docker run --rm --pull=missing -it \
169+
--env NETWORK_TYPE="single-node" \
170+
--env PROOF_LEVEL="none" \
171+
--env LOG_LEVEL="Trace" \
172+
-p 3085:3085 \
173+
-p 5432:5432 \
174+
-p 8080:8080 \
175+
-p 8181:8181 \
176+
-p 8282:8282 \
177+
o1labs/mina-local-network:o1js-main-latest-lightnet
178+
```
179+
180+
Please refer to the [Docker Hub repository](https://hub.docker.com/r/o1labs/mina-local-network) for more information.
181+
182+
Next up, you will need the Mina blockchain accounts information in order to be used in your zkApp.
183+
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.
184+
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)

run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
node --enable-source-maps src/build/run.js $@
1+
node --enable-source-maps --stack-trace-limit=1000 src/build/run.js $@

src/bindings

src/examples/zkprogram/gadgets.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { Field, Provable, Gadgets, ZkProgram } from 'o1js';
33
let cs = Provable.constraintSystem(() => {
44
let f = Provable.witness(Field, () => Field(12));
55

6-
let res1 = Gadgets.rotate(f, 2, 'left');
7-
let res2 = Gadgets.rotate(f, 2, 'right');
6+
let res1 = Gadgets.rotate64(f, 2, 'left');
7+
let res2 = Gadgets.rotate64(f, 2, 'right');
88

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

2727
let expectedLeft = Field(192);
2828
actualLeft.assertEquals(expectedLeft);

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace Experimental {
124124
export type Callback<Result> = Callback_<Result>;
125125
}
126126

127-
Error.stackTraceLimit = 1000;
127+
Error.stackTraceLimit = 100000;
128128

129129
// deprecated stuff
130130
export { isReady, shutdown };

src/lib/account_update.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,13 +1505,23 @@ class AccountUpdate implements Types.AccountUpdate {
15051505
body[key] = JSON.stringify(body[key]) as any;
15061506
}
15071507
}
1508+
if (body.authorizationKind?.isProved === false) {
1509+
delete (body as any).authorizationKind?.verificationKeyHash;
1510+
}
1511+
if (
1512+
body.authorizationKind?.isProved === false &&
1513+
body.authorizationKind?.isSigned === false
1514+
) {
1515+
delete (body as any).authorizationKind;
1516+
}
15081517
if (
15091518
jsonUpdate.authorization !== undefined ||
15101519
body.authorizationKind?.isProved === true ||
15111520
body.authorizationKind?.isSigned === true
15121521
) {
15131522
(body as any).authorization = jsonUpdate.authorization;
15141523
}
1524+
15151525
body.mayUseToken = {
15161526
parentsOwnToken: this.body.mayUseToken.parentsOwnToken.toBoolean(),
15171527
inheritFromParent: this.body.mayUseToken.inheritFromParent.toBoolean(),

src/lib/bool.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { defineBinable } from '../bindings/lib/binable.js';
1111
import { NonNegativeInteger } from '../bindings/crypto/non-negative.js';
1212
import { asProver } from './provable-context.js';
1313

14-
export { BoolVar, Bool, isBool };
14+
export { BoolVar, Bool };
1515

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

3636
constructor(x: boolean | Bool | BoolVar) {
37-
if (Bool.#isBool(x)) {
37+
if (x instanceof Bool) {
3838
this.value = x.value;
3939
return;
4040
}
@@ -75,7 +75,7 @@ class Bool {
7575
if (this.isConstant() && isConstant(y)) {
7676
return new Bool(this.toBoolean() && toBoolean(y));
7777
}
78-
return new Bool(Snarky.bool.and(this.value, Bool.#toVar(y)));
78+
return new Bool(Snarky.bool.and(this.value, toFieldVar(y)));
7979
}
8080

8181
/**
@@ -87,7 +87,7 @@ class Bool {
8787
if (this.isConstant() && isConstant(y)) {
8888
return new Bool(this.toBoolean() || toBoolean(y));
8989
}
90-
return new Bool(Snarky.bool.or(this.value, Bool.#toVar(y)));
90+
return new Bool(Snarky.bool.or(this.value, toFieldVar(y)));
9191
}
9292

9393
/**
@@ -102,7 +102,7 @@ class Bool {
102102
}
103103
return;
104104
}
105-
Snarky.bool.assertEqual(this.value, Bool.#toVar(y));
105+
Snarky.bool.assertEqual(this.value, toFieldVar(y));
106106
} catch (err) {
107107
throw withMessage(err, message);
108108
}
@@ -144,7 +144,7 @@ class Bool {
144144
if (this.isConstant() && isConstant(y)) {
145145
return new Bool(this.toBoolean() === toBoolean(y));
146146
}
147-
return new Bool(Snarky.bool.equals(this.value, Bool.#toVar(y)));
147+
return new Bool(Snarky.bool.equals(this.value, toFieldVar(y)));
148148
}
149149

150150
/**
@@ -194,14 +194,14 @@ class Bool {
194194
}
195195

196196
static toField(x: Bool | boolean): Field {
197-
return new Field(Bool.#toVar(x));
197+
return new Field(toFieldVar(x));
198198
}
199199

200200
/**
201201
* Boolean negation.
202202
*/
203203
static not(x: Bool | boolean): Bool {
204-
if (Bool.#isBool(x)) {
204+
if (x instanceof Bool) {
205205
return x.not();
206206
}
207207
return new Bool(!x);
@@ -211,7 +211,7 @@ class Bool {
211211
* Boolean AND operation.
212212
*/
213213
static and(x: Bool | boolean, y: Bool | boolean): Bool {
214-
if (Bool.#isBool(x)) {
214+
if (x instanceof Bool) {
215215
return x.and(y);
216216
}
217217
return new Bool(x).and(y);
@@ -221,7 +221,7 @@ class Bool {
221221
* Boolean OR operation.
222222
*/
223223
static or(x: Bool | boolean, y: Bool | boolean): Bool {
224-
if (Bool.#isBool(x)) {
224+
if (x instanceof Bool) {
225225
return x.or(y);
226226
}
227227
return new Bool(x).or(y);
@@ -231,7 +231,7 @@ class Bool {
231231
* Asserts if both {@link Bool} are equal.
232232
*/
233233
static assertEqual(x: Bool, y: Bool | boolean): void {
234-
if (Bool.#isBool(x)) {
234+
if (x instanceof Bool) {
235235
x.assertEquals(y);
236236
return;
237237
}
@@ -242,7 +242,7 @@ class Bool {
242242
* Checks two {@link Bool} for equality.
243243
*/
244244
static equal(x: Bool | boolean, y: Bool | boolean): Bool {
245-
if (Bool.#isBool(x)) {
245+
if (x instanceof Bool) {
246246
return x.equals(y);
247247
}
248248
return new Bool(x).equals(y);
@@ -342,15 +342,6 @@ class Bool {
342342
return new Bool(x.value);
343343
},
344344
};
345-
346-
static #isBool(x: boolean | Bool | BoolVar): x is Bool {
347-
return x instanceof Bool;
348-
}
349-
350-
static #toVar(x: boolean | Bool): BoolVar {
351-
if (Bool.#isBool(x)) return x.value;
352-
return FieldVar.constant(B(x));
353-
}
354345
}
355346

356347
const BoolBinable = defineBinable({
@@ -362,6 +353,8 @@ const BoolBinable = defineBinable({
362353
},
363354
});
364355

356+
// internal helper functions
357+
365358
function isConstant(x: boolean | Bool): x is boolean | ConstantBool {
366359
if (typeof x === 'boolean') {
367360
return true;
@@ -370,17 +363,18 @@ function isConstant(x: boolean | Bool): x is boolean | ConstantBool {
370363
return x.isConstant();
371364
}
372365

373-
function isBool(x: unknown) {
374-
return x instanceof Bool;
375-
}
376-
377366
function toBoolean(x: boolean | Bool): boolean {
378367
if (typeof x === 'boolean') {
379368
return x;
380369
}
381370
return x.toBoolean();
382371
}
383372

373+
function toFieldVar(x: boolean | Bool): BoolVar {
374+
if (x instanceof Bool) return x.value;
375+
return FieldVar.constant(B(x));
376+
}
377+
384378
// TODO: This is duplicated
385379
function withMessage(error: unknown, message?: string) {
386380
if (message === undefined || !(error instanceof Error)) return error;

0 commit comments

Comments
 (0)