Skip to content

Instantly share code, notes, and snippets.

@lajarre
Last active January 7, 2025 19:14
Show Gist options
  • Save lajarre/4149b97a72b4f51714620ecfaaf139fc to your computer and use it in GitHub Desktop.
Save lajarre/4149b97a72b4f51714620ecfaaf139fc to your computer and use it in GitHub Desktop.

Open this in zkREPL →

This file can be included into other zkREPLs with include "gist:4149b97a72b4f51714620ecfaaf139fc";

pragma circom 2.0.9;
include "./hash-state.circom";
include "../node_modules/circomlib/circuits/comparators.circom";
include "../node_modules/circomlib/circuits/smt/smtverifier.circom";
/**
* Merke leaf: idx, ethAddress, tokenID, ay, sign, nonce, balance
*/
template dcw(nLevels) {
signal input root; // public
signal input idx;
signal input ethAddres;
signal input tokenID;
signal input ay;
signal input sign;
signal input nonce;
signal input balance;
signal input siblings[nLevels + 1];
// comparre nonce minnonce
var MIN_NONCE = 10;
component minNonce = GreaterThan(253);
minNonce.in[0] <== nonce;
minNonce.in[1] <== MIN_NONCE;
minNonce.out === 1;
//
component hashState = HashState();
hashState.tokenID <== tokenID;
hashState.nonce <== nonce;
hashState.sign <== sign;
hashState.balance <== balance;
hashState.ay <== ay;
hashState.ethAddr <== ethAddress;
// verify leaf exist on the given root
component smtVerify = SMTVerifier(nLevels + 1);
smtVerify.enabled <== 1;
smtVerify.fnc <== 0;
smtVerify.root <== root;
for (var i = 0; i < nLevels + 1; i++) {
smtVerify.siblings[i] <== siblings[i];
}
smtVerify.oldKey <== 0;
smtVerify.oldValue <== 0;
smtVerify.isOld0 <== 0;
smtVerify.key <== idx;
smtVerify.value <== state.out;
}
pragma circom 2.0.8;
include "circomlib/poseidon.circom";
// include "https://github.com/0xPARC/circom-secp256k1/blob/master/circuits/bigint.circom";
template Example () {
signal input a;
signal input b;
signal output c;
var unused = 4;
c <== a * b;
assert(a > 2);
component hash = Poseidon(2);
hash.inputs[0] <== a;
hash.inputs[1] <== b;
log("hash", hash.out);
}
component main { public [ a ] } = Example();
/* INPUT = {
"a": "5",
"b": "77"
} */
pragma circom 2.0.9;
/**
* Merke tree state: idx, ethAddress, tokenId, ay, sign, nonce, balance
*/
template dcw(nLevels) {
signal input root; // public
signal input idx;
signal input ethAddress;
signal input tokenId;
signal input ay;
signal input sign;
signal input nonce;
signal input balance;
signal input siblings[nLevels + 1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment