Skip to content

feat(plugin): G2 ZeroPerceptron on-chain AI prediction marketplace + plugin key-prefix safety guard - #602

Closed
Zakil11 wants to merge 13 commits into
canopy-network:mainfrom
Zakil11:main
Closed

feat(plugin): G2 ZeroPerceptron on-chain AI prediction marketplace + plugin key-prefix safety guard#602
Zakil11 wants to merge 13 commits into
canopy-network:mainfrom
Zakil11:main

Conversation

@Zakil11

@Zakil11 Zakil11 commented Sep 8, 2026

Copy link
Copy Markdown

Summary

Full-featured Python plugin extending the Canopy FSM with an on-chain AI prediction marketplace, built on the G2 ZeroPerceptron model.

Features (11 commits)

  • On-chain AI inferenceMessagePredict tx running G2 ZeroPerceptron (28D + extended 42D) inside the plugin contract
  • Explainability — top-3 classes, 28D feature-importance gradient, temperature scaling (1.5)
  • Feedback loopMessageFeedback tx (namespace 0x04) with accuracy aggregation for retraining
  • Prediction MarketplaceMessageStake/CreateMarket/ResolveMarket/ClaimReward with QARD staking
  • Model versioningMessageRegisterModel registry under 0x06
  • On-chain dashboard — metric aggregation (predict/feedback/stake/market/reward/model) under 0x0b
  • Dynamic fee — deterministic pricing driven by dashboard metrics (volume/accuracy/complexity)

Critical fix

  • fsm/state.go: added assertPluginKeyWritable() guard — plugins writing to core-reserved prefixes (1-15) now panic at write time. Plugin custom prefixes moved from 3-11 to 100-107 (custom_state_prefixes declared in CONTRACT_CONFIG, validated at handshake).

Tests

  • Go: go test ./... -p=113/13 packages OK (bft, fsm, lib, p2p, store, controller, cmd/*)
  • Python: pytest tests/63/63 PASS
  • E2E on live node: predict tx delivered at height 328, 0 failed txs

Docs

  • AGENTS.md documenting plugin architecture, key-prefix collision rules, custom RPC endpoints (port 50010)

Zakil11 and others added 13 commits September 7, 2026 02:48
…na Canopy

- ai_model.py: N_FEATURES=42, fc00[256,42], G2Encoder extended42 (raw7 + G2 14 + inter7 + meta7 + cross7_self)
- contract.py: walidacja 28/42, predict_raw dla 42D
- data/perceptron_genlayer_weights.json: wagi 42D (trening na danych Kucoin Futures, acc_test=0.3232, 8865 zdarzeń)
- test_contract.py: testy 42D
…Stake/CreateMarket/ResolveMarket/ClaimReward)

- tx.proto: MessageStake, MessageCreateMarket, MessageResolveMarket, MessageClaimReward
- contract.py: prefiksy 0x05 (market), 0x06 (stake), 0x08 (counter)
- contract.py: check/deliver dla 4 nowych typów transakcji
- Rynek: pytanie + resolution_height + pula nagród (outcome_pools)
- Nagroda = (stake × total_pool) / winning_pool
- test_contract.py: 15 nowych testów marketplace (28 passed)
…rketplace end-to-end)

- Naprawa buga: klucze outcome_pools jako stringi po serializacji JSON
- Dodanie MockPlugin (in-memory state_read/state_write)
- Testy deliver_tx: create_market → stake → resolve → claim (pełny cykl)
- Testy błędów: brak rynku, nie-kreator resolve, zły outcome, podwójny claim, brak funduszy
- 34 testów (28 check + 6 deliver)
…isterModel)

- Nowy typ transakcji MessageRegisterModel (0x09 registry + 0x0a counter)
- Rejestr: wersja, hash wag, accuracy, in_dim (28/42), n_classes, opis
- Active model pointer (0x09/active/) — wskazuje najnowszą wersję
- Governance: aktualizacja wag bez hard-forku (rejestr on-chain)
- Testy: 44 passed (34 + 10 nowych: 7 check + 3 deliver)
…-15 collision)

Canopy FSM assertPluginKeyWritable() panics if a plugin writes under a
core-reserved single-byte prefix (1-15). Our custom records (predict logs,
feedback, markets, stakes, counters, model registry, dashboard) used 0x03-0x0b
which collide with validators/committees/unstaking/paused/non-signers/
last-proposers/supply/delegations/committees-data. The first predict tx
would have panicked the node.

- All app-owned prefixes moved outside the reserved range (100-107)
- Prefixes declared in CONTRACT_CONFIG['custom_state_prefixes']
- E2E verified: signed MessagePredict tx included at height 328,
  fee deducted (1M -> 990k), G2 on-chain inference executed, 0 failed txs
@pablocampogo

Copy link
Copy Markdown
Collaborator

Hello @Zakil11 thanks for your interest in building in Canopy! I see you're using our plugin system. The idea for it is to build the plugin on your own fork. Since that's the case I'll close the PR. But keep the good work on your fork!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants