Skip to content

Methodology

justSid26 edited this page Apr 21, 2026 · 6 revisions

Methodology / Working

Step-by-Step Working

Step 1 — User Submits a Contract

The user provides a smart contract artifact (.sol or .wasm) through one of two interfaces:

  • CLI: using curl -F "file=@contract.wasm" http://localhost:3000/api/validate or curl -F "file=@ValidContract.sol" http://localhost:3000/api/validate
  • Web UI: by navigating to http://localhost:3001, clicking Validate, and selecting a .sol or .wasm file via the file picker

Step 2 — HTTP Request Received by Rust Server

The Rust backend (running on port 3000) receives a POST /api/validate request with the file as multipart/form-data. The server extracts the binary payload from the multipart stream.


Step 3 — Validation by Contract Type

The validation engine applies checks based on the selected contract type:

  1. Solidity path — Parses and validates Solidity input, and can return ABI/bytecode artifacts for deployment.
  2. WASM magic number check — Verifies CosmWasm binaries start with WASM magic bytes \0asm and valid version.
  3. WASM section parsing — Parses key WASM sections for structural correctness.
  4. CosmWasm interface/memory checks — Verifies required exports and memory constraints.
  5. Size validation — Records the binary size in bytes.

Step 4 — Response Construction

The validator returns a structured result to the HTTP handler, which serializes it to JSON:

// Valid contract
{ "valid": true,  "message": "WASM contract passed CosmWasm validation", "size_bytes": 134639 }

// Invalid contract
{ "valid": false, "message": "<error description>", "size_bytes": <n> }

Step 5 — Result Displayed

  • CLI users see the raw JSON in the terminal.
  • Web UI users see a formatted result card on the page indicating pass/fail, the message, and the contract size.

Algorithms Used

CosmWasm WASM Validation Algorithm (Pseudocode)

function validate(wasm_bytes):
    if wasm_bytes[0:4] != WASM_MAGIC:
        return { valid: false, message: "Not a valid WASM file" }

    sections = parse_wasm_sections(wasm_bytes)

    if not sections.has_valid_structure():
        return { valid: false, message: "Malformed WASM sections" }

    exports = sections.get_exports()
    required = ["instantiate", "execute", "query"]

    for entry_point in required:
        if entry_point not in exports:
            return { valid: false, message: "Missing required export: " + entry_point }

    if sections.memory_pages > MAX_MEMORY_PAGES:
        return { valid: false, message: "Memory exceeds CosmWasm limits" }

    return { valid: true, message: "WASM contract passed CosmWasm validation", size: len(wasm_bytes) }

Data Flow Diagram

[User / curl]
     │
     │  .wasm binary (multipart POST)
     ▼
[Rust HTTP Server — /api/validate]
     │
     │  raw bytes
     ▼
[WASM Binary Parser]
     ├── Magic number check ──────────────────────▶ FAIL → return error JSON
     ├── Section structure check ─────────────────▶ FAIL → return error JSON
     ├── CosmWasm export interface check ─────────▶ FAIL → return error JSON
     └── Memory limits check ─────────────────────▶ FAIL → return error JSON
     │
     │  all checks pass
     ▼
[Build success JSON response]
     │
     ▼
[Return to client: { valid, message, size_bytes }]

Flowchart

         ┌─────────────────────┐
         │  User uploads .wasm │
         └──────────┬──────────┘
                    │
         ┌──────────▼──────────┐
         │  POST /api/validate │
         └──────────┬──────────┘
                    │
         ┌──────────▼──────────┐
         │  Valid WASM magic?  │──── NO ────▶ { valid: false }
         └──────────┬──────────┘
                   YES
         ┌──────────▼──────────┐
         │  Valid sections?    │──── NO ────▶ { valid: false }
         └──────────┬──────────┘
                   YES
         ┌──────────▼────────────────┐
         │  CosmWasm exports present?│── NO ─▶ { valid: false }
         └──────────┬────────────────┘
                   YES
         ┌──────────▼──────────┐
         │  Memory within      │
         │  limits?            │──── NO ────▶ { valid: false }
         └──────────┬──────────┘
                   YES
         ┌──────────▼──────────┐
         │  { valid: true }    │
         └─────────────────────┘

Solidity Support, Wallet Connection, and Deployment

Solidity Contract Support

The platform also supports Solidity contract workflows in addition to CosmWasm validation. Users can select the Solidity mode from the frontend validator interface and upload .sol files. The frontend sends the selected file to the backend validation API through the same user flow. For Solidity responses, the backend can return compiled artifacts such as ABI and bytecode. This enables a continuous path from validation to deployment readiness inside one interface.

Wallet Connection Workflow

For Solidity and EVM-compatible deployment, wallet integration is handled through MetaMask. The UI provides a wallet connect button that requests account access from the browser wallet provider. Connected account state is retained in frontend context so deploy actions can use the active address. If no wallet is detected, the UI prevents deployment and prompts the user with a clear error. For CosmWasm workflows, Keplr wallet integration is used with explicit testnet chain configuration.

Contract Deployment Flow

After successful validation, users can trigger deployment from the file result row in the UI. For Solidity, deployment uses the returned bytecode and sends a transaction via eth_sendTransaction. The app then polls transaction receipt status until a contract address is available. When deployment succeeds, the deployed contract address is displayed in the interface. For CosmWasm, deployment follows upload and instantiate steps through SigningCosmWasmClient. This design keeps validation, wallet authorization, and deployment in one cohesive experience.

Operational Notes

Deployment actions are intentionally available only for contracts that pass validation first. This gating reduces accidental deployment of malformed or unverified contract artifacts. Wallet-related failures are reported to the user to support quick recovery and retries. Using this combined flow improves developer productivity during local testing and demos.

Clone this wiki locally