Skip to content
Open
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: 1 addition & 1 deletion examples/confidential-coins/scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ POWERSOFTAUFILE="${TEST_DIR}/powersOfTau28_hez_final_08.ptau"
# Pre-generated powersOfTau from snarkjs
#
if ! [ -e ${POWERSOFTAUFILE} ] ; then
curl https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_08.ptau --output ${POWERSOFTAUFILE}
curl https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_08.ptau --output ${POWERSOFTAUFILE}
fi

# We just need the following files from this setup script.
Expand Down
3 changes: 1 addition & 2 deletions examples/demo-app/core/scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ circom ${TEST_DIR}/circuit.circom --r1cs --wasm --output ${TEST_DIR}
POWERSOFTAUFILE="${TEST_DIR}/powersOfTau28_hez_final_08.ptau"

# Pre-generated powersOfTau from snarkjs
#
if ! [ -e ${POWERSOFTAUFILE} ] ; then
curl https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_08.ptau --output ${POWERSOFTAUFILE}
curl https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_08.ptau --output ${POWERSOFTAUFILE}
fi

# We just need the following files from this setup script.
Expand Down
2 changes: 1 addition & 1 deletion upa/scripts/test_upa
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pushd _test_upa
# --submission-file submit-multi-4.submission.json

# Extract the submissions
upa get-submission `cat submit-1.tx.hash` > submit-1.submission.json
upa get-submission --events `cat submit-1.tx.hash` > submit-1.submission.json
upa get-submission `cat submit-multi-4.tx.hash` > submit-multi-4.submission.json

multi_4_submissionid=`jq -r .submissionId submit-multi-4.submission.json`
Expand Down
13 changes: 10 additions & 3 deletions upa/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,20 @@ function start_daemon() {

# 1 - name
function stop_daemon() {
pid_file="$1.pid"
cid_file="$1.cid"
if [ "${DOCKER}" == "1" ] ; then
cid_file="$1.cid"
if ! [ -e ${cid_file} ] ; then
echo "$1 has no CID file: ${cid_file}"
return
fi

cid=$(cat ${cid_file})
docker container kill ${cid}
docker container kill ${cid} || \
echo "Failed stopping container ${cid}. It may have died."

rm ${cid_file}
else
pid_file="$1.pid"
if ! [ -e ${pid_file} ] ; then
echo "$1 has no PID file: ${pid_file}"
return
Expand Down
41 changes: 41 additions & 0 deletions upa/src/sdk/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ export abstract class EventGetterBase<
return output;
}

public parseTransactionReceipt(
txReceipt: ethers.TransactionReceipt
): EventSet<EventOutput> {
const evName = this.eventName();
const events: EventOutput[] = [];
for (const log of txReceipt.logs) {
const parsed = this.upa.interface.parseLog(log as unknown as ethers.Log)!;
const name = parsed.name;
if (name === evName) {
events.push(this.parseEvent(parsed as unknown as TypedEventLog<Event>));
}
}
return {
blockNumber: txReceipt.blockNumber,
txHash: txReceipt.hash,
events,
};
}

abstract eventName(): string;

// TODO: There should be a generic way to write this.
abstract parseEvent(ev: TypedEventLog<Event>): EventOutput;
}
Expand Down Expand Up @@ -151,6 +172,10 @@ export class ProofSubmittedEventGetter extends EventGetterBase<
super(upa, upa.filters.ProofSubmitted(...args));
}

eventName(): string {
return "ProofSubmitted";
}

parseEvent(
ev: TypedEventLog<ProofSubmittedEvent.Event>
): ProofSubmittedEvent.OutputObject {
Expand Down Expand Up @@ -345,6 +370,10 @@ export class SubmissionVerifiedEventGetter extends EventGetterBase<
super(upa, upa.filters.SubmissionVerified(...args));
}

eventName(): string {
return "SubmissionVerified";
}

parseEvent(
ev: TypedEventLog<SubmissionVerifiedEvent.Event>
): SubmissionVerifiedEvent.OutputObject {
Expand Down Expand Up @@ -416,6 +445,10 @@ export class VKRegisteredEventGetter extends EventGetterBase<
super(upa, upa.filters.VKRegistered());
}

eventName(): string {
return "VKRegistered";
}

parseEvent(
ev: TypedEventLog<VKRegisteredEvent.Event>
): VKRegisteredEvent.OutputObject {
Expand All @@ -439,6 +472,10 @@ export class ChallengeEventGetter extends EventGetterBase<
super(upa, upa.filters.Challenge());
}

eventName(): string {
return "Challenge";
}

// eslint-disable-next-line
parseEvent(ev: TypedEventLog<ChallengeEvent.Event>): ChallengeEventOutput {
return {};
Expand All @@ -458,6 +495,10 @@ export class SubmissionChallengeSuccessEventGetter extends EventGetterBase<
super(upa, upa.filters.SubmissionChallengeSuccess());
}

eventName(): string {
return "SubmissionChallengeSuccess";
}

// eslint-disable-next-line
parseEvent(ev: TypedEventLog<ChallengeEvent.Event>): ChallengeEventOutput {
return {};
Expand Down
29 changes: 27 additions & 2 deletions upa/src/tool/getSubmission.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { command, positional, string } from "cmd-ts";
import { command, flag, positional, string } from "cmd-ts";
import * as options from "./options";
import * as ethers from "ethers";
import * as config from "./config";
import * as utils from "../sdk/utils";
import { Submission } from "../sdk";
import { EventSet, ProofSubmittedEventGetter } from "../sdk/events";
// eslint-disable-next-line
import { ProofSubmittedEvent } from "../../typechain-types/contracts/tests/TestUpgradedUpaVerifier";

export const getSubmission = command({
name: "get-submission",
Expand All @@ -15,9 +18,18 @@ export const getSubmission = command({
displayName: "tx-id",
description: "Tx Id of the submission to retrieve",
}),
events: flag({
long: "events",
description: "Dump event data for the submission",
}),
},
description: "Get the on-chain submission information associated with a Tx",
handler: async function ({ chainEndpoint, instance, txId }): Promise<void> {
handler: async function ({
chainEndpoint,
instance,
txId,
events,
}): Promise<void> {
const provider = new ethers.JsonRpcProvider(chainEndpoint);
const { verifier } = await config.upaFromInstanceFile(instance, provider);

Expand All @@ -30,6 +42,19 @@ export const getSubmission = command({
txReceipt
);

// If the events flag is given, dump the event data.
if (events) {
const evGetter = new ProofSubmittedEventGetter(verifier);
const eventSet = evGetter.parseTransactionReceipt(txReceipt);
// Put the event set on an `eventSet` attribute of the submission
// object.
(
submission as unknown as {
eventSet: EventSet<ProofSubmittedEvent.OutputObject>;
}
).eventSet = eventSet;
}

console.log(utils.JSONstringify(submission));
},
});
34 changes: 34 additions & 0 deletions upa/src/tool/isVerified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,37 @@ export const isVerified = command({
process.exit(verified ? 0 : 1);
},
});

export const isUnitSubmissionVerified = command({
name: "is-unit-submission",
description:
"Query UPA contract for verification status of a single-proof submission " +
"with the given proofid",
args: {
chainEndpoint: options.chainEndpoint(),
instance: options.instance(),
proofId: positional({
type: string,
displayName: "proof-id",
description: "Proof Id to verifiy (must be part of single submission)",
}),

proofReferenceFile: options.proofReferenceFile(),
},
handler: async function ({
chainEndpoint,
instance,
proofId,
}): Promise<void> {
const provider = new ethers.JsonRpcProvider(chainEndpoint);
const upa = await config.upaFromInstanceFile(instance, provider);

const verified = await upa.verifier.getFunction("isProofVerified(bytes32)")(
proofId
);

// write 1/0 to stdout and use exit status to indicate validity
console.log(verified ? "1" : "0");
process.exit(verified ? 0 : 1);
},
});
7 changes: 6 additions & 1 deletion upa/src/tool/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { getConfig } from "./getConfig";
import { chainEndpoint, instance } from "./options";
import { ethers } from "ethers";
import { upaFromInstanceFile } from "./config";
import { isVerified, isSubmissionVerified } from "./isVerified";
import {
isVerified,
isSubmissionVerified,
isUnitSubmissionVerified,
} from "./isVerified";
import { getAggregatedProofVerifier } from "./aggregatedProofVerifier";

const getVerifierByteCode = command({
Expand Down Expand Up @@ -39,5 +43,6 @@ export const query = subcommands({
"verifier-bytecode": getVerifierByteCode,
"is-verified": isVerified,
"is-submission-verified": isSubmissionVerified,
"is-unit-submission-verified": isUnitSubmissionVerified,
},
});