Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ runs:
if: ${{ inputs.skip-compact != 'true' }}
uses: midnightntwrk/setup-compact-action@4130145456ad3f45934788dd4a65647eb283e658 # loose commit/not released
with:
compact-version: "0.26.0"
compact-version: "0.28.0"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Confirm your Compact toolchain:
```bash
$ compact compile --version

Compactc version: 0.26.0
0.26.0
Compactc version: 0.28.0
0.28.0
```

## Getting started
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
"types": "turbo run types",
"clean": "turbo run clean"
},
"dependencies": {
"@midnight-ntwrk/compact-runtime": "^0.9.0"
},
"devDependencies": {
"@biomejs/biome": "2.3.8",
"@midnight-ntwrk/ledger": "^4.0.0",
"@midnight-ntwrk/ledger-v7": "^7.0.0",
"@midnight-ntwrk/zswap": "^4.0.0",
"@types/node": "24.10.1",
"ts-node": "^10.9.2",
Expand Down
22 changes: 11 additions & 11 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Verify your Compact installation:

```bash
$ compact compile --version
Compactc version: 0.26.0
Compactc version: 0.28.0
```

## Binaries
Expand Down Expand Up @@ -52,7 +52,7 @@ compact-compiler [options]
| `--out <directory>` | Output directory for compiled artifacts | `artifacts` |
| `--hierarchical` | Preserve source directory structure in output | `false` |
| `--skip-zk` | Skip zero-knowledge proof generation | `false` |
| `+<version>` | Use specific toolchain version (e.g., `+0.26.0`) | (default) |
| `+<version>` | Use specific toolchain version (e.g., `+0.28.0`) | (default) |

### Environment Variables

Expand Down Expand Up @@ -102,7 +102,7 @@ compact-compiler --dir security
compact-compiler --skip-zk

# Use specific toolchain version
compact-compiler +0.26.0
compact-compiler +0.28.0

# Custom source and output directories
compact-compiler --src contracts --out build
Expand Down Expand Up @@ -155,7 +155,7 @@ import { CompactCompiler } from '@openzeppelin/compact-tools-cli';
const compiler = new CompactCompiler({
flags: '--skip-zk',
targetDir: 'security',
version: '0.26.0',
version: '0.28.0',
hierarchical: true,
srcDir: 'src',
outDir: 'artifacts',
Expand All @@ -167,7 +167,7 @@ await compiler.compile();
const compiler = CompactCompiler.fromArgs([
'--dir', 'security',
'--skip-zk',
'+0.26.0'
'+0.28.0'
]);

await compiler.compile();
Expand Down Expand Up @@ -196,7 +196,7 @@ class CompactBuilder {
interface CompilerOptions {
flags?: string; // Compiler flags (e.g., '--skip-zk --verbose')
targetDir?: string; // Subdirectory within srcDir to compile
version?: string; // Toolchain version (e.g., '0.26.0')
version?: string; // Toolchain version (e.g., '0.28.0')
hierarchical?: boolean; // Preserve directory structure in output
srcDir?: string; // Source directory (default: 'src')
outDir?: string; // Output directory (default: 'artifacts')
Expand Down Expand Up @@ -233,15 +233,15 @@ yarn clean

## Output Example

```
```bash
ℹ [COMPILE] Compact compiler started
ℹ [COMPILE] Compact developer tools: compact 0.1.0
ℹ [COMPILE] Compact toolchain: Compactc version: 0.26.0
ℹ [COMPILE] Compact developer tools: compact 0.2.0
ℹ [COMPILE] Compact toolchain: Compactc version: 0.28.0
ℹ [COMPILE] Found 2 .compact file(s) to compile
✔ [COMPILE] [1/2] Compiled AccessControl.compact
Compactc version: 0.26.0
Compactc version: 0.28.0
✔ [COMPILE] [2/2] Compiled Token.compact
Compactc version: 0.26.0
Compactc version: 0.28.0
```

## License
Expand Down
4 changes: 2 additions & 2 deletions packages/simulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ allowing you to simulate contract behavior locally without blockchain deployment

```typescript
import { createSimulator } from '@openzeppelin-compact/contracts-simulator';
import { Contract, ledger } from './artifacts/MyContract/contract/index.cjs';
import { Contract, ledger } from './artifacts/MyContract/contract/index.js';

// 1. Define your contract arguments type
type MyContractArgs = readonly [owner: Uint8Array, value: bigint];
Expand Down Expand Up @@ -46,7 +46,7 @@ The base simulator acts as a configuration class that the actual simulator will

```typescript
import { createSimulator } from '@openzeppelin-compact/contracts-simulator';
import { Contract as MyContract, ledger } from './artifacts/MyContract/contract/index.cjs';
import { Contract as MyContract, ledger } from './artifacts/MyContract/contract/index.js';
import { MyContractWitnesses, MyContractPrivateState } from './MyContractWitnesses.js';

// Define contract constructor arguments as a tuple type
Expand Down
4 changes: 2 additions & 2 deletions packages/simulator/package.json
Comment thread
andrew-fleming marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"clean": "git clean -fXd"
},
"devDependencies": {
"@midnight-ntwrk/ledger": "^4.0.0",
"@midnight-ntwrk/ledger-v7": "^7.0.0",
"@midnight-ntwrk/zswap": "^4.0.0",
"@tsconfig/node24": "^24.0.3",
"@types/node": "24.10.1",
Expand All @@ -39,6 +39,6 @@
"vitest": "^4.0.15"
},
"dependencies": {
"@midnight-ntwrk/compact-runtime": "^0.9.0"
"@midnight-ntwrk/compact-runtime": "0.14.0"
}
}
10 changes: 5 additions & 5 deletions packages/simulator/src/core/AbstractSimulator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
CircuitContext,
CoinPublicKey,
ContractState,
StateValue,
} from '@midnight-ntwrk/compact-runtime';
import type {
ContextlessCircuits,
Expand Down Expand Up @@ -79,12 +79,12 @@ export abstract class AbstractSimulator<P, L>
}

/**
* Retrieves the original contract state from the circuit context.
* Retrieves the current contract state data.
*
* @returns The current contract state from the blockchain
* @returns The current state value containing the ledger data
*/
public getContractState(): ContractState {
return this.circuitContext.originalState;
public getContractState(): StateValue {
return this.circuitContext.currentQueryContext.state.state;
Comment thread
0xisk marked this conversation as resolved.
}

/**
Expand Down
15 changes: 8 additions & 7 deletions packages/simulator/src/core/CircuitContextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
type ConstructorContext,
type ContractAddress,
type ContractState,
constructorContext,
CostModel,
createConstructorContext,
type EncodedZswapLocalState,
QueryContext,
} from '@midnight-ntwrk/compact-runtime';
Expand Down Expand Up @@ -44,22 +45,22 @@ export class CircuitContextManager<P> {
contractAddress: ContractAddress,
...contractArgs: any[]
) {
const initCtx = constructorContext(privateState, coinPK);
const initCtx = createConstructorContext(privateState, coinPK);

const {
currentPrivateState,
currentContractState,
currentZswapLocalState,
} = contract.initialState(initCtx, ...contractArgs);

// Extract ChargedState from the compiler-generated ContractState
const chargedState = currentContractState.data;

this.context = {
currentPrivateState,
currentZswapLocalState,
originalState: currentContractState,
transactionContext: new QueryContext(
currentContractState.data,
contractAddress,
),
currentQueryContext: new QueryContext(chargedState, contractAddress),
costModel: CostModel.initialCostModel(),
Comment thread
0xisk marked this conversation as resolved.
};
}

Expand Down
8 changes: 6 additions & 2 deletions packages/simulator/src/core/ContractSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ export abstract class ContractSimulator<P, L> extends AbstractSimulator<P, L> {
*/
public getCallerContext(): CircuitContext<P> {
const activeCaller = this.callerOverride || this.persistentCallerOverride;
const baseCtx = this.circuitContext;
Comment thread
0xisk marked this conversation as resolved.

return {
...this.circuitContext,
Comment thread
0xisk marked this conversation as resolved.
currentPrivateState: baseCtx.currentPrivateState,
currentQueryContext: baseCtx.currentQueryContext,
currentZswapLocalState: activeCaller
? emptyZswapLocalState(activeCaller)
: this.circuitContext.currentZswapLocalState,
: baseCtx.currentZswapLocalState,
costModel: baseCtx.costModel,
gasLimit: baseCtx.gasLimit,
};
}

Expand Down
10 changes: 5 additions & 5 deletions packages/simulator/src/factory/createSimulator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WitnessContext } from '@midnight-ntwrk/compact-runtime';
import { sampleContractAddress } from '@midnight-ntwrk/zswap';
import { dummyContractAddress } from '@midnight-ntwrk/compact-runtime';
import { CircuitContextManager } from '../core/CircuitContextManager.js';
import { ContractSimulator } from '../core/ContractSimulator.js';
import type { IMinimalContract } from '../types/Contract.js';
Expand Down Expand Up @@ -49,7 +49,7 @@ export function createSimulator<
privateState = config.defaultPrivateState(),
witnesses = config.witnessesFactory(),
coinPK = '0'.repeat(64),
contractAddress = sampleContractAddress(),
contractAddress = dummyContractAddress(),
} = options;

this._witnesses = witnesses;
Expand All @@ -65,7 +65,7 @@ export function createSimulator<
...processedArgs,
);

this.contractAddress = this.circuitContext.transactionContext.address;
this.contractAddress = this.circuitContext.currentQueryContext.address;
}

public _pureCircuitProxy?: ContextlessCircuits<
Expand Down Expand Up @@ -143,7 +143,7 @@ export function createSimulator<
*/
getPublicState(): L {
return config.ledgerExtractor(
this.circuitContext.transactionContext.state,
this.circuitContext.currentQueryContext.state.state,
);
}

Expand Down Expand Up @@ -191,7 +191,7 @@ export function createSimulator<
return {
ledger: this.getPublicState(),
privateState: circuitCtx.currentPrivateState,
contractAddress: circuitCtx.transactionContext.address,
contractAddress: circuitCtx.currentQueryContext.address,
};
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/simulator/src/types/Simulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
CircuitContext,
ContractState,
StateValue,
} from '@midnight-ntwrk/compact-runtime';

/**
Expand Down Expand Up @@ -31,7 +31,7 @@ export interface IContractSimulator<P, L> {
getPrivateState(): P;

/**
* Returns the original contract state.
* Returns the current contract state.
*/
getContractState(): ContractState;
getContractState(): StateValue;
}
22 changes: 14 additions & 8 deletions packages/simulator/src/utils/CircuitContextUtils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
type ChargedState,
type CircuitContext,
type CoinPublicKey,
type ContractAddress,
type ContractState,
CostModel,
emptyZswapLocalState,
QueryContext,
} from '@midnight-ntwrk/compact-runtime';
Expand All @@ -15,22 +16,22 @@ import type { IContractSimulator } from '../types/index.js';
* for executing circuits, including contract state, private state,
* sender identity, and transaction data.
* @param privateState - The private state data specific to the contract
* @param contractState - The current contract state from the blockchain
* @param chargedState - The charged state (wraps StateValue with cost tracking)
* @param sender - The public key of the transaction sender
* @param contractAddress - The address of the contract being executed
* @returns A complete CircuitContext ready for circuit execution
*/
export function useCircuitContext<P>(
privateState: P,
contractState: ContractState,
chargedState: ChargedState,
sender: CoinPublicKey,
contractAddress: ContractAddress,
): CircuitContext<P> {
return {
originalState: contractState,
currentPrivateState: privateState,
transactionContext: new QueryContext(contractState.data, contractAddress),
currentQueryContext: new QueryContext(chargedState, contractAddress),
currentZswapLocalState: emptyZswapLocalState(sender),
costModel: CostModel.initialCostModel(),
};
}

Expand All @@ -47,14 +48,19 @@ export function useCircuitContextSender<
L,
C extends IContractSimulator<P, L>,
>(contract: C, sender: CoinPublicKey): CircuitContext<P> {
const currentCircuitContext = contract.circuitContext;
const currentPrivateState = contract.getPrivateState();
const originalState = contract.getContractState();
const existingChargedState = currentCircuitContext.currentQueryContext.state;
const contractAddress = contract.contractAddress;

return {
originalState,
currentPrivateState,
transactionContext: new QueryContext(originalState.data, contractAddress),
currentQueryContext: new QueryContext(
existingChargedState,
contractAddress,
),
currentZswapLocalState: emptyZswapLocalState(sender),
costModel: currentCircuitContext.costModel,
gasLimit: currentCircuitContext.gasLimit,
};
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// Sample contract for testing
// DO NOT USE IN PRODUCTION!!!

pragma language_version >= 0.18.0;
pragma language_version >= 0.20.0;

import CompactStandardLibrary;
import {
Either,
Counter,
ZswapCoinPublicKey,
ContractAddress,
persistentHash,
ownPublicKey,
} from CompactStandardLibrary;

export { ZswapCoinPublicKey, ContractAddress, Either };
export ledger _ownerCommitment: Bytes<32>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pragma language_version >= 0.18.0;
// Sample contract for testing
// DO NOT USE IN PRODUCTION!!!

import CompactStandardLibrary;
pragma language_version >= 0.20.0;

import { ZswapCoinPublicKey, ContractAddress, Either, Maybe } from CompactStandardLibrary;

export { ZswapCoinPublicKey, ContractAddress, Either, Maybe };
export ledger _val: Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pragma language_version >= 0.18.0;
// Sample contract for testing
// DO NOT USE IN PRODUCTION!!!

import CompactStandardLibrary;
pragma language_version >= 0.20.0;

import { ZswapCoinPublicKey, ContractAddress, Either, Maybe } from CompactStandardLibrary;

export { ZswapCoinPublicKey, ContractAddress, Either, Maybe };
export ledger _valBytes: Bytes<32>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getRandomValues } from 'node:crypto';
import type { WitnessContext } from '@midnight-ntwrk/compact-runtime';
import type { Ledger } from '../../artifacts/SampleZOwnable/contract/index.cjs';
import type { Ledger } from '../../artifacts/SampleZOwnable/contract/index.js';

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