midnight-mcp 0.1.36 → 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.
|
@@ -358,5 +358,20 @@ witness lookup_value(key: Bytes<32>): Field;`,
|
|
|
358
358
|
WRONG: Choice::rock, GameState::waiting
|
|
359
359
|
CORRECT: Choice.rock, GameState.waiting`,
|
|
360
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
|
+
},
|
|
361
376
|
];
|
|
362
377
|
//# sourceMappingURL=compact-version.js.map
|
|
@@ -197,18 +197,20 @@ export pure circuit hash(x: Field): Bytes<32> // No state access
|
|
|
197
197
|
|
|
198
198
|
Witnesses provide off-chain/private data to circuits. They run locally, not on-chain.
|
|
199
199
|
|
|
200
|
+
**CRITICAL**: Witnesses are declarations only - NO implementation body in Compact!
|
|
201
|
+
The implementation goes in your TypeScript prover.
|
|
202
|
+
|
|
200
203
|
\`\`\`compact
|
|
201
|
-
//
|
|
204
|
+
// ✅ CORRECT - declaration only, semicolon at end
|
|
202
205
|
witness local_secret_key(): Bytes<32>;
|
|
203
|
-
|
|
204
|
-
// Witness with parameters
|
|
205
206
|
witness get_merkle_path(leaf: Bytes<32>): MerkleTreePath<10, Bytes<32>>;
|
|
206
|
-
|
|
207
|
-
// Witness that returns nothing (side effect only)
|
|
208
207
|
witness store_locally(data: Field): [];
|
|
209
|
-
|
|
210
|
-
// Witness returning optional
|
|
211
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
|
+
}
|
|
212
214
|
\`\`\`
|
|
213
215
|
|
|
214
216
|
---
|
|
@@ -229,6 +231,27 @@ constructor(initNonce: Bytes<32>) {
|
|
|
229
231
|
|
|
230
232
|
---
|
|
231
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
|
+
|
|
232
255
|
## 8. Common Patterns
|
|
233
256
|
|
|
234
257
|
### Authentication Pattern
|
|
@@ -416,6 +416,16 @@ export circuit increment(): [] {
|
|
|
416
416
|
correct: "Choice.rock (dot notation)",
|
|
417
417
|
error: 'parse error: found ":" looking for ")"',
|
|
418
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
|
+
},
|
|
419
429
|
],
|
|
420
430
|
syntaxReference: compactReference,
|
|
421
431
|
sections: [
|