mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
Merge pull request #2 from yssf-io/updatedCircuits
fixed the "original" vs "groth" library problem
This commit is contained in:
19
zkrsa/circom-rsa-verify/scripts/generateProof.ts
vendored
19
zkrsa/circom-rsa-verify/scripts/generateProof.ts
vendored
@@ -31,12 +31,15 @@ const main = () => {
|
||||
const hashed = bigInt(
|
||||
"68047946378308475289293787357717828552636626916964367437434418622917273241319"
|
||||
);
|
||||
const address = bigInt("70997970C51812dc3A010C7d01b50e0d17dc79C8", 16);
|
||||
const address = bigInt("9D392187c08fc28A86e1354aD63C70897165b982", 16);
|
||||
|
||||
console.log("address", address.toString(10));
|
||||
console.log("address", address);
|
||||
console.log("address.toString(10)", address.toString(10));
|
||||
|
||||
// my test account: 0x9D392187c08fc28A86e1354aD63C70897165b982
|
||||
// hardhat otherAccount: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
|
||||
// hardhat owner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
|
||||
|
||||
const input = Object.assign(
|
||||
{},
|
||||
splitToWords(sign, 64, 32, "sign"),
|
||||
@@ -46,26 +49,26 @@ const main = () => {
|
||||
// splitToWords(address, 64, 4, "address")
|
||||
);
|
||||
|
||||
// input["address[0]"] = address.toString(10).padStart(64, "0");
|
||||
input["address"] = address.toString(10);
|
||||
|
||||
console.log("input:", input);
|
||||
console.log("Calculating witness...");
|
||||
const witness = circuit.calculateWitness(input);
|
||||
|
||||
// CAUTION: this is loading old hardcoded ones
|
||||
console.log("witness", witness);
|
||||
|
||||
console.log("Loading vk proof...");
|
||||
const vkProof = JSON.parse(
|
||||
fs.readFileSync(`./vkeys/${circuitName}.vk_proof`, "utf8")
|
||||
fs.readFileSync(`./groth16_zkey_prove.json`, "utf8")
|
||||
);
|
||||
|
||||
console.log("Loading vk verifier...");
|
||||
const vkVerifier = JSON.parse(
|
||||
fs.readFileSync(`./vkeys/${circuitName}.vk_verifier`, "utf8")
|
||||
fs.readFileSync(`./groth16_zkey_verify.json`, "utf8")
|
||||
);
|
||||
|
||||
console.log("Generating proof...");
|
||||
const { proof, publicSignals } = snarkjs.original.genProof(
|
||||
const { proof, publicSignals } = snarkjs.groth.genProof(
|
||||
unstringifyBigInts(vkProof),
|
||||
unstringifyBigInts(witness)
|
||||
);
|
||||
@@ -73,7 +76,7 @@ const main = () => {
|
||||
console.log("publicSignals:", publicSignals);
|
||||
|
||||
if (
|
||||
snarkjs.original.isValid(
|
||||
snarkjs.groth.isValid(
|
||||
unstringifyBigInts(vkVerifier),
|
||||
unstringifyBigInts(proof),
|
||||
unstringifyBigInts(publicSignals)
|
||||
|
||||
BIN
zkrsa/frontend/public/android-chrome-192x192.png
Normal file
BIN
zkrsa/frontend/public/android-chrome-192x192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
BIN
zkrsa/frontend/public/android-chrome-512x512.png
Normal file
BIN
zkrsa/frontend/public/android-chrome-512x512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 472 KiB |
BIN
zkrsa/frontend/public/apple-touch-icon.png
Normal file
BIN
zkrsa/frontend/public/apple-touch-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
BIN
zkrsa/frontend/public/favicon-16x16.png
Normal file
BIN
zkrsa/frontend/public/favicon-16x16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 839 B |
BIN
zkrsa/frontend/public/favicon-32x32.png
Normal file
BIN
zkrsa/frontend/public/favicon-32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
zkrsa/frontend/public/favicon.ico
Normal file
BIN
zkrsa/frontend/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
1
zkrsa/frontend/public/site.webmanifest
Normal file
1
zkrsa/frontend/public/site.webmanifest
Normal file
@@ -0,0 +1 @@
|
||||
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
PropsButtonExportProof,
|
||||
PropsButtonSearchPassport,
|
||||
} from '../types';
|
||||
import bigInt from 'big-integer';
|
||||
|
||||
const exp = '65537';
|
||||
const devHash = process.env['NEXT_PUBLIC_HASH'] as string | null;
|
||||
@@ -37,7 +38,15 @@ export const theme = createTheme({
|
||||
|
||||
export const ButtonGenerateProof: FunctionComponent<
|
||||
PropsButtonGenerateProof
|
||||
> = ({ setpublicSignals, setproof, hash, signature, publicKey, vkeyProof }) => {
|
||||
> = ({
|
||||
setpublicSignals,
|
||||
setproof,
|
||||
hash,
|
||||
signature,
|
||||
publicKey,
|
||||
address,
|
||||
vkeyProof,
|
||||
}) => {
|
||||
const buttonDisabled = hash && signature && publicKey ? false : true;
|
||||
const [loading, setloading] = useState(false);
|
||||
const workerRef = useRef<Worker>();
|
||||
@@ -82,17 +91,26 @@ export const ButtonGenerateProof: FunctionComponent<
|
||||
disabled={buttonDisabled}
|
||||
onClick={async () => {
|
||||
try {
|
||||
console.log('address:', address);
|
||||
// const a = bigInt(
|
||||
// (address as string).substring(2),
|
||||
// 16
|
||||
// );
|
||||
// console.log('a', a);
|
||||
// console.log('a.toString(10)', a.toString(10));
|
||||
|
||||
setloading(true);
|
||||
seterrorMessage(null);
|
||||
if (devHash) {
|
||||
// @dev handle dev environment here
|
||||
hash = devHash;
|
||||
signature = devSignature;
|
||||
publicKey = devPublicKey;
|
||||
}
|
||||
// if (devHash) {
|
||||
// // @dev handle dev environment here
|
||||
// hash = devHash;
|
||||
// signature = devSignature;
|
||||
// publicKey = devPublicKey;
|
||||
// }
|
||||
setcurrentStep(
|
||||
'Downloading circuit and vkeys...'
|
||||
);
|
||||
console.log('Downloading circuit and vkeys...');
|
||||
const data = await (
|
||||
await axios.get(
|
||||
process.env[
|
||||
@@ -100,6 +118,7 @@ export const ButtonGenerateProof: FunctionComponent<
|
||||
] as any
|
||||
)
|
||||
).data;
|
||||
console.log('got circuit');
|
||||
const circuit = new snarkjs.Circuit(data);
|
||||
const vkeyProof = (
|
||||
await axios.get(
|
||||
@@ -108,6 +127,7 @@ export const ButtonGenerateProof: FunctionComponent<
|
||||
] as string
|
||||
)
|
||||
).data;
|
||||
console.log('got vKey');
|
||||
const input = Object.assign(
|
||||
{},
|
||||
splitToWords(signature, 64, 32, 'sign'),
|
||||
@@ -115,8 +135,23 @@ export const ButtonGenerateProof: FunctionComponent<
|
||||
splitToWords(publicKey, 64, 32, 'modulus'),
|
||||
splitToWords(hash, 64, 4, 'hashed')
|
||||
);
|
||||
if (!address) {
|
||||
console.log('no address');
|
||||
return;
|
||||
}
|
||||
console.log('address:', address);
|
||||
input.address = bigInt(
|
||||
address.substring(2),
|
||||
16
|
||||
).toString(10);
|
||||
console.log('input:', input);
|
||||
|
||||
const witness = circuit.calculateWitness(input);
|
||||
console.log('Generating proof...');
|
||||
setcurrentStep('Generating proof...');
|
||||
console.log('witness:', witness);
|
||||
console.log('vkeyProof:', vkeyProof);
|
||||
console.log('circuit:', circuit);
|
||||
workerRef.current!.postMessage({
|
||||
vkeyProof,
|
||||
witness,
|
||||
|
||||
@@ -54,7 +54,7 @@ export const Footer: NextComponentType = () => {
|
||||
rel={'noreferrer'}
|
||||
href="https://appliedzkp.org/"
|
||||
>
|
||||
A P.S.E. project
|
||||
A Bangr Labs project with help from P.S.E.
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -32,9 +32,14 @@ const Home: NextPage<PropsAppPage> = ({
|
||||
const [passport, setPassport] = useState<null | string>(null);
|
||||
const [signature, setsignature] = useState<null | string>(null);
|
||||
const [publicKey, setpublicKey] = useState<null | string>(null);
|
||||
const [publicSignals, setpublicSignals] = useState<null | any>(null);
|
||||
const [publicSignals, setpublicSignals] = useState<null | any>(null); //
|
||||
const [compiledCircuit, setcompiledCircuit] = useState(null);
|
||||
|
||||
// TODO : set the right address. For now, mine hardcoded
|
||||
const [address, setAddress] = useState(
|
||||
'0x9D392187c08fc28A86e1354aD63C70897165b982'
|
||||
);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mt-5 ml-5">
|
||||
@@ -75,6 +80,7 @@ const Home: NextPage<PropsAppPage> = ({
|
||||
<ButtonGenerateProof
|
||||
vkeyVerifier={vkeyVerifier}
|
||||
vkeyProof={vkeyProof}
|
||||
address={address}
|
||||
setcompiledCircuit={setcompiledCircuit}
|
||||
setpublicSignals={setpublicSignals}
|
||||
hash={hash}
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface PropsButtonGenerateProof {
|
||||
setproof: SetProof;
|
||||
setcompiledCircuit: Dispatch<SetStateAction<null>>;
|
||||
hash: string | null;
|
||||
address: string | null;
|
||||
signature: string | null;
|
||||
publicKey: string | null;
|
||||
vkeyProof: null | any;
|
||||
|
||||
@@ -6,7 +6,7 @@ import snarkjs from 'snarkjs';
|
||||
addEventListener(
|
||||
'message',
|
||||
async (event: MessageEvent<{ vkeyProof: any; witness: any }>) => {
|
||||
const { proof, publicSignals } = snarkjs.original.genProof(
|
||||
const { proof, publicSignals } = snarkjs.groth.genProof(
|
||||
unstringifyBigInts(event.data.vkeyProof),
|
||||
unstringifyBigInts(event.data.witness)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user