enigma-memory 0.1.18 → 0.1.22
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.
- package/README.md +76 -24
- package/apps/cli/bin/enigma-desktop.mjs +140 -0
- package/apps/cli/bin/enigma-terminal.mjs +78 -0
- package/apps/cli/bin/enigma.mjs +1923 -285
- package/apps/desktop/electron-main.cjs +217 -0
- package/apps/desktop/package.json +12 -0
- package/apps/desktop/src/app.js +264 -7
- package/apps/desktop/src/index.html +3514 -1373
- package/apps/desktop/src/launch-electron.mjs +51 -0
- package/apps/desktop/src/server.mjs +2914 -0
- package/apps/desktop/src/styles.css +2972 -260
- package/apps/desktop/src/zk-browser-prove.mjs +53 -0
- package/apps/desktop/src/zk-state.mjs +1789 -0
- package/apps/gateway/bin/enigma-gateway.mjs +102 -5
- package/apps/gateway/src/server.mjs +271 -8
- package/apps/ios/EnigmaCore/Package.swift +12 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/EnigmaAPIClient.swift +227 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/Models.swift +278 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/PKCE.swift +96 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/PrivacyMinimizer.swift +187 -0
- package/apps/ios/EnigmaCore/Sources/EnigmaCore/ToolModels.swift +129 -0
- package/apps/ios/EnigmaCore/Tests/EnigmaCoreTests/EnigmaCoreTests.swift +42 -0
- package/apps/ios/EnigmaIOS/Enigma/AppModel.swift +346 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AccentColor.colorset/Contents.json +12 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AppIcon.appiconset/Contents.json +11 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/AppIcon.appiconset/EnigmaAppIcon.png +0 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/Contents.json +3 -0
- package/apps/ios/EnigmaIOS/Enigma/Assets.xcassets/LaunchBackground.colorset/Contents.json +12 -0
- package/apps/ios/EnigmaIOS/Enigma/ChatView.swift +181 -0
- package/apps/ios/EnigmaIOS/Enigma/CouncilView.swift +78 -0
- package/apps/ios/EnigmaIOS/Enigma/CreateView.swift +152 -0
- package/apps/ios/EnigmaIOS/Enigma/EnigmaApp.swift +52 -0
- package/apps/ios/EnigmaIOS/Enigma/Info.plist +52 -0
- package/apps/ios/EnigmaIOS/Enigma/NaturalLanguagePrivacyTagger.swift +26 -0
- package/apps/ios/EnigmaIOS/Enigma/OAuthClient.swift +321 -0
- package/apps/ios/EnigmaIOS/Enigma/OnboardingView.swift +105 -0
- package/apps/ios/EnigmaIOS/Enigma/PrivateVaultView.swift +275 -0
- package/apps/ios/EnigmaIOS/Enigma/SecureStore.swift +76 -0
- package/apps/ios/EnigmaIOS/Enigma/SettingsView.swift +60 -0
- package/apps/ios/EnigmaIOS/Enigma/Theme.swift +80 -0
- package/apps/ios/EnigmaIOS/EnigmaIOS.xcodeproj/project.pbxproj +211 -0
- package/apps/ios/EnigmaIOS/EnigmaIOS.xcodeproj/xcshareddata/xcschemes/Enigma.xcscheme +23 -0
- package/apps/native-host/README.md +19 -8
- package/apps/native-host/bin/enigma-native-host.mjs +229 -13
- package/apps/relay/bin/enigma-relay.mjs +103 -5
- package/apps/relay/src/federation-runtime.mjs +618 -0
- package/apps/relay/src/server.mjs +310 -9
- package/apps/verifier/bin/enigma-verify.mjs +327 -11
- package/cortex-v3/circuits/build/intent_vk_bytes.json +35 -0
- package/cortex-v3/circuits/build/sale_vk_bytes.json +35 -0
- package/cortex-v3/circuits/build/vk_bytes.json +32 -0
- package/cortex-v3/proving-assets.json +64 -0
- package/cortex-v3/zk/BUILD-CONTRACT.md +87 -0
- package/cortex-v3/zk/action-transition-vk.json +119 -0
- package/cortex-v3/zk/alias-adversarial.test.mjs +220 -0
- package/cortex-v3/zk/groth16-verify-child.mjs +17 -0
- package/cortex-v3/zk/intent-witness.mjs +365 -0
- package/cortex-v3/zk/intent-witness.test.mjs +485 -0
- package/cortex-v3/zk/proving-assets.mjs +203 -0
- package/cortex-v3/zk/sale-witness.mjs +783 -0
- package/cortex-v3/zk/sale-witness.test.mjs +784 -0
- package/cortex-v3/zk/sealed-sale-release-vk.json +119 -0
- package/cortex-v3/zk/settlement-evidence.mjs +722 -0
- package/cortex-v3/zk/setup-intent.mjs +688 -0
- package/cortex-v3/zk/setup-sale.mjs +666 -0
- package/cortex-v3/zk/setup.mjs +594 -0
- package/cortex-v3/zk/witness.mjs +184 -0
- package/cortex-v3/zk/zk-codec.mjs +232 -0
- package/cortex-v3/zk/zk-codec.test.mjs +293 -0
- package/cortex-v3/zk/zk-settle.mjs +370 -0
- package/cortex-v3/zk/zk-tree.mjs +256 -0
- package/cortex-v3/zk/zk-tree.test.mjs +419 -0
- package/deploy/docker-compose.local-production-simulation.yml +36 -0
- package/docs/browser-extension-install.md +8 -6
- package/docs/client-connectors.md +15 -11
- package/docs/developer-ecosystem.md +15 -13
- package/docs/enigma-memory-ready-conformance.md +11 -9
- package/docs/install-anywhere.md +61 -28
- package/docs/installers-and-desktop.md +8 -7
- package/docs/novelty-invention-candidates.md +161 -161
- package/docs/proof-network-claim-boundaries.md +320 -318
- package/examples/01-quickstart-agent/index.mjs +49 -0
- package/examples/01_agent_memory_quickstart.mjs +57 -0
- package/examples/02-multi-agent-swarm/index.mjs +57 -0
- package/examples/02_cross_model_passport.mjs +64 -0
- package/examples/03-langchain-memory/index.mjs +41 -0
- package/examples/03_poseidon_commitment_verification.mjs +71 -0
- package/examples/04-python-trading-agent/trader.py +49 -0
- package/examples/README.md +27 -0
- package/examples/ci/github-actions.yml +7 -2
- package/package.json +142 -11
- package/packages/adapters/PACKAGE_CONTRACT.md +1 -1
- package/packages/connectors/src/index.js +196 -4
- package/packages/connectors/swarm-router.mjs +168 -0
- package/packages/core/src/index.js +248 -1
- package/packages/core/src/version.mjs +7 -0
- package/packages/dev-tools/package.json +19 -0
- package/packages/dev-tools/src/index.js +4 -0
- package/packages/dev-tools/src/memory-benchmark-suite.js +112 -0
- package/packages/dev-tools/src/swarm-simulator.js +101 -0
- package/packages/dev-tools/src/vault-inspector.js +114 -0
- package/packages/dev-tools/src/vector-benchmark.js +100 -0
- package/packages/developer-platform/src/access-credentials.js +341 -0
- package/packages/developer-platform/src/http.js +132 -0
- package/packages/developer-platform/src/index.js +4 -0
- package/packages/developer-platform/src/usage-http.js +60 -0
- package/packages/developer-platform/src/usage.js +295 -0
- package/packages/enclave-runtime/attestation.mjs +159 -0
- package/packages/enclave-runtime/index.mjs +47 -0
- package/packages/enclave-runtime/session-manager.mjs +253 -0
- package/packages/enclave-runtime/zeroization-proof.mjs +227 -0
- package/packages/enigma-reflex/package.json +14 -0
- package/packages/enigma-reflex/src/index.js +204 -0
- package/packages/enigma-reflex/training/generate-dataset.mjs +40 -0
- package/packages/enigma-reflex/training/requirements.txt +8 -0
- package/packages/enigma-reflex/training/train.py +314 -0
- package/packages/enigma-weave/LICENSE +22 -0
- package/packages/enigma-weave/UPSTREAM.json +21 -0
- package/packages/enigma-weave/package.json +14 -0
- package/packages/enigma-weave/src/index.js +286 -0
- package/packages/hosted-cloud/src/index.js +80 -5
- package/packages/importers/src/index.js +432 -0
- package/packages/inference-runtime/src/browser.js +401 -0
- package/packages/inference-runtime/src/chat.js +265 -0
- package/packages/inference-runtime/src/code.js +407 -0
- package/packages/inference-runtime/src/contracts.js +162 -0
- package/packages/inference-runtime/src/http.js +232 -0
- package/packages/inference-runtime/src/image.js +186 -0
- package/packages/inference-runtime/src/index.js +10 -0
- package/packages/inference-runtime/src/model-router.js +320 -0
- package/packages/inference-runtime/src/platform.js +125 -0
- package/packages/inference-runtime/src/privacy.js +400 -0
- package/packages/inference-runtime/src/video.js +253 -0
- package/packages/mcp-server/README.md +22 -6
- package/packages/mcp-server/bin/enigma-mcp.mjs +2 -1
- package/packages/mcp-server/src/index.js +1418 -105
- package/packages/mcp-server/src/oauth.js +561 -0
- package/packages/mcp-server/src/private-handoff.js +84 -0
- package/packages/mcp-server/src/remote-http.js +273 -0
- package/packages/mcp-server/src/remote-policy.js +72 -0
- package/packages/mcp-server/swarm-bridge.mjs +361 -0
- package/packages/mesh/index.d.ts +283 -0
- package/packages/mesh/package.json +23 -0
- package/packages/mesh/src/crypto.js +189 -0
- package/packages/mesh/src/federation-packets.js +353 -0
- package/packages/mesh/src/gossip.js +311 -0
- package/packages/mesh/src/index.js +6 -0
- package/packages/mesh/src/protocol.js +255 -0
- package/packages/mesh/src/router.js +279 -0
- package/packages/mesh/src/transport.js +306 -0
- package/packages/passport/src/index.js +426 -1
- package/packages/private-economy/src/credits-http.js +100 -0
- package/packages/private-economy/src/credits.js +447 -0
- package/packages/private-economy/src/index.js +5 -0
- package/packages/private-economy/src/payments-http.js +120 -0
- package/packages/private-economy/src/payments.js +509 -0
- package/packages/private-economy/src/x402.js +346 -0
- package/packages/proof-network/PACKAGE_CONTRACT.md +21 -0
- package/packages/rag/index.d.ts +182 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/THIRD_PARTY_LICENSES.txt +207 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/config.json +25 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/onnx/model_quantized.onnx +0 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/sha256-manifest.json +28 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/tokenizer.json +30686 -0
- package/packages/rag/models/Xenova/all-MiniLM-L6-v2/tokenizer_config.json +15 -0
- package/packages/rag/package.json +27 -0
- package/packages/rag/src/blinded-search.js +109 -0
- package/packages/rag/src/bm25.js +169 -0
- package/packages/rag/src/embeddings.js +459 -0
- package/packages/rag/src/hybrid.js +76 -0
- package/packages/rag/src/index.js +38 -0
- package/packages/rag/src/reranker.js +61 -0
- package/packages/rag/src/research.js +107 -0
- package/packages/rag/src/vector-store.js +430 -0
- package/packages/rag/src/verify-model-artifacts.mjs +4 -0
- package/packages/sdk/index.d.ts +760 -0
- package/packages/sdk/package.json +33 -0
- package/packages/sdk/python/README.md +24 -0
- package/packages/sdk/python/enigma_sdk.py +250 -0
- package/packages/sdk/python/pyproject.toml +34 -0
- package/packages/sdk/python/requirements.txt +1 -0
- package/packages/sdk/python/setup.py +20 -0
- package/packages/sdk/src/federation/capability-grant.js +389 -0
- package/packages/sdk/src/federation/federation-router.js +360 -0
- package/packages/sdk/src/federation/ghostmesh-bridge.js +497 -0
- package/packages/sdk/src/federation/index.js +3 -0
- package/packages/sdk/src/index.js +1796 -0
- package/packages/sdk/src/intelligence/contradiction.js +337 -0
- package/packages/sdk/src/intelligence/decision-engine.js +155 -0
- package/packages/sdk/src/intelligence/index.js +4 -0
- package/packages/sdk/src/intelligence/ontology.js +122 -0
- package/packages/sdk/src/intelligence/temporal.js +123 -0
- package/packages/sdk/src/market-client.js +142 -0
- package/packages/sdk/src/mesh-client.js +110 -0
- package/packages/sdk/src/middleware/index.js +3 -0
- package/packages/sdk/src/middleware/langchain.js +159 -0
- package/packages/sdk/src/middleware/llamaindex.js +101 -0
- package/packages/sdk/src/middleware/vercel-ai.js +112 -0
- package/packages/sdk/src/rag-client.js +85 -0
- package/packages/sdk/src/swarm-orchestrator.js +260 -0
- package/packages/settlement/PACKAGE_CONTRACT.md +1 -1
- package/packages/snapcompact/THIRD_PARTY_LICENSES.txt +40 -0
- package/packages/snapcompact/assets/8x13-latin1.bdf +3837 -0
- package/packages/snapcompact/index.d.ts +284 -0
- package/packages/snapcompact/package.json +25 -0
- package/packages/snapcompact/src/index.js +716 -0
- package/packages/storage/PACKAGE_CONTRACT.md +1 -1
- package/packages/terminal-console/animations.mjs +240 -0
- package/packages/terminal-console/auto-anchor.mjs +220 -0
- package/packages/terminal-console/banner.mjs +91 -0
- package/packages/terminal-console/commands.mjs +459 -0
- package/packages/terminal-console/delegation.mjs +152 -0
- package/packages/terminal-console/index.mjs +5 -0
- package/packages/terminal-console/outbox.mjs +143 -0
- package/packages/terminal-console/phantom-bridge.mjs +637 -0
- package/packages/terminal-console/repl.mjs +136 -0
- package/packages/terminal-console/signer-store.mjs +130 -0
- package/packages/terminal-console/solana-rpc.mjs +214 -0
- package/packages/terminal-console/solana-transport.mjs +189 -0
- package/packages/terminal-tui/dashboard.mjs +214 -0
- package/packages/terminal-tui/index.mjs +28 -0
- package/packages/terminal-tui/merkle-tree-renderer.mjs +268 -0
- package/packages/terminal-tui/telemetry-hud.mjs +137 -0
- package/packages/vault/index.d.ts +449 -0
- package/packages/vault/package.json +27 -0
- package/packages/vault/src/e2ee.mjs +393 -0
- package/packages/vault/src/enclave.js +481 -0
- package/packages/vault/src/erasure.js +207 -0
- package/packages/vault/src/index.js +1018 -155
- package/packages/vault/src/persistence.js +307 -0
- package/packages/vault/src/poseidon.js +354 -0
- package/packages/vault/src/receipt.js +459 -0
- package/scripts/benchmark-optical-context.mjs +166 -0
- package/scripts/bootstrap-enigma.mjs +502 -0
- package/scripts/build-edge-backend-workers.mjs +20 -5
- package/scripts/build-goal-completion-audit.mjs +72 -25
- package/scripts/build-hosted-api-key-lifecycle.mjs +26 -8
- package/scripts/build-hosted-customer-lifecycle.mjs +20 -3
- package/scripts/build-hosted-probe-worker.mjs +19 -4
- package/scripts/build-installer-assets.mjs +41 -21
- package/scripts/build-operator-evidence-starter.mjs +59 -1
- package/scripts/build-production-backend-env-kit.mjs +2 -0
- package/scripts/build-production-unblocker.mjs +3 -0
- package/scripts/check.mjs +17 -3
- package/scripts/collect-hosted-backend-live-evidence.mjs +49 -12
- package/scripts/install-enigma-local.mjs +18 -5
- package/scripts/release-audit.mjs +65 -109
- package/scripts/release-provenance.mjs +6 -0
- package/scripts/run-backend-readiness-smoke.mjs +112 -10
- package/scripts/scan-secrets.mjs +1 -0
- package/scripts/simulate-production-env.mjs +7 -2
- package/scripts/validate-hosted-backend-live.mjs +112 -1
- package/specs/antibody-pack-v1.schema.json +95 -0
- package/specs/antigen-envelope-v1.schema.json +81 -0
- package/specs/boundary-manifest-v1.schema.json +35 -35
- package/specs/capsule-v1.schema.json +55 -55
- package/specs/claim-boundary-manifest-v1.schema.json +22 -22
- package/specs/claim-ledger-v1.schema.json +291 -0
- package/specs/context-passport-v1.schema.json +59 -0
- package/specs/deletion-tombstone-v1.schema.json +26 -26
- package/specs/evidence-packet-v1.schema.json +177 -0
- package/specs/hosted-backend-live-evidence-v1.schema.json +72 -3
- package/specs/immune-scan-report-v1.schema.json +112 -0
- package/specs/lifecycle-receipt-log-v1.schema.json +67 -0
- package/specs/memory-atom-v1.schema.json +59 -0
- package/specs/memory-event-v1.schema.json +42 -42
- package/specs/passport-v1.schema.json +50 -50
- package/specs/proof-of-non-use-v1.schema.json +65 -0
- package/specs/quarantine-record-v1.schema.json +126 -0
- package/specs/receipt-v1.schema.json +61 -61
- package/specs/state-checkpoint-v1.schema.json +37 -37
- package/specs/trust-bundle-v1.schema.json +56 -56
- package/specs/trust-card-v1.schema.json +119 -0
- package/docs/proof-network-launch-plan.md +0 -421
- package/packages/metering/PACKAGE_CONTRACT.md +0 -20
- package/scripts/build-ai-orchestration-plan.mjs +0 -248
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"protocol": "groth16",
|
|
3
|
+
"curve": "bn128",
|
|
4
|
+
"nPublic": 6,
|
|
5
|
+
"vk_alpha_1": [
|
|
6
|
+
"20491192805390485299153009773594534940189261866228447918068658471970481763042",
|
|
7
|
+
"9383485363053290200918347156157836566562967994039712273449902621266178545958",
|
|
8
|
+
"1"
|
|
9
|
+
],
|
|
10
|
+
"vk_beta_2": [
|
|
11
|
+
[
|
|
12
|
+
"6375614351688725206403948262868962793625744043794305715222011528459656738731",
|
|
13
|
+
"4252822878758300859123897981450591353533073413197771768651442665752259397132"
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"10505242626370262277552901082094356697409835680220590971873171140371331206856",
|
|
17
|
+
"21847035105528745403288232691147584728191162732299865338377159692350059136679"
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"1",
|
|
21
|
+
"0"
|
|
22
|
+
]
|
|
23
|
+
],
|
|
24
|
+
"vk_gamma_2": [
|
|
25
|
+
[
|
|
26
|
+
"10857046999023057135944570762232829481370756359578518086990519993285655852781",
|
|
27
|
+
"11559732032986387107991004021392285783925812861821192530917403151452391805634"
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
"8495653923123431417604973247489272438418190587263600148770280649306958101930",
|
|
31
|
+
"4082367875863433681332203403145435568316851327593401208105741076214120093531"
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"1",
|
|
35
|
+
"0"
|
|
36
|
+
]
|
|
37
|
+
],
|
|
38
|
+
"vk_delta_2": [
|
|
39
|
+
[
|
|
40
|
+
"13737662410675739411863134805140287859060923769822448201927359014696163081734",
|
|
41
|
+
"4117678118637767853444917675194014084295990843761821712032859657573845168793"
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
"12440663807394144368844811397485796369005354387040694274244057858904591863934",
|
|
45
|
+
"14918784436058974714769646045917855067545813731749283109383306566509970063914"
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"1",
|
|
49
|
+
"0"
|
|
50
|
+
]
|
|
51
|
+
],
|
|
52
|
+
"vk_alphabeta_12": [
|
|
53
|
+
[
|
|
54
|
+
[
|
|
55
|
+
"2029413683389138792403550203267699914886160938906632433982220835551125967885",
|
|
56
|
+
"21072700047562757817161031222997517981543347628379360635925549008442030252106"
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
"5940354580057074848093997050200682056184807770593307860589430076672439820312",
|
|
60
|
+
"12156638873931618554171829126792193045421052652279363021382169897324752428276"
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
"7898200236362823042373859371574133993780991612861777490112507062703164551277",
|
|
64
|
+
"7074218545237549455313236346927434013100842096812539264420499035217050630853"
|
|
65
|
+
]
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
[
|
|
69
|
+
"7077479683546002997211712695946002074877511277312570035766170199895071832130",
|
|
70
|
+
"10093483419865920389913245021038182291233451549023025229112148274109565435465"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"4595479056700221319381530156280926371456704509942304414423590385166031118820",
|
|
74
|
+
"19831328484489333784475432780421641293929726139240675179672856274388269393268"
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
"11934129596455521040620786944827826205713621633706285934057045369193958244500",
|
|
78
|
+
"8037395052364110730298837004334506829870972346962140206007064471173334027475"
|
|
79
|
+
]
|
|
80
|
+
]
|
|
81
|
+
],
|
|
82
|
+
"IC": [
|
|
83
|
+
[
|
|
84
|
+
"17280374774876985846576072155775428516496713436280020899969455256740600851464",
|
|
85
|
+
"2671616274471658023769750029773332756237435115913176879115442697574865188504",
|
|
86
|
+
"1"
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
"2751614090515481590396962831401435765981832671548864424231114586290804339579",
|
|
90
|
+
"16428749235453947228504302900037063604472053005766132106401972790975458744568",
|
|
91
|
+
"1"
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
"15534383599204355668299964644425285581617198919119365038272985785250172114179",
|
|
95
|
+
"19738745792178322068371965888908382453886170122899730042053198979780669618452",
|
|
96
|
+
"1"
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
"20918951320925303999718884037532749487091705086799263428894345973067477369719",
|
|
100
|
+
"2238654040295421993050985142411549503013736162286374355578022239924997748959",
|
|
101
|
+
"1"
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"19310512165623498566554150832696933132378225334866219165202410444613582137484",
|
|
105
|
+
"19520562604893676100742722752037908641381116593594160616565283205759504663879",
|
|
106
|
+
"1"
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
"3002913514489910657253716597454484439734159929193355076313837586280075955821",
|
|
110
|
+
"11280484143192028440413145680326119197314222133146217088623894210455485551233",
|
|
111
|
+
"1"
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
"3748279575462613177944311348202437507732869101809965496229575295667816904847",
|
|
115
|
+
"1996549668722327272255704796991151399572019816051051495186051999353345441680",
|
|
116
|
+
"1"
|
|
117
|
+
]
|
|
118
|
+
]
|
|
119
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// alias-adversarial.test.mjs — adversarial-witness regression test for the
|
|
2
|
+
// FieldLessThan x+r aliasing vulnerability in circuits/action_transition.circom.
|
|
3
|
+
//
|
|
4
|
+
// THE BUG (fixed): FieldLessThan originally decomposed its operands with plain
|
|
5
|
+
// Num2Bits(254). Over Fr = BN254 scalar field (r), a 254-bit decomposition is
|
|
6
|
+
// NOT unique: any x < 2^254 - r also satisfies the bit-sum constraint as the
|
|
7
|
+
// integer x + r (since x + r ≡ x mod r and x + r < 2^254). An adversarial
|
|
8
|
+
// prover hand-crafting a witness (the compiled wasm calculator always produces
|
|
9
|
+
// canonical bits, so generated-witness tests CANNOT catch this) could encode a
|
|
10
|
+
// comparison operand as x + r and flip the IMT strict ordering
|
|
11
|
+
// predValue < nf < predNextValue — e.g. insert a nullifier at a wrong IMT
|
|
12
|
+
// position (breaking sortedness, enabling a later double-revocation of an
|
|
13
|
+
// already-spent nullifier), or pass nf < nf as nf < nf + r.
|
|
14
|
+
//
|
|
15
|
+
// Verified during development (pre-fix r1cs, 89,845 constraints): a witness
|
|
16
|
+
// tampered to read predNextValue as predNextValue + r PASSED
|
|
17
|
+
// `snarkjs wtns check` against the vulnerable R1CS. That artifact was removed
|
|
18
|
+
// in repo hygiene; the fix below is what this test guards.
|
|
19
|
+
//
|
|
20
|
+
// THE FIX: both operands now use circomlib Num2Bits_strict(), whose AliasCheck
|
|
21
|
+
// constrains the represented integer < r, killing the alias.
|
|
22
|
+
//
|
|
23
|
+
// This test:
|
|
24
|
+
// 1. builds a VALID revoke witness via TreeWitness's buildActionWitness,
|
|
25
|
+
// 2. produces the witness bin via the compiled witness_calculator
|
|
26
|
+
// (control: `snarkjs wtns check` ACCEPTS it),
|
|
27
|
+
// 3. tampers the ltLo operand encoding predValue = 0 to its alias 0 + r
|
|
28
|
+
// (bit-level, exactly what an adversarial prover controls) and asserts
|
|
29
|
+
// `snarkjs wtns check` REJECTS the tampered witness,
|
|
30
|
+
// 4. asserts the calculator canonicalizes x + r at the INPUT layer
|
|
31
|
+
// (calculateWTNSBin normalizes mod r → identical witness),
|
|
32
|
+
// 5. source guard: FieldLessThan must use Num2Bits_strict, and the circuit
|
|
33
|
+
// must contain no plain Num2Bits(254).
|
|
34
|
+
//
|
|
35
|
+
// Run: node --test cortex-v3/zk/alias-adversarial.test.mjs
|
|
36
|
+
|
|
37
|
+
import test from "node:test";
|
|
38
|
+
import assert from "node:assert/strict";
|
|
39
|
+
import { execFileSync } from "node:child_process";
|
|
40
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
41
|
+
import { createRequire } from "node:module";
|
|
42
|
+
import { tmpdir } from "node:os";
|
|
43
|
+
import { dirname, join, resolve } from "node:path";
|
|
44
|
+
import { fileURLToPath } from "node:url";
|
|
45
|
+
|
|
46
|
+
import {
|
|
47
|
+
DOMAIN_REVOCATION,
|
|
48
|
+
FIELD_R,
|
|
49
|
+
NoteTree,
|
|
50
|
+
NullifierIMT,
|
|
51
|
+
poseidon,
|
|
52
|
+
} from "./zk-tree.mjs";
|
|
53
|
+
import { buildActionWitness } from "./witness.mjs";
|
|
54
|
+
|
|
55
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
56
|
+
const PKG_ROOT = resolve(__dirname, "..");
|
|
57
|
+
const BUILD = join(PKG_ROOT, "circuits", "build");
|
|
58
|
+
const R1CS = join(BUILD, "action_transition.r1cs");
|
|
59
|
+
const SYM = join(BUILD, "action_transition.sym");
|
|
60
|
+
const WASM = join(BUILD, "action_transition_js", "action_transition.wasm");
|
|
61
|
+
const WITNESS_CALC = join(BUILD, "action_transition_js", "witness_calculator.js");
|
|
62
|
+
const CIRCUIT_SRC = join(PKG_ROOT, "circuits", "action_transition.circom");
|
|
63
|
+
|
|
64
|
+
const require = createRequire(import.meta.url);
|
|
65
|
+
|
|
66
|
+
const OWNER_KEY = 1111111111111111111111111111111111111111111111111111111111111111n;
|
|
67
|
+
const RHO = 2222222222222222222222222222222222222222222222222222222222222222n;
|
|
68
|
+
const PAYLOAD = 3333333333333333333333333333333333333333333333333333333333333333n;
|
|
69
|
+
const OWNER_KEY2 = 4444444444444444444444444444444444444444444444444444444444444444n;
|
|
70
|
+
const RHO2 = 5555555555555555555555555555555555555555555555555555555555555555n;
|
|
71
|
+
const PAYLOAD2 = 6666666666666666666666666666666666666666666666666666666666666666n;
|
|
72
|
+
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Minimal .wtns (snarkjs witness binary) reader/writer.
|
|
75
|
+
// Layout: "wtns" | u32 version | u32 nSections | sections {u32 type, u64 size,
|
|
76
|
+
// payload}; section 1 = header {u32 n8, n8 bytes prime, u32 nVars};
|
|
77
|
+
// section 2 = nVars little-endian field elements (wire 0 first).
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
function readWtns(path) {
|
|
80
|
+
const b = readFileSync(path);
|
|
81
|
+
assert.equal(b.toString("utf8", 0, 4), "wtns", "bad wtns magic");
|
|
82
|
+
const nSec = b.readUInt32LE(8);
|
|
83
|
+
let off = 12;
|
|
84
|
+
let n8 = 0;
|
|
85
|
+
let nVars = 0;
|
|
86
|
+
let dataOff = 0;
|
|
87
|
+
for (let i = 0; i < nSec; i++) {
|
|
88
|
+
const type = b.readUInt32LE(off);
|
|
89
|
+
const size = Number(b.readBigUInt64LE(off + 4));
|
|
90
|
+
off += 12;
|
|
91
|
+
if (type === 1) {
|
|
92
|
+
n8 = b.readUInt32LE(off);
|
|
93
|
+
nVars = b.readUInt32LE(off + 4 + n8);
|
|
94
|
+
}
|
|
95
|
+
if (type === 2) dataOff = off;
|
|
96
|
+
off += size;
|
|
97
|
+
}
|
|
98
|
+
const vals = [];
|
|
99
|
+
for (let i = 0; i < nVars; i++) {
|
|
100
|
+
vals.push(BigInt("0x" + Buffer.from(b.subarray(dataOff + i * n8, dataOff + (i + 1) * n8)).reverse().toString("hex")));
|
|
101
|
+
}
|
|
102
|
+
return { raw: b, n8, nVars, dataOff, vals };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function writeWtns(path, tmpl, vals) {
|
|
106
|
+
const out = Buffer.from(tmpl.raw);
|
|
107
|
+
for (let i = 0; i < vals.length; i++) {
|
|
108
|
+
const le = Buffer.from(vals[i].toString(16).padStart(tmpl.n8 * 2, "0"), "hex").reverse();
|
|
109
|
+
le.copy(out, tmpl.dataOff + i * tmpl.n8);
|
|
110
|
+
}
|
|
111
|
+
writeFileSync(path, out);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// .sym format: <labelId>,<wireIndex>,<componentId>,<name>; wireIndex -1 marks
|
|
115
|
+
// signals eliminated by constraint simplification (aliases — no wire exists).
|
|
116
|
+
function symWireMap(path) {
|
|
117
|
+
const m = new Map();
|
|
118
|
+
for (const line of readFileSync(path, "utf8").split("\n")) {
|
|
119
|
+
if (!line.trim()) continue;
|
|
120
|
+
const [, wire, , name] = line.split(",");
|
|
121
|
+
m.set(name.trim(), Number(wire));
|
|
122
|
+
}
|
|
123
|
+
return m;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** `snarkjs wtns check` → true if the witness satisfies the R1CS. */
|
|
127
|
+
function wtnsCheck(wtnsPath) {
|
|
128
|
+
try {
|
|
129
|
+
execFileSync("npx", ["snarkjs", "wtns", "check", R1CS, wtnsPath], {
|
|
130
|
+
shell: true,
|
|
131
|
+
stdio: "pipe",
|
|
132
|
+
cwd: PKG_ROOT,
|
|
133
|
+
});
|
|
134
|
+
return true;
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
test("adversarial x+r alias witness is rejected by the hardened circuit", async (t) => {
|
|
141
|
+
const tmp = mkdtempSync(join(tmpdir(), "enigma-alias-"));
|
|
142
|
+
t.after(() => rmSync(tmp, { recursive: true, force: true }));
|
|
143
|
+
|
|
144
|
+
// -- 1. valid revoke witness via TreeWitness's buildActionWitness ----------
|
|
145
|
+
const noteTree = new NoteTree();
|
|
146
|
+
const imt = new NullifierIMT();
|
|
147
|
+
buildActionWitness({ // note at index 0
|
|
148
|
+
mode: "append", noteTree, nullifierTree: imt,
|
|
149
|
+
ownerKey: OWNER_KEY2, rho: RHO2, payloadCommit: PAYLOAD2,
|
|
150
|
+
});
|
|
151
|
+
buildActionWitness({ // note at index 1
|
|
152
|
+
mode: "append", noteTree, nullifierTree: imt,
|
|
153
|
+
ownerKey: OWNER_KEY, rho: RHO, payloadCommit: PAYLOAD,
|
|
154
|
+
});
|
|
155
|
+
const input = buildActionWitness({ // first revoke → genesis predecessor
|
|
156
|
+
mode: "revoke", noteTree, nullifierTree: imt, noteIndex: 1,
|
|
157
|
+
ownerKey: OWNER_KEY, rho: RHO, payloadCommit: PAYLOAD,
|
|
158
|
+
});
|
|
159
|
+
assert.equal(input.predValue, "0", "test assumes genesis predecessor (predValue 0)");
|
|
160
|
+
assert.equal(
|
|
161
|
+
input.nullifier,
|
|
162
|
+
poseidon([DOMAIN_REVOCATION, OWNER_KEY, RHO]).toString(),
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
// -- 2. witness bin via the compiled witness_calculator --------------------
|
|
166
|
+
const buildCalc = require(WITNESS_CALC);
|
|
167
|
+
const calc = await buildCalc(readFileSync(WASM));
|
|
168
|
+
const honestBin = Buffer.from(await calc.calculateWTNSBin(input, true));
|
|
169
|
+
const honestPath = join(tmp, "honest.wtns");
|
|
170
|
+
writeFileSync(honestPath, honestBin);
|
|
171
|
+
|
|
172
|
+
// control: the honest witness satisfies the R1CS
|
|
173
|
+
assert.ok(wtnsCheck(honestPath), "control failed: honest revoke witness must pass wtns check");
|
|
174
|
+
|
|
175
|
+
// -- 3. tamper: encode ltLo operand predValue=0 as its alias 0 + r ---------
|
|
176
|
+
// ltLo checks predValue < nf. predValue is 0 (genesis predecessor); the bit
|
|
177
|
+
// decomposition of the integer r (= 0 + r, a 254-bit value) satisfies every
|
|
178
|
+
// plain-Num2Bits constraint over Fr but represents a different integer, so
|
|
179
|
+
// the comparator would evaluate r < nf instead of 0 < nf. An adversarial
|
|
180
|
+
// prover picks whichever alias makes a FALSE ordering pass.
|
|
181
|
+
const sym = symWireMap(SYM);
|
|
182
|
+
const tmpl = readWtns(honestPath);
|
|
183
|
+
const tampered = tmpl.vals.slice();
|
|
184
|
+
for (let i = 0; i < 254; i++) {
|
|
185
|
+
const name = `main.ltLo.aBits.out[${i}]`;
|
|
186
|
+
const w = sym.get(name);
|
|
187
|
+
assert.ok(w !== undefined, `sym missing ${name}`);
|
|
188
|
+
assert.notEqual(w, -1, `${name} unexpectedly eliminated by simplification`);
|
|
189
|
+
tampered[w] = (FIELD_R >> BigInt(i)) & 1n; // alias: 0 → 0 + r
|
|
190
|
+
}
|
|
191
|
+
const tamperedPath = join(tmp, "tampered.wtns");
|
|
192
|
+
writeWtns(tamperedPath, tmpl, tampered);
|
|
193
|
+
|
|
194
|
+
assert.equal(
|
|
195
|
+
wtnsCheck(tamperedPath),
|
|
196
|
+
false,
|
|
197
|
+
"VULNERABILITY: x+r aliased FieldLessThan operand was ACCEPTED — " +
|
|
198
|
+
"FieldLessThan must use Num2Bits_strict (see file header)",
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// -- 4. the calculator canonicalizes x + r at the input layer --------------
|
|
202
|
+
// Inputs are normalized mod r, so supplying predValue as 0 + r through the
|
|
203
|
+
// honest tooling yields the identical (canonical, accepted) witness — the
|
|
204
|
+
// alias is only reachable by hand-crafted witnesses, which leg 3 rejects.
|
|
205
|
+
const aliasedInput = { ...input, predValue: (0n + FIELD_R).toString() };
|
|
206
|
+
const canonBin = Buffer.from(await calc.calculateWTNSBin(aliasedInput, true));
|
|
207
|
+
assert.ok(canonBin.equals(honestBin), "calculator must normalize predValue 0+r ≡ 0");
|
|
208
|
+
const canonPath = join(tmp, "canonicalized.wtns");
|
|
209
|
+
writeFileSync(canonPath, canonBin);
|
|
210
|
+
assert.ok(wtnsCheck(canonPath), "canonicalized witness must pass wtns check");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("source guard: FieldLessThan uses Num2Bits_strict, no plain Num2Bits(254) anywhere", () => {
|
|
214
|
+
const src = readFileSync(CIRCUIT_SRC, "utf8");
|
|
215
|
+
const code = src.replace(/\/\/[^\n]*/g, ""); // strip line comments (docs may quote the pattern)
|
|
216
|
+
const m = code.match(/template FieldLessThan\(\) \{[\s\S]*?\n\}/);
|
|
217
|
+
assert.ok(m, "FieldLessThan template not found in circuit source");
|
|
218
|
+
assert.match(m[0], /Num2Bits_strict\(\)/, "FieldLessThan must use Num2Bits_strict (x+r alias guard)");
|
|
219
|
+
assert.doesNotMatch(code, /Num2Bits\(254\)/, "plain Num2Bits(254) is aliasable over Fr — forbidden");
|
|
220
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
const snarkjs = require('snarkjs');
|
|
5
|
+
|
|
6
|
+
process.once('message', async (request) => {
|
|
7
|
+
try {
|
|
8
|
+
const verified = await snarkjs.groth16.verify(
|
|
9
|
+
request.verificationKey,
|
|
10
|
+
request.publicSignals,
|
|
11
|
+
request.proof,
|
|
12
|
+
);
|
|
13
|
+
process.send({ verified }, () => process.exit(0));
|
|
14
|
+
} catch (error) {
|
|
15
|
+
process.send({ error: error.message }, () => process.exit(1));
|
|
16
|
+
}
|
|
17
|
+
});
|