Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/CODEOWNERS → .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@

# Global:

* @OpenZeppelin/contracts-midnight-maintainers
* @OpenZeppelin/contracts-midnight-maintainers
SECURITY.md @OpenZeppelin/product-security @OpenZeppelin/contracts-midnight-maintainers
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Codebase improvement
about: Provide your feedback for the existing codebase. Suggest a better solution for algorithms, development tools, etc.
title: "dev: "
labels: "enhancement"
assignees: ""
---
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: OpenZeppelin Compact Tools Community Support
url: https://github.com/OpenZeppelin/compact-tools/discussions
about: Please ask and answer questions here.
138 changes: 138 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: "Setup Environment"
description: "Sets up the environment with yarn, Node.js, turbo, and Compact compiler"

inputs:
skip-compact:
description: "Skip Compact compiler installation"
required: false
default: "false"

outputs:
compact-home:
description: "Path to Compact compiler installation"
value: ${{ steps.compact-outputs.outputs.compact-home }}
compact-version:
description: "Installed Compact compiler version"
value: ${{ steps.compact-outputs.outputs.version }}

runs:
using: "composite"
steps:
- name: Set shared environment variables
shell: bash
run: |
echo "COMPILER_VERSION=0.26.0" >> $GITHUB_ENV
echo "LANGUAGE_VERSION=0.18.0" >> $GITHUB_ENV

- name: Get yarn cache directory path
shell: bash
run: corepack enable

- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ hashFiles('.turbo/*') }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-${{ hashFiles('.turbo/*') }}

- name: Cache Compact compiler
if: inputs.skip-compact != 'true'
uses: actions/cache@v4
id: compact-cache
with:
path: |
~/.local/bin/compact
key: compact-compiler-${{ env.COMPILER_VERSION }}-${{ runner.os }}

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"
cache: "yarn"

- name: Install dependencies
shell: bash
run: yarn install --immutable

- name: Install Turbo Globally
shell: bash
env:
TURBO_MAJOR_VERSION: 2
TURBO_TELEMETRY_DISABLED: 1
run: npm install turbo@${{ env.TURBO_MAJOR_VERSION }} -g

- name: Install Compact compiler
if: inputs.skip-compact != 'true' && steps.compact-cache.outputs.cache-hit != 'true'
shell: bash
run: |
set -euo pipefail
COMPACT_HOME="$HOME/.local/bin"
mkdir -p "$COMPACT_HOME"

# Require COMPACT_INSTALLER_URL to be provided by the caller
if [ -z "${COMPACT_INSTALLER_URL:-}" ]; then
echo "::error::COMPACT_INSTALLER_URL is required but not set. Provide it via env or secrets."
exit 1
fi

echo "🔧 Installing Compact compiler from $COMPACT_INSTALLER_URL ..."
curl --proto '=https' --tlsv1.2 -LsSf "$COMPACT_INSTALLER_URL" | sh

echo "🔧 Updating Compact compiler to $COMPILER_VERSION..."
"$COMPACT_HOME/compact" update "$COMPILER_VERSION"

echo "✅ Compact compiler installed"

- name: Setup Compact environment
if: inputs.skip-compact != 'true'
shell: bash
run: |
COMPACT_HOME="$HOME/.local/bin"
echo "📁 Setting Compact environment variables..."
echo "COMPACT_HOME=$COMPACT_HOME" >> "$GITHUB_ENV"
echo "$COMPACT_HOME" >> "$GITHUB_PATH"

if [ -f "$COMPACT_HOME/compact" ]; then
echo "✅ Compact compiler is installed at $COMPACT_HOME"
else
echo "::error::❌ Compact compiler not found in $COMPACT_HOME"
exit 1
fi

- name: Set Compact outputs
if: inputs.skip-compact != 'true'
id: compact-outputs
shell: bash
run: |
echo "compact-home=$HOME/.local/bin" >> $GITHUB_OUTPUT
echo "version=$COMPILER_VERSION" >> $GITHUB_OUTPUT

- name: Check compiler and language version
if: inputs.skip-compact != 'true'
shell: bash
run: |
set -euo pipefail

echo "🔧 Updating Compact compiler to $COMPILER_VERSION..."
"$COMPACT_HOME/compact" update "$COMPILER_VERSION"

echo "🔍 Checking Compact compiler version..."
COMPILER_OUTPUT=$("$COMPACT_HOME/compact" compile --version)
COMPUTED_COMPILER_VERSION=$(echo "$COMPILER_OUTPUT" | grep -oP '\b0\.[0-9]+\.[0-9]+\b' | head -n 1)

if [ "$COMPUTED_COMPILER_VERSION" != "$COMPILER_VERSION" ]; then
echo "::error::❌ Compiler version mismatch!%0AExpected: $COMPILER_VERSION%0AGot: $COMPUTED_COMPILER_VERSION"
exit 1
fi
echo "✅ Compiler version matches: $COMPUTED_COMPILER_VERSION"

echo "🔍 Checking Compact language version..."
LANGUAGE_OUTPUT=$("$COMPACT_HOME/compact" compile --language-version)
COMPUTED_LANGUAGE_VERSION=$(echo "$LANGUAGE_OUTPUT" | grep -oP '\b0\.[0-9]+\.[0-9]+\b' | tail -n 1)

if [ "$COMPUTED_LANGUAGE_VERSION" != "$LANGUAGE_VERSION" ]; then
echo "::error::❌ Language version mismatch!%0AExpected: $LANGUAGE_VERSION%0AGot: $COMPUTED_LANGUAGE_VERSION"
exit 1
fi
echo "✅ Language version matches: $COMPUTED_LANGUAGE_VERSION"
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
version: 2
# opt in to updates for ecosystems that are not yet GA.
enable-beta-ecosystems: true
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
groups:
actions-deps:
patterns:
- '*'
commit-message:
prefix: 'chore(deps): '

- package-ecosystem: npm
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 5
rebase-strategy: auto
36 changes: 36 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Format and Lint

env:
TURBO_TELEMETRY_DISABLED: 1

on:
pull_request:
push:
branches:
- main

jobs:
checks:
name: Run Checks
runs-on: ubuntu-24.04

env:
COMPACT_INSTALLER_URL: ${{ vars.COMPACT_INSTALLER_URL }}

steps:
- name: Check out code
uses: actions/checkout@v5
with:
fetch-depth: 2 # Recommended by turbo team

- name: Setup Environment
uses: ./.github/actions/setup

- name: Format & Lint
run: yarn fmt-and-lint:ci

- name: Run type checks
run: yarn types

- name: Run tests
run: yarn test
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Tools for compiling, building, and testing Compact smart contracts. This is a monorepo containing:

- `packages/compact`: CLI utilities to run the Compact compiler and builder
- `packages/cli`: CLI utilities to run the Compact compiler and builder
- `packages/simulator`: TypeScript simulator to run and test Compact contracts locally

## External usage (via git submodule until npm publish)
Expand All @@ -29,13 +29,13 @@ yarn --cwd tools/compact-tools build
yarn install

# Call the CLIs directly or via scripts
node compact-tools/packages/compact/dist/runCompiler.js --help
node compact-tools/packages/compact/dist/runBuilder.js --help
node compact-tools/packages/cli/dist/runCompiler.js --help
node compact-tools/packages/cli/dist/runBuilder.js --help
```

## Requirements

- Node.js >= 20 (root and `packages/compact`), >= 22 for `packages/simulator`
- Node.js >= 20 (root and `packages/cli`), >= 22 for `packages/simulator`
- Yarn 4 (Berry)
- Turbo
- Optional: Midnight Compact toolchain installed and available in `PATH`
Expand Down Expand Up @@ -85,13 +85,13 @@ yarn clean

## Packages

### `@openzeppelin/compact-tools-compact` (packages/compact)
### `@openzeppelin/compact-tools-cli` (packages/cli)

Utilities and CLIs around the Compact compiler and builder.

- Binaries provided:
- `compact-compiler` → `packages/compact/dist/runCompiler.js`
- `compact-builder` → `packages/compact/dist/runBuilder.js`
- `compact-compiler` → `packages/cli/dist/runCompiler.js`
- `compact-builder` → `packages/cli/dist/runBuilder.js`

Useful commands:

Expand All @@ -100,7 +100,7 @@ Useful commands:
yarn compact

# Or inside the package
cd packages/compact
cd packages/cli
yarn build # compile TypeScript
yarn test # run unit tests
yarn types # type-check only
Expand Down
11 changes: 3 additions & 8 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"!**/tsconfig*.json",
"!**/*.compact",
"!**/artifacts/**/*",
"!**/test-artifacts/**/*",
"!**/coverage/**/*",
"!**/dist/**/*",
"!**/reports/**/*"
Expand All @@ -23,9 +22,7 @@
"formatter": {
"enabled": true,
"indentStyle": "space",
"includes": [
"**"
]
"includes": ["**"]
},
"assist": {
"actions": {
Expand Down Expand Up @@ -96,9 +93,7 @@
"noConsole": {
"level": "error",
"options": {
"allow": [
"log"
]
"allow": ["log"]
}
}
},
Expand All @@ -115,4 +110,4 @@
"indentStyle": "space"
}
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"scripts": {
"build": "turbo run build --log-prefix=none",
"test": "turbo run test --filter=@openzeppelin/compact-tools-compact --log-prefix=none",
"test": "turbo run test --log-prefix=none",
"fmt-and-lint": "biome check . --changed",
"fmt-and-lint:fix": "biome check . --changed --write",
"fmt-and-lint:ci": "biome ci . --changed --no-errors-on-unmatched",
Expand Down
5 changes: 3 additions & 2 deletions packages/compact/package.json → packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@openzeppelin/compact-tools-compact",
"name": "@openzeppelin/compact-tools-cli",
"private": true,
"description": "Compiler and builder for Compact smart contracts",
"description": "CLI for compiling and building Compact smart contracts",
"version": "0.0.1",
"keywords": [
"compact",
"cli",
"compiler",
"builder",
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { exec } from 'node:child_process';
import { promisify } from 'node:util';
import chalk from 'chalk';
import ora, { type Ora } from 'ora';
import { CompactCompiler } from './Compiler.js';
import { isPromisifiedChildProcessError } from './types/errors.js';
import { CompactCompiler } from './Compiler.ts';
import { isPromisifiedChildProcessError } from './types/errors.ts';

// Promisified exec for async execution
const execAsync = promisify(exec);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import chalk from 'chalk';
import ora from 'ora';
import { CompactBuilder } from './Builder.js';
import { CompactBuilder } from './Builder.ts';

/**
* Executes the Compact builder CLI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import chalk from 'chalk';
import ora, { type Ora } from 'ora';
import { CompactCompiler } from './Compiler.js';
import { CompactCompiler } from './Compiler.ts';
import {
type CompilationError,
isPromisifiedChildProcessError,
} from './types/errors.js';
} from './types/errors.ts';

/**
* Executes the Compact compiler CLI with improved error handling and user feedback.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/simulator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export type {
ExtractImpureCircuits,
ExtractPureCircuits,
IContractSimulator,
IMinimalContract
IMinimalContract,
} from './types/index.js';
export type { BaseSimulatorOptions } from './types/Options.js';
4 changes: 2 additions & 2 deletions packages/simulator/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ test/
Test fixtures contain reusable components and resources shared across tests.
These help keep test files clean and consistent.

- `test-contracts/` – Smart contracts and associated simulators used exclusively for testing.
- `artifacts/` – Precompiled contract artifacts needed by tests.
- `sample-contracts/` – Smart contracts and associated simulators used exclusively for testing.
- `artifacts/` – Dynamically compiled contract artifacts (generated during test setup, not committed to git).
- `utils/` – Helper functions and common utilities for key encoding and keypair generation.

### 🔗 Integration Tests (`test/integration`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getRandomValues } from 'node:crypto';
import type { WitnessContext } from '@midnight-ntwrk/compact-runtime';
import type { Ledger } from '../../test-artifacts/SampleZOwnable/contract/index.cjs';
import type { Ledger } from '../../artifacts/SampleZOwnable/contract/index.cjs';

/**
* @description Interface defining the witness methods for SampleZOwnable operations.
Expand Down
Loading