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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
"formatter": {
"enabled": true,
"indentStyle": "space",
"includes": [
"**"
]
"includes": ["**"]
},
"assist": {
"actions": {
Expand Down Expand Up @@ -96,9 +94,7 @@
"noConsole": {
"level": "error",
"options": {
"allow": [
"log"
]
"allow": ["log"]
}
}
},
Expand All @@ -115,4 +111,4 @@
"indentStyle": "space"
}
}
}
}
18 changes: 17 additions & 1 deletion packages/simulator/src/factory/createSimulator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { WitnessContext } from '@midnight-ntwrk/compact-runtime';
import type {
EncodedZswapLocalState,
WitnessContext,
} from '@midnight-ntwrk/compact-runtime';
import { sampleContractAddress } from '@midnight-ntwrk/zswap';
import { CircuitContextManager } from '../core/CircuitContextManager.js';
import { ContractSimulator } from '../core/ContractSimulator.js';
Expand Down Expand Up @@ -173,5 +176,18 @@ export function createSimulator<P, L, W, TArgs extends readonly any[]>(
contractAddress: circuitCtx.transactionContext.address,
};
}

/**
* Gets the current Zswap local state containing coin inputs/outputs and transaction data.
*
* @returns The encoded Zswap state including:
* - `coinPublicKey`: The public key associated with this transaction
* - `currentIndex`: The current index in the Zswap state
* - `inputs`: Array of consumed coin inputs
* - `outputs`: Array of created coin outputs
*/
public getZswapState(): EncodedZswapLocalState {
return this.circuitContext.currentZswapLocalState;
}
};
}
2 changes: 1 addition & 1 deletion packages/simulator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export type {
ExtractImpureCircuits,
ExtractPureCircuits,
IContractSimulator,
IMinimalContract
IMinimalContract,
} from './types/index.js';
export type { BaseSimulatorOptions } from './types/Options.js';
38 changes: 38 additions & 0 deletions packages/simulator/test/fixtures/sample-contracts/UTXO.compact
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
pragma language_version >= 0.18.0;

import CompactStandardLibrary;

export { ZswapCoinPublicKey, ContractAddress, Either, Maybe, CoinInfo, QualifiedCoinInfo };

export ledger _coin: QualifiedCoinInfo;

export circuit mint(
domain: Bytes<32>,
amount: Uint<64>,
nonce: Bytes<32>,
recipient: Either<ZswapCoinPublicKey, ContractAddress>
): [] {
mintToken(disclose(domain), disclose(amount), disclose(nonce), disclose(recipient));
}

export circuit sendToken(
input: QualifiedCoinInfo,
recipient: Either<ZswapCoinPublicKey, ContractAddress>,
value: Uint<64>
): [] {
send(disclose(input), disclose(recipient), disclose(value));
}

export circuit receiveToken(coin: CoinInfo): [] {
const disclosedCoin = disclose(coin);
receive(disclosedCoin);
const thisContract = right<ZswapCoinPublicKey, ContractAddress>(kernel.self());
_coin.writeCoin(disclosedCoin, thisContract);
}

export circuit receiveTokenSendChange(coin: CoinInfo, change: Uint<64>): [] {
const dislosedCoin = disclose(coin);
receive(dislosedCoin);
const eitherCaller = left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey());
sendImmediate(dislosedCoin, eitherCaller, disclose(change));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type UTXOPrivateState = Record<string, never>;
export const UTXOPrivateState: UTXOPrivateState = {};
export const UTXOWitnesses = () => ({});
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
{
"circuits": [
{
"name": "mint",
"pure": false,
"arguments": [
{
"name": "domain",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "amount",
"type": {
"type-name": "Uint",
"maxval": 18446744073709551615
}
},
{
"name": "nonce",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "recipient",
"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
}
}
]
}
}
]
}
}
],
"result-type": {
"type-name": "Tuple",
"types": [
]
}
},
{
"name": "sendToken",
"pure": false,
"arguments": [
{
"name": "input",
"type": {
"type-name": "Struct",
"name": "QualifiedCoinInfo",
"elements": [
{
"name": "nonce",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "color",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "value",
"type": {
"type-name": "Uint",
"maxval": 340282366920938463463374607431768211455
}
},
{
"name": "mt_index",
"type": {
"type-name": "Uint",
"maxval": 18446744073709551615
}
}
]
}
},
{
"name": "recipient",
"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": "value",
"type": {
"type-name": "Uint",
"maxval": 18446744073709551615
}
}
],
"result-type": {
"type-name": "Tuple",
"types": [
]
}
},
{
"name": "receiveToken",
"pure": false,
"arguments": [
{
"name": "coin",
"type": {
"type-name": "Struct",
"name": "CoinInfo",
"elements": [
{
"name": "nonce",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "color",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "value",
"type": {
"type-name": "Uint",
"maxval": 340282366920938463463374607431768211455
}
}
]
}
}
],
"result-type": {
"type-name": "Tuple",
"types": [
]
}
},
{
"name": "receiveTokenSendChange",
"pure": false,
"arguments": [
{
"name": "coin",
"type": {
"type-name": "Struct",
"name": "CoinInfo",
"elements": [
{
"name": "nonce",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "color",
"type": {
"type-name": "Bytes",
"length": 32
}
},
{
"name": "value",
"type": {
"type-name": "Uint",
"maxval": 340282366920938463463374607431768211455
}
}
]
}
},
{
"name": "change",
"type": {
"type-name": "Uint",
"maxval": 18446744073709551615
}
}
],
"result-type": {
"type-name": "Tuple",
"types": [
]
}
}
],
"witnesses": [
],
"contracts": [
]
}
Loading