circuitscan
Advanced tools
Comparing version 0.0.3-alpha to 0.0.5-alpha
@@ -5,2 +5,3 @@ #!/usr/bin/env node | ||
import {verify, deploy} from './index.js'; | ||
import {instanceSizes} from './src/utils.js'; | ||
@@ -20,6 +21,7 @@ const program = new Command(); | ||
.option('-v, --circom-version <circomVersion>', 'Specify the Circom version (e.g. "v2.1.8")') | ||
.option('-i, --instance <memorySize>', 'Specify the memory (GB) of compiler instance: 4 for testing (default: 10GB lambda, faster init for small circuits)') | ||
.option('-i, --instance <memorySize>', `Specify the memory (GB) of compiler instance: ${Object.keys(instanceSizes).join(', ')} (default: 10GB lambda, faster init for small circuits)`) | ||
.option('-l, --localhost <localPort>', 'Use a circom compiler container running on a specific port') | ||
.action(verify); | ||
// TODO .option('-b, --browser-wallet', 'Send transaction in browser instead of by passing private key env var') | ||
program | ||
@@ -31,3 +33,3 @@ .command('deploy <mainCircomFile> <chainId>') | ||
.option('-v, --circom-version <circomVersion>', 'Specify the Circom version (e.g. "v2.1.8")') | ||
.option('-i, --instance <memorySize>', 'Specify the memory (GB) of compiler instance: 4 for testing (default: 10GB lambda, faster init for small circuits)') | ||
.option('-i, --instance <memorySize>', `Specify the memory (GB) of compiler instance: ${Object.keys(instanceSizes).join(', ')} (default: 10GB lambda, faster init for small circuits)`) | ||
.option('-l, --localhost <localPort>', 'Use a circom compiler container running on a specific port') | ||
@@ -34,0 +36,0 @@ .action(deploy); |
112
index.js
@@ -18,4 +18,4 @@ import {relative, dirname} from 'node:path'; | ||
// Default running on AWS Lambda max 10GB ram | ||
const circomCompilerURL = 'https://uvopzbfbfz5i5m4i3tsgq7rjeu0glwdl.lambda-url.us-west-2.on.aws/'; | ||
const stackStarterURL = 'https://fydvjclemuhxdzsv2treynl32q0rwtpp.lambda-url.us-west-2.on.aws/'; | ||
const lambdaCompilerURL = 'https://uvopzbfbfz5i5m4i3tsgq7rjeu0glwdl.lambda-url.us-west-2.on.aws/'; | ||
const ec2CompilerURL = 'https://yps4edoigeexpc2hzhvswru3b40mfbal.lambda-url.us-west-2.on.aws/'; | ||
const blobUrl = 'https://blob.circuitscan.org/'; | ||
@@ -25,4 +25,4 @@ | ||
const chain = findChain(chainId); | ||
if(!chain) throw new Error('invalid_chain'); | ||
const {curCompilerURL, stackId} = await determineCompilerUrl(options); | ||
if(!chain) throw new Error('INVALID_CHAIN'); | ||
const {curCompilerURL} = await determineCompilerUrl(options); | ||
try { | ||
@@ -34,5 +34,2 @@ const compiled = await compileFile(file, options, { curCompilerURL }); | ||
} | ||
if(stackId) { | ||
await stopInstance(stackId); | ||
} | ||
} | ||
@@ -42,3 +39,3 @@ | ||
const chain = findChain(chainId); | ||
if(!chain) throw new Error('invalid_chain'); | ||
if(!chain) throw new Error('INVALID_CHAIN'); | ||
const privateKey = process.env.DEPLOYER_PRIVATE_KEY; | ||
@@ -49,10 +46,5 @@ if(!privateKey || !isHex(privateKey) || privateKey.length !== 66) | ||
throw new Error('MISSING_' + chain.apiKeyEnvVar); | ||
const {curCompilerURL, stackId} = await determineCompilerUrl(options); | ||
let instanceRunning = !!stackId; | ||
const {curCompilerURL} = await determineCompilerUrl(options); | ||
try { | ||
const compiled = await compileFile(file, options, { curCompilerURL }); | ||
if(stackId) { | ||
await stopInstance(stackId); | ||
instanceRunning = false; | ||
} | ||
const contractSource = await (await fetch(`${blobUrl}${compiled.pkgName}/verifier.sol`)).text(); | ||
@@ -78,10 +70,6 @@ const solcOutput = compileContract(contractSource); | ||
} | ||
if(stackId && instanceRunning) { | ||
await stopInstance(stackId); | ||
} | ||
} | ||
async function determineCompilerUrl(options) { | ||
let curCompilerURL = circomCompilerURL; | ||
let stackId; | ||
let curCompilerURL = lambdaCompilerURL; | ||
if(options.localhost) { | ||
@@ -91,70 +79,6 @@ if(isNaN(options.localhost)) throw new Error('Invalid localhost port specified'); | ||
} else if(options.instance) { | ||
stackId = await startInstance(options); | ||
curCompilerURL = `https://${stackId}.circuitscan.org/2015-03-31/functions/function/invocations`; | ||
curCompilerURL = ec2CompilerURL; | ||
} | ||
return {curCompilerURL, stackId}; | ||
return {curCompilerURL}; | ||
} | ||
async function startInstance(options) { | ||
if(!(options.instance in instanceSizes)) | ||
throw new Error('Invalid instance size'); | ||
const instanceType = instanceSizes[options.instance]; | ||
// instance starting... | ||
console.log(`# Starting ${instanceType} instance...`); | ||
const startResult = await fetchJson(stackStarterURL, { | ||
action: 'start', | ||
params: { instanceType }, | ||
}); | ||
if(!('stackId' in startResult)) { | ||
console.error(startResult); | ||
throw new Error('Invalid response starting instance.'); | ||
} | ||
console.log('# Waiting for instance to boot...'); | ||
const stackId = startResult.stackId.match( | ||
/arn:aws:cloudformation:[^:]+:[^:]+:stack\/([^\/]+)/)[1]; | ||
const publicHost = `https://${stackId}.circuitscan.org`; | ||
let statusResult; | ||
while(statusResult = await fetchJson(stackStarterURL, { | ||
action: 'status', | ||
params: { stackId }, | ||
})) { | ||
if(statusResult.status === 'CREATE_COMPLETE') break; | ||
else if(statusResult.status !== 'CREATE_IN_PROGRESS') | ||
throw new Error('Instance failed to start.'); | ||
process.stdout.write('.'); | ||
await delay(5000); | ||
} | ||
console.log('# Waiting for service to be ready...'); | ||
let serviceResult; | ||
while(true) { | ||
await delay(5000); | ||
process.stdout.write('.'); | ||
try { | ||
serviceResult = await fetchJson(publicHost, { | ||
payload: { | ||
action: 'invalid', | ||
} | ||
}); | ||
break; | ||
} catch(error) { | ||
if(error.cause && (error.cause.code !== 'ENOTFOUND')) throw error; | ||
if(!error.cause) break; | ||
} | ||
} | ||
return stackId; | ||
} | ||
async function stopInstance(stackId) { | ||
console.log(`# Stopping instance ${stackId}...`); | ||
const stopResult = await fetchJson(stackStarterURL, { | ||
action: 'stop', | ||
params: { stackId }, | ||
}); | ||
if(stopResult.message !== 'Stack deletion initiated') { | ||
console.log(stopResult); | ||
throw new Error('ERROR_WHILE_DELETING_STACK'); | ||
} | ||
} | ||
async function compileFile(file, options, {curCompilerURL}) { | ||
@@ -180,2 +104,5 @@ const loaded = loadCircom(file); | ||
const status = new StatusLogger(`${blobUrl}status/${requestId}.json`, 3000); | ||
if('instance' in options && !(options.instance in instanceSizes)) | ||
throw new Error('INVALID_INSTANCE_SIZE'); | ||
const instanceType = options.instance ? instanceSizes[options.instance] : undefined; | ||
@@ -185,2 +112,3 @@ const event = { | ||
requestId, | ||
instanceType, | ||
action: 'build', | ||
@@ -214,6 +142,7 @@ files, | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
const body = await response.text(); | ||
throw new Error('Network response was not ok: ' + body); | ||
} | ||
const data = await response.json(); | ||
const body = 'body' in data ? JSON.parse(data.body) : data; | ||
let body = 'body' in data ? JSON.parse(data.body) : data; | ||
if('errorType' in body) { | ||
@@ -223,2 +152,11 @@ throw new Error('Invalid compilation result'); | ||
if(data.status === 'ok' && !('pkgName' in body)) { | ||
console.log('# Instance started. Wait a few minutes for initialization...'); | ||
while(!status.lastData || !status.lastData.find(x => x.msg === 'Complete.')) { | ||
await delay(5000); | ||
} | ||
const response = await fetch(`${blobUrl}instance-response/${requestId}.json`); | ||
const data = await response.json(); | ||
body = JSON.parse(data.body); | ||
} | ||
status.stop(); | ||
@@ -225,0 +163,0 @@ return body; |
{ | ||
"name": "circuitscan", | ||
"version": "0.0.3-alpha", | ||
"version": "0.0.5-alpha", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -11,2 +11,3 @@ import https from 'https'; | ||
this.stopped = false; | ||
this.lastData = null; | ||
this.start(); | ||
@@ -31,2 +32,3 @@ } | ||
const json = JSON.parse(data); | ||
this.lastData = json; | ||
resolve(json); | ||
@@ -33,0 +35,0 @@ } catch (e) { |
@@ -68,9 +68,9 @@ import {accessSync} from 'node:fs'; | ||
4: 't3.medium', | ||
// 32: 'x2gd.large', | ||
// 64: 'x2gd.xlarge', | ||
// 128: 'x2gd.2xlarge', | ||
// 256: 'x2gd.4xlarge', | ||
// 512: 'x2gd.8xlarge', | ||
// 768: 'x2gd.12xlarge', | ||
// 1024: 'x2gd.16xlarge', | ||
// 16: 'r7i.large', | ||
// 32: 'r7i.xlarge', | ||
// 64: 'r7i.2xlarge', | ||
// 128: 'r7i.4xlarge', | ||
// 256: 'r7i.8xlarge', | ||
// 384: 'r7i.12xlarge', | ||
// 1536: 'r7i.16xlarge', | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33734
19
770
8