Skip to content

Commit 976f212

Browse files
committed
Merge branch 'main' into feature/ffmul
2 parents ccb55c7 + ac75360 commit 976f212

File tree

7 files changed

+72
-25
lines changed

7 files changed

+72
-25
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3232

3333
### Changed
3434

35+
- `Lightnet` namespace API updates with added `listAcquiredKeyPairs()` method https://github.com/o1-labs/o1js/pull/1256
3536
- Expose raw provable methods of a `ZkProgram` on `zkProgram.rawMethods` https://github.com/o1-labs/o1js/pull/1241
37+
- Reduce number of constraints needed by `rotate()`, `leftShift()` and, `rightShift()` gadgets https://github.com/o1-labs/o1js/pull/1201
38+
39+
### Fixed
40+
41+
- Add a parameter to `checkZkappTransaction` for block length to check for transaction inclusion. This fixes a case where `Transaction.wait()` only checked the latest block, which led to an error once the transaction was included in a block that was not the latest. https://github.com/o1-labs/o1js/pull/1239
3642

3743
## [0.14.1](https://github.com/o1-labs/o1js/compare/e8e7510e1...26363465d)
3844

@@ -56,7 +62,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
5662

5763
### Added
5864

59-
- `Lightnet` namespace to interact with the account manager provided by the [lightnet Mina network](https://hub.docker.com/r/o1labs/mina-local-network). https://github.com/o1-labs/o1js/pull/1167
65+
- `Lightnet` namespace to interact with the account manager provided by the [lightnet Mina network](https://hub.docker.com/r/o1labs/mina-local-network) https://github.com/o1-labs/o1js/pull/1167
6066
- Internal support for several custom gates (range check, bitwise operations, foreign field operations) and lookup tables https://github.com/o1-labs/o1js/pull/1176
6167
- `Gadgets.rangeCheck64()`, new provable method to do efficient 64-bit range checks using lookup tables https://github.com/o1-labs/o1js/pull/1181
6268
- `Gadgets.rotate()`, new provable method to support bitwise rotation for native field elements. https://github.com/o1-labs/o1js/pull/1182

src/lib/fetch.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ type LastBlockQueryFailureCheckResponse = {
481481
}[];
482482
};
483483

484-
const lastBlockQueryFailureCheck = `{
485-
bestChain(maxLength: 1) {
484+
const lastBlockQueryFailureCheck = (length: number) => `{
485+
bestChain(maxLength: ${length}) {
486486
transactions {
487487
zkappCommands {
488488
hash
@@ -496,10 +496,11 @@ const lastBlockQueryFailureCheck = `{
496496
}`;
497497

498498
async function fetchLatestBlockZkappStatus(
499+
blockLength: number,
499500
graphqlEndpoint = networkConfig.minaEndpoint
500501
) {
501502
let [resp, error] = await makeGraphqlRequest(
502-
lastBlockQueryFailureCheck,
503+
lastBlockQueryFailureCheck(blockLength),
503504
graphqlEndpoint,
504505
networkConfig.minaFallbackEndpoints
505506
);
@@ -513,9 +514,8 @@ async function fetchLatestBlockZkappStatus(
513514
return bestChain;
514515
}
515516

516-
async function checkZkappTransaction(txnId: string) {
517-
let bestChainBlocks = await fetchLatestBlockZkappStatus();
518-
517+
async function checkZkappTransaction(txnId: string, blockLength = 20) {
518+
let bestChainBlocks = await fetchLatestBlockZkappStatus(blockLength);
519519
for (let block of bestChainBlocks.bestChain) {
520520
for (let zkappCommand of block.transactions.zkappCommands) {
521521
if (zkappCommand.hash === txnId) {
@@ -1019,7 +1019,7 @@ namespace Lightnet {
10191019
* If an error is returned by the specified endpoint, an error is thrown. Otherwise,
10201020
* the data is returned.
10211021
*
1022-
* @param options.isRegularAccount Whether to acquire regular or zkApp account (one with already configured verification key)
1022+
* @param options.isRegularAccount Whether to acquire key pair of regular or zkApp account (one with already configured verification key)
10231023
* @param options.lightnetAccountManagerEndpoint Account manager endpoint to fetch from
10241024
* @returns Key pair
10251025
*/
@@ -1096,6 +1096,44 @@ namespace Lightnet {
10961096

10971097
return null;
10981098
}
1099+
1100+
/**
1101+
* Gets previously acquired key pairs list.
1102+
*
1103+
* @param options.lightnetAccountManagerEndpoint Account manager endpoint to fetch from
1104+
* @returns Key pairs list or null if the request failed
1105+
*/
1106+
export async function listAcquiredKeyPairs(options: {
1107+
lightnetAccountManagerEndpoint?: string;
1108+
}): Promise<Array<{
1109+
publicKey: PublicKey;
1110+
privateKey: PrivateKey;
1111+
}> | null> {
1112+
const {
1113+
lightnetAccountManagerEndpoint = networkConfig.lightnetAccountManagerEndpoint,
1114+
} = options;
1115+
const response = await fetch(
1116+
`${lightnetAccountManagerEndpoint}/list-acquired-accounts`,
1117+
{
1118+
method: 'GET',
1119+
headers: {
1120+
'Content-Type': 'application/json',
1121+
},
1122+
}
1123+
);
1124+
1125+
if (response.ok) {
1126+
const data = await response.json();
1127+
if (data) {
1128+
return data.map((account: any) => ({
1129+
publicKey: PublicKey.fromBase58(account.pk),
1130+
privateKey: PrivateKey.fromBase58(account.sk),
1131+
}));
1132+
}
1133+
}
1134+
1135+
return null;
1136+
}
10991137
}
11001138

11011139
function updateActionState(actions: string[][], actionState: Field) {

src/lib/gadgets/bitwise.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ function rot(
276276
);
277277
// Compute next row
278278
rangeCheck64(shifted);
279-
// Compute following row
280-
rangeCheck64(excess);
279+
// note: range-checking `shifted` and `field` is enough.
280+
// * excess < 2^rot follows from the bound check and the rotation equation in the gate
281+
// * rotated < 2^64 follows from rotated = excess + shifted (because shifted has to be a multiple of 2^rot)
282+
// for a proof, see https://github.com/o1-labs/o1js/pull/1201
281283
return [rotated, excess, shifted];
282284
}
283285

src/lib/gadgets/bitwise.unit-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ZkProgram } from '../proof_system.js';
22
import {
3-
equivalent,
3+
equivalentProvable as equivalent,
44
equivalentAsync,
55
field,
66
fieldWithRng,
@@ -224,7 +224,7 @@ constraintSystem.fromZkProgram(
224224
ifNotAllConstant(contains(xorChain(64)))
225225
);
226226

227-
let rotChain: GateType[] = ['Rot64', 'RangeCheck0', 'RangeCheck0'];
227+
let rotChain: GateType[] = ['Rot64', 'RangeCheck0'];
228228
let isJustRotate = ifNotAllConstant(
229229
and(contains(rotChain), withoutGenerics(equals(rotChain)))
230230
);

src/lib/gadgets/foreign-field.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ function singleAdd(x: Field3, y: Field3, sign: Sign, f: bigint) {
8181
let f_ = split(f);
8282

8383
let [r0, r1, r2, overflow, carry] = exists(5, () => {
84-
let x_ = bigint3(x);
85-
let y_ = bigint3(y);
84+
let x_ = toBigint3(x);
85+
let y_ = toBigint3(y);
8686

8787
// figure out if there's overflow
8888
let r = collapse(x_) + sign * collapse(y_);
@@ -228,9 +228,9 @@ function multiplyNoRangeCheck(a: Field3, b: Field3, f: bigint) {
228228
let f2Bound = (1n << l) - f2 - 1n;
229229

230230
let witnesses = exists(21, () => {
231-
// split inputs into 3 limbs
232-
let [a0, a1, a2] = bigint3(a);
233-
let [b0, b1, b2] = bigint3(b);
231+
// convert inputs to bigints
232+
let [a0, a1, a2] = toBigint3(a);
233+
let [b0, b1, b2] = toBigint3(b);
234234

235235
// compute q and r such that a*b = q*f + r
236236
let ab = collapse([a0, a1, a2]) * collapse([b0, b1, b2]);
@@ -337,7 +337,7 @@ const Field3 = {
337337
* Turn a 3-tuple of Fields into a bigint
338338
*/
339339
toBigint(x: Field3): bigint {
340-
return collapse(bigint3(x));
340+
return collapse(toBigint3(x));
341341
},
342342

343343
/**
@@ -356,7 +356,7 @@ const Field2 = {
356356
},
357357
};
358358

359-
function bigint3(x: Field3): bigint3 {
359+
function toBigint3(x: Field3): bigint3 {
360360
return Tuple.map(x, (x) => x.toBigInt());
361361
}
362362

tests/vk-regression/plain-constraint-system.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const GroupCS = constraintSystem('Group Primitive', {
3636
const BitwiseCS = constraintSystem('Bitwise Primitive', {
3737
rot() {
3838
let a = Provable.witness(Field, () => new Field(12));
39+
Gadgets.rangeCheck64(a); // `rotate()` doesn't do this
3940
Gadgets.rotate(a, 2, 'left');
4041
Gadgets.rotate(a, 2, 'right');
4142
Gadgets.rotate(a, 4, 'left');

tests/vk-regression/vk-regression.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@
169169
"digest": "Bitwise Primitive",
170170
"methods": {
171171
"rot": {
172-
"rows": 13,
173-
"digest": "2c0dadbba96fd7ddb9adb7d643425ce3"
172+
"rows": 10,
173+
"digest": "c38703de755b10edf77bf24269089274"
174174
},
175175
"xor": {
176176
"rows": 15,
@@ -185,12 +185,12 @@
185185
"digest": "b12ad7e8a3fd28b765e059357dbe9e44"
186186
},
187187
"leftShift": {
188-
"rows": 7,
189-
"digest": "66de39ad3dd5807f760341ec85a6cc41"
188+
"rows": 5,
189+
"digest": "451f550bf73fecf53c9be82367572cb8"
190190
},
191191
"rightShift": {
192-
"rows": 7,
193-
"digest": "a32264f2d4c3092f30d600fa9506385b"
192+
"rows": 5,
193+
"digest": "d0793d4a326d480eaa015902dc34bc39"
194194
},
195195
"and": {
196196
"rows": 19,

0 commit comments

Comments
 (0)