Skip to main content

The Contract

pragma language_version 0.16;

import CompactStandardLibrary;

// Unsigned integers - bounded type
export ledger counter: Uint<0..1000>;

// Unsigned integers - sized type (32 bits)
export ledger balance: Uint<32>;

// Field element for ZK computations
export ledger commitment: Field;

// Fixed-length byte array
export ledger hash: Bytes<32>;

// Opaque type for private data
export ledger secretValue: Opaque<"string">;

export circuit updateCounter(newValue: Uint<0..1000>): [] {
  disclose(counter = newValue);
}

export circuit updateBalance(amount: Uint<32>): [] {
  disclose(balance = balance + amount);
}

export circuit storeCommitment(value: Field): [] {
  disclose(commitment = value);
}

export circuit storeHash(data: Bytes<32>): [] {
  disclose(hash = data);
}

export circuit updateSecret(secret: Opaque<"string">): [] {
  disclose(secretValue = secret);
}

How It Works

Unsigned Integer Types - Bounded

export ledger counter: Uint<0..1000>;
Uint<m..n> represents values from m to n (inclusive). Lower bound must be 0.

Unsigned Integer Types - Sized

export ledger balance: Uint<32>;
Uint<n> uses up to n bits, equivalent to Uint<0..(2^n - 1)>.

Field Type

export ledger commitment: Field;
Elements in the scalar prime field for zero-knowledge computations. Arithmetic wraps around (modulo).

Bytes Type

export ledger hash: Bytes<32>;
Fixed-length byte arrays. Bytes<n> for exactly n bytes.

Opaque Types

export ledger secretValue: Opaque<"string">;
Values opaque to circuits, represented by their hash. For private data.

Boolean Type

const flag: Boolean = true;
Two values: true and false.

What’s Next