rb125 commited on
Commit
03c8703
·
1 Parent(s): dc9dd70

0g chain contracts + storage + wallet + on-chain bridge

Browse files
.env.example ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copy this file to `.env` and fill in real values.
2
+ # Never commit real secrets.
3
+
4
+ # ---------------------------------------------------------------------------
5
+ # Azure (shared key for OpenAI + AI Foundry models)
6
+ # ---------------------------------------------------------------------------
7
+ AZURE_API_KEY=
8
+ AZURE_OPENAI_API_ENDPOINT=https://your-resource.cognitiveservices.azure.com/
9
+ FOUNDRY_MODELS_ENDPOINT=https://your-resource.services.ai.azure.com/openai/v1/
10
+
11
+ # ---------------------------------------------------------------------------
12
+ # AWS Bedrock (ABSK bearer token for nova-pro, claude, MiniMax, jury models)
13
+ # ---------------------------------------------------------------------------
14
+ AWS_BEARER_TOKEN_BEDROCK=
15
+
16
+ # ---------------------------------------------------------------------------
17
+ # Gemma via Modal (self-hosted, OpenAI-compatible)
18
+ # ---------------------------------------------------------------------------
19
+ GEMMA_BASE_URL=
20
+ GEMMA_API_KEY=not-needed
21
+
22
+ # ---------------------------------------------------------------------------
23
+ # Framework service endpoints (optional)
24
+ # ---------------------------------------------------------------------------
25
+ CDCT_API_URL=https://cdct-framework.vercel.app/
26
+ DDFT_API_URL=https://ddft-framework.vercel.app/
27
+ EECT_API_URL=https://eect-framework.vercel.app/
28
+
29
+ # ---------------------------------------------------------------------------
30
+ # 0G Storage
31
+ # ---------------------------------------------------------------------------
32
+ ZG_PRIVATE_KEY=
33
+ ZG_RPC_URL=https://evmrpc-testnet.0g.ai
34
+ ZG_INDEXER_RPC=https://indexer-storage-testnet-turbo.0g.ai
35
+
36
+ # ---------------------------------------------------------------------------
37
+ # Smart contract deployment / treasury wallet
38
+ # ---------------------------------------------------------------------------
39
+ PRIVATE_KEY=
40
+ CGAE_REGISTRY_ADDRESS=
41
+ CGAE_ESCROW_ADDRESS=
42
+
43
+ # ---------------------------------------------------------------------------
44
+ # Dashboard
45
+ # ---------------------------------------------------------------------------
46
+ MODAL_ENDPOINT=
.gitignore CHANGED
@@ -1,4 +1,24 @@
1
  *.pyc
2
  __pycache__/
3
  .env
4
- .venv/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  *.pyc
2
  __pycache__/
3
  .env
4
+ .venv/
5
+ .pytest_cache/
6
+
7
+ # Node
8
+ node_modules/
9
+ package-lock.json
10
+
11
+ # Hardhat
12
+ contracts/artifacts/
13
+ contracts/cache/
14
+
15
+ # Simulation results (generated)
16
+ server/results/
17
+ server/live_results/
18
+
19
+ # Next.js
20
+ dashboard-next/.next/
21
+ dashboard-next/node_modules/
22
+
23
+ # OS
24
+ .DS_Store
cgae_engine/audit.py CHANGED
@@ -471,10 +471,7 @@ class AuditOrchestrator:
471
  return cc, False
472
  except Exception:
473
  pass
474
- logger.info(
475
- f" [pre-computed audit] CDCT done for {model_name}: "
476
- f"CC={default_cc:.3f} (fallback default)"
477
- )
478
  return default_cc, True
479
 
480
  def _load_ddft_score(self, model_name: str) -> tuple[float, bool]:
@@ -488,10 +485,7 @@ class AuditOrchestrator:
488
  return er, False
489
  except Exception:
490
  pass
491
- logger.info(
492
- f" [pre-computed audit] DDFT done for {model_name}: "
493
- f"ER={default_er:.3f} (fallback default)"
494
- )
495
  return default_er, True
496
 
497
  def _load_eect_score(self, model_name: str) -> tuple[float, bool]:
@@ -505,10 +499,7 @@ class AuditOrchestrator:
505
  return as_, False
506
  except Exception:
507
  pass
508
- logger.info(
509
- f" [pre-computed audit] EECT done for {model_name}: "
510
- f"AS={default_as:.3f} (fallback default)"
511
- )
512
  return default_as, True
513
 
514
  def _load_ih_score(self, model_name: str) -> tuple[float, bool]:
@@ -521,10 +512,7 @@ class AuditOrchestrator:
521
  return ih, False
522
  except Exception:
523
  pass
524
- logger.info(
525
- f" [pre-computed audit] DDFT done for {model_name}: "
526
- f"IH={default_ih:.3f} (fallback default)"
527
- )
528
  return default_ih, True
529
 
530
  @staticmethod
 
471
  return cc, False
472
  except Exception:
473
  pass
474
+ logger.debug(f" [pre-computed audit] CDCT fallback for {model_name}: CC={default_cc:.3f}")
 
 
 
475
  return default_cc, True
476
 
477
  def _load_ddft_score(self, model_name: str) -> tuple[float, bool]:
 
485
  return er, False
486
  except Exception:
487
  pass
488
+ logger.debug(f" [pre-computed audit] DDFT fallback for {model_name}: ER={default_er:.3f}")
 
 
 
489
  return default_er, True
490
 
491
  def _load_eect_score(self, model_name: str) -> tuple[float, bool]:
 
499
  return as_, False
500
  except Exception:
501
  pass
502
+ logger.debug(f" [pre-computed audit] EECT fallback for {model_name}: AS={default_as:.3f}")
 
 
 
503
  return default_as, True
504
 
505
  def _load_ih_score(self, model_name: str) -> tuple[float, bool]:
 
512
  return ih, False
513
  except Exception:
514
  pass
515
+ logger.debug(f" [pre-computed audit] DDFT fallback for {model_name}: IH={default_ih:.3f}")
 
 
 
516
  return default_ih, True
517
 
518
  @staticmethod
cgae_engine/onchain.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CGAE On-Chain Bridge — Writes certifications to CGAERegistry on 0G Chain.
3
+
4
+ Calls CGAERegistry.certify() after each audit so the robustness vector
5
+ and 0G Storage root hash are permanently recorded on-chain.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import logging
12
+ import os
13
+ from pathlib import Path
14
+ from typing import Optional
15
+
16
+ from web3 import Web3
17
+ from eth_account import Account
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+ _CONTRACTS_DIR = Path(__file__).resolve().parent.parent / "contracts"
22
+
23
+
24
+ def _load_registry_abi() -> list:
25
+ abi_path = _CONTRACTS_DIR / "artifacts" / "src" / "CGAERegistry.sol" / "CGAERegistry.json"
26
+ if not abi_path.exists():
27
+ raise FileNotFoundError(f"Registry ABI not found at {abi_path}. Run: cd contracts && npx hardhat compile")
28
+ return json.loads(abi_path.read_text())["abi"]
29
+
30
+
31
+ def _load_deployed() -> dict:
32
+ path = _CONTRACTS_DIR / "deployed.json"
33
+ if not path.exists():
34
+ raise FileNotFoundError("contracts/deployed.json not found. Run: npm run deploy:0g")
35
+ return json.loads(path.read_text())
36
+
37
+
38
+ class OnChainBridge:
39
+ """
40
+ Bridges Python-side certifications to the on-chain CGAERegistry.
41
+
42
+ On each certify() call, sends a tx to CGAERegistry.certify() with
43
+ the robustness vector (scaled to uint16) and the 0G Storage root hash.
44
+ """
45
+
46
+ def __init__(
47
+ self,
48
+ rpc_url: Optional[str] = None,
49
+ private_key: Optional[str] = None,
50
+ registry_address: Optional[str] = None,
51
+ ):
52
+ self.rpc_url = rpc_url or os.getenv("ZG_RPC_URL", "https://evmrpc-testnet.0g.ai")
53
+ self._key = private_key or os.getenv("PRIVATE_KEY")
54
+ self.w3 = Web3(Web3.HTTPProvider(self.rpc_url))
55
+
56
+ if self._key:
57
+ key = self._key if self._key.startswith("0x") else f"0x{self._key}"
58
+ self._account = Account.from_key(key)
59
+ else:
60
+ self._account = None
61
+
62
+ # Load registry contract
63
+ if registry_address:
64
+ self._registry_addr = registry_address
65
+ else:
66
+ deployed = _load_deployed()
67
+ self._registry_addr = deployed["contracts"]["CGAERegistry"]["address"]
68
+
69
+ abi = _load_registry_abi()
70
+ self.registry = self.w3.eth.contract(
71
+ address=Web3.to_checksum_address(self._registry_addr), abi=abi
72
+ )
73
+ self._tx_log: list[dict] = []
74
+
75
+ @property
76
+ def is_live(self) -> bool:
77
+ return self._account is not None
78
+
79
+ def certify_agent(
80
+ self,
81
+ agent_address: str,
82
+ cc: float, er: float, as_: float, ih: float,
83
+ audit_type: str = "registration",
84
+ audit_hash: str = "",
85
+ ) -> Optional[str]:
86
+ """
87
+ Register (if needed) then certify an agent on-chain.
88
+
89
+ Scores are floats in [0,1], scaled to uint16 [0,10000].
90
+ Returns tx hash or None on failure.
91
+ """
92
+ if not self.is_live:
93
+ logger.info(f" [onchain] Dry run certify {agent_address[:10]}… (no key)")
94
+ return None
95
+
96
+ agent_addr = Web3.to_checksum_address(agent_address)
97
+
98
+ # Auto-register if not yet on-chain
99
+ try:
100
+ record = self.registry.functions.getAgent(agent_addr).call()
101
+ if record[4] == 0: # registrationTime == 0 means not registered
102
+ self._register_agent_onchain(agent_addr, audit_type)
103
+ except Exception:
104
+ self._register_agent_onchain(agent_addr, audit_type)
105
+
106
+ # Scale [0,1] → [0,10000]
107
+ cc_u = min(10000, int(cc * 10000))
108
+ er_u = min(10000, int(er * 10000))
109
+ as_u = min(10000, int(as_ * 10000))
110
+ ih_u = min(10000, int(ih * 10000))
111
+
112
+ try:
113
+ nonce = self.w3.eth.get_transaction_count(self._account.address)
114
+ tx = self.registry.functions.certify(
115
+ Web3.to_checksum_address(agent_address),
116
+ cc_u, er_u, as_u, ih_u,
117
+ audit_type,
118
+ audit_hash or "",
119
+ ).build_transaction({
120
+ "from": self._account.address,
121
+ "nonce": nonce,
122
+ "gas": 300_000,
123
+ "gasPrice": self.w3.eth.gas_price,
124
+ "chainId": self.w3.eth.chain_id,
125
+ })
126
+
127
+ signed = self._account.sign_transaction(tx)
128
+ tx_hash = self.w3.eth.send_raw_transaction(signed.raw_transaction)
129
+ receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)
130
+
131
+ result = {
132
+ "agent": agent_address,
133
+ "tx_hash": tx_hash.hex(),
134
+ "status": "confirmed" if receipt["status"] == 1 else "failed",
135
+ "scores": {"cc": cc, "er": er, "as": as_, "ih": ih},
136
+ "audit_hash": audit_hash,
137
+ }
138
+ self._tx_log.append(result)
139
+ logger.info(f" [onchain] Certified {agent_address[:10]}… tx={tx_hash.hex()[:16]}…")
140
+ return tx_hash.hex()
141
+
142
+ except Exception as e:
143
+ logger.error(f" [onchain] Certify failed for {agent_address[:10]}…: {e}")
144
+ self._tx_log.append({"agent": agent_address, "error": str(e)})
145
+ return None
146
+
147
+ @property
148
+ def tx_log(self) -> list[dict]:
149
+ return list(self._tx_log)
150
+
151
+ def _register_agent_onchain(self, agent_addr: str, model_name: str = "cgae-agent"):
152
+ """Register an agent on-chain via registerAgent()."""
153
+ try:
154
+ arch_hash = Web3.keccak(text=model_name)[:16] # first 16 bytes of keccak(model_name)
155
+ nonce = self.w3.eth.get_transaction_count(self._account.address)
156
+ tx = self.registry.functions.registerAgent(
157
+ agent_addr, arch_hash, model_name
158
+ ).build_transaction({
159
+ "from": self._account.address,
160
+ "nonce": nonce,
161
+ "gas": 200_000,
162
+ "gasPrice": self.w3.eth.gas_price,
163
+ "chainId": self.w3.eth.chain_id,
164
+ })
165
+ signed = self._account.sign_transaction(tx)
166
+ tx_hash = self.w3.eth.send_raw_transaction(signed.raw_transaction)
167
+ self.w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)
168
+ logger.info(f" [onchain] Registered {agent_addr[:10]}… tx={tx_hash.hex()[:16]}…")
169
+ except Exception as e:
170
+ logger.warning(f" [onchain] Register failed for {agent_addr[:10]}…: {e}")
cgae_engine/wallet.py ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CGAE Wallet Manager — Real ETH wallet integration for agents.
3
+
4
+ Each agent gets a unique Ethereum keypair on registration.
5
+ A treasury wallet funds agents and disburses ETH on successful contract completion.
6
+
7
+ Usage:
8
+ from cgae_engine.wallet import WalletManager
9
+
10
+ wm = WalletManager(rpc_url="https://evmrpc-testnet.0g.ai",
11
+ treasury_private_key=os.getenv("PRIVATE_KEY"))
12
+ wallet = wm.create_agent_wallet("agent_abc123")
13
+ tx = wm.disburse(wallet.address, amount_wei=10**15) # 0.001 ETH
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import logging
20
+ import os
21
+ from dataclasses import dataclass, field
22
+ from pathlib import Path
23
+ from typing import Optional
24
+
25
+ from eth_account import Account
26
+ from web3 import Web3
27
+
28
+ logger = logging.getLogger(__name__)
29
+
30
+
31
+ @dataclass
32
+ class AgentWallet:
33
+ """An agent's Ethereum wallet."""
34
+ agent_id: str
35
+ address: str
36
+ private_key: str # hex with 0x prefix
37
+
38
+ def to_dict(self, redact_key: bool = True) -> dict:
39
+ return {
40
+ "agent_id": self.agent_id,
41
+ "address": self.address,
42
+ "private_key": self.private_key[:10] + "..." if redact_key else self.private_key,
43
+ }
44
+
45
+
46
+ class WalletManager:
47
+ """
48
+ Manages ETH wallets for CGAE agents.
49
+
50
+ - Creates a unique keypair per agent
51
+ - Sends real ETH from a treasury wallet on contract settlement
52
+ - Tracks all disbursements for audit trail
53
+ """
54
+
55
+ def __init__(
56
+ self,
57
+ rpc_url: Optional[str] = None,
58
+ treasury_private_key: Optional[str] = None,
59
+ dry_run: bool = False,
60
+ ):
61
+ self.rpc_url = rpc_url or os.getenv("ZG_RPC_URL", "https://evmrpc-testnet.0g.ai")
62
+ self._treasury_key = treasury_private_key or os.getenv("PRIVATE_KEY")
63
+ self.dry_run = dry_run
64
+
65
+ self.w3 = Web3(Web3.HTTPProvider(self.rpc_url))
66
+ self._wallets: dict[str, AgentWallet] = {} # agent_id -> wallet
67
+ self._disbursements: list[dict] = []
68
+
69
+ if self._treasury_key:
70
+ key = self._treasury_key if self._treasury_key.startswith("0x") else f"0x{self._treasury_key}"
71
+ self._treasury_account = Account.from_key(key)
72
+ self.treasury_address = self._treasury_account.address
73
+ else:
74
+ self._treasury_account = None
75
+ self.treasury_address = None
76
+
77
+ @property
78
+ def is_live(self) -> bool:
79
+ """True if we can send real transactions."""
80
+ return self._treasury_account is not None and not self.dry_run
81
+
82
+ def create_agent_wallet(self, agent_id: str) -> AgentWallet:
83
+ """Generate a new ETH keypair for an agent."""
84
+ if agent_id in self._wallets:
85
+ return self._wallets[agent_id]
86
+
87
+ acct = Account.create()
88
+ wallet = AgentWallet(
89
+ agent_id=agent_id,
90
+ address=acct.address,
91
+ private_key=acct.key.hex() if isinstance(acct.key, bytes) else acct.key,
92
+ )
93
+ self._wallets[agent_id] = wallet
94
+ logger.info(f" [wallet] Created wallet for {agent_id}: {wallet.address}")
95
+ return wallet
96
+
97
+ def get_wallet(self, agent_id: str) -> Optional[AgentWallet]:
98
+ return self._wallets.get(agent_id)
99
+
100
+ def get_balance(self, address: str) -> float:
101
+ """Get balance in ETH."""
102
+ try:
103
+ wei = self.w3.eth.get_balance(Web3.to_checksum_address(address))
104
+ return float(Web3.from_wei(wei, "ether"))
105
+ except Exception as e:
106
+ logger.warning(f" [wallet] Balance check failed for {address}: {e}")
107
+ return 0.0
108
+
109
+ def get_treasury_balance(self) -> float:
110
+ if not self.treasury_address:
111
+ return 0.0
112
+ return self.get_balance(self.treasury_address)
113
+
114
+ def disburse(self, to_address: str, amount_eth: float, reason: str = "") -> Optional[dict]:
115
+ """
116
+ Send ETH from treasury to an agent wallet.
117
+ Returns tx receipt dict or None if dry_run / failed.
118
+ """
119
+ amount_wei = Web3.to_wei(amount_eth, "ether")
120
+
121
+ record = {
122
+ "to": to_address,
123
+ "amount_eth": amount_eth,
124
+ "reason": reason,
125
+ "tx_hash": None,
126
+ "status": "pending",
127
+ }
128
+
129
+ if not self.is_live:
130
+ record["status"] = "dry_run"
131
+ self._disbursements.append(record)
132
+ logger.info(f" [wallet] DRY RUN disburse {amount_eth:.6f} ETH → {to_address} ({reason})")
133
+ return record
134
+
135
+ try:
136
+ nonce = self.w3.eth.get_transaction_count(self.treasury_address)
137
+ tx = {
138
+ "from": self.treasury_address,
139
+ "to": Web3.to_checksum_address(to_address),
140
+ "value": amount_wei,
141
+ "gas": 21000,
142
+ "gasPrice": self.w3.eth.gas_price,
143
+ "nonce": nonce,
144
+ "chainId": self.w3.eth.chain_id,
145
+ }
146
+ signed = self._treasury_account.sign_transaction(tx)
147
+ tx_hash = self.w3.eth.send_raw_transaction(signed.raw_transaction)
148
+ receipt = self.w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)
149
+
150
+ record["tx_hash"] = tx_hash.hex()
151
+ record["status"] = "confirmed" if receipt["status"] == 1 else "failed"
152
+ self._disbursements.append(record)
153
+
154
+ logger.info(
155
+ f" [wallet] Disbursed {amount_eth:.6f} ETH → {to_address} "
156
+ f"(tx: {tx_hash.hex()[:16]}… status: {record['status']})"
157
+ )
158
+ return record
159
+
160
+ except Exception as e:
161
+ record["status"] = f"error: {e}"
162
+ self._disbursements.append(record)
163
+ logger.error(f" [wallet] Disburse failed: {e}")
164
+ return record
165
+
166
+ def fund_agent(self, agent_id: str, amount_eth: float) -> Optional[dict]:
167
+ """Convenience: disburse ETH to an agent by agent_id."""
168
+ wallet = self._wallets.get(agent_id)
169
+ if not wallet:
170
+ logger.warning(f" [wallet] No wallet for {agent_id}")
171
+ return None
172
+ return self.disburse(wallet.address, amount_eth, reason=f"fund:{agent_id}")
173
+
174
+ def disburse_reward(self, agent_id: str, amount_eth: float, contract_id: str = "") -> Optional[dict]:
175
+ """Disburse contract reward to agent."""
176
+ wallet = self._wallets.get(agent_id)
177
+ if not wallet:
178
+ return None
179
+ return self.disburse(wallet.address, amount_eth, reason=f"reward:{contract_id}")
180
+
181
+ @property
182
+ def disbursements(self) -> list[dict]:
183
+ return list(self._disbursements)
184
+
185
+ def summary(self) -> dict:
186
+ total_disbursed = sum(d["amount_eth"] for d in self._disbursements if d["status"] in ("confirmed", "dry_run"))
187
+ return {
188
+ "treasury_address": self.treasury_address,
189
+ "treasury_balance_eth": self.get_treasury_balance() if self.is_live else None,
190
+ "agents_with_wallets": len(self._wallets),
191
+ "total_disbursements": len(self._disbursements),
192
+ "total_eth_disbursed": total_disbursed,
193
+ "is_live": self.is_live,
194
+ "rpc_url": self.rpc_url,
195
+ }
196
+
197
+ def export_wallets(self, path: str, redact_keys: bool = True):
198
+ """Export wallet mapping to JSON."""
199
+ data = {aid: w.to_dict(redact_key=redact_keys) for aid, w in self._wallets.items()}
200
+ Path(path).write_text(json.dumps(data, indent=2))
contracts/deployed.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "network": "zgTestnet",
3
+ "chainId": 16602,
4
+ "deployedAt": "2026-04-25T20:23:43.280Z",
5
+ "deployer": "0xCE2de05Cd27DBCFe07b9d7862aa69301991c8592",
6
+ "contracts": {
7
+ "CGAERegistry": {
8
+ "address": "0xc4Ff2BC9855483eE3806eE08112cdC30dBf6b27A",
9
+ "deployTx": "0x37ef76d5b40ed9fa6896c28df7e21a7c6271057ab77c44ef201edd0d8b85d271"
10
+ },
11
+ "CGAEEscrow": {
12
+ "address": "0xA236106DE28FE9480509e06d1750dcfA4474bcfB",
13
+ "deployTx": "0xb8cc59fb3cd624727e61314c1dc5fb1b70a6a868101378ab5b2456608bc6776d"
14
+ }
15
+ },
16
+ "rpc": "https://evmrpc-testnet.0g.ai",
17
+ "explorer": "https://chainscan-galileo.0g.ai",
18
+ "storage": {
19
+ "indexer": "https://indexer-storage-testnet-turbo.0g.ai",
20
+ "scan": "https://storagescan-galileo.0g.ai"
21
+ }
22
+ }
contracts/hardhat.config.js ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ require("@nomicfoundation/hardhat-toolbox");
2
+
3
+ /**
4
+ * Hardhat configuration for CGAE smart contracts.
5
+ *
6
+ * Targets:
7
+ * zgTestnet — 0G Chain Testnet (EVM-compatible)
8
+ * localhost — Local Hardhat node for development
9
+ *
10
+ * Required env vars for 0G Testnet deployment:
11
+ * PRIVATE_KEY — hex private key (no 0x prefix) of the deployer wallet
12
+ *
13
+ * Testnet resources:
14
+ * Token Faucet: https://faucet.0g.ai
15
+ * Explorer: https://chainscan-galileo.0g.ai
16
+ * EVM RPC: https://evmrpc-testnet.0g.ai
17
+ *
18
+ * Usage:
19
+ * cd contracts
20
+ * npm install
21
+ * export PRIVATE_KEY=<your_hex_key>
22
+ * npm run deploy:0g
23
+ */
24
+
25
+ const PRIVATE_KEY = process.env.PRIVATE_KEY ||
26
+ // Fallback zero key for compilation/testing only — never deploy with this
27
+ "0000000000000000000000000000000000000000000000000000000000000001";
28
+
29
+ /** @type import('hardhat/config').HardhatUserConfig */
30
+ module.exports = {
31
+ solidity: {
32
+ version: "0.8.20",
33
+ settings: {
34
+ optimizer: {
35
+ enabled: true,
36
+ runs: 200,
37
+ },
38
+ viaIR: true,
39
+ },
40
+ },
41
+
42
+ networks: {
43
+ // 0G Chain Testnet (EVM-compatible)
44
+ zgTestnet: {
45
+ url: process.env.ZG_RPC_URL || "https://evmrpc-testnet.0g.ai",
46
+ chainId: 16602,
47
+ accounts: [`0x${PRIVATE_KEY}`],
48
+ gas: 10_000_000,
49
+ gasPrice: 2_500_000_000,
50
+ timeout: 120_000,
51
+ },
52
+
53
+ // Local development
54
+ localhost: {
55
+ url: "http://127.0.0.1:8545",
56
+ chainId: 31337,
57
+ },
58
+ },
59
+
60
+ paths: {
61
+ sources: "./src",
62
+ artifacts: "./artifacts",
63
+ cache: "./cache",
64
+ },
65
+ };
contracts/package.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "cgae-contracts",
3
+ "version": "2.0.0",
4
+ "description": "CGAE smart contracts for 0G Chain",
5
+ "private": true,
6
+ "scripts": {
7
+ "compile": "npx hardhat compile",
8
+ "deploy:0g": "npx hardhat run scripts/deploy.js --network zgTestnet",
9
+ "deploy:local": "npx hardhat run scripts/deploy.js --network localhost",
10
+ "test": "npx hardhat test"
11
+ },
12
+ "devDependencies": {
13
+ "@nomicfoundation/hardhat-toolbox": "^5.0.0",
14
+ "hardhat": "^2.28.6"
15
+ },
16
+ "dependencies": {
17
+ "ethers": "^6.0.0"
18
+ }
19
+ }
contracts/scripts/deploy.js ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * CGAE Deployment Script — 0G Chain Testnet
3
+ * ==========================================
4
+ * Deploys CGAERegistry and CGAEEscrow to 0G Chain and writes
5
+ * the resulting contract addresses to deployed.json.
6
+ *
7
+ * Usage:
8
+ * cd contracts
9
+ * npm install
10
+ * export PRIVATE_KEY=<hex_private_key_no_0x>
11
+ * npm run deploy:0g
12
+ */
13
+
14
+ const { ethers } = require("hardhat");
15
+ const fs = require("fs");
16
+ const path = require("path");
17
+
18
+ async function main() {
19
+ const [deployer] = await ethers.getSigners();
20
+ const network = await ethers.provider.getNetwork();
21
+ const chainId = Number(network.chainId);
22
+
23
+ console.log("=".repeat(60));
24
+ console.log("CGAE Contract Deployment — 0G Chain");
25
+ console.log("=".repeat(60));
26
+ console.log(`Network: ${network.name} (chain ${chainId})`);
27
+ console.log(`Deployer: ${deployer.address}`);
28
+
29
+ const balance = await ethers.provider.getBalance(deployer.address);
30
+ console.log(`Balance: ${ethers.formatEther(balance)} A0GI\n`);
31
+
32
+ if (balance === 0n) {
33
+ console.error("ERROR: Deployer wallet has 0 tokens.");
34
+ console.error("Get testnet tokens from: https://faucet.0g.ai");
35
+ process.exit(1);
36
+ }
37
+
38
+ // Deploy CGAERegistry
39
+ console.log("Deploying CGAERegistry...");
40
+ const RegistryFactory = await ethers.getContractFactory("CGAERegistry");
41
+ const registry = await RegistryFactory.deploy();
42
+ await registry.waitForDeployment();
43
+ const registryAddress = await registry.getAddress();
44
+ console.log(` CGAERegistry deployed to: ${registryAddress}`);
45
+
46
+ // Deploy CGAEEscrow
47
+ console.log("Deploying CGAEEscrow...");
48
+ const EscrowFactory = await ethers.getContractFactory("CGAEEscrow");
49
+ const escrow = await EscrowFactory.deploy(registryAddress);
50
+ await escrow.waitForDeployment();
51
+ const escrowAddress = await escrow.getAddress();
52
+ console.log(` CGAEEscrow deployed to: ${escrowAddress}`);
53
+
54
+ // Authorize escrow as auditor
55
+ console.log("Authorizing CGAEEscrow as auditor in CGAERegistry...");
56
+ const authTx = await registry.authorizeAuditor(escrowAddress);
57
+ await authTx.wait();
58
+ console.log(` Authorized (tx: ${authTx.hash})`);
59
+
60
+ // Write deployment manifest
61
+ const explorer = chainId === 16602
62
+ ? "https://chainscan-galileo.0g.ai"
63
+ : "http://localhost";
64
+
65
+ const manifest = {
66
+ network: network.name,
67
+ chainId,
68
+ deployedAt: new Date().toISOString(),
69
+ deployer: deployer.address,
70
+ contracts: {
71
+ CGAERegistry: {
72
+ address: registryAddress,
73
+ deployTx: registry.deploymentTransaction()?.hash || null,
74
+ },
75
+ CGAEEscrow: {
76
+ address: escrowAddress,
77
+ deployTx: escrow.deploymentTransaction()?.hash || null,
78
+ },
79
+ },
80
+ rpc: process.env.ZG_RPC_URL || "https://evmrpc-testnet.0g.ai",
81
+ explorer,
82
+ storage: {
83
+ indexer: "https://indexer-storage-testnet-turbo.0g.ai",
84
+ scan: "https://storagescan-galileo.0g.ai",
85
+ },
86
+ };
87
+
88
+ const deployedPath = path.join(__dirname, "..", "deployed.json");
89
+ fs.writeFileSync(deployedPath, JSON.stringify(manifest, null, 2));
90
+ console.log(`\nDeployment manifest written to: deployed.json`);
91
+
92
+ console.log("\n" + "=".repeat(60));
93
+ console.log("Deployment complete!");
94
+ console.log("=".repeat(60));
95
+ console.log(`CGAERegistry : ${explorer}/address/${registryAddress}`);
96
+ console.log(`CGAEEscrow : ${explorer}/address/${escrowAddress}`);
97
+ console.log("\nNext steps:");
98
+ console.log(` 1. CGAE_REGISTRY_ADDRESS=${registryAddress}`);
99
+ console.log(` CGAE_ESCROW_ADDRESS=${escrowAddress}`);
100
+ console.log(" 2. python -m server.live_runner");
101
+ console.log("=".repeat(60));
102
+ }
103
+
104
+ main()
105
+ .then(() => process.exit(0))
106
+ .catch((err) => {
107
+ console.error("Deployment failed:", err);
108
+ process.exit(1);
109
+ });
contracts/src/CGAEEscrow.sol ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.20;
3
+
4
+ import "./CGAERegistry.sol";
5
+
6
+ /**
7
+ * @title CGAEEscrow
8
+ * @notice Contract management and escrow for the CGAE economy.
9
+ * Implements tier-gated contract assignment with budget ceiling enforcement
10
+ * (Theorem 1: Bounded Economic Exposure).
11
+ *
12
+ * @dev All economic activity is mediated through formally specified contracts.
13
+ * Rewards are escrowed until verification. Penalties are enforced on failure.
14
+ */
15
+ contract CGAEEscrow {
16
+
17
+ // -----------------------------------------------------------------------
18
+ // Types
19
+ // -----------------------------------------------------------------------
20
+
21
+ enum ContractStatus {
22
+ Open,
23
+ Assigned,
24
+ Completed,
25
+ Failed,
26
+ Expired,
27
+ Cancelled
28
+ }
29
+
30
+ struct EconomicContract {
31
+ bytes32 contractId;
32
+ address issuer;
33
+ address assignedAgent;
34
+ string objective;
35
+ bytes32 constraintsHash; // Hash of machine-verifiable constraint set (Phi)
36
+ string verifierSpecHash; // 0G Storage hash or pointer to verifier specification
37
+ uint8 minTier;
38
+ uint256 reward;
39
+ uint256 penalty;
40
+ uint64 deadline;
41
+ uint64 createdAt;
42
+ ContractStatus status;
43
+ string domain;
44
+ }
45
+
46
+ // -----------------------------------------------------------------------
47
+ // State
48
+ // -----------------------------------------------------------------------
49
+
50
+ CGAERegistry public registry;
51
+
52
+ mapping(bytes32 => EconomicContract) public contracts;
53
+ bytes32[] public contractIds;
54
+
55
+ // Agent -> total active penalty exposure
56
+ mapping(address => uint256) public activeExposure;
57
+
58
+ // Economic accounting
59
+ uint256 public totalRewardsPaid;
60
+ uint256 public totalPenaltiesCollected;
61
+ uint256 public totalEscrowed;
62
+
63
+ address public admin;
64
+
65
+ // -----------------------------------------------------------------------
66
+ // Events
67
+ // -----------------------------------------------------------------------
68
+
69
+ event ContractCreated(bytes32 indexed contractId, uint8 minTier, uint256 reward, string domain);
70
+ event ContractAssigned(bytes32 indexed contractId, address indexed agent);
71
+ event ContractCompleted(bytes32 indexed contractId, address indexed agent, uint256 reward);
72
+ event ContractFailed(bytes32 indexed contractId, address indexed agent, uint256 penalty);
73
+ event ContractExpired(bytes32 indexed contractId);
74
+
75
+ // -----------------------------------------------------------------------
76
+ // Constructor
77
+ // -----------------------------------------------------------------------
78
+
79
+ constructor(address _registry) {
80
+ registry = CGAERegistry(_registry);
81
+ admin = msg.sender;
82
+ }
83
+
84
+ // -----------------------------------------------------------------------
85
+ // Contract Lifecycle
86
+ // -----------------------------------------------------------------------
87
+
88
+ /**
89
+ * @notice Create a new contract. Issuer deposits reward as escrow.
90
+ */
91
+ function createContract(
92
+ string calldata objective,
93
+ bytes32 constraintsHash,
94
+ string calldata verifierSpecHash,
95
+ uint8 minTier,
96
+ uint256 penalty,
97
+ uint64 deadline,
98
+ string calldata domain
99
+ ) external payable {
100
+ require(msg.value > 0, "Must escrow reward");
101
+ require(minTier > 0 && minTier <= 5, "Invalid tier");
102
+ require(deadline > block.timestamp, "Deadline must be in future");
103
+ require(constraintsHash != bytes32(0), "Missing constraints hash");
104
+ require(bytes(verifierSpecHash).length > 0, "Missing verifier spec");
105
+
106
+ bytes32 contractId = keccak256(abi.encodePacked(
107
+ msg.sender, block.timestamp, objective, contractIds.length
108
+ ));
109
+
110
+ contracts[contractId] = EconomicContract({
111
+ contractId: contractId,
112
+ issuer: msg.sender,
113
+ assignedAgent: address(0),
114
+ objective: objective,
115
+ constraintsHash: constraintsHash,
116
+ verifierSpecHash: verifierSpecHash,
117
+ minTier: minTier,
118
+ reward: msg.value,
119
+ penalty: penalty,
120
+ deadline: deadline,
121
+ createdAt: uint64(block.timestamp),
122
+ status: ContractStatus.Open,
123
+ domain: domain
124
+ });
125
+
126
+ contractIds.push(contractId);
127
+ totalEscrowed += msg.value;
128
+
129
+ emit ContractCreated(contractId, minTier, msg.value, domain);
130
+ }
131
+
132
+ /**
133
+ * @notice Agent accepts a contract. Enforces:
134
+ * 1. Agent tier >= min_tier
135
+ * 2. Agent exposure + penalty <= budget ceiling (Theorem 1)
136
+ */
137
+ function acceptContract(bytes32 contractId) external payable {
138
+ EconomicContract storage c = contracts[contractId];
139
+ require(c.status == ContractStatus.Open, "Not open");
140
+ require(block.timestamp < c.deadline, "Past deadline");
141
+
142
+ // Tier check
143
+ CGAERegistry.AgentRecord memory agent = registry.getAgent(msg.sender);
144
+ require(agent.active, "Agent not active");
145
+ require(agent.currentTier >= c.minTier, "Tier too low");
146
+
147
+ // Budget ceiling check (Theorem 1: Bounded Economic Exposure)
148
+ uint256 ceiling = registry.getBudgetCeiling(agent.currentTier);
149
+ require(
150
+ activeExposure[msg.sender] + c.penalty <= ceiling,
151
+ "Would exceed budget ceiling"
152
+ );
153
+
154
+ // Agent must deposit penalty as collateral
155
+ require(msg.value >= c.penalty, "Insufficient penalty collateral");
156
+
157
+ c.assignedAgent = msg.sender;
158
+ c.status = ContractStatus.Assigned;
159
+ activeExposure[msg.sender] += c.penalty;
160
+
161
+ emit ContractAssigned(contractId, msg.sender);
162
+ }
163
+
164
+ /**
165
+ * @notice Mark a contract as completed. Called by admin/verifier after
166
+ * output verification. Releases reward to agent, returns collateral.
167
+ */
168
+ function completeContract(bytes32 contractId) external {
169
+ require(msg.sender == admin, "Only admin/verifier");
170
+ EconomicContract storage c = contracts[contractId];
171
+ require(c.status == ContractStatus.Assigned, "Not assigned");
172
+
173
+ c.status = ContractStatus.Completed;
174
+
175
+ // Release exposure
176
+ activeExposure[c.assignedAgent] -= c.penalty;
177
+
178
+ // Pay reward to agent
179
+ uint256 reward = c.reward;
180
+ totalEscrowed -= reward;
181
+ totalRewardsPaid += reward;
182
+
183
+ // Return penalty collateral + pay reward
184
+ uint256 payout = reward + c.penalty;
185
+ payable(c.assignedAgent).transfer(payout);
186
+
187
+ // Record on registry
188
+ registry.recordContractOutcome(c.assignedAgent, true, reward);
189
+
190
+ emit ContractCompleted(contractId, c.assignedAgent, reward);
191
+ }
192
+
193
+ /**
194
+ * @notice Mark a contract as failed. Penalty is forfeited.
195
+ */
196
+ function failContract(bytes32 contractId) external {
197
+ require(msg.sender == admin, "Only admin/verifier");
198
+ EconomicContract storage c = contracts[contractId];
199
+ require(c.status == ContractStatus.Assigned, "Not assigned");
200
+
201
+ c.status = ContractStatus.Failed;
202
+
203
+ // Release exposure
204
+ activeExposure[c.assignedAgent] -= c.penalty;
205
+
206
+ // Forfeit penalty collateral
207
+ totalPenaltiesCollected += c.penalty;
208
+
209
+ // Return escrowed reward to issuer
210
+ totalEscrowed -= c.reward;
211
+ payable(c.issuer).transfer(c.reward);
212
+
213
+ // Record on registry
214
+ registry.recordContractOutcome(c.assignedAgent, false, c.penalty);
215
+
216
+ emit ContractFailed(contractId, c.assignedAgent, c.penalty);
217
+ }
218
+
219
+ /**
220
+ * @notice Expire contracts past deadline. Anyone can call this.
221
+ */
222
+ function expireContract(bytes32 contractId) external {
223
+ EconomicContract storage c = contracts[contractId];
224
+ require(c.status == ContractStatus.Open, "Not open");
225
+ require(block.timestamp >= c.deadline, "Not expired yet");
226
+
227
+ c.status = ContractStatus.Expired;
228
+ totalEscrowed -= c.reward;
229
+ payable(c.issuer).transfer(c.reward);
230
+
231
+ emit ContractExpired(contractId);
232
+ }
233
+
234
+ // -----------------------------------------------------------------------
235
+ // Views
236
+ // -----------------------------------------------------------------------
237
+
238
+ function getContract(bytes32 contractId) external view returns (EconomicContract memory) {
239
+ return contracts[contractId];
240
+ }
241
+
242
+ function getContractCount() external view returns (uint256) {
243
+ return contractIds.length;
244
+ }
245
+
246
+ function getExposure(address agent) external view returns (uint256) {
247
+ return activeExposure[agent];
248
+ }
249
+
250
+ function getEconomicsSummary() external view returns (
251
+ uint256 _totalRewards,
252
+ uint256 _totalPenalties,
253
+ uint256 _totalEscrowed,
254
+ uint256 _contractCount
255
+ ) {
256
+ return (totalRewardsPaid, totalPenaltiesCollected, totalEscrowed, contractIds.length);
257
+ }
258
+
259
+ // -----------------------------------------------------------------------
260
+ // Admin
261
+ // -----------------------------------------------------------------------
262
+
263
+ function updateAdmin(address newAdmin) external {
264
+ require(msg.sender == admin, "Only admin");
265
+ admin = newAdmin;
266
+ }
267
+
268
+ receive() external payable {}
269
+ }
contracts/src/CGAERegistry.sol ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.20;
3
+
4
+ /**
5
+ * @title CGAERegistry
6
+ * @notice Agent Identity and Registration for the Comprehension-Gated Agent Economy.
7
+ * Implements Definition 5 from cgae.tex: Reg(A) = (id_A, h(arch), prov, R_0, t_reg)
8
+ *
9
+ * @dev Deployed on 0G Chain (or Mainnet). Agents register with an architecture
10
+ * hash and receive robustness certifications from authorized auditors.
11
+ */
12
+ contract CGAERegistry {
13
+
14
+ // -----------------------------------------------------------------------
15
+ // Types
16
+ // -----------------------------------------------------------------------
17
+
18
+ struct RobustnessVector {
19
+ uint16 cc; // Constraint Compliance [0, 10000] = [0.0, 1.0] scaled by 10000
20
+ uint16 er; // Epistemic Robustness
21
+ uint16 as_; // Behavioral Alignment
22
+ uint16 ih; // Intrinsic Hallucination integrity
23
+ }
24
+
25
+ struct Certification {
26
+ RobustnessVector robustness;
27
+ uint8 tier; // 0-5
28
+ uint64 timestamp;
29
+ string auditType; // "registration", "upgrade", "spot", "decay"
30
+ string auditHash; // 0G Storage Merkle root hash of the audit JSON
31
+ }
32
+
33
+ struct AgentRecord {
34
+ address owner; // Agent's wallet address
35
+ bytes16 architectureHash; // h(arch)
36
+ string modelName;
37
+ uint8 currentTier;
38
+ uint64 registrationTime;
39
+ uint64 lastAuditTime;
40
+ bool active;
41
+ uint256 totalEarned;
42
+ uint256 totalPenalties;
43
+ uint32 contractsCompleted;
44
+ uint32 contractsFailed;
45
+ }
46
+
47
+ // -----------------------------------------------------------------------
48
+ // State
49
+ // -----------------------------------------------------------------------
50
+
51
+ mapping(address => AgentRecord) public agents;
52
+ mapping(address => Certification) public currentCertifications;
53
+ mapping(address => Certification[]) public certificationHistory;
54
+ address[] public agentList;
55
+
56
+ address public admin;
57
+ mapping(address => bool) public authorizedAuditors;
58
+
59
+ // Tier thresholds (scaled by 10000). Index = tier number.
60
+ uint16[6] public ccThresholds = [0, 3000, 5000, 6500, 8000, 9000];
61
+ uint16[6] public erThresholds = [0, 3000, 5000, 6500, 8000, 9000];
62
+ uint16[6] public asThresholds = [0, 2500, 4500, 6000, 7500, 8500];
63
+ uint16 public ihThreshold = 5000; // IHT trigger threshold
64
+
65
+ // Budget ceilings per tier (in wei). Indexed by tier.
66
+ uint256[6] public budgetCeilings;
67
+
68
+ // -----------------------------------------------------------------------
69
+ // Events
70
+ // -----------------------------------------------------------------------
71
+
72
+ event AgentRegistered(address indexed agent, string modelName, bytes16 architectureHash);
73
+ event AgentCertified(address indexed agent, uint8 tier, string auditType, string auditHash);
74
+ event AgentDemoted(address indexed agent, uint8 oldTier, uint8 newTier, string reason);
75
+ event AgentDeactivated(address indexed agent, string reason);
76
+ event AuditorAuthorized(address indexed auditor);
77
+ event AuditorRevoked(address indexed auditor);
78
+ event ThresholdsUpdated();
79
+
80
+ // -----------------------------------------------------------------------
81
+ // Modifiers
82
+ // -----------------------------------------------------------------------
83
+
84
+ modifier onlyAdmin() {
85
+ require(msg.sender == admin, "Only admin");
86
+ _;
87
+ }
88
+
89
+ modifier onlyAuditor() {
90
+ require(authorizedAuditors[msg.sender], "Not an authorized auditor");
91
+ _;
92
+ }
93
+
94
+ modifier agentExists(address agent) {
95
+ require(agents[agent].registrationTime > 0, "Agent not registered");
96
+ _;
97
+ }
98
+
99
+ // -----------------------------------------------------------------------
100
+ // Constructor
101
+ // -----------------------------------------------------------------------
102
+
103
+ constructor() {
104
+ admin = msg.sender;
105
+ authorizedAuditors[msg.sender] = true;
106
+
107
+ // Default budget ceilings (in wei: 1 ETH = 1e18)
108
+ budgetCeilings[0] = 0;
109
+ budgetCeilings[1] = 0.01 ether;
110
+ budgetCeilings[2] = 0.1 ether;
111
+ budgetCeilings[3] = 1 ether;
112
+ budgetCeilings[4] = 10 ether;
113
+ budgetCeilings[5] = 100 ether;
114
+ }
115
+
116
+ // -----------------------------------------------------------------------
117
+ // Registration
118
+ // -----------------------------------------------------------------------
119
+
120
+ /**
121
+ * @notice Register a new agent in the CGAE economy.
122
+ * @param architectureHash Hash of model architecture/weights
123
+ * @param modelName Human-readable model identifier
124
+ */
125
+ function register(bytes16 architectureHash, string calldata modelName) external {
126
+ require(agents[msg.sender].registrationTime == 0, "Already registered");
127
+
128
+ agents[msg.sender] = AgentRecord({
129
+ owner: msg.sender,
130
+ architectureHash: architectureHash,
131
+ modelName: modelName,
132
+ currentTier: 0,
133
+ registrationTime: uint64(block.timestamp),
134
+ lastAuditTime: 0,
135
+ active: false,
136
+ totalEarned: 0,
137
+ totalPenalties: 0,
138
+ contractsCompleted: 0,
139
+ contractsFailed: 0
140
+ });
141
+
142
+ agentList.push(msg.sender);
143
+ emit AgentRegistered(msg.sender, modelName, architectureHash);
144
+ }
145
+
146
+ /**
147
+ * @notice Register an agent on behalf of its wallet address (auditor-only).
148
+ */
149
+ function registerAgent(address agent, bytes16 architectureHash, string calldata modelName) external onlyAuditor {
150
+ require(agents[agent].registrationTime == 0, "Already registered");
151
+
152
+ agents[agent] = AgentRecord({
153
+ owner: agent,
154
+ architectureHash: architectureHash,
155
+ modelName: modelName,
156
+ currentTier: 0,
157
+ registrationTime: uint64(block.timestamp),
158
+ lastAuditTime: 0,
159
+ active: false,
160
+ totalEarned: 0,
161
+ totalPenalties: 0,
162
+ contractsCompleted: 0,
163
+ contractsFailed: 0
164
+ });
165
+
166
+ agentList.push(agent);
167
+ emit AgentRegistered(agent, modelName, architectureHash);
168
+ }
169
+
170
+ // -----------------------------------------------------------------------
171
+ // Certification (Auditor-only)
172
+ // -----------------------------------------------------------------------
173
+
174
+ /**
175
+ * @notice Certify an agent with a new robustness vector.
176
+ * Computes tier via the weakest-link gate function.
177
+ * The auditHash is the 0G Storage root hash of the pinned audit JSON,
178
+ * providing an immutable, verifiable proof of the certification.
179
+ * @param agent The agent's address
180
+ * @param cc Constraint Compliance score (0-10000)
181
+ * @param er Epistemic Robustness score (0-10000)
182
+ * @param as_ Behavioral Alignment score (0-10000)
183
+ * @param ih Intrinsic Hallucination integrity (0-10000)
184
+ * @param auditType Type of audit ("registration", "upgrade", "spot", "decay")
185
+ * @param auditHash 0G Storage root hash of the pinned audit result JSON
186
+ */
187
+ function certify(
188
+ address agent,
189
+ uint16 cc,
190
+ uint16 er,
191
+ uint16 as_,
192
+ uint16 ih,
193
+ string calldata auditType,
194
+ string calldata auditHash
195
+ ) external onlyAuditor agentExists(agent) {
196
+ RobustnessVector memory r = RobustnessVector(cc, er, as_, ih);
197
+ uint8 tier = _computeTier(r);
198
+
199
+ Certification memory cert = Certification({
200
+ robustness: r,
201
+ tier: tier,
202
+ timestamp: uint64(block.timestamp),
203
+ auditType: auditType,
204
+ auditHash: auditHash
205
+ });
206
+
207
+ uint8 oldTier = agents[agent].currentTier;
208
+ currentCertifications[agent] = cert;
209
+ certificationHistory[agent].push(cert);
210
+ agents[agent].currentTier = tier;
211
+ agents[agent].lastAuditTime = uint64(block.timestamp);
212
+ agents[agent].active = tier > 0;
213
+
214
+ emit AgentCertified(agent, tier, auditType, auditHash);
215
+
216
+ if (tier < oldTier) {
217
+ emit AgentDemoted(agent, oldTier, tier, auditType);
218
+ }
219
+ }
220
+
221
+ /**
222
+ * @notice Get the 0G Storage root hash of an agent's current audit proof.
223
+ * @param agent The agent's address
224
+ * @return The root hash string stored on 0G Storage
225
+ */
226
+ function getAuditHash(address agent) external view returns (string memory) {
227
+ return currentCertifications[agent].auditHash;
228
+ }
229
+
230
+ // -----------------------------------------------------------------------
231
+ // Gate Function (Definition 6: weakest-link)
232
+ // -----------------------------------------------------------------------
233
+
234
+ /**
235
+ * @notice Compute tier from robustness vector using weakest-link gate.
236
+ * f(R) = T_k where k = min(g1(CC), g2(ER), g3(AS))
237
+ * IH* < threshold triggers T0 (mandatory re-audit).
238
+ */
239
+ function _computeTier(RobustnessVector memory r) internal view returns (uint8) {
240
+ // IHT cross-cutting modifier
241
+ if (r.ih < ihThreshold) {
242
+ return 0;
243
+ }
244
+
245
+ uint8 gCC = _stepFunction(r.cc, ccThresholds);
246
+ uint8 gER = _stepFunction(r.er, erThresholds);
247
+ uint8 gAS = _stepFunction(r.as_, asThresholds);
248
+
249
+ // Weakest link
250
+ uint8 tier = gCC;
251
+ if (gER < tier) tier = gER;
252
+ if (gAS < tier) tier = gAS;
253
+
254
+ return tier;
255
+ }
256
+
257
+ /**
258
+ * @notice Step function g_i(x) = max{k : x >= theta_i^k}
259
+ */
260
+ function _stepFunction(uint16 score, uint16[6] storage thresholds) internal view returns (uint8) {
261
+ uint8 tier = 0;
262
+ for (uint8 k = 1; k < 6; k++) {
263
+ if (score >= thresholds[k]) {
264
+ tier = k;
265
+ } else {
266
+ break;
267
+ }
268
+ }
269
+ return tier;
270
+ }
271
+
272
+ // -----------------------------------------------------------------------
273
+ // Views
274
+ // -----------------------------------------------------------------------
275
+
276
+ function computeTier(uint16 cc, uint16 er, uint16 as_, uint16 ih) external view returns (uint8) {
277
+ return _computeTier(RobustnessVector(cc, er, as_, ih));
278
+ }
279
+
280
+ function getAgent(address agent) external view returns (AgentRecord memory) {
281
+ return agents[agent];
282
+ }
283
+
284
+ function getCertification(address agent) external view returns (Certification memory) {
285
+ return currentCertifications[agent];
286
+ }
287
+
288
+ function getCertificationHistory(address agent) external view returns (Certification[] memory) {
289
+ return certificationHistory[agent];
290
+ }
291
+
292
+ function getAgentCount() external view returns (uint256) {
293
+ return agentList.length;
294
+ }
295
+
296
+ function getBudgetCeiling(uint8 tier) external view returns (uint256) {
297
+ require(tier < 6, "Invalid tier");
298
+ return budgetCeilings[tier];
299
+ }
300
+
301
+ function isActive(address agent) external view returns (bool) {
302
+ return agents[agent].active;
303
+ }
304
+
305
+ // -----------------------------------------------------------------------
306
+ // Admin
307
+ // -----------------------------------------------------------------------
308
+
309
+ function authorizeAuditor(address auditor) external onlyAdmin {
310
+ authorizedAuditors[auditor] = true;
311
+ emit AuditorAuthorized(auditor);
312
+ }
313
+
314
+ function revokeAuditor(address auditor) external onlyAdmin {
315
+ authorizedAuditors[auditor] = false;
316
+ emit AuditorRevoked(auditor);
317
+ }
318
+
319
+ function updateThresholds(
320
+ uint16[6] calldata cc,
321
+ uint16[6] calldata er,
322
+ uint16[6] calldata as_,
323
+ uint16 ih
324
+ ) external onlyAdmin {
325
+ ccThresholds = cc;
326
+ erThresholds = er;
327
+ asThresholds = as_;
328
+ ihThreshold = ih;
329
+ emit ThresholdsUpdated();
330
+ }
331
+
332
+ function updateBudgetCeilings(uint256[6] calldata ceilings) external onlyAdmin {
333
+ budgetCeilings = ceilings;
334
+ }
335
+
336
+ function recordContractOutcome(
337
+ address agent,
338
+ bool success,
339
+ uint256 amount
340
+ ) external onlyAuditor agentExists(agent) {
341
+ if (success) {
342
+ agents[agent].contractsCompleted++;
343
+ agents[agent].totalEarned += amount;
344
+ } else {
345
+ agents[agent].contractsFailed++;
346
+ agents[agent].totalPenalties += amount;
347
+ }
348
+ }
349
+ }
server/results/agent_details.json DELETED
@@ -1,157 +0,0 @@
1
- {
2
- "conservative_0": {
3
- "agent_id": "agent_cf56e1c14e84",
4
- "model_name": "conservative_0",
5
- "architecture_hash": "8374b7c44322b61a",
6
- "status": "active",
7
- "current_tier": "T3",
8
- "balance": 0.49150872061921697,
9
- "total_earned": 0.035680765649084345,
10
- "total_spent": 0.038000000000000034,
11
- "total_penalties": 0.0061720450298669545,
12
- "total_topups": 0.0,
13
- "contracts_completed": 13,
14
- "contracts_failed": 7,
15
- "registration_time": 0.0,
16
- "audit_cid": null,
17
- "wallet_address": null,
18
- "robustness": {
19
- "cc": 0.9255496218337828,
20
- "er": 0.7985244829016913,
21
- "as": 0.772250481405939,
22
- "ih": 0.8472803268022182
23
- },
24
- "strategy": "conservative",
25
- "true_robustness": {
26
- "cc": 0.85,
27
- "er": 0.8,
28
- "as": 0.75,
29
- "ih": 0.9
30
- },
31
- "decisions_count": 20
32
- },
33
- "aggressive_1": {
34
- "agent_id": "agent_28f8af722342",
35
- "model_name": "aggressive_1",
36
- "architecture_hash": "06cf6cd1e0157f7e",
37
- "status": "active",
38
- "current_tier": "T1",
39
- "balance": 0.5277924652461742,
40
- "total_earned": 0.04979246524617394,
41
- "total_spent": 0.022000000000000026,
42
- "total_penalties": 0.0,
43
- "total_topups": 0.0,
44
- "contracts_completed": 15,
45
- "contracts_failed": 0,
46
- "registration_time": 0.0,
47
- "audit_cid": null,
48
- "wallet_address": null,
49
- "robustness": {
50
- "cc": 0.4237871475106476,
51
- "er": 0.43773895056453505,
52
- "as": 0.34136116942599515,
53
- "ih": 0.6714820583560304
54
- },
55
- "strategy": "aggressive",
56
- "true_robustness": {
57
- "cc": 0.35,
58
- "er": 0.4,
59
- "as": 0.3,
60
- "ih": 0.7
61
- },
62
- "decisions_count": 20
63
- },
64
- "balanced_2": {
65
- "agent_id": "agent_90781acc6dc0",
66
- "model_name": "balanced_2",
67
- "architecture_hash": "ea00df5aae26a51e",
68
- "status": "active",
69
- "current_tier": "T1",
70
- "balance": 0.5403475830647143,
71
- "total_earned": 0.14271936033504076,
72
- "total_spent": 0.022,
73
- "total_penalties": 0.08037177727032704,
74
- "total_topups": 0.0,
75
- "contracts_completed": 9,
76
- "contracts_failed": 11,
77
- "registration_time": 0.0,
78
- "audit_cid": null,
79
- "wallet_address": null,
80
- "robustness": {
81
- "cc": 0.6509882462532015,
82
- "er": 0.529896012603673,
83
- "as": 0.4386817356571334,
84
- "ih": 0.8320949702616935
85
- },
86
- "strategy": "balanced",
87
- "true_robustness": {
88
- "cc": 0.6,
89
- "er": 0.55,
90
- "as": 0.5,
91
- "ih": 0.8
92
- },
93
- "decisions_count": 20
94
- },
95
- "adaptive_3": {
96
- "agent_id": "agent_33d2e87d3579",
97
- "model_name": "adaptive_3",
98
- "architecture_hash": "b191a86339607a12",
99
- "status": "active",
100
- "current_tier": "T1",
101
- "balance": 0.4866801928830522,
102
- "total_earned": 0.002893322731259686,
103
- "total_spent": 0.013999999999999999,
104
- "total_penalties": 0.0022131298482070774,
105
- "total_topups": 0.0,
106
- "contracts_completed": 1,
107
- "contracts_failed": 2,
108
- "registration_time": 0.0,
109
- "audit_cid": null,
110
- "wallet_address": null,
111
- "robustness": {
112
- "cc": 0.5696990952039601,
113
- "er": 0.5033152153233149,
114
- "as": 0.42785035192965537,
115
- "ih": 0.7695601289753685
116
- },
117
- "strategy": "adaptive",
118
- "true_robustness": {
119
- "cc": 0.55,
120
- "er": 0.5,
121
- "as": 0.45,
122
- "ih": 0.8
123
- },
124
- "decisions_count": 20
125
- },
126
- "cheater_4": {
127
- "agent_id": "agent_85b2a0234c59",
128
- "model_name": "cheater_4",
129
- "architecture_hash": "73482227d1d7b2b3",
130
- "status": "active",
131
- "current_tier": "T0",
132
- "balance": 0.48599999999999954,
133
- "total_earned": 0.0,
134
- "total_spent": 0.013999999999999999,
135
- "total_penalties": 0.0,
136
- "total_topups": 0.0,
137
- "contracts_completed": 0,
138
- "contracts_failed": 0,
139
- "registration_time": 0.0,
140
- "audit_cid": null,
141
- "wallet_address": null,
142
- "robustness": {
143
- "cc": 0.707390265856336,
144
- "er": 0.2893324248161214,
145
- "as": 0.6512497059171015,
146
- "ih": 0.5968103011868765
147
- },
148
- "strategy": "cheater",
149
- "true_robustness": {
150
- "cc": 0.7,
151
- "er": 0.25,
152
- "as": 0.65,
153
- "ih": 0.6
154
- },
155
- "decisions_count": 20
156
- }
157
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server/results/agent_metrics.json DELETED
@@ -1,338 +0,0 @@
1
- {
2
- "balances": {
3
- "conservative_0": [
4
- 0.49081387449515695,
5
- 0.49343559279595983,
6
- 0.48850458919327977,
7
- 0.49146401935422707,
8
- 0.4946749359413105,
9
- 0.49636326754063087,
10
- 0.4952029352774256,
11
- 0.4940040393824217,
12
- 0.4966972071867608,
13
- 0.4980884768993407,
14
- 0.49248891838223513,
15
- 0.4912914260198051,
16
- 0.4928912988916253,
17
- 0.4947083713787377,
18
- 0.49763670817523475,
19
- 0.5001232423589304,
20
- 0.49096027864859226,
21
- 0.4897716498250345,
22
- 0.492686327089706,
23
- 0.49150872061921697
24
- ],
25
- "aggressive_1": [
26
- 0.49479282257430807,
27
- 0.49808816823059615,
28
- 0.49778816823059613,
29
- 0.49300299022864275,
30
- 0.4927029902286427,
31
- 0.495411537233485,
32
- 0.4980393843454029,
33
- 0.5012766927720629,
34
- 0.5009766927720629,
35
- 0.5035887816802933,
36
- 0.5068851162502124,
37
- 0.5065851162502124,
38
- 0.5098062143226315,
39
- 0.5129977676974148,
40
- 0.5161602642380944,
41
- 0.5189561722987545,
42
- 0.5219453351696965,
43
- 0.5250587164014742,
44
- 0.5247587164014742,
45
- 0.5277924652461742
46
- ],
47
- "balanced_2": [
48
- 0.5088319063260909,
49
- 0.5234635405742646,
50
- 0.5140244465183659,
51
- 0.5047625504836085,
52
- 0.5204227495801004,
53
- 0.5123727283326304,
54
- 0.5286477931330813,
55
- 0.5220918053639299,
56
- 0.5380628598027662,
57
- 0.5537254286259184,
58
- 0.5459980422068574,
59
- 0.5403249089008585,
60
- 0.5335986427751808,
61
- 0.5259763458300242,
62
- 0.5167580159101,
63
- 0.5333363337968263,
64
- 0.5253121303690602,
65
- 0.5385243079966603,
66
- 0.5537207450841788,
67
- 0.5403475830647143
68
- ],
69
- "adaptive_3": [
70
- 0.49169999999999997,
71
- 0.49139999999999995,
72
- 0.4910999999999999,
73
- 0.4907999999999999,
74
- 0.4904999999999999,
75
- 0.49309332273125955,
76
- 0.49279332273125953,
77
- 0.4924933227312595,
78
- 0.49109371302682636,
79
- 0.49079371302682634,
80
- 0.4904937130268263,
81
- 0.4901937130268263,
82
- 0.48989371302682627,
83
- 0.48959371302682625,
84
- 0.4892937130268262,
85
- 0.4889937130268262,
86
- 0.4886937130268262,
87
- 0.48839371302682616,
88
- 0.48809371302682614,
89
- 0.4866801928830522
90
- ],
91
- "cheater_4": [
92
- 0.49169999999999997,
93
- 0.49139999999999995,
94
- 0.4910999999999999,
95
- 0.4907999999999999,
96
- 0.4904999999999999,
97
- 0.49019999999999986,
98
- 0.48989999999999984,
99
- 0.4895999999999998,
100
- 0.4892999999999998,
101
- 0.48899999999999977,
102
- 0.48869999999999975,
103
- 0.4883999999999997,
104
- 0.4880999999999997,
105
- 0.4877999999999997,
106
- 0.48749999999999966,
107
- 0.48719999999999963,
108
- 0.4868999999999996,
109
- 0.4865999999999996,
110
- 0.48629999999999957,
111
- 0.48599999999999954
112
- ]
113
- },
114
- "tiers": {
115
- "conservative_0": [
116
- 3,
117
- 3,
118
- 3,
119
- 3,
120
- 3,
121
- 3,
122
- 3,
123
- 3,
124
- 3,
125
- 3,
126
- 3,
127
- 3,
128
- 3,
129
- 3,
130
- 3,
131
- 3,
132
- 4,
133
- 4,
134
- 4,
135
- 3
136
- ],
137
- "aggressive_1": [
138
- 1,
139
- 1,
140
- 1,
141
- 1,
142
- 1,
143
- 1,
144
- 1,
145
- 1,
146
- 1,
147
- 1,
148
- 1,
149
- 1,
150
- 1,
151
- 1,
152
- 1,
153
- 1,
154
- 1,
155
- 1,
156
- 1,
157
- 1
158
- ],
159
- "balanced_2": [
160
- 2,
161
- 2,
162
- 2,
163
- 2,
164
- 2,
165
- 2,
166
- 2,
167
- 2,
168
- 2,
169
- 2,
170
- 2,
171
- 2,
172
- 2,
173
- 2,
174
- 2,
175
- 2,
176
- 2,
177
- 2,
178
- 2,
179
- 1
180
- ],
181
- "adaptive_3": [
182
- 1,
183
- 1,
184
- 1,
185
- 1,
186
- 1,
187
- 1,
188
- 1,
189
- 1,
190
- 1,
191
- 1,
192
- 1,
193
- 1,
194
- 1,
195
- 1,
196
- 1,
197
- 1,
198
- 1,
199
- 1,
200
- 1,
201
- 1
202
- ],
203
- "cheater_4": [
204
- 0,
205
- 0,
206
- 0,
207
- 0,
208
- 0,
209
- 0,
210
- 0,
211
- 0,
212
- 0,
213
- 0,
214
- 0,
215
- 0,
216
- 0,
217
- 0,
218
- 0,
219
- 0,
220
- 0,
221
- 0,
222
- 0,
223
- 0
224
- ]
225
- },
226
- "earnings": {
227
- "conservative_0": [
228
- 0.0,
229
- 0.002921718300802926,
230
- 0.006290714698122897,
231
- 0.009550144859070195,
232
- 0.013061061446153663,
233
- 0.015049393045474056,
234
- 0.015049393045474056,
235
- 0.015049393045474056,
236
- 0.018042560849813163,
237
- 0.0197338305623931,
238
- 0.022434272045287508,
239
- 0.022434272045287508,
240
- 0.02433414491710776,
241
- 0.026451217404220177,
242
- 0.029679554200717252,
243
- 0.032466088384412846,
244
- 0.032466088384412846,
245
- 0.032466088384412846,
246
- 0.035680765649084345,
247
- 0.035680765649084345
248
- ],
249
- "aggressive_1": [
250
- 0.003092822574308115,
251
- 0.006688168230596231,
252
- 0.006688168230596231,
253
- 0.010202990228642848,
254
- 0.010202990228642848,
255
- 0.013211537233485171,
256
- 0.016139384345403053,
257
- 0.019676692772063034,
258
- 0.019676692772063034,
259
- 0.02258878168029342,
260
- 0.026185116250212498,
261
- 0.026185116250212498,
262
- 0.029706214322631524,
263
- 0.03319776769741471,
264
- 0.03666026423809421,
265
- 0.03975617229875429,
266
- 0.04304533516969639,
267
- 0.04645871640147403,
268
- 0.04645871640147403,
269
- 0.04979246524617394
270
- ],
271
- "balanced_2": [
272
- 0.017131906326090882,
273
- 0.03206354057426457,
274
- 0.03206354057426457,
275
- 0.03206354057426457,
276
- 0.04802373967075634,
277
- 0.04802373967075634,
278
- 0.06459880447120725,
279
- 0.06459880447120725,
280
- 0.08086985891004358,
281
- 0.09683242773319581,
282
- 0.09683242773319581,
283
- 0.09683242773319581,
284
- 0.09683242773319581,
285
- 0.09683242773319581,
286
- 0.09683242773319581,
287
- 0.11371074561992217,
288
- 0.11371074561992217,
289
- 0.12722292324752224,
290
- 0.14271936033504076,
291
- 0.14271936033504076
292
- ],
293
- "adaptive_3": [
294
- 0.0,
295
- 0.0,
296
- 0.0,
297
- 0.0,
298
- 0.0,
299
- 0.002893322731259686,
300
- 0.002893322731259686,
301
- 0.002893322731259686,
302
- 0.002893322731259686,
303
- 0.002893322731259686,
304
- 0.002893322731259686,
305
- 0.002893322731259686,
306
- 0.002893322731259686,
307
- 0.002893322731259686,
308
- 0.002893322731259686,
309
- 0.002893322731259686,
310
- 0.002893322731259686,
311
- 0.002893322731259686,
312
- 0.002893322731259686,
313
- 0.002893322731259686
314
- ],
315
- "cheater_4": [
316
- 0.0,
317
- 0.0,
318
- 0.0,
319
- 0.0,
320
- 0.0,
321
- 0.0,
322
- 0.0,
323
- 0.0,
324
- 0.0,
325
- 0.0,
326
- 0.0,
327
- 0.0,
328
- 0.0,
329
- 0.0,
330
- 0.0,
331
- 0.0,
332
- 0.0,
333
- 0.0,
334
- 0.0,
335
- 0.0
336
- ]
337
- }
338
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server/results/economy_state.json DELETED
@@ -1,144 +0,0 @@
1
- {
2
- "timestamp": 20.0,
3
- "config": {
4
- "decay_rate": 0.005,
5
- "ih_threshold": 0.45,
6
- "initial_balance": 0.5
7
- },
8
- "agents": {
9
- "agent_cf56e1c14e84": {
10
- "agent_id": "agent_cf56e1c14e84",
11
- "model_name": "conservative_0",
12
- "architecture_hash": "8374b7c44322b61a",
13
- "status": "active",
14
- "current_tier": "T3",
15
- "balance": 0.49150872061921697,
16
- "total_earned": 0.035680765649084345,
17
- "total_spent": 0.038000000000000034,
18
- "total_penalties": 0.0061720450298669545,
19
- "total_topups": 0.0,
20
- "contracts_completed": 13,
21
- "contracts_failed": 7,
22
- "registration_time": 0.0,
23
- "audit_cid": null,
24
- "wallet_address": null,
25
- "robustness": {
26
- "cc": 0.9255496218337828,
27
- "er": 0.7985244829016913,
28
- "as": 0.772250481405939,
29
- "ih": 0.8472803268022182
30
- }
31
- },
32
- "agent_28f8af722342": {
33
- "agent_id": "agent_28f8af722342",
34
- "model_name": "aggressive_1",
35
- "architecture_hash": "06cf6cd1e0157f7e",
36
- "status": "active",
37
- "current_tier": "T1",
38
- "balance": 0.5277924652461742,
39
- "total_earned": 0.04979246524617394,
40
- "total_spent": 0.022000000000000026,
41
- "total_penalties": 0.0,
42
- "total_topups": 0.0,
43
- "contracts_completed": 15,
44
- "contracts_failed": 0,
45
- "registration_time": 0.0,
46
- "audit_cid": null,
47
- "wallet_address": null,
48
- "robustness": {
49
- "cc": 0.4237871475106476,
50
- "er": 0.43773895056453505,
51
- "as": 0.34136116942599515,
52
- "ih": 0.6714820583560304
53
- }
54
- },
55
- "agent_90781acc6dc0": {
56
- "agent_id": "agent_90781acc6dc0",
57
- "model_name": "balanced_2",
58
- "architecture_hash": "ea00df5aae26a51e",
59
- "status": "active",
60
- "current_tier": "T1",
61
- "balance": 0.5403475830647143,
62
- "total_earned": 0.14271936033504076,
63
- "total_spent": 0.022,
64
- "total_penalties": 0.08037177727032704,
65
- "total_topups": 0.0,
66
- "contracts_completed": 9,
67
- "contracts_failed": 11,
68
- "registration_time": 0.0,
69
- "audit_cid": null,
70
- "wallet_address": null,
71
- "robustness": {
72
- "cc": 0.6509882462532015,
73
- "er": 0.529896012603673,
74
- "as": 0.4386817356571334,
75
- "ih": 0.8320949702616935
76
- }
77
- },
78
- "agent_33d2e87d3579": {
79
- "agent_id": "agent_33d2e87d3579",
80
- "model_name": "adaptive_3",
81
- "architecture_hash": "b191a86339607a12",
82
- "status": "active",
83
- "current_tier": "T1",
84
- "balance": 0.4866801928830522,
85
- "total_earned": 0.002893322731259686,
86
- "total_spent": 0.013999999999999999,
87
- "total_penalties": 0.0022131298482070774,
88
- "total_topups": 0.0,
89
- "contracts_completed": 1,
90
- "contracts_failed": 2,
91
- "registration_time": 0.0,
92
- "audit_cid": null,
93
- "wallet_address": null,
94
- "robustness": {
95
- "cc": 0.5696990952039601,
96
- "er": 0.5033152153233149,
97
- "as": 0.42785035192965537,
98
- "ih": 0.7695601289753685
99
- }
100
- },
101
- "agent_85b2a0234c59": {
102
- "agent_id": "agent_85b2a0234c59",
103
- "model_name": "cheater_4",
104
- "architecture_hash": "73482227d1d7b2b3",
105
- "status": "active",
106
- "current_tier": "T0",
107
- "balance": 0.48599999999999954,
108
- "total_earned": 0.0,
109
- "total_spent": 0.013999999999999999,
110
- "total_penalties": 0.0,
111
- "total_topups": 0.0,
112
- "contracts_completed": 0,
113
- "contracts_failed": 0,
114
- "registration_time": 0.0,
115
- "audit_cid": null,
116
- "wallet_address": null,
117
- "robustness": {
118
- "cc": 0.707390265856336,
119
- "er": 0.2893324248161214,
120
- "as": 0.6512497059171015,
121
- "ih": 0.5968103011868765
122
- }
123
- }
124
- },
125
- "contracts": {
126
- "total_contracts": 220,
127
- "status_distribution": {
128
- "failed": 20,
129
- "open": 162,
130
- "completed": 38
131
- },
132
- "total_rewards_paid": 0.23108591396155878,
133
- "total_penalties_collected": 0.08875695214840107,
134
- "total_escrowed": 54.72028111841184,
135
- "active_exposures": {
136
- "agent_cf56e1c14e84": 0,
137
- "agent_28f8af722342": 0,
138
- "agent_90781acc6dc0": 0,
139
- "agent_33d2e87d3579": 0
140
- }
141
- },
142
- "aggregate_safety": 0.7608347665972391,
143
- "total_test_eth_topups": 0.0
144
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server/results/protocol_events.json DELETED
@@ -1 +0,0 @@
1
- []
 
 
server/results/strategy_summary.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "survival": {
3
- "conservative": 1,
4
- "aggressive": 1,
5
- "balanced": 1,
6
- "adaptive": 1,
7
- "cheater": 1
8
- },
9
- "total_earned": {
10
- "conservative": 0.035680765649084345,
11
- "aggressive": 0.04979246524617394,
12
- "balanced": 0.14271936033504076,
13
- "adaptive": 0.002893322731259686,
14
- "cheater": 0.0
15
- },
16
- "final_tier": {
17
- "conservative": 3,
18
- "aggressive": 1,
19
- "balanced": 1,
20
- "adaptive": 1,
21
- "cheater": 0
22
- }
23
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server/results/task_results.json DELETED
@@ -1,1055 +0,0 @@
1
- [
2
- {
3
- "agent": "conservative_0",
4
- "task_id": "contract_a762c024c23b",
5
- "tier": "T1",
6
- "domain": "data_labeling",
7
- "proof_cid": "0xe3788e9a12befa04d89985ec593eebf7",
8
- "verification": {
9
- "overall_pass": false,
10
- "constraints_passed": [],
11
- "constraints_failed": [
12
- "format_compliance",
13
- "completeness"
14
- ]
15
- },
16
- "settlement": {
17
- "reward": 0.0,
18
- "penalty": 0.0008861255048430355
19
- },
20
- "output_preview": "Synthetic execution of contract_a762c024c23b: FAILURE"
21
- },
22
- {
23
- "agent": "aggressive_1",
24
- "task_id": "contract_6a04b2ca71e6",
25
- "tier": "T1",
26
- "domain": "summarization",
27
- "proof_cid": "0x0de9d6b5ac920e35a143b7de2828138d",
28
- "verification": {
29
- "overall_pass": true,
30
- "constraints_passed": [],
31
- "constraints_failed": []
32
- },
33
- "settlement": {
34
- "reward": 0.003092822574308115,
35
- "penalty": 0.0
36
- },
37
- "output_preview": "Synthetic execution of contract_6a04b2ca71e6: SUCCESS"
38
- },
39
- {
40
- "agent": "balanced_2",
41
- "task_id": "contract_e254b22fba41",
42
- "tier": "T2",
43
- "domain": "analysis",
44
- "proof_cid": "0x72bb23b6fddbea88e0dd14a2e40f95cb",
45
- "verification": {
46
- "overall_pass": true,
47
- "constraints_passed": [],
48
- "constraints_failed": []
49
- },
50
- "settlement": {
51
- "reward": 0.017131906326090882,
52
- "penalty": 0.0
53
- },
54
- "output_preview": "Synthetic execution of contract_e254b22fba41: SUCCESS"
55
- },
56
- {
57
- "agent": "conservative_0",
58
- "task_id": "contract_9d11e654a1af",
59
- "tier": "T1",
60
- "domain": "summarization",
61
- "proof_cid": "0x10f8962cb9e6f69fbb4c32c81eaf51fa",
62
- "verification": {
63
- "overall_pass": true,
64
- "constraints_passed": [],
65
- "constraints_failed": []
66
- },
67
- "settlement": {
68
- "reward": 0.002921718300802926,
69
- "penalty": 0.0
70
- },
71
- "output_preview": "Synthetic execution of contract_9d11e654a1af: SUCCESS"
72
- },
73
- {
74
- "agent": "aggressive_1",
75
- "task_id": "contract_ea289c611e45",
76
- "tier": "T1",
77
- "domain": "summarization",
78
- "proof_cid": "0xafdbb688086437a054dda6aafea164d5",
79
- "verification": {
80
- "overall_pass": true,
81
- "constraints_passed": [],
82
- "constraints_failed": []
83
- },
84
- "settlement": {
85
- "reward": 0.003595345656288116,
86
- "penalty": 0.0
87
- },
88
- "output_preview": "Synthetic execution of contract_ea289c611e45: SUCCESS"
89
- },
90
- {
91
- "agent": "balanced_2",
92
- "task_id": "contract_b97498b9138f",
93
- "tier": "T2",
94
- "domain": "analysis",
95
- "proof_cid": "0xfd719cb4f2e7cde733c8bdfbb1ba22a3",
96
- "verification": {
97
- "overall_pass": true,
98
- "constraints_passed": [],
99
- "constraints_failed": []
100
- },
101
- "settlement": {
102
- "reward": 0.014931634248173686,
103
- "penalty": 0.0
104
- },
105
- "output_preview": "Synthetic execution of contract_b97498b9138f: SUCCESS"
106
- },
107
- {
108
- "agent": "conservative_0",
109
- "task_id": "contract_8f83ccb818b2",
110
- "tier": "T1",
111
- "domain": "summarization",
112
- "proof_cid": "0x881a1b4fd780c04cf4eb02e07349fa16",
113
- "verification": {
114
- "overall_pass": true,
115
- "constraints_passed": [],
116
- "constraints_failed": []
117
- },
118
- "settlement": {
119
- "reward": 0.0033689963973199716,
120
- "penalty": 0.0
121
- },
122
- "output_preview": "Synthetic execution of contract_8f83ccb818b2: SUCCESS"
123
- },
124
- {
125
- "agent": "balanced_2",
126
- "task_id": "contract_d6f27d89c8ef",
127
- "tier": "T2",
128
- "domain": "analysis",
129
- "proof_cid": "0xab250c0c87d8aab0cd891579832c533e",
130
- "verification": {
131
- "overall_pass": false,
132
- "constraints_passed": [],
133
- "constraints_failed": [
134
- "format_compliance",
135
- "accuracy",
136
- "completeness"
137
- ]
138
- },
139
- "settlement": {
140
- "reward": 0.0,
141
- "penalty": 0.009139094055898793
142
- },
143
- "output_preview": "Synthetic execution of contract_d6f27d89c8ef: FAILURE"
144
- },
145
- {
146
- "agent": "conservative_0",
147
- "task_id": "contract_26627eeeea32",
148
- "tier": "T1",
149
- "domain": "summarization",
150
- "proof_cid": "0x393ded3cb91de8d0659b65697eb40420",
151
- "verification": {
152
- "overall_pass": true,
153
- "constraints_passed": [],
154
- "constraints_failed": []
155
- },
156
- "settlement": {
157
- "reward": 0.003259430160947298,
158
- "penalty": 0.0
159
- },
160
- "output_preview": "Synthetic execution of contract_26627eeeea32: SUCCESS"
161
- },
162
- {
163
- "agent": "aggressive_1",
164
- "task_id": "contract_5044b25e64ba",
165
- "tier": "T1",
166
- "domain": "summarization",
167
- "proof_cid": "0x717dc9278dbae3187d2accd765517646",
168
- "verification": {
169
- "overall_pass": true,
170
- "constraints_passed": [],
171
- "constraints_failed": []
172
- },
173
- "settlement": {
174
- "reward": 0.003514821998046617,
175
- "penalty": 0.0
176
- },
177
- "output_preview": "Synthetic execution of contract_5044b25e64ba: SUCCESS"
178
- },
179
- {
180
- "agent": "balanced_2",
181
- "task_id": "contract_8a5344725b1b",
182
- "tier": "T2",
183
- "domain": "analysis",
184
- "proof_cid": "0xb44a4ca6377c11611d8ecf66ca433482",
185
- "verification": {
186
- "overall_pass": false,
187
- "constraints_passed": [],
188
- "constraints_failed": [
189
- "format_compliance",
190
- "accuracy",
191
- "completeness"
192
- ]
193
- },
194
- "settlement": {
195
- "reward": 0.0,
196
- "penalty": 0.008961896034757435
197
- },
198
- "output_preview": "Synthetic execution of contract_8a5344725b1b: FAILURE"
199
- },
200
- {
201
- "agent": "conservative_0",
202
- "task_id": "contract_da1cc69e5fcf",
203
- "tier": "T1",
204
- "domain": "summarization",
205
- "proof_cid": "0x3b18ea0666a093e5910678a11a119a2a",
206
- "verification": {
207
- "overall_pass": true,
208
- "constraints_passed": [],
209
- "constraints_failed": []
210
- },
211
- "settlement": {
212
- "reward": 0.003510916587083468,
213
- "penalty": 0.0
214
- },
215
- "output_preview": "Synthetic execution of contract_da1cc69e5fcf: SUCCESS"
216
- },
217
- {
218
- "agent": "balanced_2",
219
- "task_id": "contract_c24512d81eb2",
220
- "tier": "T2",
221
- "domain": "analysis",
222
- "proof_cid": "0xa207087fb8f4d91e65a3246c12d7b671",
223
- "verification": {
224
- "overall_pass": true,
225
- "constraints_passed": [],
226
- "constraints_failed": []
227
- },
228
- "settlement": {
229
- "reward": 0.015960199096491774,
230
- "penalty": 0.0
231
- },
232
- "output_preview": "Synthetic execution of contract_c24512d81eb2: SUCCESS"
233
- },
234
- {
235
- "agent": "conservative_0",
236
- "task_id": "contract_774f2afce35d",
237
- "tier": "T1",
238
- "domain": "data_labeling",
239
- "proof_cid": "0xf2c334d0b1eb999eeea1c89175518109",
240
- "verification": {
241
- "overall_pass": true,
242
- "constraints_passed": [],
243
- "constraints_failed": []
244
- },
245
- "settlement": {
246
- "reward": 0.0019883315993203927,
247
- "penalty": 0.0
248
- },
249
- "output_preview": "Synthetic execution of contract_774f2afce35d: SUCCESS"
250
- },
251
- {
252
- "agent": "aggressive_1",
253
- "task_id": "contract_30bae7d33b63",
254
- "tier": "T1",
255
- "domain": "summarization",
256
- "proof_cid": "0x7b266462496c6df47778d5473897a8ec",
257
- "verification": {
258
- "overall_pass": true,
259
- "constraints_passed": [],
260
- "constraints_failed": []
261
- },
262
- "settlement": {
263
- "reward": 0.003008547004842323,
264
- "penalty": 0.0
265
- },
266
- "output_preview": "Synthetic execution of contract_30bae7d33b63: SUCCESS"
267
- },
268
- {
269
- "agent": "balanced_2",
270
- "task_id": "contract_267621db5452",
271
- "tier": "T2",
272
- "domain": "analysis",
273
- "proof_cid": "0xd75813e6bbdd205ea4900a153f4f0ba2",
274
- "verification": {
275
- "overall_pass": false,
276
- "constraints_passed": [],
277
- "constraints_failed": [
278
- "format_compliance",
279
- "accuracy",
280
- "completeness"
281
- ]
282
- },
283
- "settlement": {
284
- "reward": 0.0,
285
- "penalty": 0.007750021247470094
286
- },
287
- "output_preview": "Synthetic execution of contract_267621db5452: FAILURE"
288
- },
289
- {
290
- "agent": "adaptive_3",
291
- "task_id": "contract_832d70fc55c6",
292
- "tier": "T1",
293
- "domain": "summarization",
294
- "proof_cid": "0x7e0aa4424e9a6ac90ced69357f454c9c",
295
- "verification": {
296
- "overall_pass": true,
297
- "constraints_passed": [],
298
- "constraints_failed": []
299
- },
300
- "settlement": {
301
- "reward": 0.002893322731259686,
302
- "penalty": 0.0
303
- },
304
- "output_preview": "Synthetic execution of contract_832d70fc55c6: SUCCESS"
305
- },
306
- {
307
- "agent": "conservative_0",
308
- "task_id": "contract_abb67f7418ec",
309
- "tier": "T1",
310
- "domain": "summarization",
311
- "proof_cid": "0xb80745d02c2cae2b14de66af7ced8639",
312
- "verification": {
313
- "overall_pass": false,
314
- "constraints_passed": [],
315
- "constraints_failed": [
316
- "length_constraint",
317
- "accuracy"
318
- ]
319
- },
320
- "settlement": {
321
- "reward": 0.0,
322
- "penalty": 0.0008603322632052347
323
- },
324
- "output_preview": "Synthetic execution of contract_abb67f7418ec: FAILURE"
325
- },
326
- {
327
- "agent": "aggressive_1",
328
- "task_id": "contract_9b870ef54e9d",
329
- "tier": "T1",
330
- "domain": "summarization",
331
- "proof_cid": "0x5ae50e8a2c6560a194cc21cefcb442b0",
332
- "verification": {
333
- "overall_pass": true,
334
- "constraints_passed": [],
335
- "constraints_failed": []
336
- },
337
- "settlement": {
338
- "reward": 0.0029278471119178833,
339
- "penalty": 0.0
340
- },
341
- "output_preview": "Synthetic execution of contract_9b870ef54e9d: SUCCESS"
342
- },
343
- {
344
- "agent": "balanced_2",
345
- "task_id": "contract_585e86184d7e",
346
- "tier": "T2",
347
- "domain": "analysis",
348
- "proof_cid": "0x8a5fc294c236b93ecac0d4c870a4c398",
349
- "verification": {
350
- "overall_pass": true,
351
- "constraints_passed": [],
352
- "constraints_failed": []
353
- },
354
- "settlement": {
355
- "reward": 0.016575064800450907,
356
- "penalty": 0.0
357
- },
358
- "output_preview": "Synthetic execution of contract_585e86184d7e: SUCCESS"
359
- },
360
- {
361
- "agent": "conservative_0",
362
- "task_id": "contract_8405e50a5ebc",
363
- "tier": "T1",
364
- "domain": "data_labeling",
365
- "proof_cid": "0x5f3870dc8ac36788dd6e4a60515f9fe3",
366
- "verification": {
367
- "overall_pass": false,
368
- "constraints_passed": [],
369
- "constraints_failed": [
370
- "format_compliance",
371
- "completeness"
372
- ]
373
- },
374
- "settlement": {
375
- "reward": 0.0,
376
- "penalty": 0.0008988958950038638
377
- },
378
- "output_preview": "Synthetic execution of contract_8405e50a5ebc: FAILURE"
379
- },
380
- {
381
- "agent": "aggressive_1",
382
- "task_id": "contract_60e2abeab26f",
383
- "tier": "T1",
384
- "domain": "summarization",
385
- "proof_cid": "0xb6d703438a944c5b6912fa5495ea950f",
386
- "verification": {
387
- "overall_pass": true,
388
- "constraints_passed": [],
389
- "constraints_failed": []
390
- },
391
- "settlement": {
392
- "reward": 0.003537308426659982,
393
- "penalty": 0.0
394
- },
395
- "output_preview": "Synthetic execution of contract_60e2abeab26f: SUCCESS"
396
- },
397
- {
398
- "agent": "balanced_2",
399
- "task_id": "contract_911afcedcc61",
400
- "tier": "T2",
401
- "domain": "translation",
402
- "proof_cid": "0xd77412a07afea5bc9b32c6b4c9654928",
403
- "verification": {
404
- "overall_pass": false,
405
- "constraints_passed": [],
406
- "constraints_failed": [
407
- "accuracy",
408
- "terminology_consistency"
409
- ]
410
- },
411
- "settlement": {
412
- "reward": 0.0,
413
- "penalty": 0.00625598776915143
414
- },
415
- "output_preview": "Synthetic execution of contract_911afcedcc61: FAILURE"
416
- },
417
- {
418
- "agent": "conservative_0",
419
- "task_id": "contract_47a2465077bf",
420
- "tier": "T1",
421
- "domain": "summarization",
422
- "proof_cid": "0x962cc7636be73ebf96af5019fe8d96d0",
423
- "verification": {
424
- "overall_pass": true,
425
- "constraints_passed": [],
426
- "constraints_failed": []
427
- },
428
- "settlement": {
429
- "reward": 0.0029931678043391063,
430
- "penalty": 0.0
431
- },
432
- "output_preview": "Synthetic execution of contract_47a2465077bf: SUCCESS"
433
- },
434
- {
435
- "agent": "balanced_2",
436
- "task_id": "contract_74c517e69b09",
437
- "tier": "T2",
438
- "domain": "analysis",
439
- "proof_cid": "0x715788df4865bb682a9f2df8d4143c76",
440
- "verification": {
441
- "overall_pass": true,
442
- "constraints_passed": [],
443
- "constraints_failed": []
444
- },
445
- "settlement": {
446
- "reward": 0.016271054438836335,
447
- "penalty": 0.0
448
- },
449
- "output_preview": "Synthetic execution of contract_74c517e69b09: SUCCESS"
450
- },
451
- {
452
- "agent": "adaptive_3",
453
- "task_id": "contract_28e3ff49574c",
454
- "tier": "T1",
455
- "domain": "summarization",
456
- "proof_cid": "0xac2b041fa9422c6c6fad4780f4ec5aba",
457
- "verification": {
458
- "overall_pass": false,
459
- "constraints_passed": [],
460
- "constraints_failed": [
461
- "length_constraint",
462
- "accuracy"
463
- ]
464
- },
465
- "settlement": {
466
- "reward": 0.0,
467
- "penalty": 0.0010996097044331404
468
- },
469
- "output_preview": "Synthetic execution of contract_28e3ff49574c: FAILURE"
470
- },
471
- {
472
- "agent": "conservative_0",
473
- "task_id": "contract_292b64d4eb34",
474
- "tier": "T1",
475
- "domain": "data_labeling",
476
- "proof_cid": "0x0d9859a99ed15eab50872a8511ef3f4a",
477
- "verification": {
478
- "overall_pass": true,
479
- "constraints_passed": [],
480
- "constraints_failed": []
481
- },
482
- "settlement": {
483
- "reward": 0.0016912697125799397,
484
- "penalty": 0.0
485
- },
486
- "output_preview": "Synthetic execution of contract_292b64d4eb34: SUCCESS"
487
- },
488
- {
489
- "agent": "aggressive_1",
490
- "task_id": "contract_8bacab0d4544",
491
- "tier": "T1",
492
- "domain": "summarization",
493
- "proof_cid": "0xaebf575423009fa0bb556d8f07851973",
494
- "verification": {
495
- "overall_pass": true,
496
- "constraints_passed": [],
497
- "constraints_failed": []
498
- },
499
- "settlement": {
500
- "reward": 0.0029120889082303865,
501
- "penalty": 0.0
502
- },
503
- "output_preview": "Synthetic execution of contract_8bacab0d4544: SUCCESS"
504
- },
505
- {
506
- "agent": "balanced_2",
507
- "task_id": "contract_12555ae63e88",
508
- "tier": "T2",
509
- "domain": "analysis",
510
- "proof_cid": "0x3a02751becc8df4c6ca5035e784ba75b",
511
- "verification": {
512
- "overall_pass": true,
513
- "constraints_passed": [],
514
- "constraints_failed": []
515
- },
516
- "settlement": {
517
- "reward": 0.01596256882315222,
518
- "penalty": 0.0
519
- },
520
- "output_preview": "Synthetic execution of contract_12555ae63e88: SUCCESS"
521
- },
522
- {
523
- "agent": "conservative_0",
524
- "task_id": "contract_fa617f94d520",
525
- "tier": "T1",
526
- "domain": "summarization",
527
- "proof_cid": "0x755485295416028ccd6c26d151d75609",
528
- "verification": {
529
- "overall_pass": true,
530
- "constraints_passed": [],
531
- "constraints_failed": []
532
- },
533
- "settlement": {
534
- "reward": 0.002700441482894405,
535
- "penalty": 0.0
536
- },
537
- "output_preview": "Synthetic execution of contract_fa617f94d520: SUCCESS"
538
- },
539
- {
540
- "agent": "aggressive_1",
541
- "task_id": "contract_88fd92bae684",
542
- "tier": "T1",
543
- "domain": "summarization",
544
- "proof_cid": "0xa17f835b71f8220f03516b1a3b4c7f5a",
545
- "verification": {
546
- "overall_pass": true,
547
- "constraints_passed": [],
548
- "constraints_failed": []
549
- },
550
- "settlement": {
551
- "reward": 0.0035963345699190756,
552
- "penalty": 0.0
553
- },
554
- "output_preview": "Synthetic execution of contract_88fd92bae684: SUCCESS"
555
- },
556
- {
557
- "agent": "balanced_2",
558
- "task_id": "contract_58a6cf8906eb",
559
- "tier": "T2",
560
- "domain": "analysis",
561
- "proof_cid": "0xdb3a9312247f8d1dbf9324f70165bbd2",
562
- "verification": {
563
- "overall_pass": false,
564
- "constraints_passed": [],
565
- "constraints_failed": [
566
- "format_compliance",
567
- "accuracy",
568
- "completeness"
569
- ]
570
- },
571
- "settlement": {
572
- "reward": 0.0,
573
- "penalty": 0.007427386419061029
574
- },
575
- "output_preview": "Synthetic execution of contract_58a6cf8906eb: FAILURE"
576
- },
577
- {
578
- "agent": "conservative_0",
579
- "task_id": "contract_0d0c5c4043dd",
580
- "tier": "T1",
581
- "domain": "summarization",
582
- "proof_cid": "0xac1b7ebde0853facfcccd71df1e6c12a",
583
- "verification": {
584
- "overall_pass": false,
585
- "constraints_passed": [],
586
- "constraints_failed": [
587
- "length_constraint",
588
- "accuracy"
589
- ]
590
- },
591
- "settlement": {
592
- "reward": 0.0,
593
- "penalty": 0.0008974923624300554
594
- },
595
- "output_preview": "Synthetic execution of contract_0d0c5c4043dd: FAILURE"
596
- },
597
- {
598
- "agent": "balanced_2",
599
- "task_id": "contract_2f565829d3bb",
600
- "tier": "T2",
601
- "domain": "translation",
602
- "proof_cid": "0xf359c2dae17fab61b523d962e160893f",
603
- "verification": {
604
- "overall_pass": false,
605
- "constraints_passed": [],
606
- "constraints_failed": [
607
- "accuracy",
608
- "terminology_consistency"
609
- ]
610
- },
611
- "settlement": {
612
- "reward": 0.0,
613
- "penalty": 0.005373133305998998
614
- },
615
- "output_preview": "Synthetic execution of contract_2f565829d3bb: FAILURE"
616
- },
617
- {
618
- "agent": "conservative_0",
619
- "task_id": "contract_eee77bdc994a",
620
- "tier": "T1",
621
- "domain": "data_labeling",
622
- "proof_cid": "0x96c179c1294253c64178491b45cd2965",
623
- "verification": {
624
- "overall_pass": true,
625
- "constraints_passed": [],
626
- "constraints_failed": []
627
- },
628
- "settlement": {
629
- "reward": 0.0018998728718202518,
630
- "penalty": 0.0
631
- },
632
- "output_preview": "Synthetic execution of contract_eee77bdc994a: SUCCESS"
633
- },
634
- {
635
- "agent": "aggressive_1",
636
- "task_id": "contract_ee6438a35eb2",
637
- "tier": "T1",
638
- "domain": "summarization",
639
- "proof_cid": "0x66ec2a457304d380e1219388b1d3f0cc",
640
- "verification": {
641
- "overall_pass": true,
642
- "constraints_passed": [],
643
- "constraints_failed": []
644
- },
645
- "settlement": {
646
- "reward": 0.0035210980724190246,
647
- "penalty": 0.0
648
- },
649
- "output_preview": "Synthetic execution of contract_ee6438a35eb2: SUCCESS"
650
- },
651
- {
652
- "agent": "balanced_2",
653
- "task_id": "contract_2df338eb83dc",
654
- "tier": "T2",
655
- "domain": "translation",
656
- "proof_cid": "0x687de0274a2f0b6e66f5c47459872e19",
657
- "verification": {
658
- "overall_pass": false,
659
- "constraints_passed": [],
660
- "constraints_failed": [
661
- "accuracy",
662
- "terminology_consistency"
663
- ]
664
- },
665
- "settlement": {
666
- "reward": 0.0,
667
- "penalty": 0.00642626612567779
668
- },
669
- "output_preview": "Synthetic execution of contract_2df338eb83dc: FAILURE"
670
- },
671
- {
672
- "agent": "conservative_0",
673
- "task_id": "contract_3971377c6105",
674
- "tier": "T1",
675
- "domain": "data_labeling",
676
- "proof_cid": "0xa375d7b10b82ba39f65dc4a0f4f717d5",
677
- "verification": {
678
- "overall_pass": true,
679
- "constraints_passed": [],
680
- "constraints_failed": []
681
- },
682
- "settlement": {
683
- "reward": 0.0021170724871124183,
684
- "penalty": 0.0
685
- },
686
- "output_preview": "Synthetic execution of contract_3971377c6105: SUCCESS"
687
- },
688
- {
689
- "agent": "aggressive_1",
690
- "task_id": "contract_2637144a151c",
691
- "tier": "T1",
692
- "domain": "summarization",
693
- "proof_cid": "0x9f244b6e27a1f78ab7a2dc20cb571a22",
694
- "verification": {
695
- "overall_pass": true,
696
- "constraints_passed": [],
697
- "constraints_failed": []
698
- },
699
- "settlement": {
700
- "reward": 0.003491553374783192,
701
- "penalty": 0.0
702
- },
703
- "output_preview": "Synthetic execution of contract_2637144a151c: SUCCESS"
704
- },
705
- {
706
- "agent": "balanced_2",
707
- "task_id": "contract_9205ea050b7a",
708
- "tier": "T2",
709
- "domain": "analysis",
710
- "proof_cid": "0x6da58ecd76cd5116a3f1e1b7c49e1661",
711
- "verification": {
712
- "overall_pass": false,
713
- "constraints_passed": [],
714
- "constraints_failed": [
715
- "format_compliance",
716
- "accuracy",
717
- "completeness"
718
- ]
719
- },
720
- "settlement": {
721
- "reward": 0.0,
722
- "penalty": 0.0073222969451566585
723
- },
724
- "output_preview": "Synthetic execution of contract_9205ea050b7a: FAILURE"
725
- },
726
- {
727
- "agent": "conservative_0",
728
- "task_id": "contract_0f3319c6939c",
729
- "tier": "T1",
730
- "domain": "summarization",
731
- "proof_cid": "0x9f998a50c6209104f43a76d6d0e42916",
732
- "verification": {
733
- "overall_pass": true,
734
- "constraints_passed": [],
735
- "constraints_failed": []
736
- },
737
- "settlement": {
738
- "reward": 0.0032283367964970762,
739
- "penalty": 0.0
740
- },
741
- "output_preview": "Synthetic execution of contract_0f3319c6939c: SUCCESS"
742
- },
743
- {
744
- "agent": "aggressive_1",
745
- "task_id": "contract_d287fc801e29",
746
- "tier": "T1",
747
- "domain": "summarization",
748
- "proof_cid": "0xdc5f0585641df466fcf27a2d3a0b85ea",
749
- "verification": {
750
- "overall_pass": true,
751
- "constraints_passed": [],
752
- "constraints_failed": []
753
- },
754
- "settlement": {
755
- "reward": 0.003462496540679495,
756
- "penalty": 0.0
757
- },
758
- "output_preview": "Synthetic execution of contract_d287fc801e29: SUCCESS"
759
- },
760
- {
761
- "agent": "balanced_2",
762
- "task_id": "contract_5a3f9486d106",
763
- "tier": "T2",
764
- "domain": "analysis",
765
- "proof_cid": "0x3640e5366d7bb6e6c8effdb253495184",
766
- "verification": {
767
- "overall_pass": false,
768
- "constraints_passed": [],
769
- "constraints_failed": [
770
- "format_compliance",
771
- "accuracy",
772
- "completeness"
773
- ]
774
- },
775
- "settlement": {
776
- "reward": 0.0,
777
- "penalty": 0.008918329919924212
778
- },
779
- "output_preview": "Synthetic execution of contract_5a3f9486d106: FAILURE"
780
- },
781
- {
782
- "agent": "conservative_0",
783
- "task_id": "contract_8e0f8276ec96",
784
- "tier": "T1",
785
- "domain": "summarization",
786
- "proof_cid": "0xd36516b07eb0023c9c137bf47109f7c5",
787
- "verification": {
788
- "overall_pass": true,
789
- "constraints_passed": [],
790
- "constraints_failed": []
791
- },
792
- "settlement": {
793
- "reward": 0.0027865341836955915,
794
- "penalty": 0.0
795
- },
796
- "output_preview": "Synthetic execution of contract_8e0f8276ec96: SUCCESS"
797
- },
798
- {
799
- "agent": "aggressive_1",
800
- "task_id": "contract_067db520271d",
801
- "tier": "T1",
802
- "domain": "summarization",
803
- "proof_cid": "0xf7277144f75d7e1506a28bd20afaab7c",
804
- "verification": {
805
- "overall_pass": true,
806
- "constraints_passed": [],
807
- "constraints_failed": []
808
- },
809
- "settlement": {
810
- "reward": 0.003095908060660085,
811
- "penalty": 0.0
812
- },
813
- "output_preview": "Synthetic execution of contract_067db520271d: SUCCESS"
814
- },
815
- {
816
- "agent": "balanced_2",
817
- "task_id": "contract_36f16cd4c323",
818
- "tier": "T2",
819
- "domain": "analysis",
820
- "proof_cid": "0x629030341cbe0e7a5f84c0a4313b7c33",
821
- "verification": {
822
- "overall_pass": true,
823
- "constraints_passed": [],
824
- "constraints_failed": []
825
- },
826
- "settlement": {
827
- "reward": 0.016878317886726356,
828
- "penalty": 0.0
829
- },
830
- "output_preview": "Synthetic execution of contract_36f16cd4c323: SUCCESS"
831
- },
832
- {
833
- "agent": "conservative_0",
834
- "task_id": "contract_6dd7a4c98a14",
835
- "tier": "T1",
836
- "domain": "data_labeling",
837
- "proof_cid": "0x37a294db63ae2a5c16e66e3558d201f4",
838
- "verification": {
839
- "overall_pass": false,
840
- "constraints_passed": [],
841
- "constraints_failed": [
842
- "format_compliance",
843
- "completeness"
844
- ]
845
- },
846
- "settlement": {
847
- "reward": 0.0,
848
- "penalty": 0.0008629637103380356
849
- },
850
- "output_preview": "Synthetic execution of contract_6dd7a4c98a14: FAILURE"
851
- },
852
- {
853
- "agent": "aggressive_1",
854
- "task_id": "contract_58271e8e7624",
855
- "tier": "T1",
856
- "domain": "summarization",
857
- "proof_cid": "0x1c76c89a21147c831205cee5b0102f04",
858
- "verification": {
859
- "overall_pass": true,
860
- "constraints_passed": [],
861
- "constraints_failed": []
862
- },
863
- "settlement": {
864
- "reward": 0.003289162870942104,
865
- "penalty": 0.0
866
- },
867
- "output_preview": "Synthetic execution of contract_58271e8e7624: SUCCESS"
868
- },
869
- {
870
- "agent": "balanced_2",
871
- "task_id": "contract_32cd9acee782",
872
- "tier": "T2",
873
- "domain": "analysis",
874
- "proof_cid": "0x471176d4ac6d4ed3a3735c35278ee5f0",
875
- "verification": {
876
- "overall_pass": false,
877
- "constraints_passed": [],
878
- "constraints_failed": [
879
- "format_compliance",
880
- "accuracy",
881
- "completeness"
882
- ]
883
- },
884
- "settlement": {
885
- "reward": 0.0,
886
- "penalty": 0.0077242034277661235
887
- },
888
- "output_preview": "Synthetic execution of contract_32cd9acee782: FAILURE"
889
- },
890
- {
891
- "agent": "conservative_0",
892
- "task_id": "contract_aa1a90a8659f",
893
- "tier": "T1",
894
- "domain": "data_labeling",
895
- "proof_cid": "0x65e0363ece76458545f2bb0944cff748",
896
- "verification": {
897
- "overall_pass": false,
898
- "constraints_passed": [],
899
- "constraints_failed": [
900
- "format_compliance",
901
- "completeness"
902
- ]
903
- },
904
- "settlement": {
905
- "reward": 0.0,
906
- "penalty": 0.0008886288235577006
907
- },
908
- "output_preview": "Synthetic execution of contract_aa1a90a8659f: FAILURE"
909
- },
910
- {
911
- "agent": "aggressive_1",
912
- "task_id": "contract_8efbb7f13ac3",
913
- "tier": "T1",
914
- "domain": "summarization",
915
- "proof_cid": "0x15e8f78016312c17dedd87590b4a2f8f",
916
- "verification": {
917
- "overall_pass": true,
918
- "constraints_passed": [],
919
- "constraints_failed": []
920
- },
921
- "settlement": {
922
- "reward": 0.003413381231777636,
923
- "penalty": 0.0
924
- },
925
- "output_preview": "Synthetic execution of contract_8efbb7f13ac3: SUCCESS"
926
- },
927
- {
928
- "agent": "balanced_2",
929
- "task_id": "contract_703bc5dcee48",
930
- "tier": "T2",
931
- "domain": "translation",
932
- "proof_cid": "0xda3f3aa1ada8a769100280d73c08adcf",
933
- "verification": {
934
- "overall_pass": true,
935
- "constraints_passed": [],
936
- "constraints_failed": []
937
- },
938
- "settlement": {
939
- "reward": 0.013512177627600068,
940
- "penalty": 0.0
941
- },
942
- "output_preview": "Synthetic execution of contract_703bc5dcee48: SUCCESS"
943
- },
944
- {
945
- "agent": "conservative_0",
946
- "task_id": "contract_40435ef07179",
947
- "tier": "T1",
948
- "domain": "summarization",
949
- "proof_cid": "0xe46a41ebb316b37aa5588d29cf4ea185",
950
- "verification": {
951
- "overall_pass": true,
952
- "constraints_passed": [],
953
- "constraints_failed": []
954
- },
955
- "settlement": {
956
- "reward": 0.0032146772646714974,
957
- "penalty": 0.0
958
- },
959
- "output_preview": "Synthetic execution of contract_40435ef07179: SUCCESS"
960
- },
961
- {
962
- "agent": "balanced_2",
963
- "task_id": "contract_a37bf191435e",
964
- "tier": "T2",
965
- "domain": "analysis",
966
- "proof_cid": "0xcc164736fab643f47206c2a8c796984b",
967
- "verification": {
968
- "overall_pass": true,
969
- "constraints_passed": [],
970
- "constraints_failed": []
971
- },
972
- "settlement": {
973
- "reward": 0.015496437087518517,
974
- "penalty": 0.0
975
- },
976
- "output_preview": "Synthetic execution of contract_a37bf191435e: SUCCESS"
977
- },
978
- {
979
- "agent": "conservative_0",
980
- "task_id": "contract_9d22852235bd",
981
- "tier": "T1",
982
- "domain": "data_labeling",
983
- "proof_cid": "0x656c161d92f950dad015528889fe52bc",
984
- "verification": {
985
- "overall_pass": false,
986
- "constraints_passed": [],
987
- "constraints_failed": [
988
- "format_compliance",
989
- "completeness"
990
- ]
991
- },
992
- "settlement": {
993
- "reward": 0.0,
994
- "penalty": 0.000877606470489028
995
- },
996
- "output_preview": "Synthetic execution of contract_9d22852235bd: FAILURE"
997
- },
998
- {
999
- "agent": "aggressive_1",
1000
- "task_id": "contract_ef2cb460c2c2",
1001
- "tier": "T1",
1002
- "domain": "summarization",
1003
- "proof_cid": "0x139e54cdb1ba712213c401e295a3ec59",
1004
- "verification": {
1005
- "overall_pass": true,
1006
- "constraints_passed": [],
1007
- "constraints_failed": []
1008
- },
1009
- "settlement": {
1010
- "reward": 0.0033337488446999112,
1011
- "penalty": 0.0
1012
- },
1013
- "output_preview": "Synthetic execution of contract_ef2cb460c2c2: SUCCESS"
1014
- },
1015
- {
1016
- "agent": "balanced_2",
1017
- "task_id": "contract_6bf723ac3a92",
1018
- "tier": "T2",
1019
- "domain": "translation",
1020
- "proof_cid": "0xba0267f54737fb6a8656055389919db6",
1021
- "verification": {
1022
- "overall_pass": false,
1023
- "constraints_passed": [],
1024
- "constraints_failed": [
1025
- "accuracy",
1026
- "terminology_consistency"
1027
- ]
1028
- },
1029
- "settlement": {
1030
- "reward": 0.0,
1031
- "penalty": 0.005073162019464485
1032
- },
1033
- "output_preview": "Synthetic execution of contract_6bf723ac3a92: FAILURE"
1034
- },
1035
- {
1036
- "agent": "adaptive_3",
1037
- "task_id": "contract_eca507c33880",
1038
- "tier": "T1",
1039
- "domain": "summarization",
1040
- "proof_cid": "0x147ec0fe2fd131f24e0042d69b6c2f73",
1041
- "verification": {
1042
- "overall_pass": false,
1043
- "constraints_passed": [],
1044
- "constraints_failed": [
1045
- "length_constraint",
1046
- "accuracy"
1047
- ]
1048
- },
1049
- "settlement": {
1050
- "reward": 0.0,
1051
- "penalty": 0.001113520143773937
1052
- },
1053
- "output_preview": "Synthetic execution of contract_eca507c33880: FAILURE"
1054
- }
1055
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
server/results/time_series.json DELETED
@@ -1,178 +0,0 @@
1
- {
2
- "timestamps": [
3
- 1.0,
4
- 2.0,
5
- 3.0,
6
- 4.0,
7
- 5.0,
8
- 6.0,
9
- 7.0,
10
- 8.0,
11
- 9.0,
12
- 10.0,
13
- 11.0,
14
- 12.0,
15
- 13.0,
16
- 14.0,
17
- 15.0,
18
- 16.0,
19
- 17.0,
20
- 18.0,
21
- 19.0,
22
- 20.0
23
- ],
24
- "aggregate_safety": [
25
- 0.7149303399599031,
26
- 0.7113646100135703,
27
- 0.7332981455002783,
28
- 0.7299758899151536,
29
- 0.7263351199753616,
30
- 0.722712508451399,
31
- 0.7191079647777887,
32
- 0.7155213988407516,
33
- 0.7119527209759524,
34
- 0.7084018419662584,
35
- 0.7017113756760207,
36
- 0.6982115755891051,
37
- 0.6947292308279442,
38
- 0.6912642543337382,
39
- 0.6878165594818937,
40
- 0.6843860600798599,
41
- 0.7799318073119693,
42
- 0.7760418811947121,
43
- 0.7721713561649035,
44
- 0.7608347665972391
45
- ],
46
- "total_balance": [
47
- 2.477838603395556,
48
- 2.4977873016008205,
49
- 2.4825172039422414,
50
- 2.4708295600664782,
51
- 2.4888006757500536,
52
- 2.4874408558380057,
53
- 2.504583435487169,
54
- 2.499465860249674,
55
- 2.516130472788416,
56
- 2.535196400232379,
57
- 2.524565789866131,
58
- 2.5167951641977018,
59
- 2.5142898690162636,
60
- 2.5110761979330025,
61
- 2.507348701350255,
62
- 2.528609461481337,
63
- 2.513811457214175,
64
- 2.5283483872499946,
65
- 2.5455595016021846,
66
- 2.5323289618131573
67
- ],
68
- "active_agent_count": [
69
- 5,
70
- 5,
71
- 5,
72
- 5,
73
- 5,
74
- 5,
75
- 5,
76
- 5,
77
- 5,
78
- 5,
79
- 5,
80
- 5,
81
- 5,
82
- 5,
83
- 5,
84
- 5,
85
- 5,
86
- 5,
87
- 5,
88
- 5
89
- ],
90
- "contracts_completed": [
91
- 2,
92
- 5,
93
- 6,
94
- 8,
95
- 10,
96
- 13,
97
- 15,
98
- 16,
99
- 18,
100
- 21,
101
- 23,
102
- 23,
103
- 25,
104
- 27,
105
- 29,
106
- 32,
107
- 33,
108
- 35,
109
- 37,
110
- 38
111
- ],
112
- "contracts_failed": [
113
- 1,
114
- 1,
115
- 2,
116
- 3,
117
- 3,
118
- 4,
119
- 5,
120
- 7,
121
- 8,
122
- 8,
123
- 9,
124
- 11,
125
- 12,
126
- 13,
127
- 14,
128
- 14,
129
- 16,
130
- 17,
131
- 17,
132
- 20
133
- ],
134
- "rewards_paid": [
135
- 0.020224728900398996,
136
- 0.04167342710566373,
137
- 0.0450424235029837,
138
- 0.05181667566197762,
139
- 0.07128779134555285,
140
- 0.07917799268097525,
141
- 0.09868090459334405,
142
- 0.10221821302000404,
143
- 0.12148243526317948,
144
- 0.14204836270714202,
145
- 0.1483451387599555,
146
- 0.1483451387599555,
147
- 0.15376610970419477,
148
- 0.1593747355660904,
149
- 0.16606556890326696,
150
- 0.188826329034349,
151
- 0.19211549190529112,
152
- 0.20904105076466883,
153
- 0.22775216511685886,
154
- 0.23108591396155878
155
- ],
156
- "penalties_collected": [
157
- 0.0008861255048430355,
158
- 0.0008861255048430355,
159
- 0.010025219560741828,
160
- 0.018987115595499263,
161
- 0.018987115595499263,
162
- 0.026737136842969356,
163
- 0.02759746910617459,
164
- 0.03475235277032988,
165
- 0.03585196247476302,
166
- 0.03585196247476302,
167
- 0.04327934889382405,
168
- 0.04954997456225311,
169
- 0.055976240687930896,
170
- 0.06329853763308756,
171
- 0.07221686755301177,
172
- 0.07221686755301177,
173
- 0.08080403469111593,
174
- 0.08169266351467362,
175
- 0.08169266351467362,
176
- 0.08875695214840107
177
- ]
178
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
storage/__init__.py ADDED
File without changes
storage/package.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "cgae-0g-storage",
3
+ "version": "2.0.0",
4
+ "description": "0G Storage uploader for CGAE audit certificates",
5
+ "type": "module",
6
+ "private": true,
7
+ "scripts": {
8
+ "upload": "node upload_to_0g.mjs",
9
+ "check": "node -e \"import('@0gfoundation/0g-ts-sdk').then(m => console.log('SDK ok:', Object.keys(m))).catch(e => console.error('SDK missing:', e.message))\""
10
+ },
11
+ "dependencies": {
12
+ "@0gfoundation/0g-ts-sdk": "^0.7.0",
13
+ "ethers": "^6.0.0"
14
+ },
15
+ "engines": {
16
+ "node": ">=18.0.0"
17
+ }
18
+ }
storage/upload_to_0g.mjs ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CGAE 0G Storage — Audit Certificate Uploader
4
+ * ==============================================
5
+ * Uploads a JSON audit certificate to 0G decentralized storage
6
+ * and prints the resulting Merkle root hash to stdout.
7
+ *
8
+ * Usage:
9
+ * node upload_to_0g.mjs <file_path>
10
+ *
11
+ * Required env vars:
12
+ * ZG_PRIVATE_KEY — hex private key (no 0x prefix) of the funding wallet
13
+ *
14
+ * Optional env vars:
15
+ * ZG_RPC_URL — override EVM RPC (default: 0G testnet)
16
+ * ZG_INDEXER_RPC — override indexer RPC
17
+ *
18
+ * Output (stdout, JSON):
19
+ * { "rootHash": "0xabc...", "size": 1234, "ok": true }
20
+ *
21
+ * On error (stderr + exit 1):
22
+ * { "error": "...", "ok": false }
23
+ *
24
+ * Install deps (from storage/):
25
+ * npm install @0gfoundation/0g-ts-sdk ethers
26
+ */
27
+
28
+ import { readFileSync, statSync } from "fs";
29
+ import { resolve } from "path";
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // CLI
33
+ // ---------------------------------------------------------------------------
34
+
35
+ const args = process.argv.slice(2);
36
+ if (args.length === 0 || args[0] === "--help") {
37
+ console.error("Usage: node upload_to_0g.mjs <file_path>");
38
+ process.exit(1);
39
+ }
40
+
41
+ const filePath = resolve(args[0]);
42
+
43
+ // ---------------------------------------------------------------------------
44
+ // Environment
45
+ // ---------------------------------------------------------------------------
46
+
47
+ const privateKey = process.env.ZG_PRIVATE_KEY;
48
+ if (!privateKey) {
49
+ writeError("ZG_PRIVATE_KEY environment variable not set");
50
+ process.exit(1);
51
+ }
52
+
53
+ const RPC_URL = process.env.ZG_RPC_URL || "https://evmrpc-testnet.0g.ai";
54
+ const INDEXER_RPC = process.env.ZG_INDEXER_RPC || "https://indexer-storage-testnet-turbo.0g.ai";
55
+
56
+ // ---------------------------------------------------------------------------
57
+ // Main upload
58
+ // ---------------------------------------------------------------------------
59
+
60
+ async function main() {
61
+ let fileBytes;
62
+ let fileSize;
63
+ try {
64
+ fileBytes = readFileSync(filePath);
65
+ fileSize = statSync(filePath).size;
66
+ } catch (e) {
67
+ writeError(`Cannot read file: ${filePath} — ${e.message}`);
68
+ process.exit(1);
69
+ }
70
+
71
+ let Indexer, MemData, ethers;
72
+ try {
73
+ const zgSdk = await import("@0gfoundation/0g-ts-sdk");
74
+ Indexer = zgSdk.Indexer;
75
+ MemData = zgSdk.MemData;
76
+ ethers = await import("ethers");
77
+ } catch (e) {
78
+ writeError(
79
+ `Cannot load @0gfoundation/0g-ts-sdk or ethers. ` +
80
+ `Run: npm install @0gfoundation/0g-ts-sdk ethers (in storage/ directory)\n${e.message}`
81
+ );
82
+ process.exit(2); // Exit code 2 = SDK not installed (Python wrapper treats as soft fail)
83
+ }
84
+
85
+ const provider = new ethers.JsonRpcProvider(RPC_URL);
86
+ const signer = new ethers.Wallet(`0x${privateKey}`, provider);
87
+ const indexer = new Indexer(INDEXER_RPC);
88
+
89
+ console.error(`Uploading ${filePath} (${fileSize} bytes) to 0G Storage...`);
90
+
91
+ const file = new MemData(fileBytes);
92
+
93
+ let rootHash;
94
+ try {
95
+ const [hash, uploadErr] = await indexer.upload(file, RPC_URL, signer);
96
+ if (uploadErr) throw new Error(String(uploadErr));
97
+ rootHash = hash;
98
+ } catch (e) {
99
+ writeError(`Upload failed: ${e.message}`);
100
+ process.exit(1);
101
+ }
102
+
103
+ const output = {
104
+ ok: true,
105
+ rootHash: rootHash,
106
+ size: fileSize,
107
+ file: filePath,
108
+ rpc: RPC_URL,
109
+ indexer: INDEXER_RPC,
110
+ };
111
+ process.stdout.write(JSON.stringify(output) + "\n");
112
+ }
113
+
114
+ function writeError(msg) {
115
+ process.stderr.write(JSON.stringify({ ok: false, error: msg }) + "\n");
116
+ }
117
+
118
+ main().catch((e) => {
119
+ writeError(`Unexpected error: ${e.message}\n${e.stack}`);
120
+ process.exit(1);
121
+ });
storage/zg_store.py ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CGAE 0G Storage — Python Interface
3
+ ====================================
4
+ Uploads CGAE audit certificates to 0G decentralized storage via the
5
+ Node.js uploader script (storage/upload_to_0g.mjs).
6
+
7
+ 0G Storage returns a Merkle root hash (bytes32) as the content identifier,
8
+ which is stored on-chain in CGAERegistry.certify(). Anyone can verify by
9
+ downloading from 0G via the root hash and checking the Merkle proof.
10
+
11
+ Usage:
12
+ from storage.zg_store import ZgStore, StoreResult
13
+
14
+ store = ZgStore()
15
+ result = store.store_audit_result(model_name, audit_json_path)
16
+ print(result.root_hash) # "0xabc..." or deterministic fallback
17
+
18
+ 0G Integration:
19
+ Real uploads require:
20
+ 1. Node.js 18+ with `@0gfoundation/0g-ts-sdk` installed in storage/
21
+ 2. ZG_PRIVATE_KEY env var (hex, no 0x prefix)
22
+ 3. Wallet funded with testnet tokens from faucet.0g.ai
23
+
24
+ Without credentials the store falls back to a deterministic
25
+ content-addressed hash (SHA-256) so the pipeline always has a
26
+ root hash to work with. The 'real' field on StoreResult tells
27
+ callers which mode was used.
28
+
29
+ Network:
30
+ Default: 0G Testnet
31
+ EVM RPC: https://evmrpc-testnet.0g.ai
32
+ Indexer: https://indexer-storage-testnet-turbo.0g.ai
33
+ Scan: https://storagescan.0g.ai
34
+ """
35
+
36
+ from __future__ import annotations
37
+
38
+ import hashlib
39
+ import json
40
+ import logging
41
+ import os
42
+ import subprocess
43
+ from dataclasses import dataclass
44
+ from pathlib import Path
45
+ from typing import Optional
46
+
47
+ try:
48
+ from dotenv import load_dotenv
49
+ load_dotenv()
50
+ except ImportError:
51
+ pass
52
+
53
+ logger = logging.getLogger(__name__)
54
+
55
+ _STORAGE_DIR = Path(__file__).resolve().parent
56
+ _UPLOADER_SCRIPT = _STORAGE_DIR / "upload_to_0g.mjs"
57
+
58
+ ZG_RPC_URL = "https://evmrpc-testnet.0g.ai"
59
+ ZG_INDEXER_RPC = "https://indexer-storage-testnet-turbo.0g.ai"
60
+ ZG_STORAGE_SCAN = "https://storagescan.0g.ai"
61
+ ZG_FAUCET = "https://faucet.0g.ai"
62
+
63
+
64
+ @dataclass
65
+ class StoreResult:
66
+ """Result of a 0G Storage operation."""
67
+ root_hash: str # Merkle root hash (real) or sha256-derived (fallback)
68
+ real: bool # True = uploaded to 0G; False = fallback
69
+ model_name: str
70
+ file_path: str
71
+ size_bytes: int = 0
72
+ error: Optional[str] = None
73
+
74
+ @property
75
+ def scan_url(self) -> Optional[str]:
76
+ if self.real:
77
+ return f"{ZG_STORAGE_SCAN}/tx/{self.root_hash}"
78
+ return None
79
+
80
+ def to_dict(self) -> dict:
81
+ return {
82
+ "root_hash": self.root_hash,
83
+ "real": self.real,
84
+ "model_name": self.model_name,
85
+ "file_path": self.file_path,
86
+ "size_bytes": self.size_bytes,
87
+ "error": self.error,
88
+ "scan_url": self.scan_url,
89
+ }
90
+
91
+
92
+ class ZgStore:
93
+ """
94
+ Uploads audit JSON files to 0G decentralized storage.
95
+
96
+ Falls back to deterministic SHA-256 hash when upload is unavailable.
97
+ """
98
+
99
+ def __init__(
100
+ self,
101
+ private_key: Optional[str] = None,
102
+ node_cmd: Optional[str] = None,
103
+ fallback_ok: bool = True,
104
+ ):
105
+ self._private_key = private_key or os.getenv("ZG_PRIVATE_KEY")
106
+ self._node = node_cmd or _find_node()
107
+ self.fallback_ok = fallback_ok
108
+
109
+ def store_audit_result(self, model_name: str, json_path: str | Path) -> StoreResult:
110
+ json_path = Path(json_path)
111
+ if not json_path.exists():
112
+ raise FileNotFoundError(f"Audit file not found: {json_path}")
113
+
114
+ if self._can_upload():
115
+ try:
116
+ return self._upload_via_0g(model_name, json_path)
117
+ except Exception as e:
118
+ msg = str(e)
119
+ logger.warning(f" [0g] Upload failed for {model_name}: {msg}. Using fallback hash.")
120
+ if not self.fallback_ok:
121
+ raise
122
+ return self._fallback_result(model_name, json_path, error=msg)
123
+ else:
124
+ reason = self._unavailable_reason()
125
+ logger.info(f" [0g] Upload unavailable ({reason}). Using deterministic hash for {model_name}.")
126
+ return self._fallback_result(model_name, json_path, error=reason)
127
+
128
+ def _can_upload(self) -> bool:
129
+ return (
130
+ self._node is not None
131
+ and _UPLOADER_SCRIPT.exists()
132
+ and self._private_key is not None
133
+ )
134
+
135
+ def _unavailable_reason(self) -> str:
136
+ if self._node is None:
137
+ return "node.js not found in PATH"
138
+ if not _UPLOADER_SCRIPT.exists():
139
+ return f"uploader script missing: {_UPLOADER_SCRIPT}"
140
+ if self._private_key is None:
141
+ return "ZG_PRIVATE_KEY not set"
142
+ return "unknown"
143
+
144
+ def _upload_via_0g(self, model_name: str, json_path: Path) -> StoreResult:
145
+ env = {**os.environ}
146
+ if self._private_key:
147
+ env["ZG_PRIVATE_KEY"] = self._private_key
148
+
149
+ cmd = [self._node, str(_UPLOADER_SCRIPT), str(json_path)]
150
+
151
+ logger.info(f" [0g] Uploading {json_path.name} for {model_name}...")
152
+ proc = subprocess.run(cmd, capture_output=True, text=True, timeout=300, env=env)
153
+
154
+ if proc.returncode == 2:
155
+ raise RuntimeError(
156
+ "0G SDK not installed. Run: cd storage && npm install @0gfoundation/0g-ts-sdk ethers"
157
+ )
158
+
159
+ if proc.returncode != 0:
160
+ stderr = proc.stderr.strip()
161
+ try:
162
+ err_data = json.loads(stderr)
163
+ raise RuntimeError(err_data.get("error", stderr))
164
+ except (json.JSONDecodeError, KeyError):
165
+ raise RuntimeError(stderr or f"exit code {proc.returncode}")
166
+
167
+ data = json.loads(proc.stdout.strip())
168
+ if not data.get("ok"):
169
+ raise RuntimeError(data.get("error", "Unknown upload error"))
170
+
171
+ root_hash = data["rootHash"]
172
+ size = data.get("size", json_path.stat().st_size)
173
+
174
+ logger.info(f" [0g] Uploaded {json_path.name} → rootHash {root_hash} ({size} bytes)")
175
+ return StoreResult(
176
+ root_hash=root_hash, real=True, model_name=model_name,
177
+ file_path=str(json_path), size_bytes=size,
178
+ )
179
+
180
+ @staticmethod
181
+ def _fallback_result(model_name: str, json_path: Path, error: Optional[str] = None) -> StoreResult:
182
+ content = json_path.read_bytes()
183
+ digest = hashlib.sha256(content).hexdigest()
184
+ pseudo_hash = f"0x{digest}"
185
+ return StoreResult(
186
+ root_hash=pseudo_hash, real=False, model_name=model_name,
187
+ file_path=str(json_path), size_bytes=len(content), error=error,
188
+ )
189
+
190
+
191
+ def _find_node() -> Optional[str]:
192
+ for name in ["node", "nodejs"]:
193
+ try:
194
+ result = subprocess.run([name, "--version"], capture_output=True, text=True, timeout=5)
195
+ if result.returncode == 0:
196
+ return name
197
+ except (FileNotFoundError, subprocess.TimeoutExpired):
198
+ continue
199
+ return None
200
+
201
+
202
+ def check_setup() -> dict:
203
+ node = _find_node()
204
+ sdk_installed = False
205
+ if node:
206
+ nm = _STORAGE_DIR / "node_modules" / "@0gfoundation" / "0g-ts-sdk"
207
+ sdk_installed = nm.exists()
208
+ has_key = bool(os.getenv("ZG_PRIVATE_KEY"))
209
+ script_ok = _UPLOADER_SCRIPT.exists()
210
+ ready = node and sdk_installed and has_key and script_ok
211
+ return {
212
+ "ready": ready,
213
+ "node_found": node,
214
+ "sdk_installed": sdk_installed,
215
+ "private_key_set": has_key,
216
+ "uploader_script": script_ok,
217
+ "instructions": (
218
+ None if ready else
219
+ "To enable real 0G uploads:\n"
220
+ " 1. cd storage && npm install @0gfoundation/0g-ts-sdk ethers\n"
221
+ f" 2. Get testnet tokens: {ZG_FAUCET}\n"
222
+ " 3. export ZG_PRIVATE_KEY=<your_hex_private_key>\n"
223
+ " 4. Re-run the simulation"
224
+ ),
225
+ }
226
+
227
+
228
+ if __name__ == "__main__":
229
+ print(json.dumps(check_setup(), indent=2))