Skip to content

Commit b35c712

Browse files
committed
feat!: adopt optimized api interfaces & remove local
1 parent ceaa9a7 commit b35c712

File tree

32 files changed

+352
-407
lines changed

32 files changed

+352
-407
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Please note that (during testnet phrase) your address balance (in zkwasm server)
313313
#### WasmBinPath
314314

315315
- **Type:** `string`
316-
- **Default**: `[root]/build/cle_full.wasm`
316+
- **Default**: `[root]/build/cle.wasm`
317317

318318
CLE CLI Build-In a tag name is `root`.
319319
The `root` is user project root path.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@antfu/ni": "^0.21.8",
2424
"@antfu/utils": "^0.7.6",
2525
"@murongg/eslint-config": "^0.2.1",
26-
"@ora-io/cle-lib": "^1.0.1-alpha.2",
26+
"@ora-io/cle-lib": "^1.0.1-alpha.4",
2727
"@types/fs-extra": "^11.0.2",
2828
"@types/node": "^18.18.4",
2929
"assemblyscript": "^0.27.12",

packages/cle-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Please note that (during testnet phrase) your address balance (in zkwasm server)
260260
#### WasmBinPath
261261

262262
- **Type:** `string`
263-
- **Default**: `[root]/build/cle_full.wasm`
263+
- **Default**: `[root]/build/cle.wasm`
264264

265265
CLE CLI Build-In a tag name is `root`.
266266
The `root` is user project root path.

packages/cle-cli/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"start": "esno src/index.ts"
4646
},
4747
"peerDependencies": {
48-
"@ora-io/cle-lib": "^1.0.1-alpha.2"
48+
"@ora-io/cle-lib": "^1.0.1-alpha.4"
4949
},
5050
"dependencies": {
5151
"@antfu/utils": "^0.7.6",
@@ -64,10 +64,11 @@
6464
"prompts": "^2.4.2",
6565
"semver": "^7.5.4",
6666
"ts-md5": "^1.3.1",
67-
"unconfig": "^0.3.11"
67+
"unconfig": "^0.3.11",
68+
"zkwasm-toolchain": "^0.0.4"
6869
},
6970
"devDependencies": {
70-
"@ora-io/cle-lib": "^1.0.1-alpha.0",
71+
"@ora-io/cle-lib": "^1.0.1-alpha.4",
7172
"@types/js-yaml": "^4.0.6",
7273
"@types/prompts": "^2.4.6",
7374
"@types/semver": "^7.5.3"

packages/cle-cli/src/cli.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ export async function run() {
2323
const { proveUsage, execUsage } = generateCommandUsage()
2424
cli
2525
.command('compile', 'Compile for Full Image (Link Compiled with Compiler Server)')
26-
.option('--local', 'Compile for Local Image')
26+
// .option('--local', 'Compile for Local Image')
2727
.option('--yaml-path <path>', 'Path to yaml file')
2828
.option('--mapping-path <path>', 'Path to mapping file')
2929
.example('cle compile')
3030
.action((options) => {
31-
const { local = false, yamlPath = '', mappingPath = '' } = options
32-
const wasmPath = local ? config.LocalWasmBinPath : config.WasmBinPath
31+
const { yamlPath = '', mappingPath = '' } = options
32+
const wasmPath = config.WasmBinPath
3333

3434
compile({
35-
local,
35+
// local,
3636
yamlPath: yamlPath || config.YamlPath,
3737
compilerServerEndpoint: config.CompilerServerEndpoint,
3838
wasmPath,
@@ -43,14 +43,14 @@ export async function run() {
4343

4444
cli
4545
.command('exec [...params]', 'Execute Full Image')
46-
.option('--local', 'Execute Local Image')
46+
// .option('--local', 'Execute Local Image')
4747
.example('cle exec 0000000')
48-
.action((params, options) => {
49-
const { local = false } = options
50-
const wasmPath = local ? config.LocalWasmBinPath : config.WasmBinPath
48+
.action((params, _options) => {
49+
// const { local = false } = options
50+
const wasmPath = config.WasmBinPath
5151

5252
exec({
53-
local,
53+
// local,
5454
wasmPath,
5555
yamlPath: config.YamlPath,
5656
jsonRpcProviderUrl: config.JsonRpcProviderUrl,
@@ -64,13 +64,14 @@ Usage cases:
6464

6565
cli
6666
.command('setup', 'Set Up Full Image')
67-
.option('--local', 'Set Up Local Image')
67+
// .option('--local', 'Set Up Local Image')
6868
.option('-k, --circuit-size <size>', 'Circuit size (k in 2^k) of image')
6969
.example('cle setup -k 20')
7070
.action((options) => {
71-
const { circuitSize = '', local = false } = options
72-
const wasmPath = local ? config.LocalWasmBinPath : config.WasmBinPath
73-
const size = !circuitSize || circuitSize === 0 ? local ? 20 : 22 : Number(circuitSize)
71+
// const { circuitSize = '', local = false } = options
72+
const { circuitSize = '' } = options
73+
const wasmPath = config.WasmBinPath
74+
const size = !circuitSize || circuitSize === 0 ? 22 : Number(circuitSize)
7475
setup({
7576
circuitSize: size,
7677
wasmPath,
@@ -81,7 +82,7 @@ Usage cases:
8182

8283
const proveCLI = cli
8384
.command('prove [...params]', 'Prove Full Image')
84-
.option('--local', 'Prove Local Image')
85+
// .option('--local', 'Prove Local Image')
8586
.option('-i, --inputgen', 'Run in input generation Mode')
8687
.option('-t, --test', 'Run in test Mode')
8788
.option('-p, --prove', 'Run in prove Mode')
@@ -90,7 +91,7 @@ Usage cases:
9091
.example('cle prove 2279547 a60ecf32309539dd84f27a9563754dca818b815e -p')
9192
.action((params, options) => {
9293
// eslint-disable-next-line prefer-const
93-
let { inputgen = false, test = false, prove = false, local = false } = options
94+
let { inputgen = false, test = false, prove = false } = options
9495
const hasMode = proveCLIHasModeOption()
9596
if (!hasMode)
9697
test = true
@@ -100,14 +101,14 @@ Usage cases:
100101
proveCLI.outputHelp()
101102
return
102103
}
103-
const wasmPath = local ? config.LocalWasmBinPath : config.WasmBinPath
104+
const wasmPath = config.WasmBinPath
104105

105106
proveHandler({
106107
params,
107108
inputgen,
108109
test,
109110
prove,
110-
local,
111+
// local,
111112
wasmPath,
112113
yamlPath: config.YamlPath,
113114
jsonRpcProviderUrl: config.JsonRpcProviderUrl,
@@ -123,13 +124,13 @@ Usage cases:
123124

124125
cli
125126
.command('upload', 'Upload CLE (Code and Full Image)')
126-
.option('--local', 'Upload Local CLE (Code and Local Image)')
127+
// .option('--local', 'Upload Local CLE (Code and Local Image)')
127128
.example('cle upload')
128-
.action((options) => {
129-
const { local = false } = options
129+
.action((_options) => {
130+
// const { local = false } = options
130131
upload({
131-
local,
132-
wasmPath: local ? config.LocalWasmBinPath : config.WasmBinPath,
132+
// local,
133+
wasmPath: config.WasmBinPath,
133134
yamlPath: config.YamlPath,
134135
pinataEndpoint: config.PinataEndpoint,
135136
pinataJWT: config.PinataJWT,

packages/cle-cli/src/commands/compile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createOnNonexist, isTsFile } from '../utils'
77
import { logger } from '../logger'
88

99
export interface CompileOptions {
10-
local: boolean
10+
// local: boolean
1111
yamlPath?: string
1212
compilerServerEndpoint: string
1313
wasmPath: string
@@ -33,7 +33,7 @@ async function compileBasic(options: CompileOptions) {
3333
wasmPath,
3434
watPath,
3535
mappingPath,
36-
local,
36+
// local,
3737
} = options
3838
if (!yamlPath) {
3939
logger.error('no yaml path provided')
@@ -55,7 +55,7 @@ async function compileBasic(options: CompileOptions) {
5555
...fileMap,
5656
[relativeYamlPath]: yaml,
5757
}, {
58-
isLocal: local,
58+
// isLocal: local,
5959
yamlPath: path.relative(path.dirname(mappingPath), yamlPath),
6060
outWasmPath: wasmPath,
6161
outWatPath: watPath,

packages/cle-cli/src/commands/exec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import { logger } from '../logger'
77
import type { UserConfig } from '../config'
88

99
export interface ExecOptions {
10-
local: boolean
10+
// local: boolean
1111
wasmPath: string
1212
yamlPath: string
1313
jsonRpcProviderUrl: UserConfig['JsonRpcProviderUrl']
1414
params?: any[]
1515
}
1616
// TODO: prepare all params, dsp select params.
1717
export async function exec(options: ExecOptions) {
18-
const { yamlPath, jsonRpcProviderUrl, wasmPath, local, params = [] } = options
18+
const { yamlPath, jsonRpcProviderUrl, wasmPath, params = [] } = options
1919

2020
const cleYaml = loadYamlFromPath(yamlPath)
2121
if (!cleYaml) {
2222
logger.error('[-] ERROR: Failed to get yaml')
2323
return
2424
}
25-
const dsp = zkgapi.dspHub.getDSPByYaml(cleYaml, { isLocal: local })
25+
const dsp = zkgapi.dspHub.getDSPByYaml(cleYaml)
2626
if (!dsp) {
2727
logger.error('[-] ERROR: Failed to get DSP')
2828
return
@@ -56,7 +56,7 @@ export async function exec(options: ExecOptions) {
5656
const state = await zkgapi.execute(
5757
cleExecutable,
5858
execParams,
59-
local,
59+
// local,
6060
)
6161

6262
logger.info(`[+] CLE STATE OUTPUT: ${toHexString(state)}\n`)

packages/cle-cli/src/commands/prove.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { providers } from 'ethers'
33
import to from 'await-to-js'
44
import prompts from 'prompts'
55
import * as zkgapi from '@ora-io/cle-api'
6+
import type { Input } from 'zkwasm-toolchain'
67
import { convertToMd5, generateDspHubParams, loadJsonRpcProviderUrl, loadYamlFromPath, logLoadingAnimation, taskPrettyPrint, validateProvider } from '../utils'
78
import { logger } from '../logger'
89
import type { UserConfig } from '../config'
@@ -14,7 +15,7 @@ export interface ProveOptions {
1415
inputgen: boolean
1516
test: boolean
1617
prove: boolean
17-
local: boolean
18+
// local: boolean
1819
wasmPath: string
1920
yamlPath: string
2021
jsonRpcProviderUrl: UserConfig['JsonRpcProviderUrl']
@@ -30,7 +31,7 @@ export async function prove(options: ProveOptions) {
3031
inputgen,
3132
test,
3233
prove,
33-
local,
34+
// local,
3435
wasmPath,
3536
yamlPath,
3637
jsonRpcProviderUrl,
@@ -44,7 +45,7 @@ export async function prove(options: ProveOptions) {
4445
logger.error('[-] ERROR: Failed to get yaml')
4546
return
4647
}
47-
const dsp = zkgapi.dspHub.getDSPByYaml(yaml, { isLocal: local })
48+
const dsp = zkgapi.dspHub.getDSPByYaml(yaml)
4849
if (!dsp) {
4950
logger.error('[-] ERROR: Failed to get DSP')
5051
return
@@ -102,24 +103,23 @@ export async function prove(options: ProveOptions) {
102103
cleYaml: yaml as zkgapi.CLEYaml,
103104
}
104105

105-
const [privateInputStr, publicInputStr] = await zkgapi.proveInputGen(
106+
const input = await zkgapi.proveInputGen(
106107
cleExecutable,
107108
proveParams,
108-
local,
109109
)
110110

111111
if (inputgen) {
112112
// Input generation mode
113-
logger.info('[+] PRIVATE INPUT FOR ZKWASM:' + `\n${privateInputStr}`)
114-
logger.info('[+] PUBLIC INPUT FOR ZKWASM:' + `\n${publicInputStr}`)
113+
logger.info('[+] PRIVATE INPUT FOR ZKWASM:' + `\n${input.getPrivateInputStr()}`)
114+
logger.info('[+] PUBLIC INPUT FOR ZKWASM:' + `\n${input.getPublicInputStr()}`)
115115
}
116116
else if (test) {
117117
// Test mode
118-
await testMode(wasmUint8Array, privateInputStr, publicInputStr)
118+
await testMode(wasmUint8Array, input)
119119
}
120120
else if (prove) {
121121
// Prove mode
122-
await proveMode(userPrivateKey, md5, privateInputStr, publicInputStr, zkWasmProviderUrl, outputProofFilePath)
122+
await proveMode(userPrivateKey, md5, input.getPrivateInputStr(), input.getPublicInputStr(), zkWasmProviderUrl, outputProofFilePath)
123123
}
124124
}
125125
/**
@@ -128,16 +128,15 @@ export async function prove(options: ProveOptions) {
128128
* @param privateInputStr
129129
* @param publicInputStr
130130
*/
131-
async function testMode(wasmUint8Array: Uint8Array, privateInputStr: string, publicInputStr: string) {
131+
async function testMode(wasmUint8Array: Uint8Array, input: Input) {
132132
const cleExecutable = {
133133
wasmUint8Array,
134134
cleYaml: null,
135135
}
136136

137137
const [mockErr, mockSuccess] = await to(zkgapi.proveMock(
138138
cleExecutable,
139-
privateInputStr,
140-
publicInputStr,
139+
input,
141140
))
142141

143142
if (mockErr) {

packages/cle-cli/src/commands/upload.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { logger } from '../logger'
55
import { checkPinataAuthentication, loadYamlFromPath } from '../utils'
66

77
export interface UploadOptions {
8-
local: boolean
8+
// local: boolean
99
wasmPath: string
1010
userPrivateKey: string
1111
yamlPath: string
@@ -36,15 +36,16 @@ export async function upload(options: UploadOptions) {
3636
'cle.wasm': wasmFile,
3737
'cle.yaml': yamlFile,
3838
}
39+
const directoryTag = { userAddress, graphName: yaml.name }
40+
const directoryName = `${directoryTag.graphName}-${directoryTag.userAddress}`
3941

4042
const { isUploadSuccess, response, errorMessage } = await uploadApi(
4143
files,
4244
{
43-
userAddress,
44-
graphName: yaml.name,
45+
pinataEndpoint,
46+
pinataJWT,
47+
directoryName,
4548
},
46-
pinataEndpoint,
47-
pinataJWT,
4849
)
4950
if (isUploadSuccess) {
5051
logger.info('[+] IPFS UPLOAD SUCCESS!')

packages/cle-cli/src/config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ export interface UserConfig {
3737
* @default "[root]/build/cle.wasm"
3838
*/
3939
WasmBinPath?: string
40-
/**
41-
* @default "[root]/build/cle_local.wasm"
42-
*/
43-
LocalWasmBinPath?: string
4440

4541
/**
4642
* @default "[root]/src/cle.yaml"
@@ -108,7 +104,7 @@ export async function getConfig(configFile?: string, configRoot?: string) {
108104
const userConfig = await loadConfigFromFile(configFile, configRoot)
109105

110106
userConfig.WasmBinPath = parseTemplateTag(userConfig.WasmBinPath || '', TAGS)
111-
userConfig.LocalWasmBinPath = parseTemplateTag(userConfig.LocalWasmBinPath || '', TAGS)
107+
// userConfig.LocalWasmBinPath = parseTemplateTag(userConfig.LocalWasmBinPath || '', TAGS)
112108
userConfig.YamlPath = parseTemplateTag(userConfig.YamlPath || '', TAGS)
113109
userConfig.MappingPath = parseTemplateTag(userConfig.MappingPath || '', TAGS)
114110

0 commit comments

Comments
 (0)