Skip to content

Commit 66df4f2

Browse files
committed
Merge branch 'main' into feature/expose-proof-base64
2 parents 577d5e7 + cb0b270 commit 66df4f2

File tree

4 files changed

+226
-6
lines changed

4 files changed

+226
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1919

2020
### Added
2121

22+
- Add `enforceTransactionLimits` parameter on Network https://github.com/o1-labs/o1js/issues/1910
2223
- Expose low-level conversion methods `Proof.{_proofToBase64,_proofFromBase64}` https://github.com/o1-labs/o1js/pull/1928
2324

2425
### Fixed
2526

2627
- Compiling stuck in the browser for recursive zkprograms https://github.com/o1-labs/o1js/pull/1906
2728
- Error message in `rangeCheck16` gadget https://github.com/o1-labs/o1js/pull/1920
2829

30+
### Added
31+
32+
- Method for optional types to assert none https://github.com/o1-labs/o1js/pull/1922
33+
2934
## [2.1.0](https://github.com/o1-labs/o1js/compare/b04520d...e1bac02) - 2024-11-13
3035

3136
### Added
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
import {
2+
State,
3+
state,
4+
UInt64,
5+
Bool,
6+
SmartContract,
7+
Mina,
8+
AccountUpdate,
9+
method,
10+
PublicKey,
11+
Permissions,
12+
VerificationKey,
13+
Field,
14+
Int64,
15+
TokenId,
16+
TokenContract as TokenContractBase,
17+
AccountUpdateForest,
18+
PrivateKey,
19+
} from 'o1js';
20+
import { test, describe, it, before } from 'node:test';
21+
import { expect } from 'expect';
22+
23+
24+
25+
const defaultNetwork = Mina.Network({
26+
networkId: "testnet",
27+
mina: "https://example.com/graphql",
28+
archive: "https://example.com//graphql"
29+
});
30+
31+
const enforcedNetwork = Mina.Network({
32+
networkId: "testnet",
33+
mina: "https://example.com/graphql",
34+
archive: "https://example.com//graphql",
35+
bypassTransactionLimits: false
36+
});
37+
38+
const unlimitedNetwork = Mina.Network({
39+
networkId: "testnet",
40+
mina: "https://unlimited.com/graphql",
41+
archive: "https://unlimited.com//graphql",
42+
bypassTransactionLimits: true
43+
});
44+
45+
describe('Test default network', () => {
46+
let bobAccount: PublicKey,
47+
bobKey: PrivateKey;
48+
49+
before(async () => {
50+
51+
Mina.setActiveInstance(defaultNetwork);
52+
bobKey = PrivateKey.random();
53+
bobAccount = bobKey.toPublicKey();
54+
});
55+
56+
57+
it('Simple account update', async () => {
58+
59+
let txn = await Mina.transaction(async () => {
60+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(1));
61+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
62+
accountUpdateBob.balance.addInPlace(UInt64.one);
63+
});
64+
await txn.prove();
65+
await txn.sign([bobKey]).safeSend();
66+
67+
});
68+
69+
it('Multiple account update', async () => {
70+
71+
let txn = await Mina.transaction(async () => {
72+
for (let index = 0; index < 2; index++) {
73+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index));
74+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
75+
accountUpdateBob.balance.addInPlace(UInt64.one);
76+
}
77+
});
78+
await txn.prove();
79+
await txn.sign([bobKey]).safeSend();
80+
81+
});
82+
83+
it('More than limit account update', async () => {
84+
85+
let txn = await Mina.transaction(async () => {
86+
for (let index = 0; index < 12; index++) {
87+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index));
88+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
89+
accountUpdateBob.balance.addInPlace(UInt64.one);
90+
}
91+
});
92+
await txn.prove();
93+
// failure with default bypassTransactionLimits value
94+
await expect(txn.sign([bobKey]).safeSend()).rejects.toThrow();
95+
});
96+
});
97+
98+
describe('Test enforced network', () => {
99+
let bobAccount: PublicKey,
100+
bobKey: PrivateKey;
101+
102+
before(async () => {
103+
104+
Mina.setActiveInstance(enforcedNetwork);
105+
bobKey = PrivateKey.random();
106+
bobAccount = bobKey.toPublicKey();
107+
});
108+
109+
110+
it('Simple account update', async () => {
111+
112+
let txn = await Mina.transaction(async () => {
113+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(1));
114+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
115+
accountUpdateBob.balance.addInPlace(UInt64.one);
116+
});
117+
await txn.prove();
118+
await txn.sign([bobKey]).safeSend();
119+
120+
});
121+
122+
it('Multiple account update', async () => {
123+
124+
let txn = await Mina.transaction(async () => {
125+
for (let index = 0; index < 2; index++) {
126+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index));
127+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
128+
accountUpdateBob.balance.addInPlace(UInt64.one);
129+
}
130+
});
131+
await txn.prove();
132+
await txn.sign([bobKey]).safeSend();
133+
134+
});
135+
136+
it('More than limit account update', async () => {
137+
138+
let txn = await Mina.transaction(async () => {
139+
for (let index = 0; index < 12; index++) {
140+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index));
141+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
142+
accountUpdateBob.balance.addInPlace(UInt64.one);
143+
}
144+
});
145+
await txn.prove();
146+
// failure with bypassTransactionLimits = false
147+
await expect(txn.sign([bobKey]).safeSend()).rejects.toThrow();
148+
});
149+
});
150+
151+
describe('Test unlimited network', () => {
152+
let bobAccount: PublicKey,
153+
bobKey: PrivateKey;
154+
155+
before(async () => {
156+
157+
Mina.setActiveInstance(unlimitedNetwork);
158+
bobKey = PrivateKey.random();
159+
bobAccount = bobKey.toPublicKey();
160+
});
161+
162+
163+
it('Simple account update', async () => {
164+
165+
let txn = await Mina.transaction(async () => {
166+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(1));
167+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
168+
accountUpdateBob.balance.addInPlace(UInt64.one);
169+
});
170+
await txn.prove();
171+
await txn.sign([bobKey]).safeSend();
172+
173+
});
174+
175+
it('Multiple account update', async () => {
176+
177+
let txn = await Mina.transaction(async () => {
178+
for (let index = 0; index < 2; index++) {
179+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index));
180+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
181+
accountUpdateBob.balance.addInPlace(UInt64.one);
182+
}
183+
});
184+
await txn.prove();
185+
await txn.sign([bobKey]).safeSend();
186+
187+
});
188+
189+
it('More than limit account update', async () => {
190+
191+
let txn = await Mina.transaction(async () => {
192+
for (let index = 0; index < 12; index++) {
193+
const accountUpdateBob = AccountUpdate.create(bobAccount, Field.from(index));
194+
accountUpdateBob.account.balance.requireEquals(UInt64.zero);
195+
accountUpdateBob.balance.addInPlace(UInt64.one);
196+
}
197+
});
198+
await txn.prove();
199+
// success with bypassTransactionLimits = true
200+
await txn.sign([bobKey]).safeSend();
201+
});
202+
});

src/lib/mina/mina.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,24 @@ function Network(options: {
104104
mina: string | string[];
105105
archive?: string | string[];
106106
lightnetAccountManager?: string;
107+
bypassTransactionLimits?: boolean;
107108
}): Mina;
108109
function Network(
109110
options:
110111
| {
111-
networkId?: NetworkId;
112-
mina: string | string[];
113-
archive?: string | string[];
114-
lightnetAccountManager?: string;
115-
}
112+
networkId?: NetworkId;
113+
mina: string | string[];
114+
archive?: string | string[];
115+
lightnetAccountManager?: string;
116+
bypassTransactionLimits?: boolean;
117+
}
116118
| string
117119
): Mina {
118120
let minaNetworkId: NetworkId = 'testnet';
119121
let minaGraphqlEndpoint: string;
120122
let archiveEndpoint: string;
121123
let lightnetAccountManagerEndpoint: string;
124+
let enforceTransactionLimits: boolean = true;
122125

123126
if (options && typeof options === 'string') {
124127
minaGraphqlEndpoint = options;
@@ -158,6 +161,11 @@ function Network(
158161
lightnetAccountManagerEndpoint = options.lightnetAccountManager;
159162
Fetch.setLightnetAccountManagerEndpoint(lightnetAccountManagerEndpoint);
160163
}
164+
165+
if (options.bypassTransactionLimits !== undefined &&
166+
typeof options.bypassTransactionLimits === 'boolean') {
167+
enforceTransactionLimits = !options.bypassTransactionLimits;
168+
}
161169
} else {
162170
throw new Error(
163171
"Network: malformed input. Please provide a string or an object with 'mina' and 'archive' endpoints."
@@ -251,7 +259,7 @@ function Network(
251259
},
252260
sendTransaction(txn) {
253261
return toPendingTransactionPromise(async () => {
254-
verifyTransactionLimits(txn.transaction);
262+
if (enforceTransactionLimits) verifyTransactionLimits(txn.transaction);
255263

256264
let [response, error] = await Fetch.sendZkapp(txn.toJSON());
257265
let errors: string[] = [];

src/lib/provable/option.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export { Option, OptionOrValue };
99

1010
type Option<T, V = any> = { isSome: Bool; value: T } & {
1111
assertSome(message?: string): T;
12+
assertNone(message?: string): void;
1213
orElse(defaultValue: T | V): T;
1314
};
1415

@@ -104,6 +105,10 @@ function Option<A extends ProvableType>(
104105
return this.value;
105106
}
106107

108+
assertNone(message?: string): void {
109+
this.isSome.assertFalse(message);
110+
}
111+
107112
static from(value?: V | T) {
108113
return value === undefined
109114
? new Option_({

0 commit comments

Comments
 (0)