mirror of
https://github.com/tornadocash/websnark.git
synced 2025-01-15 23:47:47 +01:00
change toSolidityInput to return single byte buffer for proof vars, remove fromSolidityInput
This commit is contained in:
parent
966eafc47d
commit
c254b59622
30
src/utils.js
30
src/utils.js
@ -65,32 +65,26 @@ function convertWitness(witness) {
|
|||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toHex32(number) {
|
||||||
|
let str = number.toString(16);
|
||||||
|
while (str.length < 64) str = "0" + str;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
function toSolidityInput(proof) {
|
function toSolidityInput(proof) {
|
||||||
const result = {
|
const flatProof = unstringifyBigInts([
|
||||||
proof: [
|
|
||||||
proof.pi_a[0], proof.pi_a[1],
|
proof.pi_a[0], proof.pi_a[1],
|
||||||
proof.pi_b[0][1], proof.pi_b[0][0],
|
proof.pi_b[0][1], proof.pi_b[0][0],
|
||||||
proof.pi_b[1][1], proof.pi_b[1][0],
|
proof.pi_b[1][1], proof.pi_b[1][0],
|
||||||
proof.pi_c[0], proof.pi_c[1],
|
proof.pi_c[0], proof.pi_c[1],
|
||||||
]
|
]);
|
||||||
};
|
|
||||||
if (proof.publicSignals) {
|
|
||||||
result.publicSignals = proof.publicSignals;
|
|
||||||
}
|
|
||||||
return hexifyBigInts(unstringifyBigInts(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
function fromSolidityInput(proof) {
|
|
||||||
proof = unhexifyBigInts(proof);
|
|
||||||
const result = {
|
const result = {
|
||||||
pi_a: [proof.proof[0], proof.proof[1], bigInt(1)],
|
proof: "0x" + flatProof.map(x => toHex32(x)).join("")
|
||||||
pi_b: [[proof.proof[3], proof.proof[2]], [proof.proof[5], proof.proof[4]], [bigInt(1), bigInt(0)]],
|
|
||||||
pi_c: [proof.proof[6], proof.proof[7], bigInt(1)]
|
|
||||||
};
|
};
|
||||||
if (proof.publicSignals) {
|
if (proof.publicSignals) {
|
||||||
result.publicSignals = proof.publicSignals;
|
result.publicSignals = hexifyBigInts(unstringifyBigInts(proof.publicSignals));
|
||||||
}
|
}
|
||||||
return stringifyBigInts(proof);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function genWitness(input, circuitJson) {
|
function genWitness(input, circuitJson) {
|
||||||
@ -108,4 +102,4 @@ async function genWitnessAndProve(groth16, input, circuitJson, provingKey) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {bigInt2BytesLE, bigInt2U32LE, toSolidityInput, fromSolidityInput, genWitnessAndProve};
|
module.exports = {bigInt2BytesLE, bigInt2U32LE, toSolidityInput, genWitnessAndProve};
|
Loading…
Reference in New Issue
Block a user