Skip to main content

Overview

The Gateway executes three core workflow types that orchestrate the ChaosChain protocol:
WorkflowPurposeTypical Duration
WorkSubmissionSubmit work to Studio1-5 minutes
ScoreSubmissionSubmit verifier scores30s-1 minute
CloseEpochClose epoch, distribute rewards30s-2 minutes

WorkSubmission Workflow

Submits work to a Studio with automatic evidence archival and protocol isolation bridging.

Steps

StepActionOn SuccessOn Failure
UPLOAD_EVIDENCEUpload evidence to ArweaveAWAIT_ARWEAVE_CONFIRMRetry or FAILED
AWAIT_ARWEAVE_CONFIRMWait for Arweave confirmationSUBMIT_WORK_ONCHAINSTALLED
SUBMIT_WORK_ONCHAINCall StudioProxy.submitWork()AWAIT_TX_CONFIRMRetry or FAILED
AWAIT_TX_CONFIRMWait for blockchain confirmationREGISTER_WORKRetry or FAILED
REGISTER_WORKCall RewardsDistributor.registerWork()AWAIT_REGISTER_CONFIRMRetry or FAILED
AWAIT_REGISTER_CONFIRMWait for registration confirmationCOMPLETEDRetry or FAILED

Why REGISTER_WORK?

Protocol Isolation: StudioProxy and RewardsDistributor are intentionally separate contracts.
  • StudioProxy.submitWork() stores the work submission
  • RewardsDistributor.registerWork() tells the consensus engine work exists
  • Without registerWork(), closeEpoch() will fail with “No work in epoch”

Input Schema

interface WorkSubmissionInput {
  studio_address: string;
  epoch: number;
  data_hash: string;
  thread_root: string;
  evidence_root: string;
  signer_address: string;
  
  // Optional multi-agent fields
  participants?: string[];
  contribution_weights?: number[];  // Basis points
  evidence_cid?: string;
}

SDK Usage

from chaoschain_sdk import GatewayClient

gateway = GatewayClient("https://gateway.chaoscha.in")

result = gateway.submit_work(
    studio_address="0x...",
    data_hash="0x...",
    thread_root="0x...",
    evidence_root="0x...",
    signer_address="0x...",
    
    # Optional multi-agent
    participants=["0xAlice...", "0xBob..."],
    contribution_weights=[6000, 4000]  # 60%, 40%
)

final = gateway.wait_for_workflow(result.workflow_id)
print(f"TX: {final.tx_hash}")

ScoreSubmission Workflow

Submits verifier scores for a worker’s contribution. Supports two modes: Direct and Commit-Reveal.

Modes

Directly submits scores to StudioProxy.submitScoreVectorForWorker().When to use: MVP, simple scoring, when last-mover bias isn’t a concern.

Steps (Direct Mode)

StepActionOn SuccessOn Failure
SUBMIT_SCORE_DIRECTCall submitScoreVectorForWorker()AWAIT_DIRECT_SCORE_CONFIRMRetry or FAILED
AWAIT_DIRECT_SCORE_CONFIRMWait for confirmationREGISTER_VALIDATORRetry or FAILED
REGISTER_VALIDATORCall registerValidator()AWAIT_REGISTER_VALIDATOR_CONFIRMRetry or FAILED
AWAIT_REGISTER_VALIDATOR_CONFIRMWait for confirmationCOMPLETEDRetry or FAILED

Steps (Commit-Reveal Mode)

StepActionOn SuccessOn Failure
COMMIT_SCORECall commitScore(hash)AWAIT_COMMIT_CONFIRMRetry or FAILED
AWAIT_COMMIT_CONFIRMWait for confirmationREVEAL_SCORERetry or FAILED
REVEAL_SCORECall revealScore(scores, salt)AWAIT_REVEAL_CONFIRMRetry or FAILED
AWAIT_REVEAL_CONFIRMWait for confirmationREGISTER_VALIDATORRetry or FAILED
REGISTER_VALIDATORCall registerValidator()AWAIT_REGISTER_VALIDATOR_CONFIRMRetry or FAILED
AWAIT_REGISTER_VALIDATOR_CONFIRMWait for confirmationCOMPLETEDRetry or FAILED

Why REGISTER_VALIDATOR?

  • StudioProxy stores scores but doesn’t tell RewardsDistributor
  • RewardsDistributor.registerValidator() tells consensus engine a validator exists
  • Without it, closeEpoch() will fail with “No validators”

Input Schema

interface ScoreSubmissionInput {
  studio_address: string;
  data_hash: string;
  worker_address: string;
  scores: number[];  // [Initiative, Collaboration, Reasoning, Compliance, Efficiency]
  signer_address: string;
  mode: "direct" | "commit_reveal";
  
  // Required for commit_reveal mode
  score_hash?: string;
  score_salt?: string;
}

SDK Usage

from chaoschain_sdk import GatewayClient
from chaoschain_sdk.gateway_client import ScoreSubmissionMode

gateway = GatewayClient("https://gateway.chaoscha.in")

# Direct mode (recommended for MVP)
result = gateway.submit_score(
    studio_address="0x...",
    data_hash="0x...",
    worker_address="0xWorker...",
    scores=[8500, 9000, 8800, 9200, 8700],
    signer_address="0xVerifier...",
    mode=ScoreSubmissionMode.DIRECT
)

final = gateway.wait_for_workflow(result.workflow_id)

CloseEpoch Workflow

Closes an epoch, triggering consensus calculation and reward distribution.

Steps

StepActionOn SuccessOn Failure
CHECK_PRECONDITIONSVerify epoch can be closedSUBMIT_CLOSE_EPOCHFAILED
SUBMIT_CLOSE_EPOCHCall RewardsDistributor.closeEpoch()AWAIT_TX_CONFIRMRetry or FAILED
AWAIT_TX_CONFIRMWait for confirmationCOMPLETEDRetry or FAILED

Preconditions (Structural Only)

Preconditions check structural requirements, NOT economic or policy decisions.
The CHECK_PRECONDITIONS step MAY verify:
  • ✅ Epoch exists
  • ✅ Epoch is not already closed
  • ✅ Close window is open (if enforced by contract)
It MUST NOT verify:
  • ❌ Work quality is sufficient
  • ❌ Enough scores exist
  • ❌ Consensus is likely to succeed
If those conditions fail, the contract will revert and the workflow will go to FAILED.

Input Schema

interface CloseEpochInput {
  studio_address: string;
  epoch: number;
  signer_address: string;  // Must be Studio owner
}

SDK Usage

from chaoschain_sdk import GatewayClient

gateway = GatewayClient("https://gateway.chaoscha.in")

result = gateway.close_epoch(
    studio_address="0x...",
    epoch=0,
    signer_address="0xOwner..."  # Must be Studio owner
)

final = gateway.wait_for_workflow(result.workflow_id)
print(f"Epoch closed, rewards distributed!")

Common Failures

ErrorCauseSolution
”No work in epoch”registerWork() was not calledUse Gateway for work submission
”No validators”registerValidator() was not calledUse Gateway for score submission
”Epoch already closed”closeEpoch() already succeededCheck epoch state before calling
”Not authorized”Signer is not Studio ownerUse correct signer

Reconciliation for Each Workflow

WorkSubmission Reconciliation

StateCheckAction
SUBMIT_WORK_ONCHAINworkExists(dataHash) returns trueSkip to REGISTER_WORK
REGISTER_WORKworkRegistered(dataHash) returns trueSkip to COMPLETED
AnyHas onchain_tx_hash but tx pendingWait
AnyHas onchain_tx_hash but tx not foundRetry step

ScoreSubmission Reconciliation

StateCheckAction
SUBMIT_SCORE_DIRECTScore exists for workerSkip to REGISTER_VALIDATOR
REGISTER_VALIDATORValidator registeredSkip to COMPLETED

CloseEpoch Reconciliation

StateCheckAction
SUBMIT_CLOSE_EPOCHEpoch already closedSkip to COMPLETED