midnight-mcp 0.1.35 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -351,5 +351,27 @@ witness lookup_value(key: Bytes<32>): Field;`,
|
|
|
351
351
|
2. Range check fails (use bounded Uint)
|
|
352
352
|
3. Logic error in circuit`,
|
|
353
353
|
},
|
|
354
|
+
{
|
|
355
|
+
error: 'parse error: found ":" looking for ")"',
|
|
356
|
+
cause: "Using Rust-style :: for enum variant access",
|
|
357
|
+
fix: `Use dot notation for enum variants:
|
|
358
|
+
WRONG: Choice::rock, GameState::waiting
|
|
359
|
+
CORRECT: Choice.rock, GameState.waiting`,
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
error: 'parse error: found "{" after witness declaration',
|
|
363
|
+
cause: "Trying to add implementation body to witness",
|
|
364
|
+
fix: `Witnesses are declarations only - no body allowed:
|
|
365
|
+
WRONG: witness get_caller(): Bytes<32> { return ...; }
|
|
366
|
+
CORRECT: witness get_caller(): Bytes<32>;
|
|
367
|
+
Implementation goes in TypeScript prover, not Compact.`,
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
error: 'unbound identifier "function"',
|
|
371
|
+
cause: 'Using "pure function" instead of "pure circuit"',
|
|
372
|
+
fix: `Use "pure circuit" for helper functions:
|
|
373
|
+
WRONG: pure function helper(...): Type { }
|
|
374
|
+
CORRECT: pure circuit helper(...): Type { }`,
|
|
375
|
+
},
|
|
354
376
|
];
|
|
355
377
|
//# sourceMappingURL=compact-version.js.map
|
|
@@ -133,6 +133,16 @@ export enum GameState { waiting, playing, finished }
|
|
|
133
133
|
export enum Choice { rock, paper, scissors }
|
|
134
134
|
\`\`\`
|
|
135
135
|
|
|
136
|
+
**Enum Access Syntax** - use DOT notation (not Rust-style ::):
|
|
137
|
+
\`\`\`compact
|
|
138
|
+
// CORRECT - dot notation
|
|
139
|
+
if (choice == Choice.rock) { ... }
|
|
140
|
+
game_state = GameState.waiting;
|
|
141
|
+
|
|
142
|
+
// WRONG - Rust-style double colon
|
|
143
|
+
if (choice == Choice::rock) { ... } // ❌ Parse error: found ":" looking for ")"
|
|
144
|
+
\`\`\`
|
|
145
|
+
|
|
136
146
|
**Structs**:
|
|
137
147
|
\`\`\`compact
|
|
138
148
|
export struct PlayerConfig {
|
|
@@ -187,18 +197,20 @@ export pure circuit hash(x: Field): Bytes<32> // No state access
|
|
|
187
197
|
|
|
188
198
|
Witnesses provide off-chain/private data to circuits. They run locally, not on-chain.
|
|
189
199
|
|
|
200
|
+
**CRITICAL**: Witnesses are declarations only - NO implementation body in Compact!
|
|
201
|
+
The implementation goes in your TypeScript prover.
|
|
202
|
+
|
|
190
203
|
\`\`\`compact
|
|
191
|
-
//
|
|
204
|
+
// ✅ CORRECT - declaration only, semicolon at end
|
|
192
205
|
witness local_secret_key(): Bytes<32>;
|
|
193
|
-
|
|
194
|
-
// Witness with parameters
|
|
195
206
|
witness get_merkle_path(leaf: Bytes<32>): MerkleTreePath<10, Bytes<32>>;
|
|
196
|
-
|
|
197
|
-
// Witness that returns nothing (side effect only)
|
|
198
207
|
witness store_locally(data: Field): [];
|
|
199
|
-
|
|
200
|
-
// Witness returning optional
|
|
201
208
|
witness find_user(id: Bytes<32>): Maybe<UserData>;
|
|
209
|
+
|
|
210
|
+
// ❌ WRONG - witnesses cannot have bodies
|
|
211
|
+
witness get_caller(): Bytes<32> {
|
|
212
|
+
return public_key(local_secret_key()); // ERROR!
|
|
213
|
+
}
|
|
202
214
|
\`\`\`
|
|
203
215
|
|
|
204
216
|
---
|
|
@@ -219,6 +231,27 @@ constructor(initNonce: Bytes<32>) {
|
|
|
219
231
|
|
|
220
232
|
---
|
|
221
233
|
|
|
234
|
+
## 7.5 Pure Circuits (Helper Functions)
|
|
235
|
+
|
|
236
|
+
Use \`pure circuit\` for helper functions that don't modify ledger state:
|
|
237
|
+
|
|
238
|
+
\`\`\`compact
|
|
239
|
+
// ✅ CORRECT - use "pure circuit"
|
|
240
|
+
pure circuit determine_winner(p1: Choice, p2: Choice): Result {
|
|
241
|
+
if (p1 == p2) {
|
|
242
|
+
return Result.draw;
|
|
243
|
+
}
|
|
244
|
+
// ... logic
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ❌ WRONG - "function" keyword doesn't exist
|
|
248
|
+
pure function determine_winner(p1: Choice, p2: Choice): Result {
|
|
249
|
+
// ERROR: unbound identifier "function"
|
|
250
|
+
}
|
|
251
|
+
\`\`\`
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
222
255
|
## 8. Common Patterns
|
|
223
256
|
|
|
224
257
|
### Authentication Pattern
|
|
@@ -411,6 +411,21 @@ export circuit increment(): [] {
|
|
|
411
411
|
correct: "// Use witness: witness get_value(key): Type;",
|
|
412
412
|
error: "member access requires struct type",
|
|
413
413
|
},
|
|
414
|
+
{
|
|
415
|
+
wrong: "Choice::rock (Rust-style)",
|
|
416
|
+
correct: "Choice.rock (dot notation)",
|
|
417
|
+
error: 'parse error: found ":" looking for ")"',
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
wrong: "witness fn(): T { ... }",
|
|
421
|
+
correct: "witness fn(): T; // declaration only, no body",
|
|
422
|
+
error: "parse error after witness declaration",
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
wrong: "pure function helper(): T",
|
|
426
|
+
correct: "pure circuit helper(): T",
|
|
427
|
+
error: 'unbound identifier "function"',
|
|
428
|
+
},
|
|
414
429
|
],
|
|
415
430
|
syntaxReference: compactReference,
|
|
416
431
|
sections: [
|