Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OUTDATED] Add a sindri proof create commmand #40

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 2 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { lintCommand } from "cli/lint";
import { logger } from "cli/logging";
import { loginCommand } from "cli/login";
import { logoutCommand } from "cli/logout";
import { proofCommand } from "cli/proof";
import { whoamiCommand } from "cli/whoami";
import { loadPackageJson } from "cli/utils";

Expand All @@ -29,6 +30,7 @@ export const program = new Command()
.addCommand(lintCommand)
.addCommand(loginCommand)
.addCommand(logoutCommand)
.addCommand(proofCommand)
.addCommand(whoamiCommand)
// Parse the base command options and respond to them before invoking the subcommand.
.hook("preAction", async (command) => {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const loginCommand = new Command()
try {
// Generate a JWT token to authenticate the user.
OpenAPI.BASE = baseUrl;
const tokenResult = await TokenService.bf740E1AControllerObtainToken({
const tokenResult = await TokenService.aa5976D9ControllerObtainToken({
username,
password,
});
Expand Down
145 changes: 145 additions & 0 deletions src/cli/proof.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import fs from "fs";
import path from "path";
import process from "process";

import { Command } from "@commander-js/extra-typings";

import { Config } from "cli/config";
import { logger, print } from "cli/logging";
import { findFileUpwards } from "cli/utils";
import { ApiError, CircuitsService } from "lib/api";

const readStdin = async (): Promise<string> => {
let inputData = "";
return new Promise((resolve) => {
process.stdin.on("data", (chunk) => (inputData += chunk));
process.stdin.on("end", () => resolve(inputData));
});
};

const proofCreateCommand = new Command()
.name("create")
.description("Create a proof for the circuit.")
.option(
"-i, --input <input>",
"Input file for the proof (defaults to stdin).",
)
.option("-t, --tag <tag>", "Tag to generate the proof from.", "latest")
.action(async ({ input, tag }) => {
// Authorize the API client.
const config = new Config();
const auth = config.auth;
if (!auth) {
logger.warn("You must login first with `sindri login`.");
return process.exit(1);
}

// Find `sindri.json` and move into the root of the project directory.
const currentDirectoryPath = path.resolve(".");
if (!fs.existsSync(currentDirectoryPath)) {
logger.error(
`The "${currentDirectoryPath}" directory does not exist. Aborting.`,
);
return process.exit(1);
}
const sindriJsonPath = findFileUpwards(
/^sindri.json$/i,
currentDirectoryPath,
);
if (!sindriJsonPath) {
logger.error(
`No "sindri.json" file was found in or above "${currentDirectoryPath}". Aborting.`,
);
return process.exit(1);
}
logger.debug(`Found "sindri.json" at "${sindriJsonPath}".`);
const rootDirectory = path.dirname(sindriJsonPath);
logger.debug(`Changing current directory to "${rootDirectory}".`);
process.chdir(rootDirectory);

// Load `sindri.json` and find the circuit name.
let sindriJson: object = {};
try {
const sindriJsonContent = fs.readFileSync(sindriJsonPath, {
encoding: "utf-8",
});
sindriJson = JSON.parse(sindriJsonContent);
logger.debug(
`Successfully loaded "sindri.json" from "${sindriJsonPath}":`,
);
logger.debug(sindriJson);
} catch (error) {
logger.fatal(
`Error loading "${sindriJsonPath}", perhaps it is not valid JSON?`,
);
logger.error(error);
return process.exit(1);
}
if (!("name" in sindriJson)) {
logger.error('No "name" field found in "sindri.json". Aborting.');
return process.exit(1);
}
const circuitName = sindriJson.name;

// Reed in the proof input.
let proofInput: string | undefined;
if (input && fs.existsSync(input)) {
// Read from the specified input file.
proofInput = fs.readFileSync(input, "utf-8");
} else if (!process.stdin.isTTY) {
// Read from stdin in a non-TTY context.
proofInput = await readStdin();
} else {
// Try to load from common input filenames.
const defaultInputFiles = [
"input.json",
"example-input.json",
"Prover.toml",
];
for (const file of defaultInputFiles) {
const qualifiedFile = path.join(rootDirectory, file);
if (fs.existsSync(file)) {
proofInput = fs.readFileSync(qualifiedFile, "utf-8");
break;
}
}

if (!proofInput) {
console.error(
"No input file specified, none of the default files found, and not in a non-TTY context.",
);
process.exit(1);
}
}

const circuitIdentifier = `${circuitName}:${tag}`;
try {
const response = await CircuitsService.proofCreate(circuitIdentifier, {
proof_input: proofInput,
});
logger.debug(`/api/v1/circuit/${circuitIdentifier}/prove/ response:`);
logger.debug(response);
print({
proofId: response.proof_id,
proof: response.proof,
public: response.public,
verificationKey: response.verification_key,
});
} catch (error) {
// TODO: Better error handling.
if (error instanceof ApiError && error.status === 404) {
logger.error(
`No circuit found with the name "${circuitName}" and tag "${tag}".`,
);
} else {
logger.fatal("An unknown error occurred.");
logger.error(error);
return process.exit(1);
}
}
});

export const proofCommand = new Command()
.name("proof")
.description("Commands related to proofs for the current circuit.")
.addCommand(proofCreateCommand);
2 changes: 1 addition & 1 deletion src/lib/api/core/OpenAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type OpenAPIConfig = {

export const OpenAPI: OpenAPIConfig = {
BASE: "https://sindri.app",
VERSION: "1.5.10",
VERSION: "1.5.25",
WITH_CREDENTIALS: false,
CREDENTIALS: "include",
TOKEN: undefined,
Expand Down
1 change: 0 additions & 1 deletion src/lib/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type { APIKeyDoesNotExistResponse } from './models/APIKeyDoesNotExistResp
export type { APIKeyErrorResponse } from './models/APIKeyErrorResponse';
export type { APIKeyResponse } from './models/APIKeyResponse';
export type { CircomCircuitInfoResponse } from './models/CircomCircuitInfoResponse';
export type { CircuitCreateInput } from './models/CircuitCreateInput';
export type { CircuitDoesNotExistResponse } from './models/CircuitDoesNotExistResponse';
export { CircuitStatus } from './models/CircuitStatus';
export { CircuitType } from './models/CircuitType';
Expand Down
11 changes: 0 additions & 11 deletions src/lib/api/models/CircuitCreateInput.ts

This file was deleted.

31 changes: 29 additions & 2 deletions src/lib/api/services/CircuitsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
// DO NOT REMOVE THIS!
import FormData from "form-data";

import type { ActionResponse } from "../models/ActionResponse";
import type { CircomCircuitInfoResponse } from "../models/CircomCircuitInfoResponse";
import type { CircuitCreateInput } from "../models/CircuitCreateInput";
import type { GnarkCircuitInfoResponse } from "../models/GnarkCircuitInfoResponse";
import type { Halo2CircuitInfoResponse } from "../models/Halo2CircuitInfoResponse";
import type { NoirCircuitInfoResponse } from "../models/NoirCircuitInfoResponse";
Expand All @@ -28,7 +29,10 @@ export class CircuitsService {
| FormData // DO NOT REMOVE THIS!
| {
files: Array<Blob>;
payload?: CircuitCreateInput;
/**
* Tags for a circuit.
*/
tags?: Array<string>;
},
): CancelablePromise<
| CircomCircuitInfoResponse
Expand Down Expand Up @@ -112,6 +116,29 @@ export class CircuitsService {
});
}

/**
* Delete Circuit
* Mark the specified circuit and any related proofs as deleted.
* @param circuitId
* @returns ActionResponse OK
* @throws ApiError
*/
public static circuitDelete(
circuitId: string,
): CancelablePromise<ActionResponse> {
return __request(OpenAPI, {
method: "DELETE",
url: "/api/v1/circuit/{circuit_id}/delete",
path: {
circuit_id: circuitId,
},
errors: {
404: `Not Found`,
500: `Internal Server Error`,
},
});
}

/**
* Circuit Proofs
* Return list of ProofInfoResponse for proofs of circuit_id related to team.
Expand Down
24 changes: 24 additions & 0 deletions src/lib/api/services/ProofsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { ActionResponse } from "../models/ActionResponse";
import type { ProofInfoResponse } from "../models/ProofInfoResponse";

import type { CancelablePromise } from "../core/CancelablePromise";
Expand Down Expand Up @@ -76,4 +77,27 @@ export class ProofsService {
},
});
}

/**
* Delete Proof
* Mark the specified proof as deleted.
* @param proofId
* @returns ActionResponse OK
* @throws ApiError
*/
public static proofDelete(
proofId: string,
): CancelablePromise<ActionResponse> {
return __request(OpenAPI, {
method: "DELETE",
url: "/api/v1/proof/{proof_id}/delete",
path: {
proof_id: proofId,
},
errors: {
404: `Not Found`,
500: `Internal Server Error`,
},
});
}
}
6 changes: 3 additions & 3 deletions src/lib/api/services/TokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TokenService {
* @returns TokenObtainPairOutputSchema OK
* @throws ApiError
*/
public static bf740E1AControllerObtainToken(
public static aa5976D9ControllerObtainToken(
requestBody: TokenObtainPairInputSchema,
): CancelablePromise<TokenObtainPairOutputSchema> {
return __request(OpenAPI, {
Expand All @@ -37,7 +37,7 @@ export class TokenService {
* @returns TokenRefreshOutputSchema OK
* @throws ApiError
*/
public static db93F15ControllerRefreshToken(
public static a6E7B8BControllerRefreshToken(
requestBody: TokenRefreshInputSchema,
): CancelablePromise<TokenRefreshOutputSchema> {
return __request(OpenAPI, {
Expand All @@ -54,7 +54,7 @@ export class TokenService {
* @returns Schema OK
* @throws ApiError
*/
public static abc17FbControllerVerifyToken(
public static f559BControllerVerifyToken(
requestBody: TokenVerifyInputSchema,
): CancelablePromise<Schema> {
return __request(OpenAPI, {
Expand Down