Skip to content
Merged
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
11 changes: 6 additions & 5 deletions upa/scripts/test_upa
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ pushd _test_upa
--dump-tx \
${UPA_DIR}/upa/test/data/test.bin \
> new_agg_proof_verifier.tx
KEYFILE_PASSWORD=${DUMMY_PW} upa owner deploy-binary \
--keyfile ${KEYFILE} \
KEYFILE_PASSWORD=${DUMMY_PW} KEYFILE=`cat ${KEYFILE}` upa owner deploy-binary \
${UPA_DIR}/upa/test/data/test.bin \
> new_agg_proof_verifier.addr
# Test dumpt-tx with a different --from address
# Test dump-tx with a different --from address
upa owner set-aggregated-proof-verifier \
--keyfile ${USER_KEYFILE} \
--from ${deployer_addr} \
Expand All @@ -84,8 +83,10 @@ pushd _test_upa
${orig_max_num_inputs} --wait
[ `cat new_agg_proof_verifier.addr` == `upa query aggregated-proof-verifier` ]

# Print the config
upa query config > config.upa.json
# Print the config. Test UPA_INSTANCE as content
mv upa.instance upa.instance.bak
UPA_INSTANCE=`cat upa.instance.bak` upa query config > config.upa.json
mv upa.instance.bak upa.instance

# Test data:
# vk
Expand Down
19 changes: 13 additions & 6 deletions upa/src/tool/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ import { GnarkInputs, GnarkProof, GnarkVerificationKey } from "../sdk/gnark";
import { computeCircuitId } from "../sdk/utils";
import { SP1ProofFixture } from "../sdk/sp1";

/// Infer whether value is JSON or a filename. Return the JSON string.
export function readJSONContentOrFile(value: string): string {
// Infer from the first character. If it's '{', assume JSON.
return value.startsWith("{") ? value : fs.readFileSync(value, "ascii");
}

/// Load an instance descriptor file
export function loadInstance(instanceFile: string): UpaInstanceDescriptor {
return JSON.parse(
fs.readFileSync(instanceFile, "ascii")
) as UpaInstanceDescriptor;
const instanceStr = readJSONContentOrFile(instanceFile);
return JSON.parse(instanceStr) as UpaInstanceDescriptor;
}

/// Load an instance descriptor file and initialize and instance. Optionally
Expand All @@ -40,7 +45,8 @@ export async function upaFromInstanceFile(

/// Create a Signer from an encrypted keyfile, allowing overriding by a
/// VoidSigner (which cannot actually sign) for a specific fromAddress (for
/// simulating txs).
/// simulating txs). Keyfile can be either keyfile contents (JSON) or a
/// filename.
export async function loadWallet(
keyfile: string,
password: string,
Expand All @@ -52,7 +58,7 @@ export async function loadWallet(
return new ethers.VoidSigner(fromAddress, provider);
}

const keystoreStr = fs.readFileSync(keyfile, "ascii");
const keystoreStr = readJSONContentOrFile(keyfile);
let wallet = await ethers.Wallet.fromEncryptedJson(keystoreStr, password);
if (provider) {
wallet = wallet.connect(provider);
Expand All @@ -62,7 +68,8 @@ export async function loadWallet(

/// Read an address from a keyfile
export function readAddressFromKeyfile(keyfile: string): string {
const keystoreObj = JSON.parse(fs.readFileSync(keyfile, "ascii"));
const keystoreStr = readJSONContentOrFile(keyfile);
const keystoreObj = JSON.parse(keystoreStr);
return ethers.getAddress(keystoreObj.address);
}

Expand Down
54 changes: 21 additions & 33 deletions upa/src/tool/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,19 @@ export function keyfile(
required: boolean = true
): Option {
const defaultValue = () => {
const value = process.env.KEYFILE;
if (!value && required) {
if (required) {
// Caught by the CLI framework
throw "Keyfile not specified";
}

return value || "";
return "";
};
return option({
type: string,
long: "keyfile",
short: "k",
env: "KEYFILE",
defaultValue,
description:
description || "Keyfile to sign tx (defaults to KEYFILE env var)",
description: description || "Keyfile to sign tx (file or contents)",
});
}

Expand All @@ -47,10 +45,9 @@ export function password(description?: string | undefined): Option {
return option({
type: string,
long: "password",
defaultValue: () => process.env.KEYFILE_PASSWORD || "",
description:
description ||
"Password for keyfile (defaults to KEYFILE_PASSWORD env var)",
env: "KEYFILE_PASSWORD",
defaultValue: () => "",
description: description || "Password for keyfile",
});
}

Expand Down Expand Up @@ -79,55 +76,47 @@ export function getPassword(password?: string): string {

export function chainEndpoint(required: boolean = true): Option {
const defaultValue = () => {
const value = process.env.CHAIN_ENDPOINT;
if (!value && required) {
if (required) {
throw "CHAIN_ENDPOINT not specified";
}

return value || "http://127.0.0.1:8545/";
return "http://127.0.0.1:8545/";
};
return option({
type: string,
long: "chain-endpoint",
short: "e",
env: "CHAIN_ENDPOINT",
defaultValue,
description: "Chain RPC endpoint (defaults to CHAIN_ENDPOINT env var)",
description: "Chain RPC endpoint",
});
}

export function submissionEndpoint(): Option {
return option({
type: string,
long: "submission-endpoint",
defaultValue: () => process.env.SUBMISSION_ENDPOINT || "",
description:
"Submission endpoint (defaults to SUBMISSION_ENDPOINT env var)",
env: "SUBMISSION_ENDPOINT",
defaultValue: () => "",
description: "Submission endpoint",
});
}

export function depositContract() {
return option({
type: string,
long: "deposit-contract",
description:
"Aggregator's deposit contract (DEPOSIT_CONTRACT or query server)",
defaultValue: () => {
const val = process.env.DEPOSIT_CONTRACT;
if (val) {
return val;
}

throw "deposit contract not specified";
},
description: "Aggregator's deposit contract",
env: "DEPOSIT_CONTRACT",
});
}

export function instance(description?: string | undefined): Option {
return option({
type: string,
long: "instance",
env: "UPA_INSTANCE",
defaultValue: () => "upa.instance",
description: description || "UPA instance file",
description: description || "UPA instance file or contents",
});
}

Expand Down Expand Up @@ -254,10 +243,9 @@ export function maxFeePerGasGwei(): Option {
return option({
type: string,
long: "max-fee-per-gas",
defaultValue: () => {
return process.env.MAX_FEE_PER_GAS_GWEI || "";
},
description: "Maximum fee per gas(Gwei) (or env var MAX_FEE_PER_GAS_GWEI)",
env: "MAX_FEE_PER_GAS_GWEI",
defaultValue: () => "",
description: "Maximum fee per gas(Gwei)",
});
}

Expand Down
Loading