diff --git a/.github/ISSUE_TEMPLATE/CODEOWNERS b/.github/CODEOWNERS similarity index 77% rename from .github/ISSUE_TEMPLATE/CODEOWNERS rename to .github/CODEOWNERS index 47dbba6..4d3993e 100644 --- a/.github/ISSUE_TEMPLATE/CODEOWNERS +++ b/.github/CODEOWNERS @@ -13,4 +13,5 @@ # Global: -* @OpenZeppelin/contracts-midnight-maintainers +* @OpenZeppelin/contracts-midnight-maintainers +SECURITY.md @OpenZeppelin/product-security @OpenZeppelin/contracts-midnight-maintainers \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/01_bug_report.md similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_report.md rename to .github/ISSUE_TEMPLATE/01_bug_report.md diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md similarity index 100% rename from .github/ISSUE_TEMPLATE/feature_request.md rename to .github/ISSUE_TEMPLATE/02_FEATURE_REQUEST.md diff --git a/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md b/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md new file mode 100644 index 0000000..a4fd902 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md @@ -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: "" +--- \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..b6fdaf2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -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. diff --git a/.github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from .github/ISSUE_TEMPLATE/PULL_REQUEST_TEMPLATE.md rename to .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml new file mode 100644 index 0000000..dbdd503 --- /dev/null +++ b/.github/actions/setup/action.yml @@ -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" diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9106f1b --- /dev/null +++ b/.github/dependabot.yml @@ -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 diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..e9eb238 --- /dev/null +++ b/.github/workflows/checks.yml @@ -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 diff --git a/README.md b/README.md index 1d9add4..309be9f 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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` @@ -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: @@ -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 diff --git a/biome.json b/biome.json index 1851a12..09fbd92 100644 --- a/biome.json +++ b/biome.json @@ -14,7 +14,6 @@ "!**/tsconfig*.json", "!**/*.compact", "!**/artifacts/**/*", - "!**/test-artifacts/**/*", "!**/coverage/**/*", "!**/dist/**/*", "!**/reports/**/*" @@ -23,9 +22,7 @@ "formatter": { "enabled": true, "indentStyle": "space", - "includes": [ - "**" - ] + "includes": ["**"] }, "assist": { "actions": { @@ -96,9 +93,7 @@ "noConsole": { "level": "error", "options": { - "allow": [ - "log" - ] + "allow": ["log"] } } }, @@ -115,4 +110,4 @@ "indentStyle": "space" } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 093ebf3..7850f19 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/compact/package.json b/packages/cli/package.json similarity index 85% rename from packages/compact/package.json rename to packages/cli/package.json index 580aa33..a32b0bb 100644 --- a/packages/compact/package.json +++ b/packages/cli/package.json @@ -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" diff --git a/packages/compact/src/Builder.ts b/packages/cli/src/Builder.ts similarity index 98% rename from packages/compact/src/Builder.ts rename to packages/cli/src/Builder.ts index 43c2f40..6b0204e 100755 --- a/packages/compact/src/Builder.ts +++ b/packages/cli/src/Builder.ts @@ -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); diff --git a/packages/compact/src/Compiler.ts b/packages/cli/src/Compiler.ts similarity index 100% rename from packages/compact/src/Compiler.ts rename to packages/cli/src/Compiler.ts diff --git a/packages/compact/src/runBuilder.ts b/packages/cli/src/runBuilder.ts similarity index 96% rename from packages/compact/src/runBuilder.ts rename to packages/cli/src/runBuilder.ts index 8a9391d..c65e000 100644 --- a/packages/compact/src/runBuilder.ts +++ b/packages/cli/src/runBuilder.ts @@ -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. diff --git a/packages/compact/src/runCompiler.ts b/packages/cli/src/runCompiler.ts similarity index 98% rename from packages/compact/src/runCompiler.ts rename to packages/cli/src/runCompiler.ts index eebd491..b97200f 100644 --- a/packages/compact/src/runCompiler.ts +++ b/packages/cli/src/runCompiler.ts @@ -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. diff --git a/packages/compact/src/types/errors.ts b/packages/cli/src/types/errors.ts similarity index 100% rename from packages/compact/src/types/errors.ts rename to packages/cli/src/types/errors.ts diff --git a/packages/compact/test/Compiler.test.ts b/packages/cli/test/Compiler.test.ts similarity index 100% rename from packages/compact/test/Compiler.test.ts rename to packages/cli/test/Compiler.test.ts diff --git a/packages/compact/test/runCompiler.test.ts b/packages/cli/test/runCompiler.test.ts similarity index 100% rename from packages/compact/test/runCompiler.test.ts rename to packages/cli/test/runCompiler.test.ts diff --git a/packages/compact/tsconfig.json b/packages/cli/tsconfig.json similarity index 100% rename from packages/compact/tsconfig.json rename to packages/cli/tsconfig.json diff --git a/packages/compact/turbo.json b/packages/cli/turbo.json similarity index 100% rename from packages/compact/turbo.json rename to packages/cli/turbo.json diff --git a/packages/compact/vitest.config.ts b/packages/cli/vitest.config.ts similarity index 100% rename from packages/compact/vitest.config.ts rename to packages/cli/vitest.config.ts diff --git a/packages/simulator/src/index.ts b/packages/simulator/src/index.ts index 9785188..59523ed 100644 --- a/packages/simulator/src/index.ts +++ b/packages/simulator/src/index.ts @@ -9,6 +9,6 @@ export type { ExtractImpureCircuits, ExtractPureCircuits, IContractSimulator, - IMinimalContract + IMinimalContract, } from './types/index.js'; export type { BaseSimulatorOptions } from './types/Options.js'; diff --git a/packages/simulator/test/README.md b/packages/simulator/test/README.md index 96754a6..444e58e 100644 --- a/packages/simulator/test/README.md +++ b/packages/simulator/test/README.md @@ -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`) diff --git a/packages/simulator/test/fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.ts b/packages/simulator/test/fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.ts index 996e9cb..a4140ee 100644 --- a/packages/simulator/test/fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.ts +++ b/packages/simulator/test/fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.ts @@ -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. diff --git a/packages/simulator/test/fixtures/sample-contracts/witnesses/WitnessWitnesses.ts b/packages/simulator/test/fixtures/sample-contracts/witnesses/WitnessWitnesses.ts index 32f1242..fa2fc4c 100644 --- a/packages/simulator/test/fixtures/sample-contracts/witnesses/WitnessWitnesses.ts +++ b/packages/simulator/test/fixtures/sample-contracts/witnesses/WitnessWitnesses.ts @@ -1,6 +1,6 @@ import { getRandomValues } from 'node:crypto'; import type { WitnessContext } from '@midnight-ntwrk/compact-runtime'; -import type { Ledger } from '../../test-artifacts/Witness/contract/index.cjs'; +import type { Ledger } from '../../artifacts/Witness/contract/index.cjs'; const randomBigInt = (bits: number): bigint => { const bytes = Math.ceil(bits / 8); diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/compiler/contract-info.json b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/compiler/contract-info.json deleted file mode 100644 index 15dffd5..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/compiler/contract-info.json +++ /dev/null @@ -1,155 +0,0 @@ -{ - "circuits": [ - { - "name": "owner", - "pure": false, - "arguments": [ - ], - "result-type": { - "type-name": "Bytes", - "length": 32 - } - }, - { - "name": "transferOwnership", - "pure": false, - "arguments": [ - { - "name": "newOwnerId", - "type": { - "type-name": "Bytes", - "length": 32 - } - } - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - }, - { - "name": "renounceOwnership", - "pure": false, - "arguments": [ - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - }, - { - "name": "assertOnlyOwner", - "pure": false, - "arguments": [ - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - }, - { - "name": "_computeOwnerCommitment", - "pure": false, - "arguments": [ - { - "name": "id", - "type": { - "type-name": "Bytes", - "length": 32 - } - }, - { - "name": "counter", - "type": { - "type-name": "Uint", - "maxval": 18446744073709551615 - } - } - ], - "result-type": { - "type-name": "Bytes", - "length": 32 - } - }, - { - "name": "_computeOwnerId", - "pure": true, - "arguments": [ - { - "name": "pk", - "type": { - "type-name": "Struct", - "name": "Either", - "elements": [ - { - "name": "is_left", - "type": { - "type-name": "Boolean" - } - }, - { - "name": "left", - "type": { - "type-name": "Struct", - "name": "ZswapCoinPublicKey", - "elements": [ - { - "name": "bytes", - "type": { - "type-name": "Bytes", - "length": 32 - } - } - ] - } - }, - { - "name": "right", - "type": { - "type-name": "Struct", - "name": "ContractAddress", - "elements": [ - { - "name": "bytes", - "type": { - "type-name": "Bytes", - "length": 32 - } - } - ] - } - } - ] - } - }, - { - "name": "nonce", - "type": { - "type-name": "Bytes", - "length": 32 - } - } - ], - "result-type": { - "type-name": "Bytes", - "length": 32 - } - } - ], - "witnesses": [ - { - "name": "secretNonce", - "arguments": [ - ], - "result type": { - "type-name": "Bytes", - "length": 32 - } - } - ], - "contracts": [ - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.cjs b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.cjs deleted file mode 100644 index b0606b6..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.cjs +++ /dev/null @@ -1,670 +0,0 @@ -'use strict'; -const __compactRuntime = require('@midnight-ntwrk/compact-runtime'); -const expectedRuntimeVersionString = '0.9.0'; -const expectedRuntimeVersion = expectedRuntimeVersionString.split('-')[0].split('.').map(Number); -const actualRuntimeVersion = __compactRuntime.versionString.split('-')[0].split('.').map(Number); -if (expectedRuntimeVersion[0] != actualRuntimeVersion[0] - || (actualRuntimeVersion[0] == 0 && expectedRuntimeVersion[1] != actualRuntimeVersion[1]) - || expectedRuntimeVersion[1] > actualRuntimeVersion[1] - || (expectedRuntimeVersion[1] == actualRuntimeVersion[1] && expectedRuntimeVersion[2] > actualRuntimeVersion[2])) - throw new __compactRuntime.CompactError(`Version mismatch: compiled code expects ${expectedRuntimeVersionString}, runtime is ${__compactRuntime.versionString}`); -{ const MAX_FIELD = 52435875175126190479447740508185965837690552500527637822603658699938581184512n; - if (__compactRuntime.MAX_FIELD !== MAX_FIELD) - throw new __compactRuntime.CompactError(`compiler thinks maximum field value is ${MAX_FIELD}; run time thinks it is ${__compactRuntime.MAX_FIELD}`) -} - -const _descriptor_0 = new __compactRuntime.CompactTypeBoolean(); - -const _descriptor_1 = new __compactRuntime.CompactTypeBytes(32); - -class _ZswapCoinPublicKey_0 { - alignment() { - return _descriptor_1.alignment(); - } - fromValue(value_0) { - return { - bytes: _descriptor_1.fromValue(value_0) - } - } - toValue(value_0) { - return _descriptor_1.toValue(value_0.bytes); - } -} - -const _descriptor_2 = new _ZswapCoinPublicKey_0(); - -class _ContractAddress_0 { - alignment() { - return _descriptor_1.alignment(); - } - fromValue(value_0) { - return { - bytes: _descriptor_1.fromValue(value_0) - } - } - toValue(value_0) { - return _descriptor_1.toValue(value_0.bytes); - } -} - -const _descriptor_3 = new _ContractAddress_0(); - -class _Either_0 { - alignment() { - return _descriptor_0.alignment().concat(_descriptor_2.alignment().concat(_descriptor_3.alignment())); - } - fromValue(value_0) { - return { - is_left: _descriptor_0.fromValue(value_0), - left: _descriptor_2.fromValue(value_0), - right: _descriptor_3.fromValue(value_0) - } - } - toValue(value_0) { - return _descriptor_0.toValue(value_0.is_left).concat(_descriptor_2.toValue(value_0.left).concat(_descriptor_3.toValue(value_0.right))); - } -} - -const _descriptor_4 = new _Either_0(); - -const _descriptor_5 = new __compactRuntime.CompactTypeUnsignedInteger(65535n, 2); - -const _descriptor_6 = new __compactRuntime.CompactTypeUnsignedInteger(18446744073709551615n, 8); - -const _descriptor_7 = new __compactRuntime.CompactTypeVector(2, _descriptor_1); - -const _descriptor_8 = new __compactRuntime.CompactTypeVector(4, _descriptor_1); - -const _descriptor_9 = new __compactRuntime.CompactTypeUnsignedInteger(255n, 1); - -const _descriptor_10 = new __compactRuntime.CompactTypeUnsignedInteger(340282366920938463463374607431768211455n, 16); - -class Contract { - witnesses; - constructor(...args_0) { - if (args_0.length !== 1) { - throw new __compactRuntime.CompactError(`Contract constructor: expected 1 argument, received ${args_0.length}`); - } - const witnesses_0 = args_0[0]; - if (typeof(witnesses_0) !== 'object') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor is not an object'); - } - if (typeof(witnesses_0.secretNonce) !== 'function') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor does not contain a function-valued field named secretNonce'); - } - this.witnesses = witnesses_0; - this.circuits = { - owner: (...args_1) => { - if (args_1.length !== 1) { - throw new __compactRuntime.CompactError(`owner: expected 1 argument (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('owner', - 'argument 1 (as invoked from Typescript)', - 'SampleZOwnable.compact line 21 char 1', - 'CircuitContext', - contextOrig_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._owner_0(context, partialProofData); - partialProofData.output = { value: _descriptor_1.toValue(result_0), alignment: _descriptor_1.alignment() }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - transferOwnership: (...args_1) => { - if (args_1.length !== 2) { - throw new __compactRuntime.CompactError(`transferOwnership: expected 2 arguments (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - const newOwnerId_0 = args_1[1]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('transferOwnership', - 'argument 1 (as invoked from Typescript)', - 'SampleZOwnable.compact line 25 char 1', - 'CircuitContext', - contextOrig_0) - } - if (!(newOwnerId_0.buffer instanceof ArrayBuffer && newOwnerId_0.BYTES_PER_ELEMENT === 1 && newOwnerId_0.length === 32)) { - __compactRuntime.type_error('transferOwnership', - 'argument 1 (argument 2 as invoked from Typescript)', - 'SampleZOwnable.compact line 25 char 1', - 'Bytes<32>', - newOwnerId_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { - value: _descriptor_1.toValue(newOwnerId_0), - alignment: _descriptor_1.alignment() - }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._transferOwnership_0(context, - partialProofData, - newOwnerId_0); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - renounceOwnership: (...args_1) => { - if (args_1.length !== 1) { - throw new __compactRuntime.CompactError(`renounceOwnership: expected 1 argument (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('renounceOwnership', - 'argument 1 (as invoked from Typescript)', - 'SampleZOwnable.compact line 31 char 1', - 'CircuitContext', - contextOrig_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._renounceOwnership_0(context, partialProofData); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - assertOnlyOwner: (...args_1) => { - if (args_1.length !== 1) { - throw new __compactRuntime.CompactError(`assertOnlyOwner: expected 1 argument (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('assertOnlyOwner', - 'argument 1 (as invoked from Typescript)', - 'SampleZOwnable.compact line 36 char 1', - 'CircuitContext', - contextOrig_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._assertOnlyOwner_0(context, partialProofData); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - _computeOwnerCommitment: (...args_1) => { - if (args_1.length !== 3) { - throw new __compactRuntime.CompactError(`_computeOwnerCommitment: expected 3 arguments (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - const id_0 = args_1[1]; - const counter_0 = args_1[2]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('_computeOwnerCommitment', - 'argument 1 (as invoked from Typescript)', - 'SampleZOwnable.compact line 47 char 1', - 'CircuitContext', - contextOrig_0) - } - if (!(id_0.buffer instanceof ArrayBuffer && id_0.BYTES_PER_ELEMENT === 1 && id_0.length === 32)) { - __compactRuntime.type_error('_computeOwnerCommitment', - 'argument 1 (argument 2 as invoked from Typescript)', - 'SampleZOwnable.compact line 47 char 1', - 'Bytes<32>', - id_0) - } - if (!(typeof(counter_0) === 'bigint' && counter_0 >= 0n && counter_0 <= 18446744073709551615n)) { - __compactRuntime.type_error('_computeOwnerCommitment', - 'argument 2 (argument 3 as invoked from Typescript)', - 'SampleZOwnable.compact line 47 char 1', - 'Uint<0..18446744073709551615>', - counter_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { - value: _descriptor_1.toValue(id_0).concat(_descriptor_6.toValue(counter_0)), - alignment: _descriptor_1.alignment().concat(_descriptor_6.alignment()) - }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this.__computeOwnerCommitment_0(context, - partialProofData, - id_0, - counter_0); - partialProofData.output = { value: _descriptor_1.toValue(result_0), alignment: _descriptor_1.alignment() }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - _computeOwnerId(context, ...args_1) { - return { result: pureCircuits._computeOwnerId(...args_1), context }; - } - }; - this.impureCircuits = { - owner: this.circuits.owner, - transferOwnership: this.circuits.transferOwnership, - renounceOwnership: this.circuits.renounceOwnership, - assertOnlyOwner: this.circuits.assertOnlyOwner, - _computeOwnerCommitment: this.circuits._computeOwnerCommitment - }; - } - initialState(...args_0) { - if (args_0.length !== 3) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 3 arguments (as invoked from Typescript), received ${args_0.length}`); - } - const constructorContext_0 = args_0[0]; - const ownerId_0 = args_0[1]; - const instanceSalt_0 = args_0[2]; - if (typeof(constructorContext_0) !== 'object') { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'constructorContext' in argument 1 (as invoked from Typescript) to be an object`); - } - if (!('initialPrivateState' in constructorContext_0)) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialPrivateState' in argument 1 (as invoked from Typescript)`); - } - if (!('initialZswapLocalState' in constructorContext_0)) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialZswapLocalState' in argument 1 (as invoked from Typescript)`); - } - if (typeof(constructorContext_0.initialZswapLocalState) !== 'object') { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialZswapLocalState' in argument 1 (as invoked from Typescript) to be an object`); - } - if (!(ownerId_0.buffer instanceof ArrayBuffer && ownerId_0.BYTES_PER_ELEMENT === 1 && ownerId_0.length === 32)) { - __compactRuntime.type_error('Contract state constructor', - 'argument 1 (argument 2 as invoked from Typescript)', - 'SampleZOwnable.compact line 15 char 1', - 'Bytes<32>', - ownerId_0) - } - if (!(instanceSalt_0.buffer instanceof ArrayBuffer && instanceSalt_0.BYTES_PER_ELEMENT === 1 && instanceSalt_0.length === 32)) { - __compactRuntime.type_error('Contract state constructor', - 'argument 2 (argument 3 as invoked from Typescript)', - 'SampleZOwnable.compact line 15 char 1', - 'Bytes<32>', - instanceSalt_0) - } - const state_0 = new __compactRuntime.ContractState(); - let stateValue_0 = __compactRuntime.StateValue.newArray(); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - state_0.data = stateValue_0; - state_0.setOperation('owner', new __compactRuntime.ContractOperation()); - state_0.setOperation('transferOwnership', new __compactRuntime.ContractOperation()); - state_0.setOperation('renounceOwnership', new __compactRuntime.ContractOperation()); - state_0.setOperation('assertOnlyOwner', new __compactRuntime.ContractOperation()); - state_0.setOperation('_computeOwnerCommitment', new __compactRuntime.ContractOperation()); - const context = { - originalState: state_0, - currentPrivateState: constructorContext_0.initialPrivateState, - currentZswapLocalState: constructorContext_0.initialZswapLocalState, - transactionContext: new __compactRuntime.QueryContext(state_0.data, __compactRuntime.dummyContractAddress()) - }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_9.toValue(0n), - alignment: _descriptor_9.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(new Uint8Array(32)), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_9.toValue(1n), - alignment: _descriptor_9.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(0n), - alignment: _descriptor_6.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_9.toValue(2n), - alignment: _descriptor_9.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(new Uint8Array(32)), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - __compactRuntime.assert(!this._equal_0(ownerId_0, new Uint8Array(32)), - 'SampleZOwnable: invalid id'); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_9.toValue(2n), - alignment: _descriptor_9.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(instanceSalt_0), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - this.__transferOwnership_0(context, partialProofData, ownerId_0); - state_0.data = context.transactionContext.state; - return { - currentContractState: state_0, - currentPrivateState: context.currentPrivateState, - currentZswapLocalState: context.currentZswapLocalState - } - } - _persistentHash_0(value_0) { - const result_0 = __compactRuntime.persistentHash(_descriptor_8, value_0); - return result_0; - } - _persistentHash_1(value_0) { - const result_0 = __compactRuntime.persistentHash(_descriptor_7, value_0); - return result_0; - } - _ownPublicKey_0(context, partialProofData) { - const result_0 = __compactRuntime.ownPublicKey(context); - partialProofData.privateTranscriptOutputs.push({ - value: _descriptor_2.toValue(result_0), - alignment: _descriptor_2.alignment() - }); - return result_0; - } - _secretNonce_0(context, partialProofData) { - const witnessContext_0 = __compactRuntime.witnessContext(ledger(context.transactionContext.state), context.currentPrivateState, context.transactionContext.address); - const [nextPrivateState_0, result_0] = this.witnesses.secretNonce(witnessContext_0); - context.currentPrivateState = nextPrivateState_0; - if (!(result_0.buffer instanceof ArrayBuffer && result_0.BYTES_PER_ELEMENT === 1 && result_0.length === 32)) { - __compactRuntime.type_error('secretNonce', - 'return value', - 'SampleZOwnable.compact line 13 char 1', - 'Bytes<32>', - result_0) - } - partialProofData.privateTranscriptOutputs.push({ - value: _descriptor_1.toValue(result_0), - alignment: _descriptor_1.alignment() - }); - return result_0; - } - _owner_0(context, partialProofData) { - return _descriptor_1.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(0n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - } - _transferOwnership_0(context, partialProofData, newOwnerId_0) { - this._assertOnlyOwner_0(context, partialProofData); - __compactRuntime.assert(!this._equal_1(newOwnerId_0, new Uint8Array(32)), - 'SampleZOwnable: invalid id'); - this.__transferOwnership_0(context, partialProofData, newOwnerId_0); - return []; - } - _renounceOwnership_0(context, partialProofData) { - this._assertOnlyOwner_0(context, partialProofData); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_9.toValue(0n), - alignment: _descriptor_9.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(new Uint8Array(32)), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - return []; - } - _assertOnlyOwner_0(context, partialProofData) { - const nonce_0 = this._secretNonce_0(context, partialProofData); - const callerAsEither_0 = { is_left: true, - left: - this._ownPublicKey_0(context, partialProofData), - right: - { bytes: - new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) } }; - const id_0 = this.__computeOwnerId_0(callerAsEither_0, nonce_0); - __compactRuntime.assert(this._equal_2(_descriptor_1.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(0n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value), - this.__computeOwnerCommitment_0(context, - partialProofData, - id_0, - _descriptor_6.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(1n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: true, - result: undefined } }]).value))), - 'SampleZOwnable: caller is not the owner'); - return []; - } - __computeOwnerCommitment_0(context, partialProofData, id_0, counter_0) { - const value_0 = _descriptor_1.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(2n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - return this._persistentHash_0([id_0, - value_0, - __compactRuntime.convertFieldToBytes(32, - counter_0, - 'SampleZOwnable.compact line 56 char 7'), - new Uint8Array([83, 97, 109, 112, 108, 101, 90, 79, 119, 110, 97, 98, 108, 101, 58, 115, 104, 105, 101, 108, 100, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])]); - } - __computeOwnerId_0(pk_0, nonce_0) { - __compactRuntime.assert(pk_0.is_left, - 'SampleZOwnable: contract address owners are not yet supported'); - return this._persistentHash_1([pk_0.left.bytes, nonce_0]); - } - __transferOwnership_0(context, partialProofData, newOwnerId_0) { - const tmp_0 = 1n; - Contract._query(context, - partialProofData, - [ - { idx: { cached: false, - pushPath: true, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(1n), - alignment: _descriptor_9.alignment() } }] } }, - { addi: { immediate: parseInt(__compactRuntime.valueToBigInt( - { value: _descriptor_5.toValue(tmp_0), - alignment: _descriptor_5.alignment() } - .value - )) } }, - { ins: { cached: true, n: 1 } }]); - const tmp_1 = this.__computeOwnerCommitment_0(context, - partialProofData, - newOwnerId_0, - _descriptor_6.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(1n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: true, - result: undefined } }]).value)); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_9.toValue(0n), - alignment: _descriptor_9.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(tmp_1), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - return []; - } - _equal_0(x0, y0) { - if (!x0.every((x, i) => y0[i] === x)) { return false; } - return true; - } - _equal_1(x0, y0) { - if (!x0.every((x, i) => y0[i] === x)) { return false; } - return true; - } - _equal_2(x0, y0) { - if (!x0.every((x, i) => y0[i] === x)) { return false; } - return true; - } - static _query(context, partialProofData, prog) { - var res; - try { - res = context.transactionContext.query(prog, __compactRuntime.CostModel.dummyCostModel()); - } catch (err) { - throw new __compactRuntime.CompactError(err.toString()); - } - context.transactionContext = res.context; - var reads = res.events.filter((e) => e.tag === 'read'); - var i = 0; - partialProofData.publicTranscript = partialProofData.publicTranscript.concat(prog.map((op) => { - if(typeof(op) === 'object' && 'popeq' in op) { - return { popeq: { - ...op.popeq, - result: reads[i++].content, - } }; - } else { - return op; - } - })); - if(res.events.length == 1 && res.events[0].tag === 'read') { - return res.events[0].content; - } else { - return res.events; - } - } -} -function ledger(state) { - const context = { - originalState: state, - transactionContext: new __compactRuntime.QueryContext(state, __compactRuntime.dummyContractAddress()) - }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - return { - get _ownerCommitment() { - return _descriptor_1.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(0n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - }, - get _counter() { - return _descriptor_6.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(1n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: true, - result: undefined } }]).value); - }, - get _instanceSalt() { - return _descriptor_1.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_9.toValue(2n), - alignment: _descriptor_9.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - } - }; -} -const _emptyContext = { - originalState: new __compactRuntime.ContractState(), - transactionContext: new __compactRuntime.QueryContext(new __compactRuntime.ContractState().data, __compactRuntime.dummyContractAddress()) -}; -const _dummyContract = new Contract({ secretNonce: (...args) => undefined }); -const pureCircuits = { - _computeOwnerId: (...args_0) => { - if (args_0.length !== 2) { - throw new __compactRuntime.CompactError(`_computeOwnerId: expected 2 arguments (as invoked from Typescript), received ${args_0.length}`); - } - const pk_0 = args_0[0]; - const nonce_0 = args_0[1]; - if (!(typeof(pk_0) === 'object' && typeof(pk_0.is_left) === 'boolean' && typeof(pk_0.left) === 'object' && pk_0.left.bytes.buffer instanceof ArrayBuffer && pk_0.left.bytes.BYTES_PER_ELEMENT === 1 && pk_0.left.bytes.length === 32 && typeof(pk_0.right) === 'object' && pk_0.right.bytes.buffer instanceof ArrayBuffer && pk_0.right.bytes.BYTES_PER_ELEMENT === 1 && pk_0.right.bytes.length === 32)) { - __compactRuntime.type_error('_computeOwnerId', - 'argument 1', - 'SampleZOwnable.compact line 62 char 1', - 'struct Either>, right: struct ContractAddress>>', - pk_0) - } - if (!(nonce_0.buffer instanceof ArrayBuffer && nonce_0.BYTES_PER_ELEMENT === 1 && nonce_0.length === 32)) { - __compactRuntime.type_error('_computeOwnerId', - 'argument 2', - 'SampleZOwnable.compact line 62 char 1', - 'Bytes<32>', - nonce_0) - } - return _dummyContract.__computeOwnerId_0(pk_0, nonce_0); - } -}; -const contractReferenceLocations = { tag: 'publicLedgerArray', indices: { } }; -exports.Contract = Contract; -exports.ledger = ledger; -exports.pureCircuits = pureCircuits; -exports.contractReferenceLocations = contractReferenceLocations; -//# sourceMappingURL=index.cjs.map diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.cjs.map b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.cjs.map deleted file mode 100644 index ac13053..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.cjs.map +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 3, - "file": "index.cjs", - "sourceRoot": "../../../../../", - "sources": ["test/fixtures/sample-contracts/SampleZOwnable.compact", "compiler/standard-library.compact"], - "names": [], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcA;;;;;;;;;;;;;MAMA,AAAA,KAEC;;;;;;;;;;;;;;;;;;;;;;OAAA;MAED,AAAA,iBAIC;;;;;cAJgC,YAAqB;;;;;;;;;;;;;;;;;;yCAArB,YAAqB;;;;;;;;;mDAArB,YAAqB;;;OAIrD;MAED,AAAA,iBAGC;;;;;;;;;;;;;;;;;;;;;;OAAA;MAED,AAAA,eASC;;;;;;;;;;;;;;;;;;;;;;OAAA;MAED,AAAA,uBAaC;;;;;cAZC,IAAa;cACb,SAAiB;;;;;;;;;;;;;;;;;;;;;;;;;yCADjB,IAAa,+BACb,SAAiB;;;;;;;;;yDADjB,IAAa;yDACb,SAAiB;;;OAWlB;MAED,AAAA,eAMC;;OAAA;;;;;;;;;GAjDA;EAJD;;;;;UAAY,SAAkB;UAAE,cAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IANvD;;;;;;;;;uDAA0C;IAC1C;;;;;;;;;uDAAgC;IAChC;;;;;;;;;uDAA8C;2CAKrC,SAAO;;IACd;;;;;;;yGAAyB,cAAY;;uDAAxB;0DACM,SAAO;;;;;;;GAC3B;EC8BD,AAAA,kBAAiC;oEAAA;;;EAAjC,AAAA,kBAAiC;oEAAA;;;EAwFjC,AAAA;;;;;;;;ED5HA,AAAA,cAAiC;;0DAAjC,WAAiC;;;;;;;;;;;;;;GAAA;EAQjC,AAAA,QAEC;mCADQ;;;;;;;;;;;sFAAgB;GACxB;EAED,AAAA,oBAIC,4BAJgC,YAAqB;;2CAE7C,YAAU;;0DACE,YAAU;;GAC9B;EAED,AAAA,oBAGC;;IADC;;;;;;;;;uDAAgB;;GACjB;EAED,AAAA,kBASC;UARO,OAAqB;UACrB,gBAIL;;;;;;UACK,IAA2C,2BAAtB,gBAAc,EAAE,OAAK;kEACzC;;;;;;;;;;;qHAAgB;;;0EAA4B,IAAE;kGAAE;;;;;;;;;;;qJAAQ;;;GAChE;EAED,AAAA,0BAaC,4BAZC,IAAa,EACb,SAAiB;UAEX,OAAqB,2BAAb;;;;;;;;;;;+FAAa;mCAGvB,IAAE;mCACF,OAAK;;wEACL,SAAO;;;GAIZ;EAED,AAAA,kBAMC,CALC,IAA+C,EAC/C,OAAgB;4BAET,IAAE;;mCACoC,IAAE,aAAa,OAAK;GAClE;EAED,AAAA,qBAGC,4BAH0B,YAAqB;UAC9C,KAAQ;IAAR;;;;;;;;;;2EAAA,KAAQ;;;;sDAAA;UACR,KAAgB;;kDAAoC,YAAU;0EAAG;;;;;;;;;;;6HAAQ;IAAzE;;;;;;;yGAAA,KAAgB;;uDAAA;;GACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAhED;qCAAA;;;;;;;;;;;wFAA0C;KAAA;IAC1C;qCAAA;;;;;;;;;;;wFAAgC;KAAA;IAChC;qCAAA;;;;;;;;;;;wFAA8C;KAAA;;;;;;;;;EAmD9C,AAAA,eAMC;;;;UALC,IAA+C;UAC/C,OAAgB;;;;;;;;;;;;;;;6CADhB,IAA+C,EAC/C,OAAgB;GAIjB;;;;;;;" -} diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.d.cts b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.d.cts deleted file mode 100644 index 5404b06..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/contract/index.d.cts +++ /dev/null @@ -1,64 +0,0 @@ -import type * as __compactRuntime from '@midnight-ntwrk/compact-runtime'; - -export type ZswapCoinPublicKey = { bytes: Uint8Array }; - -export type ContractAddress = { bytes: Uint8Array }; - -export type Either = { is_left: boolean; left: A; right: B }; - -export type Witnesses = { - secretNonce(context: __compactRuntime.WitnessContext): [T, Uint8Array]; -} - -export type ImpureCircuits = { - owner(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - transferOwnership(context: __compactRuntime.CircuitContext, - newOwnerId_0: Uint8Array): __compactRuntime.CircuitResults; - renounceOwnership(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - assertOnlyOwner(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - _computeOwnerCommitment(context: __compactRuntime.CircuitContext, - id_0: Uint8Array, - counter_0: bigint): __compactRuntime.CircuitResults; -} - -export type PureCircuits = { - _computeOwnerId(pk_0: Either, - nonce_0: Uint8Array): Uint8Array; -} - -export type Circuits = { - owner(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - transferOwnership(context: __compactRuntime.CircuitContext, - newOwnerId_0: Uint8Array): __compactRuntime.CircuitResults; - renounceOwnership(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - assertOnlyOwner(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - _computeOwnerCommitment(context: __compactRuntime.CircuitContext, - id_0: Uint8Array, - counter_0: bigint): __compactRuntime.CircuitResults; - _computeOwnerId(context: __compactRuntime.CircuitContext, - pk_0: Either, - nonce_0: Uint8Array): __compactRuntime.CircuitResults; -} - -export type Ledger = { - readonly _ownerCommitment: Uint8Array; - readonly _counter: bigint; - readonly _instanceSalt: Uint8Array; -} - -export type ContractReferenceLocations = any; - -export declare const contractReferenceLocations : ContractReferenceLocations; - -export declare class Contract = Witnesses> { - witnesses: W; - circuits: Circuits; - impureCircuits: ImpureCircuits; - constructor(witnesses: W); - initialState(context: __compactRuntime.ConstructorContext, - ownerId_0: Uint8Array, - instanceSalt_0: Uint8Array): __compactRuntime.ConstructorResult; -} - -export declare function ledger(state: __compactRuntime.StateValue): Ledger; -export declare const pureCircuits: PureCircuits; diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/_computeOwnerCommitment.prover b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/_computeOwnerCommitment.prover deleted file mode 100644 index 2c176ba..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/_computeOwnerCommitment.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/_computeOwnerCommitment.verifier b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/_computeOwnerCommitment.verifier deleted file mode 100644 index 6ab1053..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/_computeOwnerCommitment.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/assertOnlyOwner.prover b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/assertOnlyOwner.prover deleted file mode 100644 index c9917d3..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/assertOnlyOwner.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/assertOnlyOwner.verifier b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/assertOnlyOwner.verifier deleted file mode 100644 index 1c73f1d..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/assertOnlyOwner.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/owner.prover b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/owner.prover deleted file mode 100644 index b82d326..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/owner.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/owner.verifier b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/owner.verifier deleted file mode 100644 index 1895d30..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/owner.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/renounceOwnership.prover b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/renounceOwnership.prover deleted file mode 100644 index 8f67fc3..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/renounceOwnership.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/renounceOwnership.verifier b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/renounceOwnership.verifier deleted file mode 100644 index 3c969b0..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/renounceOwnership.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/transferOwnership.prover b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/transferOwnership.prover deleted file mode 100644 index de4f0fb..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/transferOwnership.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/transferOwnership.verifier b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/transferOwnership.verifier deleted file mode 100644 index ad5ab66..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/keys/transferOwnership.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/_computeOwnerCommitment.bzkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/_computeOwnerCommitment.bzkir deleted file mode 100644 index 9395efa..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/_computeOwnerCommitment.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/_computeOwnerCommitment.zkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/_computeOwnerCommitment.zkir deleted file mode 100644 index af60338..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/_computeOwnerCommitment.zkir +++ /dev/null @@ -1,37 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 3, - "instructions": [ - { "op": "constrain_bits", "var": 0, "bits": 8 }, - { "op": "constrain_bits", "var": 1, "bits": 248 }, - { "op": "constrain_bits", "var": 2, "bits": 64 }, - { "op": "load_imm", "imm": "01" }, - { "op": "load_imm", "imm": "30" }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "pi_skip", "guard": 3, "count": 1 }, - { "op": "load_imm", "imm": "50" }, - { "op": "load_imm", "imm": "02" }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "pi_skip", "guard": 3, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "20" }, - { "op": "load_imm", "imm": "0C" }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "pi_skip", "guard": 3, "count": 5 }, - { "op": "div_mod_power_of_two", "var": 2, "bits": 248 }, - { "op": "load_imm", "imm": "00" }, - { "op": "load_imm", "imm": "53616D706C655A4F776E61626C653A736869656C643A" }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [0, 1, 7, 8, 11, 12, 13, 14] }, - { "op": "output", "var": 15 }, - { "op": "output", "var": 16 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/assertOnlyOwner.bzkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/assertOnlyOwner.bzkir deleted file mode 100644 index 31503d0..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/assertOnlyOwner.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/assertOnlyOwner.zkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/assertOnlyOwner.zkir deleted file mode 100644 index 2d5db59..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/assertOnlyOwner.zkir +++ /dev/null @@ -1,75 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 0, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 1, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 2, "bits": 248 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 3, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 4, "bits": 248 }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [3, 4, 1, 2] }, - { "op": "load_imm", "imm": "30" }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "load_imm", "imm": "50" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "20" }, - { "op": "load_imm", "imm": "0C" }, - { "op": "declare_pub_input", "var": 13 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 12 }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 11 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "08" }, - { "op": "load_imm", "imm": "0D" }, - { "op": "declare_pub_input", "var": 16 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 15 }, - { "op": "declare_pub_input", "var": 14 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "load_imm", "imm": "02" }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 17 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "declare_pub_input", "var": 13 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 12 }, - { "op": "declare_pub_input", "var": 18 }, - { "op": "declare_pub_input", "var": 19 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "div_mod_power_of_two", "var": 14, "bits": 248 }, - { "op": "load_imm", "imm": "53616D706C655A4F776E61626C653A736869656C643A" }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [5, 6, 18, 19, 20, 21, 9, 22] }, - { "op": "test_eq", "a": 10, "b": 23 }, - { "op": "test_eq", "a": 11, "b": 24 }, - { "op": "cond_select", "bit": 25, "a": 26, "b": 9 }, - { "op": "assert", "cond": 27 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/owner.bzkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/owner.bzkir deleted file mode 100644 index 38b14bf..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/owner.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/owner.zkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/owner.zkir deleted file mode 100644 index 50ebbfc..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/owner.zkir +++ /dev/null @@ -1,30 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 0, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "load_imm", "imm": "30" }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "load_imm", "imm": "50" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "20" }, - { "op": "load_imm", "imm": "0C" }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "output", "var": 4 }, - { "op": "output", "var": 5 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/renounceOwnership.bzkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/renounceOwnership.bzkir deleted file mode 100644 index 0eb1da1..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/renounceOwnership.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/renounceOwnership.zkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/renounceOwnership.zkir deleted file mode 100644 index ce621b6..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/renounceOwnership.zkir +++ /dev/null @@ -1,93 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 0, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 1, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 2, "bits": 248 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 3, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 4, "bits": 248 }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [3, 4, 1, 2] }, - { "op": "load_imm", "imm": "30" }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "load_imm", "imm": "50" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "20" }, - { "op": "load_imm", "imm": "0C" }, - { "op": "declare_pub_input", "var": 13 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 12 }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 11 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "08" }, - { "op": "load_imm", "imm": "0D" }, - { "op": "declare_pub_input", "var": 16 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 15 }, - { "op": "declare_pub_input", "var": 14 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "load_imm", "imm": "02" }, - { "op": "declare_pub_input", "var": 8 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 17 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "declare_pub_input", "var": 13 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 12 }, - { "op": "declare_pub_input", "var": 18 }, - { "op": "declare_pub_input", "var": 19 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "div_mod_power_of_two", "var": 14, "bits": 248 }, - { "op": "load_imm", "imm": "53616D706C655A4F776E61626C653A736869656C643A" }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [5, 6, 18, 19, 20, 21, 9, 22] }, - { "op": "test_eq", "a": 10, "b": 23 }, - { "op": "test_eq", "a": 11, "b": 24 }, - { "op": "cond_select", "bit": 25, "a": 26, "b": 9 }, - { "op": "assert", "cond": 27 }, - { "op": "load_imm", "imm": "10" }, - { "op": "declare_pub_input", "var": 28 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "load_imm", "imm": "11" }, - { "op": "declare_pub_input", "var": 29 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 12 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 0, "count": 6 }, - { "op": "load_imm", "imm": "91" }, - { "op": "declare_pub_input", "var": 30 }, - { "op": "pi_skip", "guard": 0, "count": 1 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/transferOwnership.bzkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/transferOwnership.bzkir deleted file mode 100644 index 173464e..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/transferOwnership.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/transferOwnership.zkir b/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/transferOwnership.zkir deleted file mode 100644 index 4f31458..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/SampleZOwnable/zkir/transferOwnership.zkir +++ /dev/null @@ -1,144 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 2, - "instructions": [ - { "op": "constrain_bits", "var": 0, "bits": 8 }, - { "op": "constrain_bits", "var": 1, "bits": 248 }, - { "op": "load_imm", "imm": "01" }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 3, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 4, "bits": 248 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 5, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 6, "bits": 248 }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [5, 6, 3, 4] }, - { "op": "load_imm", "imm": "30" }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 2, "count": 1 }, - { "op": "load_imm", "imm": "50" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 11 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "20" }, - { "op": "load_imm", "imm": "0C" }, - { "op": "declare_pub_input", "var": 15 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 14 }, - { "op": "declare_pub_input", "var": 12 }, - { "op": "declare_pub_input", "var": 13 }, - { "op": "pi_skip", "guard": 2, "count": 5 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 2, "count": 1 }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "08" }, - { "op": "load_imm", "imm": "0D" }, - { "op": "declare_pub_input", "var": 18 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 17 }, - { "op": "declare_pub_input", "var": 16 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 2, "count": 1 }, - { "op": "load_imm", "imm": "02" }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 19 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "declare_pub_input", "var": 15 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 14 }, - { "op": "declare_pub_input", "var": 20 }, - { "op": "declare_pub_input", "var": 21 }, - { "op": "pi_skip", "guard": 2, "count": 5 }, - { "op": "div_mod_power_of_two", "var": 16, "bits": 248 }, - { "op": "load_imm", "imm": "53616D706C655A4F776E61626C653A736869656C643A" }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [7, 8, 20, 21, 22, 23, 11, 24] }, - { "op": "test_eq", "a": 12, "b": 25 }, - { "op": "test_eq", "a": 13, "b": 26 }, - { "op": "cond_select", "bit": 27, "a": 28, "b": 11 }, - { "op": "assert", "cond": 29 }, - { "op": "test_eq", "a": 0, "b": 11 }, - { "op": "test_eq", "a": 1, "b": 11 }, - { "op": "cond_select", "bit": 30, "a": 31, "b": 11 }, - { "op": "cond_select", "bit": 32, "a": 11, "b": 2 }, - { "op": "assert", "cond": 33 }, - { "op": "load_imm", "imm": "70" }, - { "op": "declare_pub_input", "var": 34 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "load_imm", "imm": "0E" }, - { "op": "declare_pub_input", "var": 35 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "pi_skip", "guard": 2, "count": 2 }, - { "op": "load_imm", "imm": "A1" }, - { "op": "declare_pub_input", "var": 36 }, - { "op": "pi_skip", "guard": 2, "count": 1 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 2, "count": 1 }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "declare_pub_input", "var": 18 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 17 }, - { "op": "declare_pub_input", "var": 37 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "declare_pub_input", "var": 9 }, - { "op": "pi_skip", "guard": 2, "count": 1 }, - { "op": "declare_pub_input", "var": 10 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 19 }, - { "op": "pi_skip", "guard": 2, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "public_input", "guard": null }, - { "op": "declare_pub_input", "var": 15 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 14 }, - { "op": "declare_pub_input", "var": 38 }, - { "op": "declare_pub_input", "var": 39 }, - { "op": "pi_skip", "guard": 2, "count": 5 }, - { "op": "div_mod_power_of_two", "var": 37, "bits": 248 }, - { "op": "load_imm", "imm": "53616D706C655A4F776E61626C653A736869656C643A" }, - { "op": "persistent_hash", "alignment": [{ "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }, { "tag": "atom", "value": { "length": 32, "tag": "bytes" } }], "inputs": [0, 1, 38, 39, 40, 41, 11, 42] }, - { "op": "load_imm", "imm": "10" }, - { "op": "declare_pub_input", "var": 45 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 11 }, - { "op": "pi_skip", "guard": 2, "count": 5 }, - { "op": "load_imm", "imm": "11" }, - { "op": "declare_pub_input", "var": 46 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 14 }, - { "op": "declare_pub_input", "var": 43 }, - { "op": "declare_pub_input", "var": 44 }, - { "op": "pi_skip", "guard": 2, "count": 6 }, - { "op": "load_imm", "imm": "91" }, - { "op": "declare_pub_input", "var": 47 }, - { "op": "pi_skip", "guard": 2, "count": 1 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/compiler/contract-info.json b/packages/simulator/test/fixtures/test-artifacts/Simple/compiler/contract-info.json deleted file mode 100644 index 8191238..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Simple/compiler/contract-info.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "circuits": [ - { - "name": "setVal", - "pure": false, - "arguments": [ - { - "name": "n", - "type": { - "type-name": "Field" - } - } - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - }, - { - "name": "getVal", - "pure": false, - "arguments": [ - ], - "result-type": { - "type-name": "Field" - } - } - ], - "witnesses": [ - ], - "contracts": [ - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.cjs b/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.cjs deleted file mode 100644 index c6f82f2..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.cjs +++ /dev/null @@ -1,261 +0,0 @@ -'use strict'; -const __compactRuntime = require('@midnight-ntwrk/compact-runtime'); -const expectedRuntimeVersionString = '0.9.0'; -const expectedRuntimeVersion = expectedRuntimeVersionString.split('-')[0].split('.').map(Number); -const actualRuntimeVersion = __compactRuntime.versionString.split('-')[0].split('.').map(Number); -if (expectedRuntimeVersion[0] != actualRuntimeVersion[0] - || (actualRuntimeVersion[0] == 0 && expectedRuntimeVersion[1] != actualRuntimeVersion[1]) - || expectedRuntimeVersion[1] > actualRuntimeVersion[1] - || (expectedRuntimeVersion[1] == actualRuntimeVersion[1] && expectedRuntimeVersion[2] > actualRuntimeVersion[2])) - throw new __compactRuntime.CompactError(`Version mismatch: compiled code expects ${expectedRuntimeVersionString}, runtime is ${__compactRuntime.versionString}`); -{ const MAX_FIELD = 52435875175126190479447740508185965837690552500527637822603658699938581184512n; - if (__compactRuntime.MAX_FIELD !== MAX_FIELD) - throw new __compactRuntime.CompactError(`compiler thinks maximum field value is ${MAX_FIELD}; run time thinks it is ${__compactRuntime.MAX_FIELD}`) -} - -const _descriptor_0 = new __compactRuntime.CompactTypeField(); - -const _descriptor_1 = new __compactRuntime.CompactTypeUnsignedInteger(18446744073709551615n, 8); - -const _descriptor_2 = new __compactRuntime.CompactTypeBoolean(); - -const _descriptor_3 = new __compactRuntime.CompactTypeBytes(32); - -class _ContractAddress_0 { - alignment() { - return _descriptor_3.alignment(); - } - fromValue(value_0) { - return { - bytes: _descriptor_3.fromValue(value_0) - } - } - toValue(value_0) { - return _descriptor_3.toValue(value_0.bytes); - } -} - -const _descriptor_4 = new _ContractAddress_0(); - -const _descriptor_5 = new __compactRuntime.CompactTypeUnsignedInteger(255n, 1); - -const _descriptor_6 = new __compactRuntime.CompactTypeUnsignedInteger(340282366920938463463374607431768211455n, 16); - -class Contract { - witnesses; - constructor(...args_0) { - if (args_0.length !== 1) { - throw new __compactRuntime.CompactError(`Contract constructor: expected 1 argument, received ${args_0.length}`); - } - const witnesses_0 = args_0[0]; - if (typeof(witnesses_0) !== 'object') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor is not an object'); - } - this.witnesses = witnesses_0; - this.circuits = { - setVal: (...args_1) => { - if (args_1.length !== 2) { - throw new __compactRuntime.CompactError(`setVal: expected 2 arguments (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - const n_0 = args_1[1]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('setVal', - 'argument 1 (as invoked from Typescript)', - 'Simple.compact line 8 char 1', - 'CircuitContext', - contextOrig_0) - } - if (!(typeof(n_0) === 'bigint' && n_0 >= 0 && n_0 <= __compactRuntime.MAX_FIELD)) { - __compactRuntime.type_error('setVal', - 'argument 1 (argument 2 as invoked from Typescript)', - 'Simple.compact line 8 char 1', - 'Field', - n_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { - value: _descriptor_0.toValue(n_0), - alignment: _descriptor_0.alignment() - }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._setVal_0(context, partialProofData, n_0); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - getVal: (...args_1) => { - if (args_1.length !== 1) { - throw new __compactRuntime.CompactError(`getVal: expected 1 argument (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('getVal', - 'argument 1 (as invoked from Typescript)', - 'Simple.compact line 12 char 1', - 'CircuitContext', - contextOrig_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._getVal_0(context, partialProofData); - partialProofData.output = { value: _descriptor_0.toValue(result_0), alignment: _descriptor_0.alignment() }; - return { result: result_0, context: context, proofData: partialProofData }; - } - }; - this.impureCircuits = { - setVal: this.circuits.setVal, - getVal: this.circuits.getVal - }; - } - initialState(...args_0) { - if (args_0.length !== 1) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 1 argument (as invoked from Typescript), received ${args_0.length}`); - } - const constructorContext_0 = args_0[0]; - if (typeof(constructorContext_0) !== 'object') { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'constructorContext' in argument 1 (as invoked from Typescript) to be an object`); - } - if (!('initialZswapLocalState' in constructorContext_0)) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialZswapLocalState' in argument 1 (as invoked from Typescript)`); - } - if (typeof(constructorContext_0.initialZswapLocalState) !== 'object') { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialZswapLocalState' in argument 1 (as invoked from Typescript) to be an object`); - } - const state_0 = new __compactRuntime.ContractState(); - let stateValue_0 = __compactRuntime.StateValue.newArray(); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - state_0.data = stateValue_0; - state_0.setOperation('setVal', new __compactRuntime.ContractOperation()); - state_0.setOperation('getVal', new __compactRuntime.ContractOperation()); - const context = { - originalState: state_0, - currentPrivateState: constructorContext_0.initialPrivateState, - currentZswapLocalState: constructorContext_0.initialZswapLocalState, - transactionContext: new __compactRuntime.QueryContext(state_0.data, __compactRuntime.dummyContractAddress()) - }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_5.toValue(0n), - alignment: _descriptor_5.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_0.toValue(0n), - alignment: _descriptor_0.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - state_0.data = context.transactionContext.state; - return { - currentContractState: state_0, - currentPrivateState: context.currentPrivateState, - currentZswapLocalState: context.currentZswapLocalState - } - } - _setVal_0(context, partialProofData, n_0) { - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_5.toValue(0n), - alignment: _descriptor_5.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_0.toValue(n_0), - alignment: _descriptor_0.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - return []; - } - _getVal_0(context, partialProofData) { - return _descriptor_0.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_5.toValue(0n), - alignment: _descriptor_5.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - } - static _query(context, partialProofData, prog) { - var res; - try { - res = context.transactionContext.query(prog, __compactRuntime.CostModel.dummyCostModel()); - } catch (err) { - throw new __compactRuntime.CompactError(err.toString()); - } - context.transactionContext = res.context; - var reads = res.events.filter((e) => e.tag === 'read'); - var i = 0; - partialProofData.publicTranscript = partialProofData.publicTranscript.concat(prog.map((op) => { - if(typeof(op) === 'object' && 'popeq' in op) { - return { popeq: { - ...op.popeq, - result: reads[i++].content, - } }; - } else { - return op; - } - })); - if(res.events.length == 1 && res.events[0].tag === 'read') { - return res.events[0].content; - } else { - return res.events; - } - } -} -function ledger(state) { - const context = { - originalState: state, - transactionContext: new __compactRuntime.QueryContext(state, __compactRuntime.dummyContractAddress()) - }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - return { - get _val() { - return _descriptor_0.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_5.toValue(0n), - alignment: _descriptor_5.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - } - }; -} -const _emptyContext = { - originalState: new __compactRuntime.ContractState(), - transactionContext: new __compactRuntime.QueryContext(new __compactRuntime.ContractState().data, __compactRuntime.dummyContractAddress()) -}; -const _dummyContract = new Contract({ }); -const pureCircuits = {}; -const contractReferenceLocations = { tag: 'publicLedgerArray', indices: { } }; -exports.Contract = Contract; -exports.ledger = ledger; -exports.pureCircuits = pureCircuits; -exports.contractReferenceLocations = contractReferenceLocations; -//# sourceMappingURL=index.cjs.map diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.cjs.map b/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.cjs.map deleted file mode 100644 index 5b3e8d2..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.cjs.map +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 3, - "file": "index.cjs", - "sourceRoot": "../../../../../", - "sources": ["test/fixtures/sample-contracts/Simple.compact"], - "names": [], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;MAOA,AAAA,MAEC;;;;;cAFqB,GAAQ;;;;;;;;;;;;;;;;;;yCAAR,GAAQ;;;;;;;mEAAR,GAAQ;;;OAE7B;MAED,AAAA,MAEC;;;;;;;;;;;;;;;;;;;;;;OAAA;;;;;;GACA;EAdD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAKA;;;;;;;;;uDAA0B;;;;;;;GASzB;EAPD,AAAA,SAEC,4BAFqB,GAAQ;IAC5B;;;;;;;yGAAgB,GAAC;;uDAAb;;GACL;EAED,AAAA,SAEC;mCADQ;;;;;;;;;;;sFAAI;GACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IARD;qCAAA;;;;;;;;;;;wFAA0B;KAAA;;;;;;;;;;;;;;" -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.d.cts b/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.d.cts deleted file mode 100644 index b9e089a..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Simple/contract/index.d.cts +++ /dev/null @@ -1,44 +0,0 @@ -import type * as __compactRuntime from '@midnight-ntwrk/compact-runtime'; - -export type ZswapCoinPublicKey = { bytes: Uint8Array }; - -export type ContractAddress = { bytes: Uint8Array }; - -export type Either = { is_left: boolean; left: A; right: B }; - -export type Maybe = { is_some: boolean; value: T }; - -export type Witnesses = { -} - -export type ImpureCircuits = { - setVal(context: __compactRuntime.CircuitContext, n_0: bigint): __compactRuntime.CircuitResults; - getVal(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; -} - -export type PureCircuits = { -} - -export type Circuits = { - setVal(context: __compactRuntime.CircuitContext, n_0: bigint): __compactRuntime.CircuitResults; - getVal(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; -} - -export type Ledger = { - readonly _val: bigint; -} - -export type ContractReferenceLocations = any; - -export declare const contractReferenceLocations : ContractReferenceLocations; - -export declare class Contract = Witnesses> { - witnesses: W; - circuits: Circuits; - impureCircuits: ImpureCircuits; - constructor(witnesses: W); - initialState(context: __compactRuntime.ConstructorContext): __compactRuntime.ConstructorResult; -} - -export declare function ledger(state: __compactRuntime.StateValue): Ledger; -export declare const pureCircuits: PureCircuits; diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/getVal.prover b/packages/simulator/test/fixtures/test-artifacts/Simple/keys/getVal.prover deleted file mode 100644 index 84ddcc6..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/getVal.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/getVal.verifier b/packages/simulator/test/fixtures/test-artifacts/Simple/keys/getVal.verifier deleted file mode 100644 index 5a60c13..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/getVal.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/setVal.prover b/packages/simulator/test/fixtures/test-artifacts/Simple/keys/setVal.prover deleted file mode 100644 index b063604..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/setVal.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/setVal.verifier b/packages/simulator/test/fixtures/test-artifacts/Simple/keys/setVal.verifier deleted file mode 100644 index e205835..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Simple/keys/setVal.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/getVal.bzkir b/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/getVal.bzkir deleted file mode 100644 index 74acd35..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/getVal.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/getVal.zkir b/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/getVal.zkir deleted file mode 100644 index cad66eb..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/getVal.zkir +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 0, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "load_imm", "imm": "30" }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "pi_skip", "guard": 0, "count": 1 }, - { "op": "load_imm", "imm": "50" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "public_input", "guard": null }, - { "op": "load_imm", "imm": "-02" }, - { "op": "load_imm", "imm": "0C" }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "pi_skip", "guard": 0, "count": 4 }, - { "op": "output", "var": 4 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/setVal.bzkir b/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/setVal.bzkir deleted file mode 100644 index 8a9d024..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/setVal.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/setVal.zkir b/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/setVal.zkir deleted file mode 100644 index 2dd05a6..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Simple/zkir/setVal.zkir +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 1, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "load_imm", "imm": "10" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "pi_skip", "guard": 1, "count": 5 }, - { "op": "load_imm", "imm": "11" }, - { "op": "load_imm", "imm": "-02" }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "pi_skip", "guard": 1, "count": 5 }, - { "op": "load_imm", "imm": "91" }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "pi_skip", "guard": 1, "count": 1 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/compiler/contract-info.json b/packages/simulator/test/fixtures/test-artifacts/Witness/compiler/contract-info.json deleted file mode 100644 index 3bbe4e4..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/compiler/contract-info.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "circuits": [ - { - "name": "setBytes", - "pure": false, - "arguments": [ - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - }, - { - "name": "setField", - "pure": false, - "arguments": [ - { - "name": "arg", - "type": { - "type-name": "Field" - } - } - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - }, - { - "name": "setUint", - "pure": false, - "arguments": [ - { - "name": "arg1", - "type": { - "type-name": "Uint", - "maxval": 340282366920938463463374607431768211455 - } - }, - { - "name": "arg2", - "type": { - "type-name": "Uint", - "maxval": 340282366920938463463374607431768211455 - } - } - ], - "result-type": { - "type-name": "Tuple", - "types": [ - ] - } - } - ], - "witnesses": [ - { - "name": "wit_secretBytes", - "arguments": [ - ], - "result type": { - "type-name": "Bytes", - "length": 32 - } - }, - { - "name": "wit_secretFieldPlusArg", - "arguments": [ - { - "name": "arg1", - "type": { - "type-name": "Field" - } - } - ], - "result type": { - "type-name": "Field" - } - }, - { - "name": "wit_secretUintPlusArgs", - "arguments": [ - { - "name": "arg1", - "type": { - "type-name": "Uint", - "maxval": 340282366920938463463374607431768211455 - } - }, - { - "name": "arg2", - "type": { - "type-name": "Uint", - "maxval": 340282366920938463463374607431768211455 - } - } - ], - "result type": { - "type-name": "Uint", - "maxval": 340282366920938463463374607431768211455 - } - } - ], - "contracts": [ - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.cjs b/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.cjs deleted file mode 100644 index 776de1f..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.cjs +++ /dev/null @@ -1,448 +0,0 @@ -'use strict'; -const __compactRuntime = require('@midnight-ntwrk/compact-runtime'); -const expectedRuntimeVersionString = '0.9.0'; -const expectedRuntimeVersion = expectedRuntimeVersionString.split('-')[0].split('.').map(Number); -const actualRuntimeVersion = __compactRuntime.versionString.split('-')[0].split('.').map(Number); -if (expectedRuntimeVersion[0] != actualRuntimeVersion[0] - || (actualRuntimeVersion[0] == 0 && expectedRuntimeVersion[1] != actualRuntimeVersion[1]) - || expectedRuntimeVersion[1] > actualRuntimeVersion[1] - || (expectedRuntimeVersion[1] == actualRuntimeVersion[1] && expectedRuntimeVersion[2] > actualRuntimeVersion[2])) - throw new __compactRuntime.CompactError(`Version mismatch: compiled code expects ${expectedRuntimeVersionString}, runtime is ${__compactRuntime.versionString}`); -{ const MAX_FIELD = 52435875175126190479447740508185965837690552500527637822603658699938581184512n; - if (__compactRuntime.MAX_FIELD !== MAX_FIELD) - throw new __compactRuntime.CompactError(`compiler thinks maximum field value is ${MAX_FIELD}; run time thinks it is ${__compactRuntime.MAX_FIELD}`) -} - -const _descriptor_0 = new __compactRuntime.CompactTypeField(); - -const _descriptor_1 = new __compactRuntime.CompactTypeUnsignedInteger(340282366920938463463374607431768211455n, 16); - -const _descriptor_2 = new __compactRuntime.CompactTypeBytes(32); - -const _descriptor_3 = new __compactRuntime.CompactTypeUnsignedInteger(18446744073709551615n, 8); - -const _descriptor_4 = new __compactRuntime.CompactTypeBoolean(); - -class _ContractAddress_0 { - alignment() { - return _descriptor_2.alignment(); - } - fromValue(value_0) { - return { - bytes: _descriptor_2.fromValue(value_0) - } - } - toValue(value_0) { - return _descriptor_2.toValue(value_0.bytes); - } -} - -const _descriptor_5 = new _ContractAddress_0(); - -const _descriptor_6 = new __compactRuntime.CompactTypeUnsignedInteger(255n, 1); - -class Contract { - witnesses; - constructor(...args_0) { - if (args_0.length !== 1) { - throw new __compactRuntime.CompactError(`Contract constructor: expected 1 argument, received ${args_0.length}`); - } - const witnesses_0 = args_0[0]; - if (typeof(witnesses_0) !== 'object') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor is not an object'); - } - if (typeof(witnesses_0.wit_secretBytes) !== 'function') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor does not contain a function-valued field named wit_secretBytes'); - } - if (typeof(witnesses_0.wit_secretFieldPlusArg) !== 'function') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor does not contain a function-valued field named wit_secretFieldPlusArg'); - } - if (typeof(witnesses_0.wit_secretUintPlusArgs) !== 'function') { - throw new __compactRuntime.CompactError('first (witnesses) argument to Contract constructor does not contain a function-valued field named wit_secretUintPlusArgs'); - } - this.witnesses = witnesses_0; - this.circuits = { - setBytes: (...args_1) => { - if (args_1.length !== 1) { - throw new __compactRuntime.CompactError(`setBytes: expected 1 argument (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('setBytes', - 'argument 1 (as invoked from Typescript)', - 'Witness.compact line 14 char 1', - 'CircuitContext', - contextOrig_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._setBytes_0(context, partialProofData); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - setField: (...args_1) => { - if (args_1.length !== 2) { - throw new __compactRuntime.CompactError(`setField: expected 2 arguments (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - const arg_0 = args_1[1]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('setField', - 'argument 1 (as invoked from Typescript)', - 'Witness.compact line 19 char 1', - 'CircuitContext', - contextOrig_0) - } - if (!(typeof(arg_0) === 'bigint' && arg_0 >= 0 && arg_0 <= __compactRuntime.MAX_FIELD)) { - __compactRuntime.type_error('setField', - 'argument 1 (argument 2 as invoked from Typescript)', - 'Witness.compact line 19 char 1', - 'Field', - arg_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { - value: _descriptor_0.toValue(arg_0), - alignment: _descriptor_0.alignment() - }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._setField_0(context, partialProofData, arg_0); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - }, - setUint: (...args_1) => { - if (args_1.length !== 3) { - throw new __compactRuntime.CompactError(`setUint: expected 3 arguments (as invoked from Typescript), received ${args_1.length}`); - } - const contextOrig_0 = args_1[0]; - const arg1_0 = args_1[1]; - const arg2_0 = args_1[2]; - if (!(typeof(contextOrig_0) === 'object' && contextOrig_0.originalState != undefined && contextOrig_0.transactionContext != undefined)) { - __compactRuntime.type_error('setUint', - 'argument 1 (as invoked from Typescript)', - 'Witness.compact line 24 char 1', - 'CircuitContext', - contextOrig_0) - } - if (!(typeof(arg1_0) === 'bigint' && arg1_0 >= 0n && arg1_0 <= 340282366920938463463374607431768211455n)) { - __compactRuntime.type_error('setUint', - 'argument 1 (argument 2 as invoked from Typescript)', - 'Witness.compact line 24 char 1', - 'Uint<0..340282366920938463463374607431768211455>', - arg1_0) - } - if (!(typeof(arg2_0) === 'bigint' && arg2_0 >= 0n && arg2_0 <= 340282366920938463463374607431768211455n)) { - __compactRuntime.type_error('setUint', - 'argument 2 (argument 3 as invoked from Typescript)', - 'Witness.compact line 24 char 1', - 'Uint<0..340282366920938463463374607431768211455>', - arg2_0) - } - const context = { ...contextOrig_0 }; - const partialProofData = { - input: { - value: _descriptor_1.toValue(arg1_0).concat(_descriptor_1.toValue(arg2_0)), - alignment: _descriptor_1.alignment().concat(_descriptor_1.alignment()) - }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - const result_0 = this._setUint_0(context, - partialProofData, - arg1_0, - arg2_0); - partialProofData.output = { value: [], alignment: [] }; - return { result: result_0, context: context, proofData: partialProofData }; - } - }; - this.impureCircuits = { - setBytes: this.circuits.setBytes, - setField: this.circuits.setField, - setUint: this.circuits.setUint - }; - } - initialState(...args_0) { - if (args_0.length !== 1) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 1 argument (as invoked from Typescript), received ${args_0.length}`); - } - const constructorContext_0 = args_0[0]; - if (typeof(constructorContext_0) !== 'object') { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'constructorContext' in argument 1 (as invoked from Typescript) to be an object`); - } - if (!('initialPrivateState' in constructorContext_0)) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialPrivateState' in argument 1 (as invoked from Typescript)`); - } - if (!('initialZswapLocalState' in constructorContext_0)) { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialZswapLocalState' in argument 1 (as invoked from Typescript)`); - } - if (typeof(constructorContext_0.initialZswapLocalState) !== 'object') { - throw new __compactRuntime.CompactError(`Contract state constructor: expected 'initialZswapLocalState' in argument 1 (as invoked from Typescript) to be an object`); - } - const state_0 = new __compactRuntime.ContractState(); - let stateValue_0 = __compactRuntime.StateValue.newArray(); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - stateValue_0 = stateValue_0.arrayPush(__compactRuntime.StateValue.newNull()); - state_0.data = stateValue_0; - state_0.setOperation('setBytes', new __compactRuntime.ContractOperation()); - state_0.setOperation('setField', new __compactRuntime.ContractOperation()); - state_0.setOperation('setUint', new __compactRuntime.ContractOperation()); - const context = { - originalState: state_0, - currentPrivateState: constructorContext_0.initialPrivateState, - currentZswapLocalState: constructorContext_0.initialZswapLocalState, - transactionContext: new __compactRuntime.QueryContext(state_0.data, __compactRuntime.dummyContractAddress()) - }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(0n), - alignment: _descriptor_6.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_2.toValue(new Uint8Array(32)), - alignment: _descriptor_2.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(1n), - alignment: _descriptor_6.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_0.toValue(0n), - alignment: _descriptor_0.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(2n), - alignment: _descriptor_6.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(0n), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - state_0.data = context.transactionContext.state; - return { - currentContractState: state_0, - currentPrivateState: context.currentPrivateState, - currentZswapLocalState: context.currentZswapLocalState - } - } - _wit_secretBytes_0(context, partialProofData) { - const witnessContext_0 = __compactRuntime.witnessContext(ledger(context.transactionContext.state), context.currentPrivateState, context.transactionContext.address); - const [nextPrivateState_0, result_0] = this.witnesses.wit_secretBytes(witnessContext_0); - context.currentPrivateState = nextPrivateState_0; - if (!(result_0.buffer instanceof ArrayBuffer && result_0.BYTES_PER_ELEMENT === 1 && result_0.length === 32)) { - __compactRuntime.type_error('wit_secretBytes', - 'return value', - 'Witness.compact line 10 char 1', - 'Bytes<32>', - result_0) - } - partialProofData.privateTranscriptOutputs.push({ - value: _descriptor_2.toValue(result_0), - alignment: _descriptor_2.alignment() - }); - return result_0; - } - _wit_secretFieldPlusArg_0(context, partialProofData, arg1_0) { - const witnessContext_0 = __compactRuntime.witnessContext(ledger(context.transactionContext.state), context.currentPrivateState, context.transactionContext.address); - const [nextPrivateState_0, result_0] = this.witnesses.wit_secretFieldPlusArg(witnessContext_0, - arg1_0); - context.currentPrivateState = nextPrivateState_0; - if (!(typeof(result_0) === 'bigint' && result_0 >= 0 && result_0 <= __compactRuntime.MAX_FIELD)) { - __compactRuntime.type_error('wit_secretFieldPlusArg', - 'return value', - 'Witness.compact line 11 char 1', - 'Field', - result_0) - } - partialProofData.privateTranscriptOutputs.push({ - value: _descriptor_0.toValue(result_0), - alignment: _descriptor_0.alignment() - }); - return result_0; - } - _wit_secretUintPlusArgs_0(context, partialProofData, arg1_0, arg2_0) { - const witnessContext_0 = __compactRuntime.witnessContext(ledger(context.transactionContext.state), context.currentPrivateState, context.transactionContext.address); - const [nextPrivateState_0, result_0] = this.witnesses.wit_secretUintPlusArgs(witnessContext_0, - arg1_0, - arg2_0); - context.currentPrivateState = nextPrivateState_0; - if (!(typeof(result_0) === 'bigint' && result_0 >= 0n && result_0 <= 340282366920938463463374607431768211455n)) { - __compactRuntime.type_error('wit_secretUintPlusArgs', - 'return value', - 'Witness.compact line 12 char 1', - 'Uint<0..340282366920938463463374607431768211455>', - result_0) - } - partialProofData.privateTranscriptOutputs.push({ - value: _descriptor_1.toValue(result_0), - alignment: _descriptor_1.alignment() - }); - return result_0; - } - _setBytes_0(context, partialProofData) { - const val_0 = this._wit_secretBytes_0(context, partialProofData); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(0n), - alignment: _descriptor_6.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_2.toValue(val_0), - alignment: _descriptor_2.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - return []; - } - _setField_0(context, partialProofData, arg_0) { - const val_0 = this._wit_secretFieldPlusArg_0(context, - partialProofData, - arg_0); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(1n), - alignment: _descriptor_6.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_0.toValue(val_0), - alignment: _descriptor_0.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - return []; - } - _setUint_0(context, partialProofData, arg1_0, arg2_0) { - const val_0 = this._wit_secretUintPlusArgs_0(context, - partialProofData, - arg1_0, - arg2_0); - Contract._query(context, - partialProofData, - [ - { push: { storage: false, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_6.toValue(2n), - alignment: _descriptor_6.alignment() }).encode() } }, - { push: { storage: true, - value: __compactRuntime.StateValue.newCell({ value: _descriptor_1.toValue(val_0), - alignment: _descriptor_1.alignment() }).encode() } }, - { ins: { cached: false, n: 1 } }]); - return []; - } - static _query(context, partialProofData, prog) { - var res; - try { - res = context.transactionContext.query(prog, __compactRuntime.CostModel.dummyCostModel()); - } catch (err) { - throw new __compactRuntime.CompactError(err.toString()); - } - context.transactionContext = res.context; - var reads = res.events.filter((e) => e.tag === 'read'); - var i = 0; - partialProofData.publicTranscript = partialProofData.publicTranscript.concat(prog.map((op) => { - if(typeof(op) === 'object' && 'popeq' in op) { - return { popeq: { - ...op.popeq, - result: reads[i++].content, - } }; - } else { - return op; - } - })); - if(res.events.length == 1 && res.events[0].tag === 'read') { - return res.events[0].content; - } else { - return res.events; - } - } -} -function ledger(state) { - const context = { - originalState: state, - transactionContext: new __compactRuntime.QueryContext(state, __compactRuntime.dummyContractAddress()) - }; - const partialProofData = { - input: { value: [], alignment: [] }, - output: undefined, - publicTranscript: [], - privateTranscriptOutputs: [] - }; - return { - get _valBytes() { - return _descriptor_2.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_6.toValue(0n), - alignment: _descriptor_6.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - }, - get _valField() { - return _descriptor_0.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_6.toValue(1n), - alignment: _descriptor_6.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - }, - get _valUint() { - return _descriptor_1.fromValue(Contract._query(context, - partialProofData, - [ - { dup: { n: 0 } }, - { idx: { cached: false, - pushPath: false, - path: [ - { tag: 'value', - value: { value: _descriptor_6.toValue(2n), - alignment: _descriptor_6.alignment() } }] } }, - { popeq: { cached: false, - result: undefined } }]).value); - } - }; -} -const _emptyContext = { - originalState: new __compactRuntime.ContractState(), - transactionContext: new __compactRuntime.QueryContext(new __compactRuntime.ContractState().data, __compactRuntime.dummyContractAddress()) -}; -const _dummyContract = new Contract({ - wit_secretBytes: (...args) => undefined, - wit_secretFieldPlusArg: (...args) => undefined, - wit_secretUintPlusArgs: (...args) => undefined -}); -const pureCircuits = {}; -const contractReferenceLocations = { tag: 'publicLedgerArray', indices: { } }; -exports.Contract = Contract; -exports.ledger = ledger; -exports.pureCircuits = pureCircuits; -exports.contractReferenceLocations = contractReferenceLocations; -//# sourceMappingURL=index.cjs.map diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.cjs.map b/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.cjs.map deleted file mode 100644 index dcf28b2..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.cjs.map +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 3, - "file": "index.cjs", - "sourceRoot": "../../../../../", - "sources": ["test/fixtures/sample-contracts/Witness.compact"], - "names": [], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;;;;;;;;;;;;;;;;;;;MAaA,AAAA,QAGC;;;;;;;;;;;;;;;;;;;;;;OAAA;MAED,AAAA,QAGC;;;;;cAHuB,KAAU;;;;;;;;;;;;;;;;;;yCAAV,KAAU;;;;;;;qEAAV,KAAU;;;OAGjC;MAED,AAAA,OAGC;;;;;cAHsB,MAAe;cAAE,MAAe;;;;;;;;;;;;;;;;;;;;;;;;;yCAAhC,MAAe,+BAAE,MAAe;;;;;;;;;yCAAhC,MAAe;yCAAE,MAAe;;;OAGtD;;;;;;;GACA;EA3BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAKA;;;;;;;;;uDAAmC;IACnC;;;;;;;;;uDAA+B;IAC/B;;;;;;;;;uDAAkC;;;;;;;GAoBjC;EAlBD,AAAA,kBAAqC;;0DAArC,eAAqC;;;;;;;;;;;;;;GAAA;EACrC,AAAA,yBAAmD,4BAApB,MAAW;;0DAA1C,sBAAmD;iFAApB,MAAW;;;;;;;;;;;;;;GAAS;EACnD,AAAA,yBAA4E,4BAA7C,MAAe,EAAE,MAAe;;0DAA/D,sBAA4E;iFAA7C,MAAe;iFAAE,MAAe;;;;;;;;;;;;;;GAAa;EAE5E,AAAA,WAGC;UAFO,KAAuB;IAC7B;;;;;;;yGAAqB,KAAG;;uDAAf;;GACV;EAED,AAAA,WAGC,4BAHuB,KAAU;UAC1B,KAAiC;;iDAAJ,KAAG;IACtC;;;;;;;yGAAqB,KAAG;;uDAAf;;GACV;EAED,AAAA,UAGC,4BAHsB,MAAe,EAAE,MAAe;UAC/C,KAAwC;;iDAAX,MAAI;iDAAE,MAAI;IAC7C;;;;;;;yGAAoB,KAAG;;uDAAf;;GACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IArBD;qCAAA;;;;;;;;;;;wFAAmC;KAAA;IACnC;qCAAA;;;;;;;;;;;wFAA+B;KAAA;IAC/B;qCAAA;;;;;;;;;;;wFAAkC;KAAA;;;;;;;;;;;;;;;;;;" -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.d.cts b/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.d.cts deleted file mode 100644 index ea270f8..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/contract/index.d.cts +++ /dev/null @@ -1,58 +0,0 @@ -import type * as __compactRuntime from '@midnight-ntwrk/compact-runtime'; - -export type ZswapCoinPublicKey = { bytes: Uint8Array }; - -export type ContractAddress = { bytes: Uint8Array }; - -export type Either = { is_left: boolean; left: A; right: B }; - -export type Maybe = { is_some: boolean; value: T }; - -export type Witnesses = { - wit_secretBytes(context: __compactRuntime.WitnessContext): [T, Uint8Array]; - wit_secretFieldPlusArg(context: __compactRuntime.WitnessContext, - arg1_0: bigint): [T, bigint]; - wit_secretUintPlusArgs(context: __compactRuntime.WitnessContext, - arg1_0: bigint, - arg2_0: bigint): [T, bigint]; -} - -export type ImpureCircuits = { - setBytes(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - setField(context: __compactRuntime.CircuitContext, arg_0: bigint): __compactRuntime.CircuitResults; - setUint(context: __compactRuntime.CircuitContext, - arg1_0: bigint, - arg2_0: bigint): __compactRuntime.CircuitResults; -} - -export type PureCircuits = { -} - -export type Circuits = { - setBytes(context: __compactRuntime.CircuitContext): __compactRuntime.CircuitResults; - setField(context: __compactRuntime.CircuitContext, arg_0: bigint): __compactRuntime.CircuitResults; - setUint(context: __compactRuntime.CircuitContext, - arg1_0: bigint, - arg2_0: bigint): __compactRuntime.CircuitResults; -} - -export type Ledger = { - readonly _valBytes: Uint8Array; - readonly _valField: bigint; - readonly _valUint: bigint; -} - -export type ContractReferenceLocations = any; - -export declare const contractReferenceLocations : ContractReferenceLocations; - -export declare class Contract = Witnesses> { - witnesses: W; - circuits: Circuits; - impureCircuits: ImpureCircuits; - constructor(witnesses: W); - initialState(context: __compactRuntime.ConstructorContext): __compactRuntime.ConstructorResult; -} - -export declare function ledger(state: __compactRuntime.StateValue): Ledger; -export declare const pureCircuits: PureCircuits; diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setBytes.prover b/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setBytes.prover deleted file mode 100644 index 6d0aa34..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setBytes.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setBytes.verifier b/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setBytes.verifier deleted file mode 100644 index 1c6c455..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setBytes.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setField.prover b/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setField.prover deleted file mode 100644 index ceeb847..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setField.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setField.verifier b/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setField.verifier deleted file mode 100644 index 90ca30e..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setField.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setUint.prover b/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setUint.prover deleted file mode 100644 index c0f1c9a..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setUint.prover and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setUint.verifier b/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setUint.verifier deleted file mode 100644 index 91b2ba2..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/keys/setUint.verifier and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setBytes.bzkir b/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setBytes.bzkir deleted file mode 100644 index 2fb735f..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setBytes.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setBytes.zkir b/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setBytes.zkir deleted file mode 100644 index fcfb728..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setBytes.zkir +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 0, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 1, "bits": 8 }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 2, "bits": 248 }, - { "op": "load_imm", "imm": "10" }, - { "op": "load_imm", "imm": "00" }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "pi_skip", "guard": 0, "count": 5 }, - { "op": "load_imm", "imm": "11" }, - { "op": "load_imm", "imm": "20" }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 0 }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "pi_skip", "guard": 0, "count": 6 }, - { "op": "load_imm", "imm": "91" }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 0, "count": 1 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setField.bzkir b/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setField.bzkir deleted file mode 100644 index 7acd4c9..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setField.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setField.zkir b/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setField.zkir deleted file mode 100644 index c01bbe2..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setField.zkir +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 1, - "instructions": [ - { "op": "load_imm", "imm": "01" }, - { "op": "private_input", "guard": null }, - { "op": "load_imm", "imm": "10" }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "pi_skip", "guard": 1, "count": 5 }, - { "op": "load_imm", "imm": "11" }, - { "op": "load_imm", "imm": "-02" }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 1 }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "pi_skip", "guard": 1, "count": 5 }, - { "op": "load_imm", "imm": "91" }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "pi_skip", "guard": 1, "count": 1 } - ] -} diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setUint.bzkir b/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setUint.bzkir deleted file mode 100644 index 848bc6e..0000000 Binary files a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setUint.bzkir and /dev/null differ diff --git a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setUint.zkir b/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setUint.zkir deleted file mode 100644 index d6b5231..0000000 --- a/packages/simulator/test/fixtures/test-artifacts/Witness/zkir/setUint.zkir +++ /dev/null @@ -1,30 +0,0 @@ -{ - "version": { "major": 2, "minor": 0 }, - "do_communications_commitment": true, - "num_inputs": 2, - "instructions": [ - { "op": "constrain_bits", "var": 0, "bits": 128 }, - { "op": "constrain_bits", "var": 1, "bits": 128 }, - { "op": "load_imm", "imm": "01" }, - { "op": "private_input", "guard": null }, - { "op": "constrain_bits", "var": 3, "bits": 128 }, - { "op": "load_imm", "imm": "10" }, - { "op": "load_imm", "imm": "02" }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 5 }, - { "op": "pi_skip", "guard": 2, "count": 5 }, - { "op": "load_imm", "imm": "11" }, - { "op": "declare_pub_input", "var": 6 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 2 }, - { "op": "declare_pub_input", "var": 4 }, - { "op": "declare_pub_input", "var": 3 }, - { "op": "pi_skip", "guard": 2, "count": 5 }, - { "op": "load_imm", "imm": "91" }, - { "op": "declare_pub_input", "var": 7 }, - { "op": "pi_skip", "guard": 2, "count": 1 } - ] -} diff --git a/packages/simulator/test/fixtures/utils/address.ts b/packages/simulator/test/fixtures/utils/address.ts index da7578d..2541f17 100644 --- a/packages/simulator/test/fixtures/utils/address.ts +++ b/packages/simulator/test/fixtures/utils/address.ts @@ -3,7 +3,7 @@ import { encodeCoinPublicKey, } from '@midnight-ntwrk/compact-runtime'; import { encodeContractAddress } from '@midnight-ntwrk/ledger'; -import type * as Compact from '../test-artifacts/SampleZOwnable/contract/index.cjs'; +import type * as Compact from '../artifacts/SampleZOwnable/contract/index.cjs'; const PREFIX_ADDRESS = '0200'; diff --git a/packages/simulator/test/integration/SampleZOwnable.test.ts b/packages/simulator/test/integration/SampleZOwnable.test.ts index f5152c5..5133b79 100644 --- a/packages/simulator/test/integration/SampleZOwnable.test.ts +++ b/packages/simulator/test/integration/SampleZOwnable.test.ts @@ -5,8 +5,8 @@ import { persistentHash, } from '@midnight-ntwrk/compact-runtime'; import { beforeEach, describe, expect, it } from 'vitest'; +import type { ZswapCoinPublicKey } from '../fixtures/artifacts/SampleZOwnable/contract/index.cjs'; import { SampleZOwnablePrivateState } from '../fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses.js'; -import type { ZswapCoinPublicKey } from '../fixtures/test-artifacts/SampleZOwnable/contract/index.cjs'; import * as utils from '../fixtures/utils/address.js'; import { SampleZOwnableSimulator } from './SampleZOwnableSimulator.js'; diff --git a/packages/simulator/test/integration/SampleZOwnableSimulator.ts b/packages/simulator/test/integration/SampleZOwnableSimulator.ts index 7b22f12..c917d6f 100644 --- a/packages/simulator/test/integration/SampleZOwnableSimulator.ts +++ b/packages/simulator/test/integration/SampleZOwnableSimulator.ts @@ -1,15 +1,15 @@ import { type BaseSimulatorOptions, createSimulator } from '../../src/index'; -import { - SampleZOwnablePrivateState, - SampleZOwnableWitnesses, -} from '../fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses'; import { type ContractAddress, type Either, ledger, Contract as SampleZOwnable, type ZswapCoinPublicKey, -} from '../fixtures/test-artifacts/SampleZOwnable/contract/index.cjs'; +} from '../fixtures/artifacts/SampleZOwnable/contract/index.cjs'; +import { + SampleZOwnablePrivateState, + SampleZOwnableWitnesses, +} from '../fixtures/sample-contracts/witnesses/SampleZOwnableWitnesses'; /** * Type constructor args diff --git a/packages/simulator/test/integration/SimpleSimulator.ts b/packages/simulator/test/integration/SimpleSimulator.ts index 980b145..28ca49d 100644 --- a/packages/simulator/test/integration/SimpleSimulator.ts +++ b/packages/simulator/test/integration/SimpleSimulator.ts @@ -1,12 +1,12 @@ import { type BaseSimulatorOptions, createSimulator } from '../../src/index'; +import { + ledger, + Contract as SimpleContract, +} from '../fixtures/artifacts/Simple/contract/index.cjs'; import { SimplePrivateState, SimpleWitnesses, } from '../fixtures/sample-contracts/witnesses/SimpleWitnesses'; -import { - ledger, - Contract as SimpleContract, -} from '../fixtures/test-artifacts/Simple/contract/index.cjs'; /** * Base simulator diff --git a/packages/simulator/test/integration/WitnessSimulator.ts b/packages/simulator/test/integration/WitnessSimulator.ts index 3bc0953..6388cba 100644 --- a/packages/simulator/test/integration/WitnessSimulator.ts +++ b/packages/simulator/test/integration/WitnessSimulator.ts @@ -1,12 +1,12 @@ import { type BaseSimulatorOptions, createSimulator } from '../../src/index'; +import { + ledger, + Contract as SampleZOwnable, +} from '../fixtures/artifacts/Witness/contract/index.cjs'; import { WitnessPrivateState, WitnessWitnesses, } from '../fixtures/sample-contracts/witnesses/WitnessWitnesses'; -import { - ledger, - Contract as SampleZOwnable, -} from '../fixtures/test-artifacts/Witness/contract/index.cjs'; /** * Type constructor args diff --git a/packages/simulator/test/setup.ts b/packages/simulator/test/setup.ts new file mode 100644 index 0000000..8687ae7 --- /dev/null +++ b/packages/simulator/test/setup.ts @@ -0,0 +1,72 @@ +/** + * Test setup script that compiles sample contracts before running tests. + * Runs once before all tests via Vitest's globalSetup. + */ + +import { exec } from 'node:child_process'; +import { existsSync, mkdirSync, statSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { promisify } from 'node:util'; + +const execAsync = promisify(exec); + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const SAMPLE_CONTRACTS_DIR = join(__dirname, 'fixtures', 'sample-contracts'); +const ARTIFACTS_DIR = join(__dirname, 'fixtures', 'artifacts'); + +const CONTRACT_FILES = [ + 'Simple.compact', + 'Witness.compact', + 'SampleZOwnable.compact', +]; + +async function compileContract(contractFile: string): Promise { + const inputPath = join(SAMPLE_CONTRACTS_DIR, contractFile); + const contractName = contractFile.replace('.compact', ''); + const outputDir = join(ARTIFACTS_DIR, contractName); + const contractArtifact = join(outputDir, 'contract', 'index.cjs'); + + // Skip if artifact already exists and is newer than source + if (existsSync(contractArtifact) && existsSync(inputPath)) { + const artifactTime = statSync(contractArtifact).mtime; + const sourceTime = statSync(inputPath).mtime; + if (artifactTime >= sourceTime) { + console.log(`✓ ${contractFile} (already compiled)`); + return; // Already compiled and up to date + } + } + + if (!existsSync(inputPath)) { + throw new Error(`Contract file not found: ${inputPath}`); + } + + // Ensure output directory and keys subdirectory exist + mkdirSync(outputDir, { recursive: true }); + mkdirSync(join(outputDir, 'keys'), { recursive: true }); + + const command = `compact compile --skip-zk "${inputPath}" "${outputDir}"`; + await execAsync(command); + console.log(`✓ Compiled ${contractFile}`); +} + +async function setup(): Promise { + mkdirSync(ARTIFACTS_DIR, { recursive: true }); + + // Compile each contract sequentially + for (const contractFile of CONTRACT_FILES) { + await compileContract(contractFile); + } +} + +// Export setup function for Vitest's globalSetup +export default async function globalSetup(): Promise { + try { + await setup(); + } catch (error) { + console.log(`❌ Setup failed: ${error}`); + process.exit(1); + } +} diff --git a/packages/simulator/test/unit/core/StateManager.test.ts b/packages/simulator/test/unit/core/StateManager.test.ts index 871d2b4..99634da 100644 --- a/packages/simulator/test/unit/core/StateManager.test.ts +++ b/packages/simulator/test/unit/core/StateManager.test.ts @@ -12,11 +12,11 @@ import { } from '@midnight-ntwrk/compact-runtime'; import { beforeEach, describe, expect, it } from 'vitest'; import { CircuitContextManager } from '../../../src/core/CircuitContextManager'; +import { Contract as MockSimple } from '../../fixtures/artifacts/Simple/contract/index.cjs'; import { type SimplePrivateState, SimpleWitnesses, } from '../../fixtures/sample-contracts/witnesses/SimpleWitnesses'; -import { Contract as MockSimple } from '../../fixtures/test-artifacts/Simple/contract/index.cjs'; import { encodeToAddress, toHexPadded } from '../../fixtures/utils/address'; // Constants diff --git a/packages/simulator/vitest.config.ts b/packages/simulator/vitest.config.ts index d57e53a..7f52faf 100644 --- a/packages/simulator/vitest.config.ts +++ b/packages/simulator/vitest.config.ts @@ -6,5 +6,6 @@ export default defineConfig({ environment: 'node', include: ['test/**/*.test.ts'], reporters: 'verbose', + globalSetup: ['./test/setup.ts'], }, }); diff --git a/turbo.json b/turbo.json index 199d22c..ccff1cd 100644 --- a/turbo.json +++ b/turbo.json @@ -1,16 +1,9 @@ { - "extends": [ - "//" - ], "$schema": "https://turbo.build/schema.json", "tasks": { "test": { - "dependsOn": [ - "^build" - ], - "env": [ - "COMPACT_HOME" - ], + "dependsOn": ["^build"], + "env": ["COMPACT_HOME"], "inputs": [ "src/**/*.ts", "src/**/*.compact", @@ -21,12 +14,8 @@ "cache": false }, "build": { - "dependsOn": [ - "^build" - ], - "env": [ - "COMPACT_HOME" - ], + "dependsOn": ["^build"], + "env": ["COMPACT_HOME"], "inputs": [ "src/**/*.ts", "!src/**/*.test.ts", @@ -34,15 +23,11 @@ "tsconfig.build.json", ".env" ], - "outputs": [ - "dist/**" - ] + "outputs": ["dist/**"] }, "types": { "dependsOn": [], - "outputs": [ - "dist/**" - ] + "outputs": ["dist/**"] }, "fmt-and-lint": {}, "fmt-and-lint:ci": {}, @@ -54,4 +39,4 @@ "cache": false } } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 25810ba..d901727 100644 --- a/yarn.lock +++ b/yarn.lock @@ -388,9 +388,9 @@ __metadata: languageName: node linkType: hard -"@openzeppelin/compact-tools-compact@workspace:packages/compact": +"@openzeppelin/compact-tools-cli@workspace:packages/cli": version: 0.0.0-use.local - resolution: "@openzeppelin/compact-tools-compact@workspace:packages/compact" + resolution: "@openzeppelin/compact-tools-cli@workspace:packages/cli" dependencies: "@tsconfig/node24": "npm:^24.0.1" "@types/node": "npm:24.9.0"