This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template Square() { | |
signal input in; | |
signal output out; | |
out <== in * in; | |
} | |
template Add() { | |
signal input in; | |
signal output out; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IVerifier { | |
function verifyProof( | |
uint256[2] memory a, | |
uint256[2][2] memory b, | |
uint256[2] memory c, | |
uint256[1] memory input // publicSignals | |
) external view returns (bool r); | |
} | |
contract ZK { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("ZK", function () { | |
it("should process", async () => { | |
const secret = 42; | |
const input = { secret }; | |
const output = secret * secret + 6; | |
const publicSignals = [BigInt(output)]; | |
let { proof } = await groth16.fullProve(input, wasmPath, zkeyPath); | |
const calldata = await groth16.exportSolidityCallData(unstringifyBigInts(proof), publicSignals); | |
const args = JSON.parse("[" + calldata + "]"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function process(uint256[2] memory a, uint256[2][2] memory b, uint256[2] memory c, uint256[1] memory publicSignals) public { | |
require(isAnswer(publicSignals[0]), "incorrect answer"); | |
require(verifier.verifyProof(a, b, c, publicSignals), "invalid"); | |
_setGreeting("answer to the ultimate question of life, the universe, and everything"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function withdraw(bytes calldata _proof, bytes32 _root, bytes32 _nullifierHash, address payable _recipient, address payable _relayer, uint256 _fee, uint256 _refund) external payable nonReentrant { | |
require(_fee <= denomination, "Fee exceeds transfer value"); | |
require(!nullifierHashes[_nullifierHash], "The note has been already spent"); | |
require(isKnownRoot(_root), "Cannot find your merkle root"); // Make sure to use a recent one | |
require(verifier.verifyProof(_proof, [uint256(_root), uint256(_nullifierHash), uint256(_recipient), uint256(_relayer), _fee, _refund]), "Invalid withdraw proof"); | |
nullifierHashes[_nullifierHash] = true; | |
_processWithdraw(_recipient, _relayer, _fee, _refund); | |
emit Withdrawal(_recipient, _nullifierHash, _relayer, _fee); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deposit(bytes32 _commitment) external payable nonReentrant { | |
require(!commitments[_commitment], "The commitment has been submitted"); | |
uint32 insertedIndex = _insert(_commitment); | |
commitments[_commitment] = true; | |
_processDeposit(); | |
emit Deposit(_commitment, insertedIndex, block.timestamp); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
import "@openzeppelin/contracts/utils/math/SafeMath.sol"; | |
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | |
contract PriceSplitter { | |
using EnumerableSet for EnumerableSet.AddressSet; | |
// ======================================= STATE VARIABLES ======================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createApp } from 'vue' | |
import App from './App.vue' | |
import { VueDapp } from 'vue-dapp' | |
const app = createApp(App) | |
app.use(VueDapp) | |
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<img alt="Vue logo" src="./assets/logo.png" /> | |
<HelloWorld msg="Welcome to Your Vue.js App" /> | |
<!-- 這裡 --> | |
<button @click="open">Connect</button> | |
{{ address }} | |
<vdapp-board /> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import HelloWorld from './components/HelloWorld.vue' | |
import { useBoard, useEthers } from 'vue-dapp' | |
export default { | |
name: 'App', | |
components: { | |
HelloWorld, | |
}, | |
setup() { | |
const { open } = useBoard() |