Skip to content

Instantly share code, notes, and snippets.

template Square() {
signal input in;
signal output out;
out <== in * in;
}
template Add() {
signal input in;
signal output out;
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 {
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 + "]");
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");
}
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);
}
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);
}
@johnson86tw
johnson86tw / PrizeSplitter.sol
Last active July 22, 2021 00:30
A prize splitter for hackathon team to split prize evenly from the sponsors.
//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 =======================================
import { createApp } from 'vue'
import App from './App.vue'
import { VueDapp } from 'vue-dapp'
const app = createApp(App)
app.use(VueDapp)
app.mount('#app')
<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>
import HelloWorld from './components/HelloWorld.vue'
import { useBoard, useEthers } from 'vue-dapp'
export default {
name: 'App',
components: {
HelloWorld,
},
setup() {
const { open } = useBoard()